Repository navigation
Expand file tree
/
Copy pathgui_common.cpp
More file actions
745 lines (707 loc) · 20.6 KB
/
Copy pathgui_common.cpp
File metadata and controls
745 lines (707 loc) · 20.6 KB
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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
/* $Copyright: $
* Copyright (c) 2022-2025 by Steve Baker (steve.baker.llc@gmail.com)
* and Thomas Moore (darktjm@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Code in commmon with qtgui and imgui
* If one or the other is dropped, this can just be merged into the
* main qtgui/imgui code
*/
#include <unordered_map>
#include <set>
extern "C" {
#include "Aq.h"
}
#include "gui_common.h"
bool _show_menubar = true, _fullscreen = false;
// Flags for non-flag-like actions
static bool _mute = false, _keyscan = false, _lturbo = false;
// Mute is handled locally (not saved to pref file)
static int _old_vol = 0; // FIXME: read from pref file or whatever
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
romdesc _gamerom_desc = {
"Cartridge", _gamerom
};
romdesc _mainrom_desc = {
"Main (BASIC)", _mainrom, "basicrom"
};
romdesc _charrom_desc = {
"Character", _charrom, "charrom"
};
romdesc _ebrom_desc = {
"Extended BASIC", _ebrom, "ebrom"
};
struct action actions[] = {
{ "&Aq", "&About...", "Alt+H", // alt-a conflicts w/ &Aq
[]{show_about();}},
{ "&Aq", "Load &BASIC...", "Alt+B",
[]{askbasic();}},
{ "&Aq", "Change &ROMs...", "Alt+R",
[]{askroms();}},
#define RESET_ACT "RESET"
{ "&Aq", RESET_ACT, "F11",
[]{_doreset = true;}},
{ "&Aq", "&Quit", "F12",
[]{quit();}},
#define ASK_TAPE "Set &Tape File..."
{ "&Tape", ASK_TAPE, "Alt+P", // Alt+T == Tape menu
[]{asktape();}},
{ "&Tape", "Auto Ask on &Save", NULL,
[]{}, &_tape_ask_save, "tape_ask_save" },
{ "&Tape", "Auto Ask at &End", NULL,
[]{}, &_tape_ask_end, "tape_ask_end" },
{ "&Tape", "Auto Ask at &Load", NULL,
[]{}, &_tape_ask_load, "tape_ask_load" },
{ "G&UI", "Toggle &Fullscreen", "Alt+F", // imgui uses(?) Alt+Enter
[]{set_fullscreen();}, &_fullscreen, "fullscreen" },
{ "G&UI", "Show &Menu", "F10",
[]{toggle_menu();}, &_show_menubar, "menubar" },
{ "G&UI", "Bind &Keys", "Alt+K",
[]{bind_key();}},
// Non-menu acitons
// ROM actions used to be in a &ROM menu, but I llike it better as a dialog
// so they can all be set in one go, and text entries to allow manual path
// removal so they always retrieve from xdg path
{ NULL, "Set Cartridge...", "Alt+G", // Alt+C?
[]{askrom(&_gamerom_desc);}},
{ NULL, "Set BASIC ROM...", NULL,
[]{askrom(&_mainrom_desc);}},
{ NULL, "Set Character ROM...", NULL,
[]{askrom(&_charrom_desc);}},
{ NULL, "Set Extended BASIC ROM...", NULL,
[]{askrom(&_ebrom_desc);}},
{ NULL, "Use Extended BASIC", NULL,
[]{}, &_extendedbasic, "use_ebasic" },
// This makes no sense in a menu
{ NULL, "Turbo Toggle", "F1",
[]{
if(_lturbo)
_turbo |= TURBO_KEY;
else
_turbo &= ~TURBO_KEY;
win_title(_lturbo ? "Aquarius (turbo)" : "Aquarius");
}, &_lturbo},
// Volume control only barely makes sense in a menu
{ NULL, "Volume Up", NULL,
[]{
int &v = _mute ? _old_vol : _vol_shift;
if(v) {
v--;
set_config_num("snd_quiet", v);
}
}},
{ NULL, "Volume Down", NULL,
[]{
int &v = _mute ? _old_vol : _vol_shift;
if(v < 13) {
v++;
set_config_num("snd_quiet", v);
}
}},
{ NULL, "Mute Toggle", NULL,
[]{
if(_mute) {
_old_vol = _vol_shift;
_vol_shift = 15;
} else
_vol_shift = _old_vol;
}, &_mute},
// I just never thought of these as being menu items. Maybe if a future
// "other" config dialog exists, they will be moved there.
{ NULL, "Keyboard Mode Toggle", NULL,
[]{ _keymode = _keyscan ? SCAN : TIMER; }, &_keyscan, "keyscan"},
{ NULL, "Swap Joysticks", "Keypad Enter",
[]{}, &_swap_joy, "swap_joy" }
};
const size_t _num_actions = sizeof(actions)/sizeof(actions[0]);
using namespace std;
static void strip_actname(string &s)
{
// strip/ignore non-alnum except /
for(int p = s.size() - 1; p >= 0; p--)
if(!isalnum(s[p]) && s[p] != '/')
s.erase(p, 1);
else if(isupper(s[p]))
s[p] = tolower(s[p]);
}
static bool _acts_ready = false;
static unordered_map<string, int> _acts;
vector<vector<actid_t>> _chords;
const char * const dirs[] = {
"E", "ENE", "NE", "NNE", "N", "NNW", "NW", "WNW",
"W", "WSW", "SW", "SSW", "S", "SSE", "SE", "ESE"
};
actid_t parse_action(const char *act)
{
if(!act || !*act)
return 0;
// 1.._num_actions == actions[code-1] (63 max)
// +0x100 = +/- present; bits 6..7 == what:
// 0 - -
// 0x40 - +
// 0x80 - -+
// 0xc0 - +-
if(!_acts_ready) {
string n, m;
for(unsigned i = 0; i < _num_actions; i++) {
n = actions[i].name;
strip_actname(n);
if(!i || actions[i - 1].parent != actions[i].parent) {
if(actions[i].parent) {
m = actions[i].parent;
strip_actname(m);
m += '/';
}
}
_acts[n] = i + 1;
if(actions[i].parent)
_acts[m + n] = i + 1;
}
_acts_ready = true;
}
string n(act);
actid_t adj = 0;
if(n.size() > 1 && (n[0] == '+' || n[0] == '-')) {
adj += 0x100 + (n[0] == '+' ? 0x40 : 0);
if(n.size() > 2 && n[1] != n[0] && (n[1] == '-' || n[1] == '+')) {
adj += 0x80;
n.erase(0, 2);
} else
n.erase(0, 1);
}
strip_actname(n);
auto a = _acts.find(n);
if(a != _acts.end())
return a->second + adj;
// Now it must be a key or chord
const char *s = act;
int chord_id = -1;
vector<actid_t> chord;
while(1) {
// Chords are separated by +, -, or ,.
const char *p;
for(p = s; *p && *p != '+' && *p != '-' && *p != ','; p++);
// But an actual +, -, or , key is skipped
if(p == s) {
p++;
// After which there must be either a chord separator or end-of-string
if(*p && *p != '+' && *p != '-' && *p != ',') {
// parse error; FIXME: I should show a message
return 0;
}
}
// <- key is skipped as well
if(p == s + 1 && *s == '<' && *p == '-' &&
(!p[1] || p[1] == '+' || p[1] == '-' || p[1] == ','))
p++;
if(*p && chord_id < 0)
chord_id = _chords.size();
// Key
int c = p == s + 1 ? *s : 0;
if(c < 32 || c == '[' || c == ']' || c > 'z')
c = 0;
else if(isupper(c))
c = tolower(c);
if(p > s + 1) {
if(!strncasecmp(s, "SPACE", (int)(p - s)))
c = ' ';
else if(!strncasecmp(s, "RTN", (int)(p - s)))
c = '\n';
else if(!strncmp(s, "<-", (int)(p - s)) ||
!strncasecmp(s, "BS", (int)(p - s)))
c = '\b';
else if(!strncasecmp(s, "CTL", (int)(p - s)))
c = 1 - 3; // 257;
else if(!strncasecmp(s, "SHIFT", (int)(p - s)))
c = 2 - 3; // 256;
}
if(c) {
c = c < 0 ? c + 3 : findkey(c);
// plain key: 0x200 + <keyid> (_keys[] array index)
if(chord_id >= 0)
chord.push_back(c + 0x200);
else
return c + 0x200;
} else {
bool is_joy2 = false;
if(p - s < 4 || p - s > 6 || toupper(*s) != 'J' || s[2] != '_' ||
((is_joy2 = s[1] != '1' && toupper(s[1]) != 'A' && toupper(s[1]) != 'L') &&
s[1] != '2' && toupper(s[1]) != 'B' && toupper(s[1]) != 'R')) {
// parse error; FIXME: I should show a message
return 0;
}
int code = is_joy2 ? 0x100 : 0;
s += 3;
if(*s >= '1' && *s <= '6') {
if(p - s > 1) {
// parse error; FIXME: I should show a message
return 0;
}
// plain joy button: 0x400 + 0x100 * <joy> + <but>
code += 0x400 + *s - '1';
} else {
// Linear search. Don't care.
int d;
for(d = 0; d < 16; d++)
if(!strncasecmp(dirs[d], s, (int)(p - s)) && !dirs[d][(int)(p - s)])
break;
if(d == 16) {
// parser error; FIXME: I should show a message
return 0;
}
// plain joy dir: 0x1000 * <dir#> + 0x800 + 0x100 * <joy>
code += (d << 12) + 0x800;
// (axis mode)
code = -code;
}
if(chord_id >= 0)
chord.push_back(code);
else
return code;
}
if(!*p)
break;
s = p + 1;
if(!*s) {
// parse error; FIXME: I should show a message
return 0;
}
}
// multi-key/joy: 0x10000 + <chord#>
chord_id = chord_id_of(chord);
if(chord_id < 0) {
chord_id = _chords.size();
if(chord_id == (int)_chords.size())
_chords.push_back(chord);
}
return 0x10000 + chord_id;
}
int chord_id_of(vector<actid_t> &chord)
{
set<actid_t> chmap; // sort -u
for(auto a : chord)
chmap.insert(a);
chord = {};
for(auto a : chmap)
chord.push_back(a);
for(int chord_id = 0; chord_id < (int)_chords.size(); chord_id++)
if(chord == _chords[chord_id])
return chord_id;
return -1;
}
char *action_to_string(actid_t act)
{
string s;
if(!act)
return NULL;
if(act < 0)
act = -act;
if(act < 0x200) {
// 1.._num_actions == actions[code-1] (63 max)
// +0x100 = +/- present; bits 6..7 == what:
// 0 - -
// 0x40 - +
// 0x80 - -+
// 0xc0 - +-
if(act & 0x100) {
s += (act & 0x40) ? '+' : '-';
if(act & 0x80)
s += (act & 0x40) ? '-' : '+';
}
act = (act & 0x3f) - 1;
string n(actions[act].parent ? actions[act].parent : "");
if(actions[act].parent)
n += '/';
n += actions[act].name;
strip_actname(n);
s += n;
return strdup(s.c_str());
}
// multi-key/joy: 0x10000 + <chord#>
if(act >= 0x10000) {
for(auto k: _chords[act - 0x10000]) {
if(s.size())
s += '+';
char *ks = action_to_string(k);
s += ks;
free(ks);
}
return strdup(s.c_str());
}
// plain key: 0x200 + <keyid> (_keys[] array index)
if(act < 0x400) {
act &= 0x7f;
if(act == 1)
return strdup("CTL");
else if(act == 2)
return strdup("SHIFT");
else if(act == 3 + ' ')
return strdup("SPACE");
else if(act == 3 + '\n')
return strdup("RTN");
else if(act == 3 + '\b')
return strdup("<-");
char r[2] = { (char)(act - 3), 0 };
return strdup(r);
}
// plain joy button: 0x400 + 0x100 * <joy> + <but>
// plain joy dir: KV_AX + 0x1000 * <dir#> + 0x800 + 0x100 * <joy>
s = "J";
s += (act & 0x100) ? 'R' : 'L';
s += '_';
if(act < 0x800)
s += (act & 7) + '1';
else
s += dirs[act >> 12];
return strdup(s.c_str());
}
// Given an array of key/joy action codes, return all "possible" chords.
// "possible" includes the dedup'ed list of:
// - the array itself
// - any element of the array which is currently bound
// - any currently bound chord which has an element also in the array
vector<vector<actid_t>> possible_chords(vector<actid_t> chord)
{
set<vector<actid_t>> rets = { chord };
for(auto a : chord) {
if(is_bound(a))
rets.insert({a});
for(unsigned i = 0; i < _chords.size(); i++) {
auto &c = _chords[i];
for(auto e : c)
if(e == a && is_bound(0x10000 + i)) {
rets.insert(_chords[i]);
break;
}
}
}
vector<vector<actid_t>> ret;
for(auto c : rets)
ret.push_back(c);
return ret;
}
struct queued_act {
actid_t act;
Uint16 mod;
};
static vector <queued_act> _act_queue;
void queue_action(actid_t act, Uint16 mod) // mod is for key-type events
{
if(act)
_act_queue.push_back({ .act = act, .mod = mod });
}
static actid_t _asktape;
actid_t _reset_act;
#if defined(USE_QT) || defined(USE_IMGUI)
volatile bool _tape_done;
static pthread_mutex_t _asktape_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t _asktape_sig = PTHREAD_COND_INITIALIZER;
#endif
// always executed in a different thread than gui
void reqtape(void)
{
#if defined(USE_QT) || defined(USE_IMGUI)
_tape_done = false;
_act_queue.push_back({ .act = _asktape + 1, .mod = 0 });
pthread_mutex_lock(&_asktape_lock);
while(!_tape_done) {
while(pthread_cond_wait(&_asktape_sig, &_asktape_lock)) {
if(errno == EAGAIN || errno == EINTR)
continue;
perror("asktape");
exit(1);
}
}
pthread_mutex_unlock(&_asktape_lock);
#endif
}
#if defined(USE_QT) || defined(USE_IMGUI)
// called from GUI thread
void asked_tape(void)
{
pthread_mutex_lock(&_asktape_lock);
_tape_done = true;
pthread_cond_signal(&_asktape_sig);
pthread_mutex_unlock(&_asktape_lock);
}
#endif
void exec_actions(bool just_one)
{
while(_act_queue.size() > 0) {
auto act = _act_queue[0].act;
auto mod = _act_queue[0].mod;
_act_queue.erase(_act_queue.begin());
bool is_up = act < 0;
if(is_up)
act = -act;
if(act < 0x200) {
// 1.._num_actions == actions[code-1] (63 max)
// +0x100 = +/- present; bits 6..7 == what:
// 0 - -
// 0x40 - +
// 0x80 - -+
// 0xc0 - +-
unsigned ract = act & 0x3f;
if(actions[ract - 1].toggle) {
bool nval;
if(!(act & 0x80) && is_up)
return;
if(act & 0x100) {
if(act & 0x80)
nval = is_up ^ !!(act & 0x40);
else
nval = is_up ? *actions[ract - 1].toggle : !!(act & 0x40);
act &= 0x3f;
} else
nval = *actions[act - 1].toggle ^ true;
if(nval != *actions[act - 1].toggle) {
*actions[act - 1].toggle = nval;
if(actions[act - 1].pref)
set_config_bool(actions[act - 1].pref, nval);
#ifdef USE_QT
toggle_menu(act - 1);
#endif
}
} else if(is_up)
return;
actions[act - 1].f();
return;
}
// multi-key/joy: 0x10000 + <chord#>
if(act >= 0x10000) {
for(auto k: _chords[act - 0x10000])
// FIXME: these should be inserted at front, instead of back
queue_action(is_up ? -k : k, mod);
return;
}
// plain key: 0x200 + <keyid> (_keys[] array index)
if(act < 0x400) {
dokey(act & 0x7f, mod, !is_up);
return;
}
// plain joy button: 0x400 + 0x100 * <joy> + <but>
// plain joy dir: KV_AX + 0x1000 * <dir#> + 0x800 + 0x100 * <joy>
bool is_joy2 = !!(act & 0x100);
if(act < 0x800)
aqjoy_but(is_joy2, act & 7, !is_up);
else
aqjoy_dial(is_joy2, act >> 12, act & 0xff);
if(just_one)
return;
}
}
static void add_sdl_hotkeys()
{
for(unsigned i = 0; i < _num_actions; i++)
if(actions[i].def_binding) {
bind_key(actions[i].def_binding, (actid_t)i + 1);
}
aqjoy_init();
const value_t *conf = config_val("keys");
// config reader already ensures this is valid, if present
if(conf) {
for(pair_t *p = conf->o; p; p = p->next) {
const char *key = p->name, *fn = p->v.s;
if(p->v.type == VDT_NULL)
fn = NULL;
actid_t act = parse_action(fn);
if(!act && fn && *fn) {
fprintf(stderr, "warning: ignoring binding %s; action '%s' not found\n", key, fn);
continue;
}
if(!bind_key(key, act))
// this errr should never happen since it's validated by config read
fprintf(stderr, "warning: ignoring binding %s: key error\n", key);
}
}
const value_t *c = config_val("controllers");
if(c && c->type != VDT_ARRAY) {
c = NULL;
fputs("warning: ignoring controllers pref; not an array\n", stderr);
}
map_controllers(c ? c->a : NULL);
}
void init_gui_config(void)
{
// Checkbox defaults
for(unsigned i = 0; i < _num_actions; i++) {
if(actions[i].toggle && actions[i].pref) {
add_default_type(actions[i].pref, *actions[i].toggle ? VDT_TRUE : VDT_FALSE);
*actions[i].toggle = config_bool(actions[i].pref);
}
if(!strcasecmp(actions[i].name, ASK_TAPE))
_asktape = i;
else if(!strcasecmp(actions[i].name, RESET_ACT))
_reset_act = i;
}
add_default_num("snd_quiet", 0);
_vol_shift = config_num("snd_quiet");
if(_vol_shift < 0 || _vol_shift > 15)
_vol_shift = 0;
add_sdl_hotkeys();
}
void ud_rom(romdesc &real, const romdesc &tmp, const char *def)
{
if((real.where == NULL) == !tmp.buf.size() &&
(!real.where || tmp.buf == real.where))
return;
_doreset = true;
if(!tmp.where) {
real.where = def;
real.buf.clear();
if(real.pref)
set_config_str(real.pref, def);
} else if(real.pref) {
set_config_str(real.pref, tmp.buf.c_str());
real.where = config_str(real.pref);
} else {
real.buf = tmp.where;
real.where = real.buf.c_str();
}
}
// Dummy functions for non-gui
#if !defined(USE_IMGUI) && !defined(USE_QT)
void askbasic() {}
void askroms() {}
void bind_key() {}
void toggle_menu() {}
void show_about() {}
void askrom(_U romdesc *rom) {}
void asktape(void){}
extern float turbo_rate;
void win_title(_U const char *s)
{
if (_turbo) {
char title[K];
sprintf(title, "%s (turbo %.2fx)", s, turbo_rate);
SDL_SetWindowTitle(_window, title);
} else {
SDL_SetWindowTitle(_window, s);
}
}
#endif
#ifndef USE_QT
void set_fullscreen()
{
SDL_SetWindowFullscreen(_window, _fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
}
#endif
static pthread_t _evthread;
static pthread_mutex_t _evlock = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t _evsig = PTHREAD_COND_INITIALIZER;
static volatile bool _evshutdown = false;
static void *sdl_events(_U void *parm)
{
pthread_mutex_lock(&_evlock);
while(!_evshutdown) {
SDL_Event event;
struct timespec t;
clock_gettime(CLOCK_REALTIME, &t);
while(!_evshutdown && SDL_PollEvent(&event)) {
if(event.type == SDL_QUIT) {
quit();
break;
}
// FIXME: if capturing, left/right mouse click terminate capture
#ifdef USE_IMGUI
if(!_capturing && imgui_event(&event))
continue;
#endif
if(sdl_event(&event, queue_action))
continue;
// process key events
if ((event.type == SDL_KEYUP || event.type == SDL_KEYDOWN) &&
event.key.keysym.sym <= 128)
dokey(event.key.keysym.sym, event.key.keysym.mod, event.type == SDL_KEYDOWN);
}
if(_evshutdown)
break;
sdl_event(NULL, queue_action); // process stick events
#if !defined(USE_IMGUI) && !defined(USE_QT)
// not compatible with capturing, but capturing only done in GUI
exec_actions(false);
#endif
// loop every 1/60th of a second
t.tv_nsec += 1000000000UL/60;
if(t.tv_nsec >= 1000000000L) {
t.tv_nsec -= 1000000000L;
t.tv_sec++;
}
pthread_cond_timedwait(&_evsig, &_evlock, &t);
}
pthread_mutex_unlock(&_evlock);
return NULL;
}
void start_sdl_events(void)
{
static bool running = false;
if(running || _batchmode)
return;
running = true;
if(pthread_create(&_evthread, NULL, sdl_events, NULL)) {
perror("sdl event thread");
exit(1);
}
}
void stop_sdl_events(void)
{
// this is never called before start_(), so no need to check validity
_evshutdown = true; // kill thread next opportunity
if(!_batchmode && pthread_self() != _evthread) {
// wake thread if sleeping; will then exit seeing _evshutdown
pthread_mutex_lock(&_evlock);
pthread_cond_signal(&_evsig);
pthread_mutex_unlock(&_evlock);
// wait for thread to completely finish
pthread_join(_evthread, NULL);
}
}
/* Support for bindkey dialog */
#if defined(USE_QT) || defined(USE_IMGUI)
/* each row 1/2 char to right, unless left key 1.5-char wide */
const char * const aqkeys[] = { /* Primary labels */
/* top row, 13 keys (RST is blue on white; all others white on blue) */
"RST", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=",
/* row 2, 13 keys */
"CTL", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "/", "<-",
/* row 3, 12 keys */ /* SHIFT is 1.5 spaces wide */
"SHIFT", "A", "S", "D", "F", "G", "H", "J", "K", "L", ":", ";",
/* row 4, 11 keys */ /* SPACE & RTN are 1.5 spaces wide */
"SPACE", "Z", "X", "C", "V", "B", "N", "M", ".", ",", "RTN"
};
const int _row_nkeys[] = { 13, 13, 12, 11 }; // 49 total
const char aqkeys_shift[] = /* Shifted labels, upper-right */
/* always 1 char, so it's a string rather than array of strings */
/* row 1, 13 keys */ /* _, + are centered rather than upper-right */
" !\"#$%^'()?_+"
/* row 2, 13 keys */
" ^\\"
/* row 3, 12 keys */
" @*"
/* row 4, 11 keys */
" <> ";
const char * const aqkeys_ctl[] = { /* CTL labels, above key blue on black */
/* row 1, 13 keys */
0, "RUN", "LIST", "IF", "THEN", "GOTO", "ON", "GOSUB", "RETURN", "COPY", 0, "FOR", "NEXT",
/* row 2, 13 keys */
0, 0, "REM", "DIM", "RETURN", "INPUT", 0, 0, 0, 0, 0, 0, 0,
/* row 3, 12 keys */
0, "CSAVE", "STPLST", "READ", "DATA", "BELL", 0, "PSET", "PRESET", "POINT", "POKE", "PEEK",
/* row 4, 11 keys */
"CHR$", "CLOAD", "DELINE", "STOP", "LEFT$", "MID$", "RIGHT$", 0, "STR$", "VAL", 0
};
#endif