Changeset 4072


Ignore:
Timestamp:
Dec 5, 2007, 6:23:51 PM (14 years ago)
Author:
livings124
Message:

clean dock badging code

Location:
trunk/macosx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/BadgeView.h

    r3670 r4072  
    3131   
    3232    NSDictionary * fAttributes;
     33   
     34    BOOL fQuitting;
     35    NSProgressIndicator * fQuitIndicator;
    3336}
    3437
    3538- (id) initWithFrame: (NSRect) frame lib: (tr_handle *) lib;
    3639
     40- (void) setQuitting;
     41
    3742@end
  • trunk/macosx/BadgeView.m

    r4059 r4072  
    3131@interface BadgeView (Private)
    3232
    33 - (void) badgeString: (NSString *) string forRect: (NSRect) rect;
     33- (void) badge: (NSImage *) badge string: (NSString *) string atHeight: (float) height;
    3434
    3535@end
     
    4242    {
    4343        fLib = lib;
     44        fQuitting = NO;
    4445    }
    4546    return self;
     47}
     48
     49- (void) setQuitting
     50{
     51    fQuitting = YES;
    4652}
    4753
     
    5561{
    5662    [[NSImage imageNamed: @"NSApplicationIcon"] drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
     63   
     64    if (fQuitting)
     65    {
     66        return;
     67    }
    5768   
    5869    BOOL checkDownload = [[NSUserDefaults standardUserDefaults] boolForKey: @"BadgeDownloadRate"],
     
    7384        if (uploadRateString || downloadRateString)
    7485        {
    75             NSRect badgeRect = NSZeroRect;
    76             badgeRect.size = [[NSImage imageNamed: @"UploadBadge"] size];
    77            
    78             //ignore shadow of badge when placing string
    79             NSRect stringRect = badgeRect;
    80             stringRect.size.height -= BOTTOM_PADDING;
    81             stringRect.origin.y += BOTTOM_PADDING;
    82            
    83             if (uploadRateString)
    84             {
    85                 //place badge and text
    86                 [[NSImage imageNamed: @"UploadBadge"] drawInRect: badgeRect fromRect: NSZeroRect
    87                                                         operation: NSCompositeSourceOver fraction: 1.0];
    88                 [self badgeString: uploadRateString forRect: stringRect];
    89             }
     86           if (uploadRateString)
     87                [self badge: [NSImage imageNamed: @"UploadBadge"] string: uploadRateString atHeight: 0.0];
    9088           
    9189            if (downloadRateString)
    9290            {
    9391                //download rate above upload rate
    94                 if (uploadRateString)
    95                 {
    96                     float spaceBetween = badgeRect.size.height + BETWEEN_PADDING;
    97                     badgeRect.origin.y += spaceBetween;
    98                     stringRect.origin.y += spaceBetween;
    99                 }
    100                
    101                 //place badge and text
    102                 [[NSImage imageNamed: @"DownloadBadge"] drawInRect: badgeRect fromRect: NSZeroRect
    103                                                         operation: NSCompositeSourceOver fraction: 1.0];
    104                 [self badgeString: downloadRateString forRect: stringRect];
     92                float bottom = uploadRateString ? [[NSImage imageNamed: @"UploadBadge"] size].height + BETWEEN_PADDING : 0.0;
     93                [self badge: [NSImage imageNamed: @"DownloadBadge"] string: downloadRateString atHeight: bottom];
    10594            }
    10695        }
     
    113102
    114103//dock icon must have locked focus
    115 - (void) badgeString: (NSString *) string forRect: (NSRect) rect
     104- (void) badge: (NSImage *) badge string: (NSString *) string atHeight: (float) height
    116105{
    117106    if (!fAttributes)
     
    128117    }
    129118   
     119    NSRect badgeRect = NSZeroRect;
     120    badgeRect.size = [badge size];
     121    badgeRect.origin.y = height;
     122   
     123    [badge drawInRect: badgeRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
     124   
     125    //string is in center of image
    130126    NSSize stringSize = [string sizeWithAttributes: fAttributes];
    131127   
    132     //string is in center of image
    133     rect.origin.x += (rect.size.width - stringSize.width) * 0.5;
    134     rect.origin.y += (rect.size.height - stringSize.height) * 0.5;
    135     rect.size = stringSize;
    136                        
    137     [string drawInRect: rect withAttributes: fAttributes];
     128    NSRect stringRect = badgeRect;
     129    stringRect.origin.x += (badgeRect.size.width - stringSize.width) * 0.5;
     130    stringRect.origin.y += (badgeRect.size.height - stringSize.height) * 0.5;
     131    stringRect.size = stringSize;
     132   
     133    //adjust for shadow
     134    stringRect.origin.y += 1.0;
     135   
     136    [string drawInRect: stringRect withAttributes: fAttributes];
    138137}
    139138
  • trunk/macosx/Badger.h

    r3695 r4072  
    3030    tr_handle       * fLib;
    3131   
    32     NSImage         * fDockIcon, * fBadge, * fUploadBadge;
     32    NSImage         * fDockIcon, * fBadge;
    3333   
    3434    NSDictionary    * fAttributes;
     
    4242- (void) incrementCompleted;
    4343- (void) clearCompleted;
    44 - (void) clearBadge;
     44- (void) setQuitting;
    4545
    4646@end
  • trunk/macosx/Badger.m

    r4059 r4072  
    149149            dockIcon = [fDockIcon copy];
    150150           
    151             if (!fUploadBadge)
    152                 fUploadBadge = [NSImage imageNamed: @"UploadBadge"];
    153            
    154151            NSRect badgeRect;
    155             badgeRect.size = [fUploadBadge size];
     152            badgeRect.size = [[NSImage imageNamed: @"UploadBadge"] size];
    156153            badgeRect.origin = NSZeroPoint;
    157154           
     
    166163            {
    167164                //place badge and text
    168                 [fUploadBadge compositeToPoint: badgeRect.origin operation: NSCompositeSourceOver];
     165                [[NSImage imageNamed: @"UploadBadge"] compositeToPoint: badgeRect.origin operation: NSCompositeSourceOver];
    169166                [self badgeString: uploadRateString forRect: stringRect];
    170167            }
     
    221218}
    222219
    223 - (void) clearBadge
     220- (void) setQuitting
    224221{
    225222    if ([NSApp isOnLeopardOrBetter])
    226223    {
    227224        [self clearCompleted];
    228         [[NSApp dockTile] setContentView: nil];
     225        [(BadgeView *)[[NSApp dockTile] contentView] setQuitting];
     226        [[NSApp dockTile] display];
    229227    }
    230228    else
  • trunk/macosx/Controller.m

    r4064 r4072  
    3232#import "StatsWindowController.h"
    3333#import "AboutWindowController.h"
    34 #import "QuittingWindowController.h"
    3534#import "ButtonToolbarItem.h"
    3635#import "NSApplicationAdditions.h"
     
    491490- (void) applicationWillTerminate: (NSNotification *) notification
    492491{
     492    [fBadger setQuitting];
     493   
    493494    //stop timers and notification checking
    494495    [[NSNotificationCenter defaultCenter] removeObserver: self];
     
    533534    [self showFilterBar: NO animate: NO];
    534535   
    535     //show quit window
    536     QuittingWindowController * quitController = [[QuittingWindowController alloc] init];
    537     [quitController showWindow: self];
    538    
    539536    //save history
    540537    [self updateTorrentHistory];
     
    542539    [fDisplayedTorrents removeAllObjects];
    543540    [fTorrents removeAllObjects];
    544    
    545     //clear badge
    546     [fBadger clearBadge];
    547541   
    548542    //remaining calls the same as dealloc
     
    554548    [fDisplayedTorrents release];
    555549   
    556     [fBadger release];
    557550    [fOverlayWindow release];
    558551    [fIPCController release];
     
    14471440                        tr_getSessionStats(fLib, &stats);
    14481441                   
    1449                     statusString = [NSString stringWithFormat: NSLocalizedString(@"DL: %@ UL: %@", "status bar -> status label"),
     1442                    statusString = [NSString stringWithFormat: NSLocalizedString(@"DL: %@   UL: %@",
     1443                        "status bar -> status label (3 spaces between)"),
    14501444                        [NSString stringForFileSize: stats.downloadedBytes], [NSString stringForFileSize: stats.uploadedBytes]];
    14511445                }
Note: See TracChangeset for help on using the changeset viewer.