source: trunk/macosx/StatusBarView.m @ 11621

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

separate the code for the filter and status bars

  • Property svn:keywords set to Date Rev Author Id
File size: 3.7 KB
Line 
1/******************************************************************************
2 * $Id: StatusBarView.m 11621 2011-01-02 17:11:41Z 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        NSColor * lightColor = [NSColor colorWithCalibratedRed: 160.0/255.0 green: 160.0/255.0 blue: 160.0/255.0 alpha: 1.0];
40        NSColor * darkColor = [NSColor colorWithCalibratedRed: 155.0/255.0 green: 155.0/255.0 blue: 155.0/255.0 alpha: 1.0];
41        fGradient = [[NSGradient alloc] initWithStartingColor: lightColor endingColor: darkColor];
42       
43        [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reload)
44            name: NSWindowDidBecomeMainNotification object: [self window]];
45        [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reload)
46            name: NSWindowDidResignMainNotification object: [self window]];
47    }
48    return self;
49}
50
51- (void) dealloc
52{
53    [fGradient release];
54    [super dealloc];
55}
56
57- (BOOL) mouseDownCanMoveWindow
58{
59    return YES;
60}
61
62- (void) drawRect: (NSRect) rect
63{
64    const BOOL active = [[self window] isMainWindow];
65   
66    NSInteger count = 0;
67    NSRect gridRects[active ? 2 : 3];
68    NSColor * colorRects[active ? 2 : 3];
69   
70    NSRect lineBorderRect = NSMakeRect(NSMinX(rect), NSHeight([self bounds]) - 1.0, NSWidth(rect), 1.0);
71    if (active)
72    {
73        if (NSIntersectsRect(lineBorderRect, rect))
74        {
75            gridRects[count] = lineBorderRect;
76            colorRects[count] = [NSColor colorWithCalibratedWhite: 0.75 alpha: 1.0];
77            ++count;
78           
79            rect.size.height -= 1.0;
80        }
81    }
82   
83    lineBorderRect.origin.y = 0.0;
84    if (NSIntersectsRect(lineBorderRect, rect))
85    {
86        gridRects[count] = lineBorderRect;
87        colorRects[count] = active ? [NSColor colorWithCalibratedWhite: 0.25 alpha: 1.0]
88                                    : [NSColor colorWithCalibratedWhite: 0.5 alpha: 1.0];
89        ++count;
90       
91        rect.origin.y += 1.0;
92        rect.size.height -= 1.0;
93    }
94   
95    if (active)
96        [fGradient drawInRect: rect angle: 270.0];
97    else
98    {
99        gridRects[count] = rect;
100        colorRects[count] = [NSColor colorWithCalibratedWhite: 0.85 alpha: 1.0];
101        ++count;
102    }
103   
104    NSRectFillListWithColors(gridRects, colorRects, count);
105}
106
107@end
108
109@implementation StatusBarView (Private)
110
111- (void) reload
112{
113    [self setNeedsDisplay: YES];
114}
115
116@end
Note: See TracBrowser for help on using the repository browser.