source: trunk/macosx/StatusBarView.m @ 11617

Last change on this file since 11617 was 11617, checked in by livings124, 11 years ago

update the copyright years in the Mac code to 2011

  • Property svn:keywords set to Date Rev Author Id
File size: 5.6 KB
Line 
1/******************************************************************************
2 * $Id: StatusBarView.m 11617 2011-01-01 20:42:14Z livings124 $
3 *
4 * Copyright (c) 2006-2011 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 "StatusBarView.h"
26
27@interface StatusBarView (Private)
28
29- (void) reload;
30
31@end
32
33@implementation StatusBarView
34
35- (id) initWithFrame: (NSRect) rect
36{
37    if ((self = [super initWithFrame: rect]))
38    {
39        fIsFilter = NO;
40        fGrayBorderColor = [[NSColor colorWithCalibratedRed: 171.0/255.0 green: 171.0/255.0 blue: 171.0/255.0 alpha: 1.0] retain];
41       
42        NSColor * lightColor = [NSColor colorWithCalibratedRed: 160.0/255.0 green: 160.0/255.0 blue: 160.0/255.0 alpha: 1.0];
43        NSColor * darkColor = [NSColor colorWithCalibratedRed: 155.0/255.0 green: 155.0/255.0 blue: 155.0/255.0 alpha: 1.0];
44        fStatusGradient = [[NSGradient alloc] initWithStartingColor: lightColor endingColor: darkColor];
45       
46        lightColor = [NSColor colorWithCalibratedRed: 235.0/255.0 green: 235.0/255.0 blue: 235.0/255.0 alpha: 1.0];
47        darkColor = [NSColor colorWithCalibratedRed: 205.0/255.0 green: 205.0/255.0 blue: 205.0/255.0 alpha: 1.0];
48        fFilterGradient = [[NSGradient alloc] initWithStartingColor: lightColor endingColor: darkColor];
49       
50        [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reload)
51            name: NSWindowDidBecomeMainNotification object: [self window]];
52        [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reload)
53            name: NSWindowDidResignMainNotification object: [self window]];
54    }
55    return self;
56}
57
58- (void) dealloc
59{
60    [fGrayBorderColor release];
61    [fStatusGradient release];
62    [fFilterGradient release];
63    [super dealloc];
64}
65
66- (BOOL) mouseDownCanMoveWindow
67{
68    return !fIsFilter;
69}
70
71#warning get rid of asap
72- (void) setIsFilter: (BOOL) isFilter
73{
74    fIsFilter = isFilter;
75}
76
77- (void) drawRect: (NSRect) rect
78{
79    if (fIsFilter)
80    {
81        NSInteger count = 0;
82        NSRect gridRects[2];
83        NSColor * colorRects[2];
84       
85        NSRect lineBorderRect = NSMakeRect(NSMinX(rect), NSHeight([self bounds]) - 1.0, NSWidth(rect), 1.0);
86        if ([[self window] isMainWindow])
87        {
88            if (NSIntersectsRect(lineBorderRect, rect))
89            {
90                gridRects[count] = lineBorderRect;
91                colorRects[count] = [NSColor whiteColor];
92                ++count;
93               
94                rect.size.height -= 1.0;
95            }
96        }
97       
98        lineBorderRect.origin.y = 0.0;
99        if (NSIntersectsRect(lineBorderRect, rect))
100        {
101            gridRects[count] = lineBorderRect;
102            colorRects[count] = [NSColor colorWithCalibratedWhite: 0.65 alpha: 1.0];
103            ++count;
104           
105            rect.origin.y += 1.0;
106            rect.size.height -= 1.0;
107        }
108       
109        NSRectFillListWithColors(gridRects, colorRects, count);
110       
111        [fFilterGradient drawInRect: rect angle: 270.0];
112    }
113    else
114    {
115        const BOOL active = [[self window] isMainWindow];
116       
117        NSInteger count = 0;
118        NSRect gridRects[active ? 2 : 3];
119        NSColor * colorRects[active ? 2 : 3];
120       
121        NSRect lineBorderRect = NSMakeRect(NSMinX(rect), NSHeight([self bounds]) - 1.0, NSWidth(rect), 1.0);
122        if (active)
123        {
124            if (NSIntersectsRect(lineBorderRect, rect))
125            {
126                gridRects[count] = lineBorderRect;
127                colorRects[count] = [NSColor colorWithCalibratedWhite: 0.75 alpha: 1.0];
128                ++count;
129               
130                rect.size.height -= 1.0;
131            }
132        }
133       
134        lineBorderRect.origin.y = 0.0;
135        if (NSIntersectsRect(lineBorderRect, rect))
136        {
137            gridRects[count] = lineBorderRect;
138            colorRects[count] = active ? [NSColor colorWithCalibratedWhite: 0.25 alpha: 1.0]
139                                        : [NSColor colorWithCalibratedWhite: 0.5 alpha: 1.0];
140            ++count;
141           
142            rect.origin.y += 1.0;
143            rect.size.height -= 1.0;
144        }
145       
146        if (active)
147            [fStatusGradient drawInRect: rect angle: 270.0];
148        else
149        {
150            gridRects[count] = rect;
151            colorRects[count] = [NSColor colorWithCalibratedWhite: 0.85 alpha: 1.0];
152            ++count;
153        }
154       
155        NSRectFillListWithColors(gridRects, colorRects, count);
156    }
157}
158
159@end
160
161@implementation StatusBarView (Private)
162
163- (void) reload
164{
165    [self setNeedsDisplay: YES];
166}
167
168@end
Note: See TracBrowser for help on using the repository browser.