source: trunk/macosx/StatusBarView.m @ 11557

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

lighten the line at the bottom of the filter bar

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