]> granicus.if.org Git - transmission/commitdiff
use the control color for the selected inspector button; small tweaks to the updated...
authorMitchell Livingston <livings124@transmissionbt.com>
Sun, 30 Jan 2011 02:36:08 +0000 (02:36 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Sun, 30 Jan 2011 02:36:08 +0000 (02:36 +0000)
macosx/InfoTabButtonBack.h
macosx/InfoTabButtonBack.m
macosx/InfoTabButtonCell.m

index 1e0b4fb8b0dc3a1e7a0f9420a259e57e56a2e339..7e14de903391dd0934c130c41a08266dd1cda8fb 100644 (file)
@@ -26,6 +26,7 @@
 
 @interface InfoTabButtonBack : NSView
 {
+    NSGradient * fGradient;
 }
 
 @end
index 883b7116e04a7f967116cd80beaa88e7351a6ea9..faf36723a3f68806287a917e7a5b1f422da1e300 100644 (file)
 
 @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
index 287b6078408459af9c385149160c7dc4f8159e82..0d4c278823ac21122a935a32743209a6948bf754 100644 (file)
 - (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];
 }
     
     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];
     [tabImage release];
 }
 
+- (void) updateControlTint: (NSNotification *) notification
+{
+    if (fSelected)
+        [self setSelectedTab: YES];
+}
+
 @end