macOS: Change license of some VLCHUD classes
[vlc.git] / modules / gui / macosx / VLCHUDCheckboxCell.m
1 //
2 //  VLCHUDCheckboxCell.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 "VLCHUDCheckboxCell.h"
36
37 @implementation VLCHUDCheckboxCell
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     }
50     return self;
51 }
52
53 - (void) drawImage:(NSImage *)image withFrame:(NSRect)frame inView:(NSView *)controlView
54 {
55     // Set frame size correctly
56     NSRect backgroundFrame = frame;
57     if (self.controlSize == NSSmallControlSize) {
58         frame.origin.x += 4;
59         frame.origin.y += 2.5;
60         frame.size.width -= 5;
61         frame.size.height -= 5;
62         backgroundFrame = NSInsetRect(frame, 1.5, 1.5);
63     } else if (self.controlSize == NSMiniControlSize) {
64         frame.origin.x += 2.5;
65         frame.origin.y += 4;
66         frame.size.width -= 5;
67         frame.size.height -= 5;
68         backgroundFrame = NSInsetRect(frame, 2, 2);
69     }
70
71     // Set fill frame
72     NSBezierPath *backgroundPath = [NSBezierPath bezierPathWithRoundedRect:backgroundFrame
73                                                                    xRadius:2
74                                                                    yRadius:2];
75
76     // Draw background and stroke
77     if([self isEnabled]) {
78         if ([self isHighlighted]) {
79             [_highlightGradient drawInBezierPath:backgroundPath angle:90.0];
80         } else {
81             [_normalGradient drawInBezierPath:backgroundPath angle:90.0];
82         }
83         [[NSColor whiteColor] setStroke];
84     } else {
85         [[NSColor colorWithCalibratedWhite:0.25 alpha:1.0] setStroke];
86     }
87
88     [backgroundPath setLineWidth:1.0];
89     [backgroundPath stroke];
90
91     // Now drawing tick
92     if ([self intValue]) {
93         NSBezierPath* bezierPath = [NSBezierPath bezierPath];
94         [bezierPath moveToPoint: NSMakePoint(NSMinX(frame) + 3.0, NSMidY(frame) - 2.0)];
95         [bezierPath lineToPoint: NSMakePoint(NSMidX(frame), NSMidY(frame) + 2.0)];
96         [bezierPath lineToPoint: NSMakePoint((NSMinX(frame) + NSWidth(frame) - 1), NSMinY(frame) - 2.0)];
97         [bezierPath setLineWidth: 1.5];
98
99         if([self isEnabled]) {
100             [[NSColor whiteColor] setStroke];
101         } else {
102             [[NSColor colorWithCalibratedWhite:0.25 alpha:1.0] setStroke];
103         }
104         [bezierPath stroke];
105     }
106 }
107
108 @end