Ignore:
Timestamp:
Jan 28, 2010, 3:36:47 AM (12 years ago)
Author:
livings124
Message:

some cleanup of DragOverlayView?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/DragOverlayView.m

    r9844 r10028  
    2525#import "DragOverlayView.h"
    2626
    27 #define PADDING 10.0f
    28 #define ICON_WIDTH 64.0f
     27#define PADDING 10.0
     28#define ICON_WIDTH 64.0
    2929
    3030@implementation DragOverlayView
     
    3434    if ((self = [super initWithFrame: frame]))
    3535    {
    36         //create badge
    37         NSRect badgeRect = NSMakeRect(0.0f, 0.0f, 325.0f, 84.0f);
    38         NSBezierPath * bp = [NSBezierPath bezierPathWithRoundedRect: badgeRect xRadius: 15.0f yRadius: 15.0f];
    39        
    40         fBackBadge = [[NSImage alloc] initWithSize: badgeRect.size];
    41         [fBackBadge lockFocus];
    42        
    43         [[NSColor colorWithCalibratedWhite: 0.0f alpha: 0.75f] set];
    44         [bp fill];
    45        
    46         [fBackBadge unlockFocus];
    47        
    4836        //create attributes
    4937        NSShadow * stringShadow = [[NSShadow alloc] init];
    50         [stringShadow setShadowOffset: NSMakeSize(2.0f, -2.0f)];
    51         [stringShadow setShadowBlurRadius: 4.0f];
     38        [stringShadow setShadowOffset: NSMakeSize(2.0, -2.0)];
     39        [stringShadow setShadowBlurRadius: 4.0];
    5240       
    5341        NSFont * bigFont = [[NSFontManager sharedFontManager] convertFont:
    54                                 [NSFont fontWithName: @"Lucida Grande" size: 18.0f] toHaveTrait: NSBoldFontMask],
    55                 * smallFont = [NSFont fontWithName: @"Lucida Grande" size: 14.0f];
     42                                [NSFont fontWithName: @"Lucida Grande" size: 18.0] toHaveTrait: NSBoldFontMask],
     43                * smallFont = [NSFont fontWithName: @"Lucida Grande" size: 14.0];
    5644       
    5745        NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
     
    7664- (void) dealloc
    7765{
    78     [fBackBadge release];
    7966    [fBadge release];
    8067   
     
    8875{
    8976    [fBadge release];
    90     fBadge = [fBackBadge copy];
    91     NSSize badgeSize = [fBadge size];
    9277   
     78    //create badge
     79    const NSRect badgeRect = NSMakeRect(0.0, 0.0, 325.0, 84.0);
     80    NSBezierPath * bp = [NSBezierPath bezierPathWithRoundedRect: badgeRect xRadius: 15.0 yRadius: 15.0];
     81   
     82    fBadge = [[NSImage alloc] initWithSize: badgeRect.size];
    9383    [fBadge lockFocus];
    9484   
     85    [[NSColor colorWithCalibratedWhite: 0.0 alpha: 0.75] set];
     86    [bp fill];
     87   
    9588    //place icon
    96     [icon drawInRect: NSMakeRect(PADDING, (badgeSize.height - ICON_WIDTH) * 0.5f, ICON_WIDTH, ICON_WIDTH) fromRect: NSZeroRect
    97             operation: NSCompositeSourceOver fraction: 1.0f];
     89    [icon drawInRect: NSMakeRect(PADDING, (NSHeight(badgeRect) - ICON_WIDTH) * 0.5, ICON_WIDTH, ICON_WIDTH) fromRect: NSZeroRect
     90            operation: NSCompositeSourceOver fraction: 1.0];
    9891   
    9992    //place main text
    100     NSSize mainLineSize = [mainLine sizeWithAttributes: fMainLineAttributes];
    101     NSSize subLineSize = [subLine sizeWithAttributes: fSubLineAttributes];
     93    const NSSize mainLineSize = [mainLine sizeWithAttributes: fMainLineAttributes];
     94    const NSSize subLineSize = [subLine sizeWithAttributes: fSubLineAttributes];
    10295   
    103     NSRect lineRect = NSMakeRect(PADDING + ICON_WIDTH + 5.0f,
    104                         (badgeSize.height + (subLineSize.height + 2.0f - mainLineSize.height)) * 0.5f,
    105                         badgeSize.width - (PADDING + ICON_WIDTH + 2.0f) - PADDING, mainLineSize.height);
     96    NSRect lineRect = NSMakeRect(PADDING + ICON_WIDTH + 5.0,
     97                        (NSHeight(badgeRect) + (subLineSize.height + 2.0 - mainLineSize.height)) * 0.5,
     98                        NSWidth(badgeRect) - (PADDING + ICON_WIDTH + 2.0) - PADDING, mainLineSize.height);
    10699    [mainLine drawInRect: lineRect withAttributes: fMainLineAttributes];
    107100   
    108101    //place sub text
    109     lineRect.origin.y -= subLineSize.height + 2.0f;
     102    lineRect.origin.y -= subLineSize.height + 2.0;
    110103    lineRect.size.height = subLineSize.height;
    111104    [subLine drawInRect: lineRect withAttributes: fSubLineAttributes];
     
    120113    if (fBadge)
    121114    {
    122         NSRect frame = [self frame];
    123         NSSize imageSize = [fBadge size];
    124         [fBadge compositeToPoint: NSMakePoint((frame.size.width - imageSize.width) * 0.5f,
    125                     (frame.size.height - imageSize.height) * 0.5f) operation: NSCompositeSourceOver];
     115        const NSRect frame = [self frame];
     116        const NSSize imageSize = [fBadge size];
     117        [fBadge compositeToPoint: NSMakePoint((NSWidth(frame) - imageSize.width) * 0.5,
     118                    (NSHeight(frame) - imageSize.height) * 0.5) operation: NSCompositeSourceOver];
    126119    }
    127120}
Note: See TracChangeset for help on using the changeset viewer.