-
Notifications
You must be signed in to change notification settings - Fork 1
/
SPInfoView.mm
299 lines (246 loc) · 9.28 KB
/
SPInfoView.mm
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#import "SPInfoContainerView.h"
#import "SPColorProvider.h"
#import "SPPreferencesController.h"
#import "SPInfoView.h"
@implementation SPInfoView
// ----------------------------------------------------------------------------
- (void) awakeFromNib
// ----------------------------------------------------------------------------
{
[[SPPreferencesController sharedInstance] load];
index = 0;
collapsedHeight = 19.0f;
height = 128.0f;
container = (SPInfoContainerView*) [self superview];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(containerBackgroundChanged:) name:SPInfoContainerBackgroundChangedNotification object:nil];
[self containerBackgroundChanged:nil];
}
// ----------------------------------------------------------------------------
- (void) mouseDown:(NSEvent*)event
// ----------------------------------------------------------------------------
{
NSPoint mousePosition = [event locationInWindow];
NSPoint mousePositionInView = [self convertPoint:mousePosition fromView:nil];
if ((mousePositionInView.y > ([self currentHeight] - 15.0f)) && ([event clickCount] > 1))
{
BOOL collapsed = !isCollapsed;
[disclosureTriangle setState:collapsed ? 0 : 1];
[self collapse:disclosureTriangle];
}
}
// ----------------------------------------------------------------------------
- (void) drawRect:(NSRect)rect
// ----------------------------------------------------------------------------
{
// rect = [self bounds];
//
// NSColor* darkColor = nil;
// NSColor* brightColor = nil;
// if ([container hasDarkBackground])
// {
// darkColor = [NSColor colorWithDeviceRed:0.117f green:0.117f blue:0.117f alpha:1.0f];
// brightColor = [NSColor colorWithDeviceRed:0.321f green:0.321f blue:0.321f alpha:1.0f];
// }
// else
// {
// darkColor = [NSColor colorWithDeviceRed:0.381f green:0.381f blue:0.381f alpha:1.0f];
// brightColor = [NSColor colorWithDeviceRed:0.838f green:0.838f blue:0.838f alpha:1.0f];
// }
//
// float middle = rect.size.width * 0.5f;
// float ditchSize = 5.5f;
// float ypos = rect.origin.y + rect.size.height - 1.5f;
//
// [NSBezierPath setDefaultLineWidth:1.0f];
// NSBezierPath* path = [NSBezierPath bezierPath];
//
// [path moveToPoint:NSMakePoint(rect.origin.x, ypos)];
// [path lineToPoint:NSMakePoint(rect.origin.x + (middle - ditchSize), ypos)];
// [path lineToPoint:NSMakePoint(rect.origin.x + middle, ypos - ditchSize)];
// [path lineToPoint:NSMakePoint(rect.origin.x + (middle + ditchSize), ypos)];
// [path lineToPoint:NSMakePoint(rect.origin.x + rect.size.width, ypos)];
//
// [darkColor set];
// [path stroke];
//
// ypos -= 1.0f;
// path = [NSBezierPath bezierPath];
// [path moveToPoint:NSMakePoint(rect.origin.x, ypos)];
// [path lineToPoint:NSMakePoint(rect.origin.x + (middle - ditchSize), ypos)];
// [path lineToPoint:NSMakePoint(rect.origin.x + middle, ypos - ditchSize)];
// [path lineToPoint:NSMakePoint(rect.origin.x + (middle + ditchSize), ypos)];
// [path lineToPoint:NSMakePoint(rect.origin.x + rect.size.width - 1.0f, ypos)];
//
// [brightColor set];
// [path stroke];
[super drawRect:rect];
}
// ----------------------------------------------------------------------------
- (IBAction) collapse:(id)sender
// ----------------------------------------------------------------------------
{
int state = [sender state];
// Better solution: disable disclosure cells of all info views during animation
if ([container isAnimating])
{
[sender setState:(state == NSOnState) ? NSOffState : NSOnState];
return;
}
if (state == NSOnState)
[self setCollapsed:NO];
else
[self setCollapsed:YES];
switch (index)
{
case TUNEINFO_CONTAINER_INDEX:
gPreferences.mTuneInfoCollapsed = isCollapsed;
break;
case OSCILLOSCOPE_CONTAINER_INDEX:
gPreferences.mOscilloscopeCollapsed = isCollapsed;
break;
case SIDREGISTER_CONTAINER_INDEX:
gPreferences.mSidRegistersCollapsed = isCollapsed;
break;
case MIXER_CONTAINER_INDEX:
gPreferences.mMixerCollapsed = isCollapsed;
break;
case FILTER_CONTAINER_INDEX:
gPreferences.mFilterControlCollapsed = isCollapsed;
break;
// case COMPOSER_CONTAINER_INDEX:
// gPreferences.mComposerPhotoCollapsed = isCollapsed;
break;
}
[disclosureTriangle setEnabled:NO];
[container positionSubviewsWithAnimation:YES];
}
// ----------------------------------------------------------------------------
- (BOOL) isCollapsed
// ----------------------------------------------------------------------------
{
return isCollapsed;
}
// ----------------------------------------------------------------------------
- (void) setCollapsed:(BOOL)flag
// ----------------------------------------------------------------------------
{
isCollapsed = flag;
[disclosureTriangle setState:flag ? 0 : 1];
}
// ----------------------------------------------------------------------------
- (float) currentHeight
// ----------------------------------------------------------------------------
{
return isCollapsed ? collapsedHeight : height;
}
// ----------------------------------------------------------------------------
- (float) collapsedHeight
// ----------------------------------------------------------------------------
{
return collapsedHeight;
}
// ----------------------------------------------------------------------------
- (float) height
// ----------------------------------------------------------------------------
{
return height;
}
// ----------------------------------------------------------------------------
- (SPInfoContainerView*) container
// ----------------------------------------------------------------------------
{
return container;
}
// ----------------------------------------------------------------------------
- (NSButton*) disclosureTriangle;
// ----------------------------------------------------------------------------
{
return disclosureTriangle;
}
// ----------------------------------------------------------------------------
- (void) containerBackgroundChanged:(NSNotification *)aNotification
// ----------------------------------------------------------------------------
{
if ([[disclosureTriangle cell] class] == [SPDisclosureCell class])
{
SPDisclosureCell* cell = [disclosureTriangle cell];
if ([container hasDarkBackground])
{
[cell setBackgroundIsDark:YES];
[cell setBackgroundColor:[container backgroundColor]];
[titleText setTextColor:[NSColor whiteColor]];
}
else
{
[cell setBackgroundIsDark:NO];
[titleText setTextColor:[NSColor blackColor]];
}
}
}
@end
#pragma mark -
@implementation SPDisclosureCell
static NSImage* SPHudDisclosureCollapsed = nil;
static NSImage* SPHudDisclosureExpanded = nil;
static NSImage* SPHudDisclosureTransient = nil;
// ----------------------------------------------------------------------------
- (void) awakeFromNib
// ----------------------------------------------------------------------------
{
if (SPHudDisclosureCollapsed == nil)
{
SPHudDisclosureCollapsed = [NSImage imageNamed:@"disclosure_collapsed"];
SPHudDisclosureExpanded = [NSImage imageNamed:@"disclosure_expanded"];
SPHudDisclosureTransient = [NSImage imageNamed:@"disclosure_transient"];
}
}
// ----------------------------------------------------------------------------
- (void) setBackgroundIsDark:(BOOL)flag
// ----------------------------------------------------------------------------
{
backgroundIsDark = flag;
}
// ----------------------------------------------------------------------------
- (void) highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView *)controlView
// ----------------------------------------------------------------------------
{
if (backgroundIsDark)
{
NSImage* image = [(NSButton*)controlView state] == 1 ? SPHudDisclosureExpanded : SPHudDisclosureCollapsed;
NSRect imageRect = NSMakeRect(0.0f, 0.0f, [image size].width, [image size].height);
NSRect imageFrame = imageRect;
imageFrame.origin.x = (cellFrame.size.width - imageRect.size.width) / 2.0f;
imageFrame.origin.y = (cellFrame.size.height - imageRect.size.height) / 2.0f;
[image setFlipped:[controlView isFlipped]];
if (flag)
{
[image drawInRect:imageFrame fromRect:imageRect operation:NSCompositePlusDarker fraction:1.0f];
[image drawInRect:imageFrame fromRect:imageRect operation:NSCompositePlusDarker fraction:1.0f];
[image drawInRect:imageFrame fromRect:imageRect operation:NSCompositePlusDarker fraction:1.0f];
}
else
[image drawInRect:imageFrame fromRect:imageRect operation:NSCompositeSourceOver fraction:1.0f];
}
else
{
[super highlight:flag withFrame:cellFrame inView:controlView];
}
}
// ----------------------------------------------------------------------------
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
// ----------------------------------------------------------------------------
{
if (backgroundIsDark)
{
NSImage* image = [(NSButton*)controlView state] == 1 ? SPHudDisclosureExpanded : SPHudDisclosureCollapsed;
NSRect imageRect = NSMakeRect(0.0f, 0.0f, [image size].width, [image size].height);
NSRect imageFrame = imageRect;
imageFrame.origin.x = (cellFrame.size.width - imageRect.size.width) / 2.0f;
imageFrame.origin.y = (cellFrame.size.height - imageRect.size.height) / 2.0f;
[image setFlipped:[controlView isFlipped]];
[image drawInRect:imageFrame fromRect:imageRect operation:NSCompositeSourceOver fraction:1.0f];
}
else
[super drawWithFrame:cellFrame inView:controlView];
}
@end