1/******************************************************************************
2 * Copyright (c) 2011-2012 Transmission authors and contributors
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 *****************************************************************************/
22
23#import "FilterBarView.h"
24#import "NSApplicationAdditions.h"
25
26@implementation FilterBarView
27
28- (id) initWithFrame: (NSRect) rect
29{
30    if ((self = [super initWithFrame: rect]))
31    {
32        if (![NSApp isOnYosemiteOrBetter]) {
33            NSColor * lightColor = [NSColor colorWithCalibratedRed: 235.0/255.0 green: 235.0/255.0 blue: 235.0/255.0 alpha: 1.0];
34            NSColor * darkColor = [NSColor colorWithCalibratedRed: 205.0/255.0 green: 205.0/255.0 blue: 205.0/255.0 alpha: 1.0];
35            fGradient = [[NSGradient alloc] initWithStartingColor: lightColor endingColor: darkColor];
36        }
37    }
38    return self;
39}
40
41
42- (BOOL) mouseDownCanMoveWindow
43{
44    return NO;
45}
46
47- (BOOL) isOpaque
48{
49    return YES;
50}
51
52- (void) drawRect: (NSRect) rect
53{
54    if ([NSApp isOnYosemiteOrBetter]) {
55        [[NSColor windowBackgroundColor] setFill];
56        NSRectFill(rect);
57
58        const NSRect lineBorderRect = NSMakeRect(NSMinX(rect), 0.0, NSWidth(rect), 1.0);
59        if (NSIntersectsRect(lineBorderRect, rect))
60        {
61            [[NSColor gridColor] setFill];
62            NSRectFill(lineBorderRect);
63        }
64    }
65    else {
66        NSInteger count = 0;
67        NSRect gridRects[2];
68        NSColor * colorRects[2];
69
70        NSRect lineBorderRect = NSMakeRect(NSMinX(rect), NSHeight([self bounds]) - 1.0, NSWidth(rect), 1.0);
71        if (NSIntersectsRect(lineBorderRect, rect))
72        {
73            gridRects[count] = lineBorderRect;
74            colorRects[count] = [NSColor whiteColor];
75            ++count;
76
77            rect.size.height -= 1.0;
78        }
79
80        lineBorderRect.origin.y = 0.0;
81        if (NSIntersectsRect(lineBorderRect, rect))
82        {
83            gridRects[count] = lineBorderRect;
84            colorRects[count] = [NSColor colorWithCalibratedWhite: 0.65 alpha: 1.0];
85            ++count;
86
87            rect.origin.y += 1.0;
88            rect.size.height -= 1.0;
89        }
90
91        if (!NSIsEmptyRect(rect))
92        {
93            const NSRect gradientRect = NSMakeRect(NSMinX(rect), 1.0, NSWidth(rect), NSHeight([self bounds]) - 1.0 - 1.0); //proper gradient requires the full height of the bar
94            [fGradient drawInRect: gradientRect angle: 270.0];
95        }
96
97        NSRectFillListWithColors(gridRects, colorRects, count);
98    }
99}
100
101@end
102