forked from AlessandroSangiuliano/rik.theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRikScrollerArrowCell.m
155 lines (144 loc) · 5.96 KB
/
RikScrollerArrowCell.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <AppKit/AppKit.h>
#include "RikScrollerArrowCell.h"
#include "Rik.h"
@implementation RikScrollerArrowCell
- (void) setArrowType: (RikScrollerArrowType) t
{
scroller_arrow_type = t;
}
// TS: 2024-12-31
// An original version of this file apparently invoked this method
// from NSButtonCell.
// However, more modern compilers do not allow access from outside of the class.
// The solution is to copy this method from NSButtonCell and then
// modified slightly to use accessors instead of instance variables.
- (GSThemeControlState) themeControlState
{
unsigned mask;
GSThemeControlState buttonState = GSThemeNormalState;
// set the mask
// if (_cell.is_highlighted)
if ([self isHighlighted] == YES)
{
mask = _highlightsByMask;
// if (_cell.state)
if ([self state] != 0)
{
mask &= ~_showAltStateMask;
}
}
// else if (_cell.state)
else if ([self state] != 0)
mask = _showAltStateMask;
else
mask = NSNoCellMask;
/* Determine the background color.
We draw when there is a border or when highlightsByMask
is NSChangeBackgroundCellMask or NSChangeGrayCellMask,
as required by our nextstep-like look and feel. */
if (mask & (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
{
buttonState = GSThemeHighlightedState;
}
/* Pushed in buttons contents are displaced to the bottom right 1px. */
if (mask & NSPushInCellMask)
{
buttonState = GSThemeSelectedState;
}
if (_cell.is_disabled && buttonState != GSThemeHighlightedState)
{
buttonState = GSThemeDisabledState;
}
/* If we are first responder, change to the corresponding
first responder state. Note that GSThemeDisabledState
doesn't have a first responder variant, currently. */
if (_cell.shows_first_responder
&& [[[self controlView] window] firstResponder] == [self controlView]
&& [self controlView] != nil)
{
if (buttonState == GSThemeSelectedState)
buttonState = GSThemeSelectedFirstResponderState;
else if (buttonState == GSThemeHighlightedState)
buttonState = GSThemeHighlightedFirstResponderState;
else if (buttonState == GSThemeNormalState)
buttonState = GSThemeFirstResponderState;
}
return buttonState;
}
- (void) drawBezelWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
{
GSThemeControlState buttonState = [self themeControlState];
NSBezierPath * path = [self pathForFrame: cellFrame];
[(Rik*)[GSTheme theme] drawPathButton: path
in: self
state: buttonState];
}
- (NSBezierPath*) pathForFrame: (NSRect)cellFrame
{
CGFloat r = 3;
cellFrame = NSInsetRect(cellFrame, 1, 1);
cellFrame.origin.x += 0.5;
cellFrame.origin.y += 0.5;
NSRect innerRect = NSInsetRect(cellFrame, r, r);
NSBezierPath* path = [NSBezierPath bezierPath];
switch(scroller_arrow_type)
{
case RikScrollerArrowLeft:
cellFrame.origin.x += 1.0;
[path appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(innerRect), NSMinY(innerRect))
radius: r
startAngle: 180
endAngle: 270];
[path lineToPoint: NSMakePoint(NSMaxX(cellFrame), NSMinY(cellFrame))];
[path lineToPoint: NSMakePoint(NSMaxX(cellFrame), NSMaxY(cellFrame))];
[path appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(innerRect), NSMaxY(innerRect))
radius: r
startAngle: 90
endAngle: 180];
[path closePath];
break;
case RikScrollerArrowRight:
cellFrame.origin.x -= 1.0;
[path moveToPoint: NSMakePoint(NSMinX(cellFrame), NSMinY(cellFrame))];
[path appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(innerRect), NSMinY(innerRect))
radius: r
startAngle: 270
endAngle: 360];
[path appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(innerRect), NSMaxY(innerRect))
radius: r
startAngle: 0
endAngle: 90];
[path lineToPoint: NSMakePoint(NSMinX(cellFrame), NSMaxY(cellFrame))];
break;
case RikScrollerArrowDown:
cellFrame.origin.y -= 1.0;
[path moveToPoint: NSMakePoint(NSMinX(cellFrame), NSMinY(cellFrame))];
[path moveToPoint: NSMakePoint(NSMaxX(cellFrame), NSMinY(cellFrame))];
[path appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(innerRect), NSMaxY(innerRect))
radius: r
startAngle: 0
endAngle: 90];
[path appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(innerRect), NSMaxY(innerRect))
radius: r
startAngle: 90
endAngle: 180];
[path lineToPoint: NSMakePoint(NSMinX(cellFrame), NSMinY(cellFrame))];
break;
case RikScrollerArrowUp:
cellFrame.origin.y += 1.0;
[path appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(innerRect), NSMinY(innerRect))
radius: r
startAngle: 180
endAngle: 270];
[path appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(innerRect), NSMinY(innerRect))
radius: r
startAngle: 270
endAngle: 360];
[path lineToPoint: NSMakePoint(NSMaxX(cellFrame), NSMaxY(cellFrame))];
[path lineToPoint: NSMakePoint(NSMinX(cellFrame), NSMaxY(cellFrame))];
[path closePath];
break;
}
return path;
}
@end