macOS: Correct target to 10.7 for AudioEffects xib
[vlc.git] / modules / gui / macosx / VLCHUDButtonCell.m
1 //
2 //  VLCHUDButtonCell.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 "VLCHUDButtonCell.h"
36
37 @implementation VLCHUDButtonCell
38
39 - (instancetype) initWithCoder:(NSCoder *)coder
40 {
41     self = [super initWithCoder:coder];
42     if (self) {
43         _disabledGradient  = [[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         _normalGradient    = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceRed:0.251f green:0.251f blue:0.255f alpha:0.7f]
46                                                            endingColor:[NSColor colorWithDeviceRed:0.118f green:0.118f blue:0.118f alpha:0.7f]];
47         _highlightGradient = [[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         _pushedGradient    = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceRed:0.451f green:0.451f blue:0.455f alpha:1.0f]
50                                                            endingColor:[NSColor colorWithDeviceRed:0.318f green:0.318f blue:0.318f alpha:1.0f]];
51         _enabledTextColor  = [NSColor whiteColor];
52         _disabledTextColor = [NSColor grayColor];
53     }
54     return self;
55 }
56
57 - (void) drawBezelWithFrame:(NSRect)frame inView:(NSView *)controlView
58 {
59     // Set frame to the correct size
60     frame.size.height = self.cellSize.height;
61
62     // Inset rect to have enough room for the stroke
63     frame = NSInsetRect(frame, 1, 1);
64     if (self.bezelStyle == NSRoundRectBezelStyle) {
65         [self drawRoundRectButtonBezelInRect:frame];
66     } else {
67         [super drawBezelWithFrame:frame inView:controlView];
68     }
69 }
70
71 - (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView
72 {
73     NSMutableAttributedString *coloredTitle = [[NSMutableAttributedString alloc]
74                                                initWithAttributedString:title];
75     if (self.isEnabled) {
76         [coloredTitle addAttribute:NSForegroundColorAttributeName
77                              value:_enabledTextColor
78                              range:NSMakeRange(0, coloredTitle.length)];
79     } else {
80         [coloredTitle addAttribute:NSForegroundColorAttributeName
81                              value:_disabledTextColor
82                              range:NSMakeRange(0, coloredTitle.length)];
83     }
84
85     return [super drawTitle:coloredTitle withFrame:frame inView:controlView];
86 }
87
88 - (void) drawRoundRectButtonBezelInRect:(NSRect)rect
89 {
90     NSBezierPath *path;
91     if (self.controlSize == NSMiniControlSize) {
92         rect = NSInsetRect(rect, 1.0, 2.0);
93         path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:3.0 yRadius:3.0];
94     } else {
95         path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:8.0 yRadius:8.0];
96     }
97     if (self.highlighted) {
98         [_pushedGradient drawInBezierPath:path angle:90.0f];
99     } else if (!self.enabled) {
100         [_disabledGradient drawInBezierPath:path angle:90.0f];
101     } else {
102         [_normalGradient drawInBezierPath:path angle:90.0f];
103     }
104     [[NSColor colorWithCalibratedWhite:1.0 alpha:1.0] setStroke];
105     [path setLineWidth:1.0];
106     [path stroke];
107 }
108
109 @end