macOS: Correct target to 10.7 for AudioEffects xib
[vlc.git] / modules / gui / macosx / VLCHUDRadiobuttonCell.m
1 //
2 //  VLCHUDRadiobuttonCell.m
3 //  BGHUDAppKit
4 //
5 //  Created by BinaryGod on 5/25/08.
6 //
7 //  Copyright (c) 2008, Tim Davis (BinaryMethod.com, binary.god@gmail.com)
8 //  All rights reserved.
9 //
10 //  Redistribution and use in source and binary forms, with or without modification,
11 //  are permitted provided that the following conditions are met:
12 //
13 //              Redistributions of source code must retain the above copyright notice, this
14 //      list of conditions and the following disclaimer.
15 //
16 //              Redistributions in binary form must reproduce the above copyright notice,
17 //      this list of conditions and the following disclaimer in the documentation and/or
18 //      other materials provided with the distribution.
19 //
20 //              Neither the name of the BinaryMethod.com nor the names of its contributors
21 //      may be used to endorse or promote products derived from this software without
22 //      specific prior written permission.
23 //
24 //      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND
25 //      ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 //      WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 //      IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 //      INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 //      BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
30 //      OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 //      WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 //      ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 //      POSSIBILITY OF SUCH DAMAGE.
34
35 #import "VLCHUDRadiobuttonCell.h"
36
37 @implementation VLCHUDRadiobuttonCell
38
39 - (instancetype) initWithCoder:(NSCoder *)coder
40 {
41     self = [super initWithCoder:coder];
42     if (self) {
43         _normalGradient    = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceRed:0.251f green:0.251f blue:0.255f alpha:1.0f]
44                                                            endingColor:[NSColor colorWithDeviceRed:0.118f green:0.118f blue:0.118f alpha:1.0f]];
45         _highlightGradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceRed:0.451f green:0.451f blue:0.455f alpha:1.0f]
46                                                            endingColor:[NSColor colorWithDeviceRed:0.318f green:0.318f blue:0.318f alpha:1.0f]];
47         _pushedGradient    = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceRed:0.451f green:0.451f blue:0.455f alpha:1.0f]
48                                                            endingColor:[NSColor colorWithDeviceRed:0.318f green:0.318f blue:0.318f alpha:1.0f]];
49         _textColor         = [NSColor whiteColor];
50     }
51     return self;
52 }
53
54 - (void) drawImage:(NSImage *)image withFrame:(NSRect)frame inView:(NSView *)controlView
55 {
56     // Set text color
57     NSMutableAttributedString *colorTitle = [[NSMutableAttributedString alloc] initWithAttributedString:self.attributedTitle];
58     NSRange titleRange = NSMakeRange(0, [colorTitle length]);
59     [colorTitle addAttribute:NSForegroundColorAttributeName value:_textColor range:titleRange];
60     [self setAttributedTitle:colorTitle];
61
62     // Set frame size correctly
63     NSRect innerFrame = frame;
64     if (self.controlSize == NSSmallControlSize) {
65         frame.origin.x += 3.5;
66         frame.origin.y += 4;
67         frame.size.width -= 7;
68         frame.size.height -= 7;
69         innerFrame = NSInsetRect(frame, 2, 2);
70     } else if (self.controlSize == NSMiniControlSize) {
71         frame.origin.x += 2;
72         frame.origin.y += 4;
73         frame.size.width -= 6.5;
74         frame.size.height -= 6.5;
75         innerFrame = NSInsetRect(frame, 4, 4);
76     }
77
78     // Set fill frame
79     NSBezierPath *backgroundPath = [NSBezierPath bezierPathWithOvalInRect:frame];
80
81     // Draw border and background
82     [NSColor.whiteColor setStroke];
83
84     [NSGraphicsContext saveGraphicsState];
85     if ([super showsFirstResponder] && [[[self controlView] window] isKeyWindow] &&
86         ([self focusRingType] == NSFocusRingTypeDefault ||
87          [self focusRingType] == NSFocusRingTypeExterior)) {
88         NSSetFocusRingStyle(NSFocusRingOnly);
89     }
90     [backgroundPath setLineWidth:1.5];
91     [backgroundPath stroke];
92     [NSGraphicsContext restoreGraphicsState];
93
94     if ([self isEnabled]) {
95         if ([self isHighlighted]) {
96             [_normalGradient drawInBezierPath:backgroundPath angle:90.0];
97         } else {
98             [_pushedGradient drawInBezierPath:backgroundPath angle:90.0];
99         }
100     } else {
101         [[NSColor lightGrayColor] setFill];
102         [backgroundPath fill];
103     }
104
105     // Draw dot
106     if ([self integerValue] && [self isEnabled]) {
107         NSBezierPath* bezierPath = [NSBezierPath bezierPathWithOvalInRect:innerFrame];
108         [[NSColor whiteColor] setFill];
109         [bezierPath fill];
110     }
111 }
112
113 - (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView
114 {
115     NSMutableAttributedString *coloredTitle = [title mutableCopy];
116
117     if (self.isEnabled) {
118         [coloredTitle addAttribute:NSForegroundColorAttributeName
119                              value:[NSColor whiteColor]
120                              range:NSMakeRange(0, coloredTitle.length)];
121     } else {
122         [coloredTitle addAttribute:NSForegroundColorAttributeName
123                              value:[NSColor grayColor]
124                              range:NSMakeRange(0, coloredTitle.length)];
125     }
126
127     return [super drawTitle:coloredTitle withFrame:frame inView:controlView];
128 }
129
130 @end