source: trunk/macosx/DragOverlayView.m @ 10028

Last change on this file since 10028 was 10028, checked in by livings124, 12 years ago

some cleanup of DragOverlayView?

  • Property Id set to /Users/mitchell/Desktop/Transmission/macosx/ActionMenuRatioToDisplayRatioTransformer.h
  • Property svn:keywords set to Date Rev Author Id
File size: 4.9 KB
Line 
1/******************************************************************************
2 * $Id: DragOverlayView.m 10028 2010-01-28 03:36:47Z livings124 $
3 *
4 * Copyright (c) 2007-2010 Transmission authors and contributors
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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 *****************************************************************************/
24
25#import "DragOverlayView.h"
26
27#define PADDING 10.0
28#define ICON_WIDTH 64.0
29
30@implementation DragOverlayView
31
32- (id) initWithFrame: (NSRect) frame
33{
34    if ((self = [super initWithFrame: frame]))
35    {
36        //create attributes
37        NSShadow * stringShadow = [[NSShadow alloc] init];
38        [stringShadow setShadowOffset: NSMakeSize(2.0, -2.0)];
39        [stringShadow setShadowBlurRadius: 4.0];
40       
41        NSFont * bigFont = [[NSFontManager sharedFontManager] convertFont:
42                                [NSFont fontWithName: @"Lucida Grande" size: 18.0] toHaveTrait: NSBoldFontMask],
43                * smallFont = [NSFont fontWithName: @"Lucida Grande" size: 14.0];
44       
45        NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
46        [paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail];
47       
48        fMainLineAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
49                                [NSColor whiteColor], NSForegroundColorAttributeName,
50                                bigFont, NSFontAttributeName, stringShadow, NSShadowAttributeName,
51                                paragraphStyle, NSParagraphStyleAttributeName, nil];
52       
53        fSubLineAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
54                                [NSColor whiteColor], NSForegroundColorAttributeName,
55                                smallFont, NSFontAttributeName, stringShadow, NSShadowAttributeName,
56                                paragraphStyle, NSParagraphStyleAttributeName, nil];
57       
58        [stringShadow release];
59        [paragraphStyle release];
60    }
61    return self;
62}
63
64- (void) dealloc
65{
66    [fBadge release];
67   
68    [fMainLineAttributes release];
69    [fSubLineAttributes release];
70   
71    [super dealloc];
72}
73
74- (void) setOverlay: (NSImage *) icon mainLine: (NSString *) mainLine subLine: (NSString *) subLine
75{
76    [fBadge release];
77   
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];
83    [fBadge lockFocus];
84   
85    [[NSColor colorWithCalibratedWhite: 0.0 alpha: 0.75] set];
86    [bp fill];
87   
88    //place icon
89    [icon drawInRect: NSMakeRect(PADDING, (NSHeight(badgeRect) - ICON_WIDTH) * 0.5, ICON_WIDTH, ICON_WIDTH) fromRect: NSZeroRect
90            operation: NSCompositeSourceOver fraction: 1.0];
91   
92    //place main text
93    const NSSize mainLineSize = [mainLine sizeWithAttributes: fMainLineAttributes];
94    const NSSize subLineSize = [subLine sizeWithAttributes: fSubLineAttributes];
95   
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);
99    [mainLine drawInRect: lineRect withAttributes: fMainLineAttributes];
100   
101    //place sub text
102    lineRect.origin.y -= subLineSize.height + 2.0;
103    lineRect.size.height = subLineSize.height;
104    [subLine drawInRect: lineRect withAttributes: fSubLineAttributes];
105   
106    [fBadge unlockFocus];
107   
108    [self setNeedsDisplay: YES];
109}
110
111-(void) drawRect: (NSRect) rect
112{
113    if (fBadge)
114    {
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];
119    }
120}
121
122@end
Note: See TracBrowser for help on using the repository browser.