macOS: Remove unused variable
[vlc.git] / modules / gui / macosx / VLCHUDRadiobuttonCell.m
1 /*****************************************************************************
2  * VLCHUDRadiobuttonCell.m: Custom radiobutton cell UI for dark HUD Panels
3  *****************************************************************************
4  * Copyright (C) 2016 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Marvin Scholz <epirat07 -at- gmail -dot- com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #import "VLCHUDRadiobuttonCell.h"
25
26 @implementation VLCHUDRadiobuttonCell
27
28 - (instancetype) initWithCoder:(NSCoder *)coder
29 {
30     self = [super initWithCoder:coder];
31     if (self) {
32         _normalGradient    = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceRed:0.251f green:0.251f blue:0.255f alpha:1.0f]
33                                                            endingColor:[NSColor colorWithDeviceRed:0.118f green:0.118f blue:0.118f alpha:1.0f]];
34         _highlightGradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceRed:0.451f green:0.451f blue:0.455f alpha:1.0f]
35                                                            endingColor:[NSColor colorWithDeviceRed:0.318f green:0.318f blue:0.318f alpha:1.0f]];
36         _pushedGradient    = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceRed:0.451f green:0.451f blue:0.455f alpha:1.0f]
37                                                            endingColor:[NSColor colorWithDeviceRed:0.318f green:0.318f blue:0.318f alpha:1.0f]];
38         _textColor         = [NSColor whiteColor];
39     }
40     return self;
41 }
42
43 - (void) drawImage:(NSImage *)image withFrame:(NSRect)frame inView:(NSView *)controlView
44 {
45     // Set text color
46     NSMutableAttributedString *colorTitle = [[NSMutableAttributedString alloc] initWithAttributedString:self.attributedTitle];
47     NSRange titleRange = NSMakeRange(0, [colorTitle length]);
48     [colorTitle addAttribute:NSForegroundColorAttributeName value:_textColor range:titleRange];
49     [self setAttributedTitle:colorTitle];
50
51     // Set frame size correctly
52     NSRect innerFrame = frame;
53     if (self.controlSize == NSSmallControlSize) {
54         frame.origin.x += 3.5;
55         frame.origin.y += 4;
56         frame.size.width -= 7;
57         frame.size.height -= 7;
58         innerFrame = NSInsetRect(frame, 2, 2);
59     } else if (self.controlSize == NSMiniControlSize) {
60         frame.origin.x += 2;
61         frame.origin.y += 4;
62         frame.size.width -= 6.5;
63         frame.size.height -= 6.5;
64         innerFrame = NSInsetRect(frame, 4, 4);
65     }
66
67     // Set fill frame
68     NSBezierPath *backgroundPath = [NSBezierPath bezierPathWithOvalInRect:frame];
69
70     // Draw border and background
71     [NSColor.whiteColor setStroke];
72     [backgroundPath setLineWidth:1.5];
73     [backgroundPath stroke];
74
75     if ([self isEnabled]) {
76         if ([self isHighlighted]) {
77             [_normalGradient drawInBezierPath:backgroundPath angle:90.0];
78         } else {
79             [_pushedGradient drawInBezierPath:backgroundPath angle:90.0];
80         }
81     } else {
82         [[NSColor lightGrayColor] setFill];
83         [backgroundPath fill];
84     }
85
86     // Draw dot
87     if ([self integerValue] && [self isEnabled]) {
88         NSBezierPath* bezierPath = [NSBezierPath bezierPathWithOvalInRect:innerFrame];
89         [[NSColor whiteColor] setFill];
90         [bezierPath fill];
91     }
92 }
93
94 - (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView
95 {
96     NSMutableAttributedString *coloredTitle = [[NSMutableAttributedString alloc]
97                                                initWithAttributedString:title];
98     if (self.isEnabled) {
99         [coloredTitle addAttribute:NSForegroundColorAttributeName
100                              value:[NSColor whiteColor]
101                              range:NSMakeRange(0, coloredTitle.length)];
102     } else {
103         [coloredTitle addAttribute:NSForegroundColorAttributeName
104                              value:[NSColor grayColor]
105                              range:NSMakeRange(0, coloredTitle.length)];
106     }
107
108     return [super drawTitle:coloredTitle withFrame:frame inView:controlView];
109 }
110
111 @end