forked from reaper-oss/sws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sws_util.mm
495 lines (455 loc) · 20.8 KB
/
sws_util.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
/******************************************************************************
/ sws_util.mm
/
/ Copyright (c) 2010 ans later Tim Payne (SWS), Jeffos, Dominik Martin Drzic
/ Permission is hereby granted, free of charge, to any person obtaining a copy
/ of this software and associated documentation files (the "Software"), to deal
/ in the Software without restriction, including without limitation the rights to
/ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
/ of the Software, and to permit persons to whom the Software is furnished to
/ do so, subject to the following conditions:
/
/ The above copyright notice and this permission notice shall be included in all
/ copies or substantial portions of the Software.
/
/ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
/ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
/ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
/ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
/ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
/ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
/ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
/ OTHER DEALINGS IN THE SOFTWARE.
/
******************************************************************************/
#import <Cocoa/Cocoa.h>
#include "stdafx.h"
void SWS_GetDateString(int time, char* buf, int bufsize)
{
NSDate* macTime = [NSDate dateWithTimeIntervalSince1970:time];
NSDateFormatter *macTimeFmt = [[[NSDateFormatter alloc] init] autorelease];
[macTimeFmt setFormatterBehavior:NSDateFormatterBehavior10_4];
[macTimeFmt setDateStyle:NSDateFormatterShortStyle];
NSString* s = [macTimeFmt stringFromDate:macTime];
[s getCString:buf maxLength:bufsize encoding:NSUTF8StringEncoding];
}
void SWS_GetTimeString(int time, char* buf, int bufsize)
{
NSDate* macTime = [NSDate dateWithTimeIntervalSince1970:time];
NSDateFormatter *macTimeFmt = [[[NSDateFormatter alloc] init] autorelease];
[macTimeFmt setFormatterBehavior:NSDateFormatterBehavior10_4];
[macTimeFmt setTimeStyle:NSDateFormatterShortStyle];
NSString* s = [macTimeFmt stringFromDate:macTime];
[s getCString:buf maxLength:bufsize encoding:NSUTF8StringEncoding];
}
static int RGBfromNSColor(NSColor *col)
{
int r = (int) ([col redComponent] * 255.0 + 0.5) ;
int g = (int) ([col greenComponent] * 255.0 + 0.5) ;
int b = (int) ([col blueComponent] * 255.0 + 0.5) ;
if (r<0)r=0; else if (r>255) r=255;
if (g<0)g=0; else if (g>255) g=255;
if (b<0)b=0; else if (b>255) b=255;
return (r << 16) | (g << 8) | b;
}
int GetCustomColors(COLORREF custColors[])
{
NSColorPanel* cp = [NSColorPanel sharedColorPanel];
id cswatch = [cp valueForKey:@"_colorSwatch"];
NSArray *colors = NULL;
int adv,n=0;
if ([cswatch respondsToSelector:@selector(readColors)])
{
[cswatch performSelector:@selector(readColors)];
colors = [cswatch valueForKey:@"colors"];
adv = 10;
n = 16;
}
else if ([cswatch respondsToSelector:@selector(savedColors)])
{
// high sierra
colors = [cswatch performSelector:@selector(savedColors)];
adv=1;
n = [colors count];
if (n > 16) n = 16;
}
if (colors) for (int i = 0; i < n; i++)
{
NSColor* col = [colors objectAtIndex:i*adv];
col = [col colorUsingColorSpaceName:@"NSCalibratedRGBColorSpace"];
custColors[i] = RGBfromNSColor(col);
}
return 0;
}
void SetCustomColors(COLORREF custColors[])
{
NSColorPanel* cp = [NSColorPanel sharedColorPanel];
id cswatch = [cp valueForKey:@"_colorSwatch"];
if ([cswatch respondsToSelector:@selector(readColors)])
{
[cswatch performSelector:@selector(readColors)];
// Get the NSColorSwatch's internal mutable array of NSColors
NSMutableArray *colors = [cswatch valueForKey:@"colors"];
if (colors) for (int i = 0; i < 16; i++)
{
NSColor* col = [NSColor colorWithCalibratedRed:(custColors[i]>>16)/255.0 green:((custColors[i]&0xFF00)>>8)/255.0 blue:(custColors[i]&0xFF)/255.0 alpha:1.0];
[colors replaceObjectAtIndex:i*10 withObject:col];
}
[cswatch performSelector:@selector(writeColors)];
}
else if ([cswatch respondsToSelector:@selector(savedColors)])
{
// high sierra -- this part doesn't seem to work yet, sadly
NSArray *colors = [cswatch performSelector:@selector(savedColors)];
NSMutableArray *newColors = colors ? [NSMutableArray arrayWithArray:colors] : [NSMutableArray arrayWithCapacity:16];
for (int i = 0; i < 16; i++)
{
NSColor* col = [NSColor colorWithCalibratedRed:(custColors[i]>>16)/255.0 green:((custColors[i]&0xFF00)>>8)/255.0 blue:(custColors[i]&0xFF)/255.0 alpha:1.0];
if (i < [newColors count])
[newColors replaceObjectAtIndex:i withObject:col];
else
[newColors addObject:col];
}
[cswatch performSelector:@selector(setSavedColors:) withObject:newColors];
}
}
void ShowColorChooser(COLORREF initialCol)
{
NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel];
NSColor* col = [NSColor colorWithCalibratedRed:(initialCol>>16)/255.0 green:((initialCol&0xFF00)>>8)/255.0 blue:(initialCol&0xFF)/255.0 alpha:1.0];
[colorPanel setColor:col];
[[NSApplication sharedApplication] orderFrontColorPanel:(id)g_hwndParent];
}
bool GetChosenColor(COLORREF* pColor)
{
if (![[NSColorPanel sharedColorPanel] isVisible])
{
if (pColor)
{
NSColor* col = [[NSColorPanel sharedColorPanel] color];
col = [col colorUsingColorSpaceName:@"NSCalibratedRGBColorSpace"];
*pColor = RGBfromNSColor(col);
}
return true;
}
return false;
}
void HideColorChooser()
{
ShowWindow((HWND)[NSColorPanel sharedColorPanel], SW_HIDE);
}
// Modified MakeCursorFromData from Cockos WDL (supports 32x32 unlike original function which supports 16x16)
static NSCursor* SWS_MakeCursorFromData(unsigned char* data, int hotspot_x, int hotspot_y)
{
NSCursor *c=NULL;
NSBitmapImageRep* bmp = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:0
pixelsWide:32
pixelsHigh:32
bitsPerSample:8
samplesPerPixel:2
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedWhiteColorSpace
bytesPerRow:(32*2)
bitsPerPixel:16];
if (bmp)
{
unsigned char* p = [bmp bitmapData];
if (p)
{
int i;
for (i = 0; i < 32*32; ++i)
{
// tried 4 bits per sample and memcpy, didn't work
p[2*i] = (data[i]&0xF0) | data[i]>>4;
p[2*i+1] = (data[i]<<4) | (data[i]&0xf);
}
NSImage *img = [[NSImage alloc] init];
if (img)
{
[img addRepresentation:bmp];
NSPoint hs = NSMakePoint(hotspot_x, hotspot_y);
c = [[NSCursor alloc] initWithImage:img hotSpot:hs];
[img release];
}
}
[bmp release];
}
return c;
}
// Modified LoadCursor from Cockos WDL
// Supports these cursors:
// IDC_GRID_WARP
// IDC_ENV_PEN_GRID, IDC_ENV_PT_ADJ_VERT
// IDC_MISC_SPEAKER
// IDC_ZOOM_DRAG, IDC_ZOOM_IN, IDC_ZOOM_OUT, IDC_ZOOM_UNDO
HCURSOR SWS_LoadCursor(int id)
{
// bytemaps are (white<<4)|(alpha)
const unsigned char B = 0xF;
const unsigned char W = 0xFF;
//const unsigned char G = 0xF8;
static NSCursor* carr[8]; // set to NULL by compiler
NSCursor** pc=0;
int index = 0;
bool found = false;
if (!found && id == IDC_ENV_PEN_GRID) found = true; else if (!found) ++index;
if (!found && id == IDC_ENV_PT_ADJ_VERT) found = true; else if (!found) ++index;
if (!found && id == IDC_GRID_WARP) found = true; else if (!found) ++index;
if (!found && id == IDC_MISC_SPEAKER) found = true; else if (!found) ++index;
if (!found && id == IDC_ZOOM_DRAG) found = true; else if (!found) ++index;
if (!found && id == IDC_ZOOM_IN) found = true; else if (!found) ++index;
if (!found && id == IDC_ZOOM_OUT) found = true; else if (!found) ++index;
if (!found && id == IDC_ZOOM_UNDO) found = true; else if (!found) ++index;
if (!found)
return NULL;
pc = &carr[index];
if (!(*pc))
{
if (id == IDC_ENV_PEN_GRID)
{
static unsigned char p[32*32] =
{
0,0,0,0,0,0,0,0,0,0,0,0,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,B,W,B,0,0,0,B,0,0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0,0,0,0,
0,0,0,0,B,B,B,0,0,B,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,B,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,B,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,B,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,B,W,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
*pc = SWS_MakeCursorFromData(p, 5, 5);
}
}
return (HCURSOR)*pc;
}
void mouse_event(DWORD dwFlags, DWORD dx, DWORD dy, DWORD dwData, ULONG_PTR dwExtraInfo)
{
CGEventRef e = NULL;
int h = CGDisplayPixelsHigh(CGMainDisplayID());
switch(dwFlags)
{
case MOUSEEVENTF_LEFTDOWN: e = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, CGPointMake(dx, h-dy), kCGMouseButtonLeft); break;
case MOUSEEVENTF_LEFTUP: e = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseUp, CGPointMake(dx, h-dy), kCGMouseButtonLeft); break;
case MOUSEEVENTF_RIGHTDOWN: e = CGEventCreateMouseEvent(NULL, kCGEventRightMouseDown, CGPointMake(dx, h-dy), kCGMouseButtonRight); break;
case MOUSEEVENTF_RIGHTUP: e = CGEventCreateMouseEvent(NULL, kCGEventRightMouseUp, CGPointMake(dx, h-dy), kCGMouseButtonRight); break;
}
if (e)
{
CGEventPost(kCGHIDEventTap, e);
CFRelease(e);
}
}
void SWS_ShowTextScrollbar(HWND hwnd, bool show)
{
if (!hwnd) return;
DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE);
if (!show) dwStyle &= ~WS_HSCROLL;
else dwStyle |= WS_HSCROLL;
SetWindowLong(hwnd, GWL_STYLE, dwStyle);
NSTextView *tv=(NSTextView*)hwnd;
[tv setHorizontallyResizable:show?NO:YES];
NSScrollView *sc = [tv enclosingScrollView];
[sc setHasHorizontalScroller:show?YES:NO];
}
void SetMenuItemSwatch(HMENU hMenu, UINT pos, int iSize, COLORREF color)
{
if (!hMenu) return;
NSMenu *m=(NSMenu *)hMenu;
NSMenuItem *item = [m itemAtIndex:pos];
NSSize size = NSMakeSize(iSize, iSize);
if (!item)
return;
if (!item.image)
item.image = [[NSImage alloc] initWithSize:(NSSize)size];
NSColor *nscolor = [NSColor colorWithCalibratedRed:GetRValue(color)/255.0f green:GetGValue(color)/255.0f blue:GetBValue(color)/255.0f alpha:1.0f];
[item.image lockFocus];
[nscolor set];
NSRectFill(NSMakeRect(0, 0, size.width, size.height));
[item.image unlockFocus];
}