Changeset 1055 for trunk/macosx


Ignore:
Timestamp:
Nov 5, 2006, 8:35:00 PM (15 years ago)
Author:
livings124
Message:

dock badging should be a bit more accurate

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Badger.h

    r794 r1055  
    3030@interface Badger : NSObject {
    3131
    32     NSImage         * fDockIcon, * fBadgedDockIcon,
    33                     * fBadge, * fUploadBadge, * fDownloadBadge;
     32    NSImage         * fDockIcon, * fBadge, * fUploadBadge, * fDownloadBadge;
    3433                   
    3534    NSDictionary    * fAttributes;
    36    
    37     NSLock          * fLock;
    38    
    39     int             fCompleted;
    40     BOOL            fSpeedShown;
     35    BOOL            fNonDefault;
    4136}
    4237
  • trunk/macosx/Badger.m

    r794 r1055  
    4040        fBadge = [NSImage imageNamed: @"Badge"];
    4141        fDockIcon = [[NSApp applicationIconImage] copy];
    42         fBadgedDockIcon = [fDockIcon copy];
    4342        fUploadBadge = [NSImage imageNamed: @"UploadBadge"];
    4443        fDownloadBadge = [NSImage imageNamed: @"DownloadBadge"];
     
    5756        [stringShadow release];
    5857       
    59         fLock = [[NSLock alloc] init];
    60        
    61         fCompleted = 0;
    62         fSpeedShown = NO;
     58        fNonDefault = NO;
    6359    }
    6460   
     
    6965{
    7066    [fDockIcon release];
    71     [fBadgedDockIcon release];
    7267    [fAttributes release];
    73     [fLock release];
    7468
    7569    [super dealloc];
     
    7872- (void) updateBadgeWithCompleted: (int) completed uploadRate: (float) uploadRate downloadRate: (float) downloadRate
    7973{
    80     NSImage * dockIcon = nil;
    8174    NSSize iconSize = [fDockIcon size];
    8275
    83     [fLock lock]; //acquire lock to ensure completed badge is accurate
    84 
    85     //set completed badge
    86     if (fCompleted != completed)
     76    NSImage * dockIcon = nil;
     77       
     78    //set completed badge to top right
     79    if (completed > 0)
    8780    {
    8881        dockIcon = [fDockIcon copy];
     82   
     83        NSRect badgeRect;
     84        badgeRect.size = [fBadge size];
     85        badgeRect.origin.x = iconSize.width - badgeRect.size.width;
     86        badgeRect.origin.y = iconSize.height - badgeRect.size.height;
     87                                   
     88        [dockIcon lockFocus];
    8989       
    90         //set completed badge to top right
    91         if (completed > 0)
    92         {
    93             NSRect badgeRect;
    94             badgeRect.size = [fBadge size];
    95             badgeRect.origin.x = iconSize.width - badgeRect.size.width;
    96             badgeRect.origin.y = iconSize.height - badgeRect.size.height;
    97                                        
    98             [dockIcon lockFocus];
    99            
    100             //place badge
    101             [fBadge compositeToPoint: badgeRect.origin operation: NSCompositeSourceOver];
    102            
    103             //ignore shadow of badge when placing string
    104             float badgeBottomExtra = 5.0;
    105             badgeRect.size.height -= badgeBottomExtra;
    106             badgeRect.origin.y += badgeBottomExtra;
    107            
    108             //place badge text
    109             [self badgeString: [NSString stringWithInt: completed] forRect: badgeRect];
    110                        
    111             [dockIcon unlockFocus];
    112         }
     90        //place badge
     91        [fBadge compositeToPoint: badgeRect.origin operation: NSCompositeSourceOver];
    11392       
    114         [fBadgedDockIcon release];
    115         fBadgedDockIcon = [dockIcon copy];
     93        //ignore shadow of badge when placing string
     94        float badgeBottomExtra = 5.0;
     95        badgeRect.size.height -= badgeBottomExtra;
     96        badgeRect.origin.y += badgeBottomExtra;
    11697       
    117         fCompleted = completed;
     98        //place badge text
     99        [self badgeString: [NSString stringWithInt: completed] forRect: badgeRect];
     100                   
     101        [dockIcon unlockFocus];
    118102    }
    119    
    120     [fLock unlock];
    121103
    122104    //set upload and download rate badges
     
    130112    if (speedShown)
    131113    {
     114        if (!dockIcon)
     115            dockIcon = [fDockIcon copy];
     116       
    132117        NSRect badgeRect;
    133118        badgeRect.size = [fUploadBadge size];
     
    139124        stringRect.size.height -= badgeBottomExtra;
    140125        stringRect.origin.y += badgeBottomExtra;
    141 
    142         if (!dockIcon)
    143             dockIcon = [fBadgedDockIcon copy];
    144126       
    145127        [dockIcon lockFocus];
     
    173155        [dockIcon unlockFocus];
    174156    }
    175 
    176     if (dockIcon || fSpeedShown)
     157   
     158    if (fNonDefault || dockIcon)
    177159    {
    178160        if (!dockIcon)
    179             dockIcon = [fBadgedDockIcon copy];
    180            
     161        {
     162            fNonDefault = NO;
     163            dockIcon = [fDockIcon retain];
     164        }
     165        else
     166            fNonDefault = YES;
     167       
    181168        [NSApp setApplicationIconImage: dockIcon];
    182169        [dockIcon release];
    183170    }
    184    
    185     fSpeedShown = speedShown;
    186171}
    187172
    188173- (void) clearBadge
    189174{
    190     [fBadgedDockIcon release];
    191     fBadgedDockIcon = [fDockIcon copy];
    192 
    193175    [NSApp setApplicationIconImage: fDockIcon];
    194    
    195     fCompleted = 0;
    196     fSpeedShown = NO;
     176    fNonDefault = NO;
    197177}
    198178
Note: See TracChangeset for help on using the changeset viewer.