SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
Cocoa/GBHueSliderCell.m
1 #import "GBHueSliderCell.h"
2
3 @interface NSSliderCell(privateAPI)
4 - (double)_normalizedDoubleValue;
5 @end
6
7 @implementation GBHueSliderCell
8 {
9 bool _drawingTrack;
10 }
11
12 -(NSColor *)colorValue
13 {
14 double hue = self.doubleValue / 360.0;
15 double r = 0, g = 0, b =0 ;
16 double t = fmod(hue * 6, 1);
17 switch ((int)(hue * 6) % 6) {
18 case 0:
19 r = 1;
20 g = t;
21 break;
22 case 1:
23 r = 1 - t;
24 g = 1;
25 break;
26 case 2:
27 g = 1;
28 b = t;
29 break;
30 case 3:
31 g = 1 - t;
32 b = 1;
33 break;
34 case 4:
35 b = 1;
36 r = t;
37 break;
38 case 5:
39 b = 1 - t;
40 r = 1;
41 break;
42 }
43 return [NSColor colorWithRed:r green:g blue:b alpha:1.0];
44 }
45
46 -(void)drawKnob:(NSRect)knobRect
47 {
48 [super drawKnob:knobRect];
49 NSBezierPath *path = nil;
50 if (@available(macos 26.0, *)) {
51 NSRect peekRect = knobRect;
52 peekRect.size.height /= 2;
53 peekRect.size.width -= peekRect.size.height;
54 peekRect.origin.x += peekRect.size.height / 2;
55 peekRect.origin.y += peekRect.size.height / 2;
56 path = [NSBezierPath bezierPathWithRoundedRect:peekRect xRadius:peekRect.size.height / 2 yRadius:peekRect.size.height / 2];
57 }
58 else {
59 NSRect peekRect = knobRect;
60 peekRect.size.width /= 2;
61 peekRect.size.height = peekRect.size.width;
62 peekRect.origin.x += peekRect.size.width / 2;
63 peekRect.origin.y += peekRect.size.height / 2;
64 path = [NSBezierPath bezierPathWithOvalInRect:peekRect];
65
66 }
67 NSColor *color = self.colorValue;
68 if (!self.enabled) {
69 color = [color colorWithAlphaComponent:0.5];
70 }
71 [color setFill];
72 [path fill];
73 [[NSColor colorWithWhite:0 alpha:0.25] setStroke];
74 [path setLineWidth:0.5];
75 [path stroke];
76 }
77
78 -(double)_normalizedDoubleValue
79 {
80 if (_drawingTrack) return 0;
81 return [super _normalizedDoubleValue];
82 }
83
84 -(void)drawBarInside:(NSRect)rect flipped:(BOOL)flipped
85 {
86 if (!self.enabled) {
87 [super drawBarInside:rect flipped:flipped];
88 return;
89 }
90
91 _drawingTrack = true;
92 [super drawBarInside:rect flipped:flipped];
93 _drawingTrack = false;
94
95 NSGradient *gradient = [[NSGradient alloc] initWithColors:@[
96 [NSColor redColor],
97 [NSColor yellowColor],
98 [NSColor greenColor],
99 [NSColor cyanColor],
100 [NSColor blueColor],
101 [NSColor magentaColor],
102 [NSColor redColor],
103 ]];
104
105 rect.origin.y += rect.size.height / 2 - 0.5;
106 rect.size.height = 1;
107 rect.size.width -= 2;
108 rect.origin.x += 1;
109 [[NSColor redColor] set];
110 NSRectFill(rect);
111
112 rect.size.width -= self.knobThickness + 2;
113 rect.origin.x += self.knobThickness / 2 - 1;
114
115 [gradient drawInRect:rect angle:0];
116 }
117
118 @end
119
120 @implementation NSSlider (GBHueSlider)
121 - (NSColor *)colorValue
122 {
123 return ((GBHueSliderCell *)self.cell).colorValue;
124 }
125 @end
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.