generate the info tab button images when needed, add backend support for different colored tabs depending on aqua/graphite

This commit is contained in:
Mitchell Livingston 2007-10-18 00:04:01 +00:00
parent a2f3b0dac6
commit e06d38b4c7
3 changed files with 81 additions and 26 deletions

View File

@ -1993,8 +1993,8 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
- (void) updateControlTint: (NSNotification *) notification
{
if ([fDefaults boolForKey: @"SpeedLimit"])
[fSpeedLimitButton setImage: [NSColor currentControlTint] == NSBlueControlTint
? [NSImage imageNamed: @"SpeedLimitButtonBlue.png"] : [NSImage imageNamed: @"SpeedLimitButtonGraphite.png"]];
[fSpeedLimitButton setImage: [NSColor currentControlTint] == NSGraphiteControlTint
? [NSImage imageNamed: @"SpeedLimitButtonGraphite.png"] : [NSImage imageNamed: @"SpeedLimitButtonBlue.png"]];
}
- (void) applySpeedLimit: (id) sender

View File

@ -26,7 +26,9 @@
@interface InfoTabButtonCell : NSButtonCell
{
NSImage * fRegularImage, * fSelectedImage;
NSImage * fIcon, * fRegularImage, * fSelectedImage;
BOOL fSelected;
}
- (void) setSelectedTab: (BOOL) selected;

View File

@ -26,8 +26,21 @@
@implementation InfoTabButtonCell
- (void) awakeFromNib
{
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc addObserver: self selector: @selector(updateControlTint:)
name: NSControlTintDidChangeNotification object: nil];
fSelected = NO;
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
[fIcon release];
[fRegularImage release];
[fSelectedImage release];
[super dealloc];
@ -35,37 +48,77 @@
- (void) setIcon: (NSImage *) image
{
//create regular back image
[fRegularImage release];
fRegularImage = [[NSImage imageNamed: @"InfoTabBack.tif"] copy];
[fIcon release];
fIcon = image ? [image retain] : nil;
//create selected back image
[fSelectedImage release];
fSelectedImage = [[NSImage imageNamed: @"InfoTabBackBlue.tif"] copy];
//composite image to back images
if (image)
if (fRegularImage)
{
NSSize imageSize = [image size];
NSRect imageRect = NSMakeRect(0, 0, [fRegularImage size].width, [fRegularImage size].height);
NSRect rect = NSMakeRect(imageRect.origin.x + (imageRect.size.width - imageSize.width) * 0.5,
imageRect.origin.y + (imageRect.size.height - imageSize.height) * 0.5, imageSize.width, imageSize.height);
[fRegularImage lockFocus];
[image drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
[fRegularImage unlockFocus];
[fSelectedImage lockFocus];
[image drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
[fSelectedImage unlockFocus];
[fRegularImage release];
fRegularImage = nil;
}
if (fSelectedImage)
{
[fSelectedImage release];
fSelectedImage = nil;
}
[self setImage: fRegularImage];
[self setSelectedTab: fSelected];
}
- (void) setSelectedTab: (BOOL) selected
{
[self setImage: selected ? fSelectedImage : fRegularImage];
fSelected = selected;
NSImage * tabImage;
BOOL createImage = NO;
if (fSelected)
{
if (!fSelectedImage)
{
fSelectedImage = [NSColor currentControlTint] == NSGraphiteControlTint ? [[NSImage imageNamed: @"InfoTabBackBlue.tif"] copy]
: [[NSImage imageNamed: @"InfoTabBackBlue.tif"] copy];
createImage = YES;
}
tabImage = fSelectedImage;
}
else
{
if (!fRegularImage)
{
fRegularImage = [[NSImage imageNamed: @"InfoTabBack.tif"] copy];
createImage = YES;
}
tabImage = fRegularImage;
}
if (createImage)
{
if (fIcon)
{
NSSize iconSize = [fIcon size];
NSRect imageRect = NSMakeRect(0, 0, [tabImage size].width, [tabImage size].height);
NSRect rect = NSMakeRect(imageRect.origin.x + (imageRect.size.width - iconSize.width) * 0.5,
imageRect.origin.y + (imageRect.size.height - iconSize.height) * 0.5, iconSize.width, iconSize.height);
[tabImage lockFocus];
[fIcon drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
[tabImage unlockFocus];
}
}
[self setImage: tabImage];
}
- (void) updateControlTint: (NSNotification *) notification
{
if (fSelectedImage)
{
[fSelectedImage release];
fSelectedImage = nil;
}
if (fSelected)
[self setSelectedTab: YES];
}
@end