macosx: Add dark UI Elements for use on HUD Panels
[vlc.git] / modules / gui / macosx / VLCHUDCheckboxCell.m
1 /*****************************************************************************
2  * VLCHUDCheckboxCell.m: Custom checkbox 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 "VLCHUDCheckboxCell.h"
25
26 @implementation VLCHUDCheckboxCell
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     }
39     return self;
40 }
41
42 - (void) drawImage:(NSImage *)image withFrame:(NSRect)frame inView:(NSView *)controlView
43 {
44     // Set frame size correctly
45     NSRect backgroundFrame = frame;
46     if (self.controlSize == NSSmallControlSize) {
47         frame.origin.x += 4;
48         frame.origin.y += 2.5;
49         frame.size.width -= 5;
50         frame.size.height -= 5;
51         backgroundFrame = NSInsetRect(frame, 1.5, 1.5);
52     } else if (self.controlSize == NSMiniControlSize) {
53         frame.origin.x += 2.5;
54         frame.origin.y += 4;
55         frame.size.width -= 5;
56         frame.size.height -= 5;
57         backgroundFrame = NSInsetRect(frame, 2, 2);
58     }
59
60     // Set fill frame
61     NSBezierPath *backgroundPath = [NSBezierPath bezierPathWithRoundedRect:backgroundFrame
62                                                                    xRadius:2
63                                                                    yRadius:2];
64
65     // Draw border and background
66     [NSColor.whiteColor setStroke];
67     [backgroundPath setLineWidth:1];
68     [backgroundPath stroke];
69
70     if([self isEnabled]) {
71         [_normalGradient drawInBezierPath:backgroundPath angle:90.0];
72     } else {
73         [[NSColor lightGrayColor] setFill];
74         NSRectFill(backgroundFrame);
75     }
76
77     // Drawing inner contents
78     //NSRect fillFrame = NSInsetRect(frame, 4, 4);
79     if([self isHighlighted]) {
80
81         //[[NSColor colorWithCalibratedWhite:0.9f alpha:1.0f] setFill];
82     } else {
83         //[[NSColor colorWithCalibratedWhite:0.8f alpha:1.0f] setFill];
84     }
85     //NSRectFill(fillFrame);
86
87     // Now drawing tick
88     if ([self intValue]) {
89         if([self isEnabled]) {
90             NSBezierPath* bezierPath = [NSBezierPath bezierPath];
91             [bezierPath moveToPoint: NSMakePoint(NSMinX(frame) + 3.0, NSMidY(frame) - 2.0)];
92             [bezierPath lineToPoint: NSMakePoint(NSMidX(frame), NSMidY(frame) + 2.0)];
93             [bezierPath lineToPoint: NSMakePoint((NSMinX(frame) + NSWidth(frame) - 1), NSMinY(frame) - 2.0)];
94             [bezierPath setLineWidth: 1.5];
95             [bezierPath stroke];
96         } else {
97             //[[NSColor blackColor] setFill];
98         }
99         //NSRectFill(NSInsetRect(frame, 6, 6));
100     }
101 }
102
103 @end