source: trunk/macosx/StatusBarView.m @ 11558

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

use the lighter bottom line of the filter bar when the window is inactive

  • Property svn:keywords set to Date Rev Author Id
File size: 5.9 KB
Line 
1/******************************************************************************
2 * $Id: StatusBarView.m 11558 2010-12-21 03:32:33Z 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] = [NSColor colorWithCalibratedWhite: 0.65 alpha: 1.0];
108            ++count;
109           
110            rect.origin.y += 1.0;
111            rect.size.height -= 1.0;
112        }
113       
114        NSRectFillListWithColors(gridRects, colorRects, count);
115       
116        [fFilterGradient drawInRect: rect angle: 270.0];
117    }
118    else
119    {
120        const BOOL active = [[self window] isMainWindow];
121       
122        NSInteger count = 0;
123        NSRect gridRects[2];
124        NSColor * colorRects[2];
125       
126        NSRect lineBorderRect = NSMakeRect(NSMinX(rect), NSHeight([self bounds]) - 1.0, NSWidth(rect), 1.0);
127        if (active)
128        {
129            if (NSIntersectsRect(lineBorderRect, rect))
130            {
131                gridRects[count] = lineBorderRect;
132                colorRects[count] = [NSColor colorWithCalibratedWhite: 0.75 alpha: 1.0];
133                ++count;
134               
135                rect.size.height -= 1.0;
136            }
137        }
138       
139        lineBorderRect.origin.y = 0.0;
140        if (NSIntersectsRect(lineBorderRect, rect))
141        {
142            gridRects[count] = lineBorderRect;
143            colorRects[count] = [[self window] isMainWindow] ? [NSColor colorWithCalibratedWhite: 0.25 alpha: 1.0]
144                                    : [NSColor colorWithCalibratedWhite: 0.5 alpha: 1.0];
145            ++count;
146           
147            rect.origin.y += 1.0;
148            rect.size.height -= 1.0;
149        }
150       
151        if (active)
152            [fStatusGradient drawInRect: rect angle: 270.0];
153        else
154            [fInactiveGradient drawInRect: rect angle: 270.0];
155       
156        NSRectFillListWithColors(gridRects, colorRects, count);
157    }
158}
159
160@end
161
162@implementation StatusBarView (Private)
163
164- (void) reload
165{
166    [self setNeedsDisplay: YES];
167}
168
169@end
Note: See TracBrowser for help on using the repository browser.