1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-31 03:12:44 +00:00

some cleanup of DragOverlayView

This commit is contained in:
Mitchell Livingston 2010-01-28 03:36:47 +00:00
parent 0a113245b1
commit d2e491285a
2 changed files with 27 additions and 34 deletions

View file

@ -26,7 +26,7 @@
@interface DragOverlayView : NSView @interface DragOverlayView : NSView
{ {
NSImage * fBadge, * fBackBadge; NSImage * fBadge;
NSDictionary * fMainLineAttributes, * fSubLineAttributes; NSDictionary * fMainLineAttributes, * fSubLineAttributes;
} }

View file

@ -24,8 +24,8 @@
#import "DragOverlayView.h" #import "DragOverlayView.h"
#define PADDING 10.0f #define PADDING 10.0
#define ICON_WIDTH 64.0f #define ICON_WIDTH 64.0
@implementation DragOverlayView @implementation DragOverlayView
@ -33,26 +33,14 @@
{ {
if ((self = [super initWithFrame: frame])) if ((self = [super initWithFrame: frame]))
{ {
//create badge
NSRect badgeRect = NSMakeRect(0.0f, 0.0f, 325.0f, 84.0f);
NSBezierPath * bp = [NSBezierPath bezierPathWithRoundedRect: badgeRect xRadius: 15.0f yRadius: 15.0f];
fBackBadge = [[NSImage alloc] initWithSize: badgeRect.size];
[fBackBadge lockFocus];
[[NSColor colorWithCalibratedWhite: 0.0f alpha: 0.75f] set];
[bp fill];
[fBackBadge unlockFocus];
//create attributes //create attributes
NSShadow * stringShadow = [[NSShadow alloc] init]; NSShadow * stringShadow = [[NSShadow alloc] init];
[stringShadow setShadowOffset: NSMakeSize(2.0f, -2.0f)]; [stringShadow setShadowOffset: NSMakeSize(2.0, -2.0)];
[stringShadow setShadowBlurRadius: 4.0f]; [stringShadow setShadowBlurRadius: 4.0];
NSFont * bigFont = [[NSFontManager sharedFontManager] convertFont: NSFont * bigFont = [[NSFontManager sharedFontManager] convertFont:
[NSFont fontWithName: @"Lucida Grande" size: 18.0f] toHaveTrait: NSBoldFontMask], [NSFont fontWithName: @"Lucida Grande" size: 18.0] toHaveTrait: NSBoldFontMask],
* smallFont = [NSFont fontWithName: @"Lucida Grande" size: 14.0f]; * smallFont = [NSFont fontWithName: @"Lucida Grande" size: 14.0];
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail]; [paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail];
@ -75,7 +63,6 @@
- (void) dealloc - (void) dealloc
{ {
[fBackBadge release];
[fBadge release]; [fBadge release];
[fMainLineAttributes release]; [fMainLineAttributes release];
@ -87,26 +74,32 @@
- (void) setOverlay: (NSImage *) icon mainLine: (NSString *) mainLine subLine: (NSString *) subLine - (void) setOverlay: (NSImage *) icon mainLine: (NSString *) mainLine subLine: (NSString *) subLine
{ {
[fBadge release]; [fBadge release];
fBadge = [fBackBadge copy];
NSSize badgeSize = [fBadge size];
//create badge
const NSRect badgeRect = NSMakeRect(0.0, 0.0, 325.0, 84.0);
NSBezierPath * bp = [NSBezierPath bezierPathWithRoundedRect: badgeRect xRadius: 15.0 yRadius: 15.0];
fBadge = [[NSImage alloc] initWithSize: badgeRect.size];
[fBadge lockFocus]; [fBadge lockFocus];
[[NSColor colorWithCalibratedWhite: 0.0 alpha: 0.75] set];
[bp fill];
//place icon //place icon
[icon drawInRect: NSMakeRect(PADDING, (badgeSize.height - ICON_WIDTH) * 0.5f, ICON_WIDTH, ICON_WIDTH) fromRect: NSZeroRect [icon drawInRect: NSMakeRect(PADDING, (NSHeight(badgeRect) - ICON_WIDTH) * 0.5, ICON_WIDTH, ICON_WIDTH) fromRect: NSZeroRect
operation: NSCompositeSourceOver fraction: 1.0f]; operation: NSCompositeSourceOver fraction: 1.0];
//place main text //place main text
NSSize mainLineSize = [mainLine sizeWithAttributes: fMainLineAttributes]; const NSSize mainLineSize = [mainLine sizeWithAttributes: fMainLineAttributes];
NSSize subLineSize = [subLine sizeWithAttributes: fSubLineAttributes]; const NSSize subLineSize = [subLine sizeWithAttributes: fSubLineAttributes];
NSRect lineRect = NSMakeRect(PADDING + ICON_WIDTH + 5.0f, NSRect lineRect = NSMakeRect(PADDING + ICON_WIDTH + 5.0,
(badgeSize.height + (subLineSize.height + 2.0f - mainLineSize.height)) * 0.5f, (NSHeight(badgeRect) + (subLineSize.height + 2.0 - mainLineSize.height)) * 0.5,
badgeSize.width - (PADDING + ICON_WIDTH + 2.0f) - PADDING, mainLineSize.height); NSWidth(badgeRect) - (PADDING + ICON_WIDTH + 2.0) - PADDING, mainLineSize.height);
[mainLine drawInRect: lineRect withAttributes: fMainLineAttributes]; [mainLine drawInRect: lineRect withAttributes: fMainLineAttributes];
//place sub text //place sub text
lineRect.origin.y -= subLineSize.height + 2.0f; lineRect.origin.y -= subLineSize.height + 2.0;
lineRect.size.height = subLineSize.height; lineRect.size.height = subLineSize.height;
[subLine drawInRect: lineRect withAttributes: fSubLineAttributes]; [subLine drawInRect: lineRect withAttributes: fSubLineAttributes];
@ -119,10 +112,10 @@
{ {
if (fBadge) if (fBadge)
{ {
NSRect frame = [self frame]; const NSRect frame = [self frame];
NSSize imageSize = [fBadge size]; const NSSize imageSize = [fBadge size];
[fBadge compositeToPoint: NSMakePoint((frame.size.width - imageSize.width) * 0.5f, [fBadge compositeToPoint: NSMakePoint((NSWidth(frame) - imageSize.width) * 0.5,
(frame.size.height - imageSize.height) * 0.5f) operation: NSCompositeSourceOver]; (NSHeight(frame) - imageSize.height) * 0.5) operation: NSCompositeSourceOver];
} }
} }