Changeset 3453


Ignore:
Timestamp:
Oct 18, 2007, 12:04:01 AM (14 years ago)
Author:
livings124
Message:

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

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r3452 r3453  
    19941994{
    19951995    if ([fDefaults boolForKey: @"SpeedLimit"])
    1996         [fSpeedLimitButton setImage: [NSColor currentControlTint] == NSBlueControlTint
    1997             ? [NSImage imageNamed: @"SpeedLimitButtonBlue.png"] : [NSImage imageNamed: @"SpeedLimitButtonGraphite.png"]];
     1996        [fSpeedLimitButton setImage: [NSColor currentControlTint] == NSGraphiteControlTint
     1997            ? [NSImage imageNamed: @"SpeedLimitButtonGraphite.png"] : [NSImage imageNamed: @"SpeedLimitButtonBlue.png"]];
    19981998}
    19991999
  • trunk/macosx/InfoTabButtonCell.h

    r3301 r3453  
    2727@interface InfoTabButtonCell : NSButtonCell
    2828{
    29     NSImage * fRegularImage, * fSelectedImage;
     29    NSImage * fIcon, * fRegularImage, * fSelectedImage;
     30   
     31    BOOL fSelected;
    3032}
    3133
  • trunk/macosx/InfoTabButtonCell.m

    r3452 r3453  
    2727@implementation InfoTabButtonCell
    2828
     29- (void) awakeFromNib
     30{
     31    NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
     32    [nc addObserver: self selector: @selector(updateControlTint:)
     33            name: NSControlTintDidChangeNotification object: nil];
     34   
     35    fSelected = NO;
     36}
     37
    2938- (void) dealloc
    3039{
     40    [[NSNotificationCenter defaultCenter] removeObserver: self];
     41   
     42    [fIcon release];
     43   
    3144    [fRegularImage release];
    3245    [fSelectedImage release];
     
    3649- (void) setIcon: (NSImage *) image
    3750{
    38     //create regular back image
    39     [fRegularImage release];
    40     fRegularImage = [[NSImage imageNamed: @"InfoTabBack.tif"] copy];
     51    [fIcon release];
     52    fIcon = image ? [image retain] : nil;
    4153   
    42     //create selected back image
    43     [fSelectedImage release];
    44     fSelectedImage = [[NSImage imageNamed: @"InfoTabBackBlue.tif"] copy];
    45    
    46     //composite image to back images
    47     if (image)
     54    if (fRegularImage)
    4855    {
    49         NSSize imageSize = [image size];
    50         NSRect imageRect = NSMakeRect(0, 0, [fRegularImage size].width, [fRegularImage size].height);
    51         NSRect rect = NSMakeRect(imageRect.origin.x + (imageRect.size.width - imageSize.width) * 0.5,
    52                         imageRect.origin.y + (imageRect.size.height - imageSize.height) * 0.5, imageSize.width, imageSize.height);
    53        
    54         [fRegularImage lockFocus];
    55         [image drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
    56         [fRegularImage unlockFocus];
    57        
    58         [fSelectedImage lockFocus];
    59         [image drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
    60         [fSelectedImage unlockFocus];
     56        [fRegularImage release];
     57        fRegularImage = nil;
     58    }
     59    if (fSelectedImage)
     60    {
     61        [fSelectedImage release];
     62        fSelectedImage = nil;
    6163    }
    6264   
    63     [self setImage: fRegularImage];
     65    [self setSelectedTab: fSelected];
    6466}
    6567
    6668- (void) setSelectedTab: (BOOL) selected
    6769{
    68     [self setImage: selected ? fSelectedImage : fRegularImage];
     70    fSelected = selected;
     71   
     72    NSImage * tabImage;
     73    BOOL createImage = NO;
     74    if (fSelected)
     75    {
     76        if (!fSelectedImage)
     77        {
     78            fSelectedImage = [NSColor currentControlTint] == NSGraphiteControlTint ? [[NSImage imageNamed: @"InfoTabBackBlue.tif"] copy]
     79                                : [[NSImage imageNamed: @"InfoTabBackBlue.tif"] copy];
     80            createImage = YES;
     81        }
     82        tabImage = fSelectedImage;
     83    }
     84    else
     85    {
     86        if (!fRegularImage)
     87        {
     88            fRegularImage = [[NSImage imageNamed: @"InfoTabBack.tif"] copy];
     89            createImage = YES;
     90        }
     91        tabImage = fRegularImage;
     92    }
     93   
     94    if (createImage)
     95    {
     96        if (fIcon)
     97        {
     98            NSSize iconSize = [fIcon size];
     99            NSRect imageRect = NSMakeRect(0, 0, [tabImage size].width, [tabImage size].height);
     100            NSRect rect = NSMakeRect(imageRect.origin.x + (imageRect.size.width - iconSize.width) * 0.5,
     101                            imageRect.origin.y + (imageRect.size.height - iconSize.height) * 0.5, iconSize.width, iconSize.height);
     102
     103            [tabImage lockFocus];
     104            [fIcon drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
     105            [tabImage unlockFocus];
     106        }
     107    }
     108   
     109    [self setImage: tabImage];
     110}
     111
     112- (void) updateControlTint: (NSNotification *) notification
     113{
     114    if (fSelectedImage)
     115    {
     116        [fSelectedImage release];
     117        fSelectedImage = nil;
     118    }
     119   
     120    if (fSelected)
     121        [self setSelectedTab: YES];
    69122}
    70123
Note: See TracChangeset for help on using the changeset viewer.