mirror of
https://github.com/transmission/transmission
synced 2024-12-25 01:03:01 +00:00
use the control color for the selected inspector button; small tweaks to the updated button bar's drawing code
This commit is contained in:
parent
e5eed4bd05
commit
8f64909bc3
3 changed files with 72 additions and 22 deletions
|
@ -26,6 +26,7 @@
|
|||
|
||||
@interface InfoTabButtonBack : NSView
|
||||
{
|
||||
NSGradient * fGradient;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -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];
|
||||
|
||||
[[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));
|
||||
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);
|
||||
|
||||
[fGradient drawInRect: rect angle: 270.0];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue