Changeset 9731


Ignore:
Timestamp:
Dec 12, 2009, 6:29:14 PM (12 years ago)
Author:
livings124
Message:

#2662 shrink the dock badge text until it fits without being cut off

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/BadgeView.h

    r7659 r9731  
    3030    tr_session * fLib;
    3131   
    32     NSDictionary * fAttributes;
     32    NSMutableDictionary * fAttributes;
    3333   
    3434    CGFloat fDownloadRate, fUploadRate;
  • trunk/macosx/BadgeView.m

    r9241 r9731  
    2626#import "NSStringAdditions.h"
    2727
    28 #define BETWEEN_PADDING 2.0f
     28#define BETWEEN_PADDING 2.0
    2929
    3030@interface BadgeView (Private)
     
    7979        NSImage * quitBadge = [NSImage imageNamed: @"QuitBadge.png"];
    8080        [self badge: quitBadge string: NSLocalizedString(@"Quitting", "Dock Badger -> quit")
    81                 atHeight: (rect.size.height - [quitBadge size].height) * 0.5f adjustForQuit: YES];
     81                atHeight: (NSHeight(rect) - [quitBadge size].height) * 0.5 adjustForQuit: YES];
    8282        return;
    8383    }
    8484   
    85     const BOOL upload = fUploadRate >= 0.1f,
    86             download = fDownloadRate >= 0.1f;
    87     CGFloat bottom = 0.0f;
     85    const BOOL upload = fUploadRate >= 0.1,
     86            download = fDownloadRate >= 0.1;
     87    CGFloat bottom = 0.0;
    8888    if (upload)
    8989    {
     
    107107    {
    108108        NSShadow * stringShadow = [[NSShadow alloc] init];
    109         [stringShadow setShadowOffset: NSMakeSize(2.0f, -2.0f)];
    110         [stringShadow setShadowBlurRadius: 4.0f];
     109        [stringShadow setShadowOffset: NSMakeSize(2.0, -2.0)];
     110        [stringShadow setShadowBlurRadius: 4.0];
    111111       
    112         fAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
    113             [NSColor whiteColor], NSForegroundColorAttributeName,
    114             [NSFont boldSystemFontOfSize: 26.0f], NSFontAttributeName, stringShadow, NSShadowAttributeName, nil];
     112        fAttributes = [[NSMutableDictionary alloc] initWithCapacity: 3];
     113        [fAttributes setObject: [NSColor whiteColor] forKey: NSForegroundColorAttributeName];
     114        [fAttributes setObject: stringShadow forKey: NSShadowAttributeName];
    115115       
    116116        [stringShadow release];
     
    122122    badgeRect.origin.y = height;
    123123   
    124     [badge drawInRect: badgeRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0f];
     124    [badge drawInRect: badgeRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
     125   
     126    //make sure text fits on the badge
     127    CGFloat fontSize = 26.0;
     128    NSSize stringSize;
     129    do
     130    {
     131        [fAttributes setObject: [NSFont boldSystemFontOfSize: fontSize] forKey: NSFontAttributeName];
     132        stringSize = [string sizeWithAttributes: fAttributes];
     133        fontSize -= 1.0;
     134    } while (NSWidth(badgeRect) < stringSize.width);
    125135   
    126136    //string is in center of image
    127     NSSize stringSize = [string sizeWithAttributes: fAttributes];
    128    
    129137    NSRect stringRect = badgeRect;
    130     stringRect.origin.x += (badgeRect.size.width - stringSize.width) * 0.5f;
    131     stringRect.origin.y += (badgeRect.size.height - stringSize.height) * 0.5f + (quit ? 2.0f : 1.0f); //adjust for shadow, extra for quit
     138    stringRect.origin.x += (NSWidth(badgeRect) - stringSize.width) * 0.5;
     139    stringRect.origin.y += (NSHeight(badgeRect) - stringSize.height) * 0.5 + (quit ? 2.0 : 1.0); //adjust for shadow, extra for quit
    132140    stringRect.size = stringSize;
    133141   
Note: See TracChangeset for help on using the changeset viewer.