Skip to content

Commit

Permalink
Cleanup of the polished progress bar code. Also adding a tentative fi…
Browse files Browse the repository at this point in the history
…rst launch preferences window.
  • Loading branch information
Alexander Rauchfuss committed Nov 15, 2009
1 parent bb18646 commit 4521ff0
Show file tree
Hide file tree
Showing 7 changed files with 828 additions and 258 deletions.
939 changes: 751 additions & 188 deletions English.lproj/MainMenu.nib/designable.nib

Large diffs are not rendered by default.

Binary file modified English.lproj/MainMenu.nib/keyedobjects.nib
Binary file not shown.
26 changes: 22 additions & 4 deletions Progress Bar/DTPolishedProgressBar.h
Expand Up @@ -41,18 +41,36 @@
NSRect progressRect; /* This is the section of the view. Users can mouse over and click here. */
float horizontalMargin; /* How much room is given for the text on either side. */
float cornerRadius;
BOOL highContrast; /* if true fullscreen colors are used. */

NSGradient * emptyGradient;
NSGradient * barGradient;
NSGradient * shadowGradient;
NSColor * highlightColor;
NSDictionary * numberStyle;
}

/*
List of replacements for the highcontrast flag
Highlight: NSColor if nil then layout is slightly shifted.
barFill: This is the gradient of the empty portion of the progress bar
progressFill: This is the gradient of the filled portion of the pr ituogress bar.
shadow: This is the gradient that give the illusion of depth.
textStyle: Dictionary of string attributes.
*/

@property (assign) BOOL leftToRight;
@property (assign) int maxValue;
@property (assign) int currentValue;

@property (assign) NSRect progressRect;
@property (assign) float horizontalMargin;

@property (assign) int maxValue;
@property (assign) int currentValue;
@property (assign) float cornerRadius;
@property (assign) BOOL highContrast;
@property (retain) NSGradient * emptyGradient;
@property (retain) NSGradient * barGradient;
@property (retain) NSGradient * shadowGradient;
@property (retain) NSColor * highlightColor;
@property (retain) NSDictionary * numberStyle;

- (int)indexForPoint:(NSPoint)point;

Expand Down
113 changes: 49 additions & 64 deletions Progress Bar/DTPolishedProgressBar.m
Expand Up @@ -13,15 +13,36 @@
@implementation DTPolishedProgressBar


@synthesize progressRect, horizontalMargin, leftToRight, maxValue, currentValue, cornerRadius, highContrast;

@synthesize progressRect, horizontalMargin, leftToRight, maxValue, currentValue,
cornerRadius, emptyGradient, barGradient, shadowGradient, highlightColor, numberStyle;

- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.highContrast = NO;
self.shadowGradient = [[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithDeviceWhite: 0.3 alpha: 1], 0.0,
[NSColor colorWithDeviceWhite: 0.25 alpha: 1], 0.5,
[NSColor colorWithDeviceWhite: 0.2 alpha: 1], 0.5,
[NSColor colorWithDeviceWhite: 0.1 alpha: 1], 1.0, nil];
self.highlightColor = [NSColor colorWithCalibratedWhite: 0.88 alpha: 1];

self.emptyGradient = [[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithDeviceWhite: 0.25 alpha: 1], 0.0,
[NSColor colorWithDeviceWhite: 0.45 alpha: 1], 1.0, nil];
self.barGradient = [[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithDeviceWhite: 0.7 alpha: 1], 0.0,
[NSColor colorWithDeviceWhite: 0.75 alpha: 1], 0.5,
[NSColor colorWithDeviceWhite: 0.82 alpha: 1], 0.5,
[NSColor colorWithDeviceWhite: 0.92 alpha: 1], 1.0, nil];
NSShadow * stringEmboss = [NSShadow new];
[stringEmboss setShadowColor: [NSColor colorWithDeviceWhite: 0.9 alpha: 1]];
[stringEmboss setShadowBlurRadius: 0];
[stringEmboss setShadowOffset: NSMakeSize(1, -1)];
self.numberStyle = [NSDictionary dictionaryWithObjectsAndKeys:
[NSFont fontWithName: @"Lucida Grande Bold" size: 10], NSFontAttributeName,
[NSColor colorWithDeviceWhite: 0.2 alpha: 1], NSForegroundColorAttributeName,
stringEmboss, NSShadowAttributeName,
nil];
[stringEmboss release];
self.horizontalMargin = 35;
self.cornerRadius = 4.0;
[self setLeftToRight: YES];
Expand All @@ -41,6 +62,11 @@ - (void) dealloc
[self removeObserver: self forKeyPath: @"maxValue"];
[self removeTrackingArea: [[self trackingAreas] objectAtIndex: 0]];

[numberStyle release];
[barGradient release];
[emptyGradient release];
[shadowGradient release];
[highlightColor release];
[super dealloc];
}

Expand Down Expand Up @@ -71,46 +97,30 @@ - (void)drawRect:(NSRect)rect
NSBezierPath * highlight = roundedRectWithCornerRadius(barRect, self.cornerRadius);
barRect.origin.y+=0.5;
NSRect fillRect = NSInsetRect(barRect, 1, 1);
if(!self.highContrast)
if(self.highlightColor)
{
[[NSColor colorWithCalibratedWhite: 0.88 alpha: 1] set];
[self.highlightColor set];
[highlight stroke];
}

NSBezierPath * roundedMask = roundedRectWithCornerRadius(barRect, self.cornerRadius);

[NSGraphicsContext saveGraphicsState];

NSGradient * shadowGradient = [[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithDeviceWhite: 0.3 alpha: 1], 0.0,
[NSColor colorWithDeviceWhite: 0.25 alpha: 1], 0.5,
[NSColor colorWithDeviceWhite: 0.2 alpha: 1], 0.5,
[NSColor colorWithDeviceWhite: 0.1 alpha: 1], 1.0, nil];


[shadowGradient drawInBezierPath: roundedMask angle: 90];
[shadowGradient release];
roundedMask = roundedRectWithCornerRadius(fillRect, self.cornerRadius - 1);
[roundedMask addClip];
shadowGradient = [[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithDeviceWhite: 0 alpha: 0.1], 0.0,
[NSColor colorWithDeviceWhite: 0 alpha: 0.3], 1.0, nil];
// shadowGradient = [[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithDeviceWhite: 0 alpha: 0.1], 0.0,
// [NSColor colorWithDeviceWhite: 0 alpha: 0.3], 1.0, nil];


NSGradient * fillGradient;
if(self.highContrast)
{
fillGradient = [[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithDeviceWhite: 0.424 alpha: 1], 0.0,
[NSColor colorWithDeviceWhite: 0.427 alpha: 1], 1.0, nil];
}
else {
fillGradient = [[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithDeviceWhite: 0.25 alpha: 1], 0.0,
[NSColor colorWithDeviceWhite: 0.45 alpha: 1], 1.0, nil];
}
// fillGradient = [[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithDeviceWhite: 0.424 alpha: 1], 0.0,
// [NSColor colorWithDeviceWhite: 0.427 alpha: 1], 1.0, nil];

[fillGradient drawInRect: fillRect angle: 270];
[fillGradient release];
[emptyGradient drawInRect: fillRect angle: 270];

[shadowGradient drawInRect: fillRect angle: 90];
[shadowGradient release];
// [shadowGradient drawInRect: fillRect angle: 90];
// [shadowGradient release];

if(leftToRight)
{
Expand All @@ -122,54 +132,29 @@ - (void)drawRect:(NSRect)rect
fillRect.origin.x = NSMinX(barRect) + (NSWidth(barRect) - NSWidth(fillRect) - 1);
}

NSGradient * progressGradient = [[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithDeviceWhite: 0.7 alpha: 1], 0.0,
[NSColor colorWithDeviceWhite: 0.75 alpha: 1], 0.5,
[NSColor colorWithDeviceWhite: 0.82 alpha: 1], 0.5,
[NSColor colorWithDeviceWhite: 0.92 alpha: 1], 1.0, nil];
NSBezierPath * roundFill = roundedRectWithCornerRadius(fillRect, cornerRadius - 1);

[progressGradient drawInBezierPath: roundFill angle: 90];
[progressGradient release];
[self.barGradient drawInBezierPath: roundFill angle: 90];

[NSGraphicsContext restoreGraphicsState];

NSDictionary * stringAttirbutes;
NSShadow * stringEmboss = nil;
if(self.highContrast)
{
stringAttirbutes = [[NSDictionary dictionaryWithObjectsAndKeys:
[NSFont fontWithName: @"Lucida Grande" size: 10], NSFontAttributeName,
[NSColor colorWithDeviceWhite: 0.82 alpha: 1], NSForegroundColorAttributeName,
nil] retain];
stringEmboss = [NSShadow new];
[stringEmboss setShadowColor: [NSColor colorWithDeviceWhite: 0.6 alpha: 0.7]];
[stringEmboss setShadowBlurRadius: 0];
[stringEmboss setShadowOffset: NSMakeSize(1, -1)];
}
else
{
stringAttirbutes = [[NSDictionary dictionaryWithObjectsAndKeys:
[NSFont fontWithName: @"Lucida Grande Bold" size: 10], NSFontAttributeName,
[NSColor colorWithDeviceWhite: 0.2 alpha: 1], NSForegroundColorAttributeName,
nil] retain];
stringEmboss = [NSShadow new];
[stringEmboss setShadowColor: [NSColor colorWithDeviceWhite: 0.9 alpha: 1]];
[stringEmboss setShadowBlurRadius: 0];
[stringEmboss setShadowOffset: NSMakeSize(1, -1)];
[stringEmboss set];
}
// stringAttirbutes = [[NSDictionary dictionaryWithObjectsAndKeys:
// [NSFont fontWithName: @"Lucida Grande" size: 10], NSFontAttributeName,
// [NSColor colorWithDeviceWhite: 0.82 alpha: 1], NSForegroundColorAttributeName,
// nil] retain];


NSRect rightStringRect = NSMakeRect(NSMaxX(progressRect) + self.cornerRadius, NSMinY(bounds), self.horizontalMargin, NSHeight(bounds));
NSRect leftStringRect = NSMakeRect(0, NSMinY(bounds), self.horizontalMargin, NSHeight(bounds));
NSString * totalString = [NSString stringWithFormat: @"%i", maxValue];
NSSize stringSize = [totalString sizeWithAttributes: stringAttirbutes];
NSSize stringSize = [totalString sizeWithAttributes: self.numberStyle];
NSRect stringRect = rectWithSizeCenteredInRect(stringSize, self.leftToRight ? rightStringRect : leftStringRect);
[totalString drawInRect: stringRect withAttributes: stringAttirbutes];
[totalString drawInRect: stringRect withAttributes: self.numberStyle];

NSString * progressString = [NSString stringWithFormat: @"%i", self.currentValue + 1];
stringSize = [progressString sizeWithAttributes: stringAttirbutes];
stringSize = [progressString sizeWithAttributes: self.numberStyle];
stringRect = rectWithSizeCenteredInRect(stringSize, self.leftToRight ? leftStringRect : rightStringRect);
[progressString drawInRect: stringRect withAttributes: stringAttirbutes];
[stringEmboss release];
[progressString drawInRect: stringRect withAttributes: self.numberStyle];
}


Expand Down
4 changes: 2 additions & 2 deletions Session/TSSTSessionWindowController.m
Expand Up @@ -139,7 +139,7 @@ - (void)awakeFromNib
[bezelWindow setFloatingPanel: YES];
[bezelWindow setNextResponder: self];
[pageController setSelectionIndex: [[session valueForKey: @"selection"] intValue]];
[fullscreenProgressBar setHighContrast: YES];
[fullscreenProgressBar setHighlightColor: nil];

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];

Expand Down Expand Up @@ -454,7 +454,7 @@ - (void)infoPanelSetupAtPoint:(NSPoint)point
{
bar = progressBar;
[[infoWindow contentView] setBordered: NO];
point.y = (NSMaxY([bar frame]) - 7);
point.y = (NSMaxY([bar frame]) - 6);
}

cursorPoint = [bar convertPoint: point fromView: nil];
Expand Down
4 changes: 4 additions & 0 deletions SimpleComic.xcodeproj/project.pbxproj
Expand Up @@ -67,6 +67,7 @@
28C1D4080DF18251003392B4 /* TSSTManagedSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 2803B2FF0D5E541800CD7906 /* TSSTManagedSession.m */; };
28C1D5600DF1FE37003392B4 /* QuickLook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28C1D55F0DF1FE37003392B4 /* QuickLook.framework */; };
28C2FA050DEB559000AB5E35 /* Sessions_DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 28C2FA040DEB559000AB5E35 /* Sessions_DataModel.xcdatamodeld */; };
28E039A510B0B2D2003B40F8 /* welcome3.png in Resources */ = {isa = PBXBuildFile; fileRef = 28E039A410B0B2D2003B40F8 /* welcome3.png */; };
28E39CCB10A5CD6900A027A3 /* DTPolishedProgressBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 28E39CCA10A5CD6900A027A3 /* DTPolishedProgressBar.m */; };
28EF3FC00E9970BD002AD2EE /* UKXattrMetadataStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 28EF3FBF0E9970BD002AD2EE /* UKXattrMetadataStore.m */; };
28F660461067255600EC8A34 /* Help in Resources */ = {isa = PBXBuildFile; fileRef = 28F6603B1067255600EC8A34 /* Help */; };
Expand Down Expand Up @@ -246,6 +247,7 @@
28C1D70F0DF21DA7003392B4 /* TSSTCoverView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSSTCoverView.m; sourceTree = "<group>"; };
28C49D8A0DD53C05008E4857 /* TSSTBookmarkTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSSTBookmarkTableView.h; sourceTree = "<group>"; };
28C49D8B0DD53C05008E4857 /* TSSTBookmarkTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSSTBookmarkTableView.m; sourceTree = "<group>"; };
28E039A410B0B2D2003B40F8 /* welcome3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = welcome3.png; sourceTree = "<group>"; };
28E39CC910A5CD6900A027A3 /* DTPolishedProgressBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DTPolishedProgressBar.h; path = "Progress Bar/DTPolishedProgressBar.h"; sourceTree = "<group>"; };
28E39CCA10A5CD6900A027A3 /* DTPolishedProgressBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DTPolishedProgressBar.m; path = "Progress Bar/DTPolishedProgressBar.m"; sourceTree = "<group>"; };
28EBCE960DE74B87009A7DC1 /* NSFileManager+UTI_Category.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+UTI_Category.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -472,6 +474,7 @@
288693130FED554E002C6BF7 /* org_size.tiff */,
288693140FED554E002C6BF7 /* preview_1.png */,
288693150FED554E002C6BF7 /* preview_2.png */,
28E039A410B0B2D2003B40F8 /* welcome3.png */,
288693110FED554E002C6BF7 /* lr_order.tiff */,
288693160FED554E002C6BF7 /* rl_order.tiff */,
288693170FED554E002C6BF7 /* rotate_l.tiff */,
Expand Down Expand Up @@ -801,6 +804,7 @@
28073CB00FF9956600D2602B /* extract.tiff in Resources */,
28073DB00FFB0EED00D2602B /* icon.tiff in Resources */,
28F660461067255600EC8A34 /* Help in Resources */,
28E039A510B0B2D2003B40F8 /* welcome3.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file added images/welcome3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4521ff0

Please sign in to comment.