source: trunk/macosx/InfoTabButtonCell.m @ 11787

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

#3962 Update the inspector's button bar's look

  • Property svn:keywords set to Date Rev Author Id
File size: 3.9 KB
Line 
1/******************************************************************************
2 * $Id: InfoTabButtonCell.m 11787 2011-01-30 02:01:05Z livings124 $
3 *
4 * Copyright (c) 2007-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 "InfoTabButtonCell.h"
26
27@implementation InfoTabButtonCell
28
29- (void) awakeFromNib
30{
31    [(NSMatrix *)[self controlView] setToolTip: [self title] forCell: self];
32       
33    fSelected = NO;
34   
35    //expects the icon to currently be set as the image
36    fIcon = [[self image] retain];
37    [self setSelectedTab: fSelected];
38}
39
40- (void) dealloc
41{
42    [fIcon release];
43    [super dealloc];
44}
45
46- (void) setSelectedTab: (BOOL) selected
47{
48    fSelected = selected;
49   
50    NSInteger row, col;
51    [(NSMatrix *)[self controlView] getRow: &row column: &col ofCell: self];
52    const NSSize tabSize = [(NSMatrix *)[self controlView] cellFrameAtRow: row column: col].size;
53    const NSRect tabRect = NSMakeRect(0.0, 0.0, tabSize.width, tabSize.height);
54   
55    NSImage * tabImage = [[NSImage alloc] initWithSize: tabSize];
56       
57    [tabImage lockFocus];
58   
59    if (!fSelected)
60    {
61        NSColor * lightColor = [NSColor colorWithCalibratedRed: 255.0/255.0 green: 255.0/255.0 blue: 255.0/255.0 alpha: 1.0];
62        NSColor * darkColor = [NSColor colorWithCalibratedRed: 225.0/255.0 green: 225.0/255.0 blue: 225.0/255.0 alpha: 1.0];
63        NSGradient * gradient = [[NSGradient alloc] initWithStartingColor: darkColor endingColor: lightColor];
64        [gradient drawInRect: tabRect angle: 90.0];
65        [gradient release];
66    }
67    else
68    {
69        NSColor * lightColor = [NSColor colorWithCalibratedRed: 160.0/255.0 green: 160.0/255.0 blue: 160.0/255.0 alpha: 1.0];
70        NSColor * darkColor = [NSColor colorWithCalibratedRed: 150.0/255.0 green: 150.0/255.0 blue: 150.0/255.0 alpha: 1.0];
71        NSGradient * gradient = [[NSGradient alloc] initWithStartingColor: darkColor endingColor: lightColor];
72        [gradient drawInRect: tabRect angle: 90.0];
73        [gradient release];
74    }
75   
76    [[NSColor grayColor] set];
77    NSRectFill(NSMakeRect(0.0, 0.0, NSWidth(tabRect), 1.0));
78    NSRectFill(NSMakeRect(0.0, NSHeight(tabRect) - 1.0, NSWidth(tabRect), 1.0));
79    NSRectFill(NSMakeRect(NSWidth(tabRect) - 1.0, 1.0, NSWidth(tabRect) - 1.0, NSHeight(tabRect) - 2.0));
80   
81    if (fIcon)
82    {
83        const NSSize iconSize = [fIcon size];
84       
85        const NSRect iconRect = NSMakeRect(floor((tabSize.width - iconSize.width) * 0.5),
86                                            floor((tabSize.height - iconSize.height) * 0.5),
87                                            iconSize.width, iconSize.height);
88       
89        [fIcon drawInRect: iconRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
90        [tabImage unlockFocus];
91    }
92   
93    [self setImage: tabImage];
94    [tabImage release];
95}
96
97@end
Note: See TracBrowser for help on using the repository browser.