1 /******************************************************************************
2 * $Id: DragOverlayView.m 13251 2012-03-13 02:52:11Z livings124 $
4 * Copyright (c) 2007-2012 Transmission authors and contributors
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
25 #import "DragOverlayView.h"
28 #define ICON_WIDTH 64.0
30 @implementation DragOverlayView
32 - (id) initWithFrame: (NSRect) frame
34 if ((self = [super initWithFrame: frame]))
37 NSShadow * stringShadow = [[NSShadow alloc] init];
38 [stringShadow setShadowOffset: NSMakeSize(2.0, -2.0)];
39 [stringShadow setShadowBlurRadius: 4.0];
41 NSFont * bigFont = [NSFont boldSystemFontOfSize: 18.0],
42 * smallFont = [NSFont systemFontOfSize: 14.0];
44 NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
45 [paragraphStyle setLineBreakMode: NSLineBreakByTruncatingMiddle];
47 fMainLineAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
48 [NSColor whiteColor], NSForegroundColorAttributeName,
49 bigFont, NSFontAttributeName, stringShadow, NSShadowAttributeName,
50 paragraphStyle, NSParagraphStyleAttributeName, nil];
52 fSubLineAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
53 [NSColor whiteColor], NSForegroundColorAttributeName,
54 smallFont, NSFontAttributeName, stringShadow, NSShadowAttributeName,
55 paragraphStyle, NSParagraphStyleAttributeName, nil];
57 [stringShadow release];
58 [paragraphStyle release];
67 [fMainLineAttributes release];
68 [fSubLineAttributes release];
73 - (void) setOverlay: (NSImage *) icon mainLine: (NSString *) mainLine subLine: (NSString *) subLine
78 const NSRect badgeRect = NSMakeRect(0.0, 0.0, 325.0, 84.0);
80 fBadge = [[NSImage alloc] initWithSize: badgeRect.size];
83 NSBezierPath * bp = [NSBezierPath bezierPathWithRoundedRect: badgeRect xRadius: 15.0 yRadius: 15.0];
84 [[NSColor colorWithCalibratedWhite: 0.0 alpha: 0.75] set];
88 [icon drawInRect: NSMakeRect(PADDING, (NSHeight(badgeRect) - ICON_WIDTH) * 0.5, ICON_WIDTH, ICON_WIDTH) fromRect: NSZeroRect
89 operation: NSCompositeSourceOver fraction: 1.0];
92 const NSSize mainLineSize = [mainLine sizeWithAttributes: fMainLineAttributes];
93 const NSSize subLineSize = [subLine sizeWithAttributes: fSubLineAttributes];
95 NSRect lineRect = NSMakeRect(PADDING + ICON_WIDTH + 5.0,
96 (NSHeight(badgeRect) + (subLineSize.height + 2.0 - mainLineSize.height)) * 0.5,
97 NSWidth(badgeRect) - (PADDING + ICON_WIDTH + 2.0) - PADDING, mainLineSize.height);
98 [mainLine drawInRect: lineRect withAttributes: fMainLineAttributes];
101 lineRect.origin.y -= subLineSize.height + 2.0;
102 lineRect.size.height = subLineSize.height;
103 [subLine drawInRect: lineRect withAttributes: fSubLineAttributes];
105 [fBadge unlockFocus];
107 [self setNeedsDisplay: YES];
110 -(void) drawRect: (NSRect) rect
114 const NSRect frame = [self frame];
115 const NSSize imageSize = [fBadge size];
116 [fBadge compositeToPoint: NSMakePoint((NSWidth(frame) - imageSize.width) * 0.5,
117 (NSHeight(frame) - imageSize.height) * 0.5) operation: NSCompositeSourceOver];