Changeset 3386 for trunk/macosx/Badger.m


Ignore:
Timestamp:
Oct 13, 2007, 3:16:51 AM (15 years ago)
Author:
livings124
Message:

various trivial changes to the badger code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Badger.m

    r3384 r3386  
    5959{
    6060    //set completed badge to top right
    61     BOOL baseChange;
    62     if (baseChange = (fCompleted != fCompletedBadged))
     61    BOOL baseChange = fCompleted != fCompletedBadged;
     62    if (baseChange)
    6363    {
    6464        fCompletedBadged = fCompleted;
     
    100100    }
    101101   
    102     //set upload and download rate badges
    103     NSString * downloadRateString = nil, * uploadRateString = nil;
     102    NSImage * dockIcon = nil;
     103    BOOL speedBadge = NO;
    104104   
    105105    BOOL checkDownload = [[NSUserDefaults standardUserDefaults] boolForKey: @"BadgeDownloadRate"],
     
    107107    if (checkDownload || checkUpload)
    108108    {
     109        //set upload and download rate badges
     110        NSString * downloadRateString = nil, * uploadRateString = nil;
     111       
    109112        float downloadRate, uploadRate;
    110113        tr_torrentRates(fLib, &downloadRate, &uploadRate);
     
    114117        if (checkUpload && uploadRate >= 0.1)
    115118            uploadRateString = [NSString stringForSpeedAbbrev: uploadRate];
    116     }
    117    
    118     NSImage * dockIcon = nil;
    119     BOOL speedBadge = uploadRateString || downloadRateString;
    120     if (speedBadge)
    121     {
    122         if (!fDockIcon)
    123             fDockIcon = [[NSImage imageNamed: @"NSApplicationIcon"] copy];
    124         dockIcon = [fDockIcon copy];
    125        
    126         if (!fUploadBadge)
    127             fUploadBadge = [NSImage imageNamed: @"UploadBadge"];
    128         if (!fDownloadBadge)
    129             fDownloadBadge = [NSImage imageNamed: @"DownloadBadge"];
    130        
    131         NSRect badgeRect;
    132         badgeRect.size = [fUploadBadge size];
    133         badgeRect.origin = NSZeroPoint;
    134        
    135         //ignore shadow of badge when placing string
    136         NSRect stringRect = badgeRect;
    137         float badgeBottomExtra = 2.0;
    138         stringRect.size.height -= badgeBottomExtra;
    139         stringRect.origin.y += badgeBottomExtra;
    140        
    141         [dockIcon lockFocus];
    142        
    143         if (uploadRateString)
     119       
     120        speedBadge = uploadRateString || downloadRateString;
     121        if (speedBadge)
    144122        {
    145             //place badge
    146             [fUploadBadge compositeToPoint: badgeRect.origin operation: NSCompositeSourceOver];
    147            
    148             //place badge text
    149             [self badgeString: uploadRateString forRect: stringRect];
    150         }
    151        
    152         if (downloadRateString)
    153         {
    154             //download rate above upload rate
     123            if (!fDockIcon)
     124                fDockIcon = [[NSImage imageNamed: @"NSApplicationIcon"] copy];
     125            dockIcon = [fDockIcon copy];
     126           
     127            if (!fUploadBadge)
     128                fUploadBadge = [NSImage imageNamed: @"UploadBadge"];
     129            if (!fDownloadBadge)
     130                fDownloadBadge = [NSImage imageNamed: @"DownloadBadge"];
     131           
     132            NSRect badgeRect;
     133            badgeRect.size = [fUploadBadge size];
     134            badgeRect.origin = NSZeroPoint;
     135           
     136            //ignore shadow of badge when placing string
     137            NSRect stringRect = badgeRect;
     138            float badgeBottomExtra = 2.0;
     139            stringRect.size.height -= badgeBottomExtra;
     140            stringRect.origin.y += badgeBottomExtra;
     141           
     142            [dockIcon lockFocus];
     143           
    155144            if (uploadRateString)
    156145            {
    157                 float spaceBetween = badgeRect.size.height + 2.0;
    158                 badgeRect.origin.y += spaceBetween;
    159                 stringRect.origin.y += spaceBetween;
     146                //place badge and text
     147                [fUploadBadge compositeToPoint: badgeRect.origin operation: NSCompositeSourceOver];
     148                [self badgeString: uploadRateString forRect: stringRect];
    160149            }
    161        
    162             //place badge
    163             [fDownloadBadge compositeToPoint: badgeRect.origin operation: NSCompositeSourceOver];
    164            
    165             //place badge text
    166             [self badgeString: downloadRateString forRect: stringRect];
     150           
     151            if (downloadRateString)
     152            {
     153                //download rate above upload rate
     154                if (uploadRateString)
     155                {
     156                    float spaceBetween = badgeRect.size.height + 2.0;
     157                    badgeRect.origin.y += spaceBetween;
     158                    stringRect.origin.y += spaceBetween;
     159                }
     160           
     161                //place badge and text
     162                [fDownloadBadge compositeToPoint: badgeRect.origin operation: NSCompositeSourceOver];
     163                [self badgeString: downloadRateString forRect: stringRect];
     164            }
     165           
     166            [dockIcon unlockFocus];
    167167        }
    168        
    169         [dockIcon unlockFocus];
    170168    }
    171169   
Note: See TracChangeset for help on using the changeset viewer.