From 8f64909bc32c8d521ba82dd37f4a910753732a0c Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 30 Jan 2011 02:36:08 +0000 Subject: [PATCH] use the control color for the selected inspector button; small tweaks to the updated button bar's drawing code --- macosx/InfoTabButtonBack.h | 1 + macosx/InfoTabButtonBack.m | 52 ++++++++++++++++++++++++++++++++------ macosx/InfoTabButtonCell.m | 41 ++++++++++++++++++++---------- 3 files changed, 72 insertions(+), 22 deletions(-) diff --git a/macosx/InfoTabButtonBack.h b/macosx/InfoTabButtonBack.h index 1e0b4fb8b..7e14de903 100644 --- a/macosx/InfoTabButtonBack.h +++ b/macosx/InfoTabButtonBack.h @@ -26,6 +26,7 @@ @interface InfoTabButtonBack : NSView { + NSGradient * fGradient; } @end diff --git a/macosx/InfoTabButtonBack.m b/macosx/InfoTabButtonBack.m index 883b7116e..faf36723a 100644 --- a/macosx/InfoTabButtonBack.m +++ b/macosx/InfoTabButtonBack.m @@ -26,17 +26,53 @@ @implementation InfoTabButtonBack +- (id) initWithFrame: (NSRect) rect +{ + if ((self = [super initWithFrame: rect])) + { + NSColor * lightColor = [NSColor colorWithCalibratedRed: 255.0/255.0 green: 255.0/255.0 blue: 255.0/255.0 alpha: 1.0]; + NSColor * darkColor = [NSColor colorWithCalibratedRed: 225.0/255.0 green: 225.0/255.0 blue: 225.0/255.0 alpha: 1.0]; + fGradient = [[NSGradient alloc] initWithStartingColor: lightColor endingColor: darkColor]; + } + return self; +} + +- (void) dealloc +{ + [fGradient release]; + [super dealloc]; +} + - (void) drawRect: (NSRect) rect { - NSColor * lightColor = [NSColor colorWithCalibratedRed: 255.0/255.0 green: 255.0/255.0 blue: 255.0/255.0 alpha: 1.0]; - NSColor * darkColor = [NSColor colorWithCalibratedRed: 225.0/255.0 green: 225.0/255.0 blue: 225.0/255.0 alpha: 1.0]; - NSGradient * gradient = [[NSGradient alloc] initWithStartingColor: darkColor endingColor: lightColor]; - [gradient drawInRect: rect angle: 90.0]; - [gradient release]; + NSInteger count = 0; + NSRect gridRects[2]; + NSColor * colorRects[2]; + + NSRect lineBorderRect = NSMakeRect(NSMinX(rect), NSHeight([self bounds]) - 1.0, NSWidth(rect), 1.0); + if (NSIntersectsRect(lineBorderRect, rect)) + { + gridRects[count] = lineBorderRect; + colorRects[count] = [NSColor grayColor]; + ++count; + + rect.size.height -= 1.0; + } + + lineBorderRect.origin.y = 0.0; + if (NSIntersectsRect(lineBorderRect, rect)) + { + gridRects[count] = lineBorderRect; + colorRects[count] = [NSColor grayColor]; + ++count; + + rect.origin.y += 1.0; + rect.size.height -= 1.0; + } + + NSRectFillListWithColors(gridRects, colorRects, count); - [[NSColor grayColor] set]; - NSRectFill(NSMakeRect(0.0, 0.0, NSWidth(rect), 1.0)); - NSRectFill(NSMakeRect(0.0, NSHeight(rect) - 1.0, NSWidth(rect), 1.0)); + [fGradient drawInRect: rect angle: 270.0]; } @end diff --git a/macosx/InfoTabButtonCell.m b/macosx/InfoTabButtonCell.m index 287b60784..0d4c27882 100644 --- a/macosx/InfoTabButtonCell.m +++ b/macosx/InfoTabButtonCell.m @@ -29,6 +29,10 @@ - (void) awakeFromNib { [(NSMatrix *)[self controlView] setToolTip: [self title] forCell: self]; + + NSNotificationCenter * nc = [NSNotificationCenter defaultCenter]; + [nc addObserver: self selector: @selector(updateControlTint:) + name: NSControlTintDidChangeNotification object: NSApp]; fSelected = NO; @@ -39,6 +43,8 @@ - (void) dealloc { + [[NSNotificationCenter defaultCenter] removeObserver: self]; + [fIcon release]; [super dealloc]; } @@ -49,27 +55,28 @@ NSInteger row, col; [(NSMatrix *)[self controlView] getRow: &row column: &col ofCell: self]; - const NSSize tabSize = [(NSMatrix *)[self controlView] cellFrameAtRow: row column: col].size; - const NSRect tabRect = NSMakeRect(0.0, 0.0, tabSize.width, tabSize.height); + NSRect tabRect = [(NSMatrix *)[self controlView] cellFrameAtRow: row column: col]; + tabRect.origin.x = 0.0; + tabRect.origin.y = 0.0; - NSImage * tabImage = [[NSImage alloc] initWithSize: tabSize]; + NSImage * tabImage = [[NSImage alloc] initWithSize: tabRect.size]; [tabImage lockFocus]; - if (!fSelected) + if (fSelected) { - NSColor * lightColor = [NSColor colorWithCalibratedRed: 255.0/255.0 green: 255.0/255.0 blue: 255.0/255.0 alpha: 1.0]; - NSColor * darkColor = [NSColor colorWithCalibratedRed: 225.0/255.0 green: 225.0/255.0 blue: 225.0/255.0 alpha: 1.0]; - NSGradient * gradient = [[NSGradient alloc] initWithStartingColor: darkColor endingColor: lightColor]; - [gradient drawInRect: tabRect angle: 90.0]; + NSColor * lightColor = [NSColor colorForControlTint: [NSColor currentControlTint]]; + NSColor * darkColor = [lightColor blendedColorWithFraction: 0.2 ofColor: [NSColor blackColor]]; + NSGradient * gradient = [[NSGradient alloc] initWithStartingColor: lightColor endingColor: darkColor]; + [gradient drawInRect: tabRect angle: 270.0]; [gradient release]; } else { - NSColor * lightColor = [NSColor colorWithCalibratedRed: 160.0/255.0 green: 160.0/255.0 blue: 160.0/255.0 alpha: 1.0]; - NSColor * darkColor = [NSColor colorWithCalibratedRed: 150.0/255.0 green: 150.0/255.0 blue: 150.0/255.0 alpha: 1.0]; - NSGradient * gradient = [[NSGradient alloc] initWithStartingColor: darkColor endingColor: lightColor]; - [gradient drawInRect: tabRect angle: 90.0]; + NSColor * lightColor = [NSColor colorWithCalibratedRed: 255.0/255.0 green: 255.0/255.0 blue: 255.0/255.0 alpha: 1.0]; + NSColor * darkColor = [NSColor colorWithCalibratedRed: 225.0/255.0 green: 225.0/255.0 blue: 225.0/255.0 alpha: 1.0]; + NSGradient * gradient = [[NSGradient alloc] initWithStartingColor: lightColor endingColor: darkColor]; + [gradient drawInRect: tabRect angle: 270.0]; [gradient release]; } @@ -82,8 +89,8 @@ { const NSSize iconSize = [fIcon size]; - const NSRect iconRect = NSMakeRect(floor((tabSize.width - iconSize.width) * 0.5), - floor((tabSize.height - iconSize.height) * 0.5), + const NSRect iconRect = NSMakeRect(floor((NSWidth(tabRect) - iconSize.width) * 0.5), + floor((NSHeight(tabRect) - iconSize.height) * 0.5), iconSize.width, iconSize.height); [fIcon drawInRect: iconRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0]; @@ -94,4 +101,10 @@ [tabImage release]; } +- (void) updateControlTint: (NSNotification *) notification +{ + if (fSelected) + [self setSelectedTab: YES]; +} + @end -- 2.40.0