-
Notifications
You must be signed in to change notification settings - Fork 15
/
gui.c
executable file
·8846 lines (7532 loc) · 272 KB
/
gui.c
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
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** Abandon all hope all ye who enter here
** (consider this fair warning)
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#ifdef __SDL_WRAPPER__
#include <unistd.h>
#endif
#include <system_includes.h>
#include "replay.h"
#include "gui.h"
#include "util.h"
#include "about.h"
#include "undo.h"
#ifdef __APPLE__
char *osxGetPrefsPath(void);
char *osxGetResourcesPath(char *, const char*);
#endif
#ifndef __SDL_WRAPPER__
struct Library *IntuitionBase = NULL;
struct Library *P96Base = NULL;
struct Library *GfxBase = NULL;
struct Library *DataTypesBase = NULL;
struct Library *DiskfontBase = NULL;
struct Library *AslBase = NULL;
struct Library *KeymapBase = NULL;
struct Library *RequesterBase = NULL;
struct IntuitionIFace *IIntuition = NULL;
struct P96IFace *IP96 = NULL;
struct GraphicsIFace *IGraphics = NULL;
struct DataTypesIFace *IDataTypes = NULL;
struct DiskfontIFace *IDiskfont = NULL;
struct AslIFace *IAsl = NULL;
struct KeymapIFace *IKeymap = NULL;
struct RequesterIFace *IRequester = NULL;
struct InputEvent iev;
struct Window *mainwin = NULL;
struct Window *prefwin = NULL;
struct Screen *scr = NULL;
struct Gadget gad_drag;
struct Gadget gad_drag2;
struct Gadget gad_depth;
#else
struct SDL_Surface *ssrf = NULL;
BOOL needaflip = FALSE;
extern int srfdepth;
extern SDL_Event event;
extern int16 rp_audiobuffer[];
extern uint32 rp_audiobuflen;
extern BOOL aboutwin_open;
#endif
BOOL gui_savethem;
#ifndef __SDL_WRAPPER__
int32 gui_tick_signum = -1;
uint32 gui_tick_sig = 0;
uint32 mainwin_sig = 0;
uint32 prefwin_sig = 0;
uint32 gui_sigs = 0;
extern int8 *rp_audiobuffer[];
#endif
int16 pw_x = -1, pw_y = -1;
int16 pw_bl = 0, pw_bt = 0;
int32 basekey = 24;
uint8 *cbpbuf = NULL;
uint32 cbpblen = 0;
uint16 cbplcol = 0;
uint16 cbprcol = 0;
uint16 cbpchns = 0;
uint16 cbprows = 0;
extern uint32 rp_audiobuflen;
#define TRACKED_X 3
#define TRACKED_Y 324
#define TRACKED_W 740
#define TRACKED_H 272
#define TRACKED_MX (TRACKED_W-1)
#define TRACKED_MY (TRACKED_H-1)
#define POSED_X 298
#define POSED_Y 190
#define POSED_W 316
#define POSED_H 98
#define POSED_MX (POSED_W-1)
#define POSED_MY (POSED_H-1)
#define INSLIST_X 622
#define INSLIST_Y 152
#define INSLIST_W 168
#define INSLIST_H 136
#define INSLIST_MX (INSLIST_W-1)
#define INSLIST_MY (INSLIST_H-1)
#define PERF_X 291
#define PERF_Y 144
#define PERF_W 146
#define PERF_H 438
#define PERF_MX (PERF_W-1)
#define PERF_MY (PERF_H-1)
#define INSLSTB_X 474
#define INSLSTB_Y 144
#define INSLSTB_W 168
#define INSLSTB_H 438
#define INSLSTB_MX (INSLSTB_W-1)
#define INSLSTB_MY (INSLSTB_H-1)
int32 qual;
BOOL qualRMB = FALSE;
//BOOL qualShift=FALSE, qualCtrl=FALSE, qualRMB=FALSE, qualAlt, qualAmiga;
extern struct List *rp_tunelist;
extern struct SignalSemaphore *rp_list_ss;
struct ahx_tune *curtune = NULL;
extern struct ahx_tune *rp_curtune;
struct ahx_instrument *perf_lastinst = NULL;
int32 perf_laststep = -1;
int32 perf_lastcx = -1;
int32 perf_lastcy = -1;
int32 perf_lastplen = -1;
struct ahx_tune *tmr_lasttune = NULL;
uint32 tmr_lasttime = 0;
int32 vum_last[MAX_CHANNELS];
BOOL vum_needclr = 0;
int32 wm_count = 0;
int32 pref_defstereo = 4;
int32 pref_maxundobuf = 2;
BOOL pref_fullscr = FALSE;
BOOL pref_blankzeros = FALSE;
BOOL pref_dorestart = FALSE;
BOOL pref_oldfullscr;
TEXT pref_oldskindir[512];
#ifdef __SDL_WRAPPER__
BOOL pref_rctrlplaypos = FALSE;
#endif
BOOL fullscr = FALSE;
extern BOOL quitting;
enum
{
PAL_BACK = 0,
PAL_BARDARK,
PAL_BARMID,
PAL_BARLIGHT,
PAL_TEXT,
PAL_DISABLEDTEXT,
PAL_WAVEMETER,
PAL_CURSNORM,
PAL_CURSEDIT,
PAL_BTNTEXT,
PAL_BTNSHADOW,
PAL_FKEYHIGHLIGHT,
PAL_POSEDCHIND,
PAL_TABTEXT,
PAL_TABSHADOW,
PAL_END
};
uint32 pal[] = { 0x000000, 0x500000, 0x780000, 0xff5555, 0xffffff, 0x808080, 0xff88ff, 0xffffff, 0xffff88, 0xffffff, 0x000000, 0xffffff, 0xffffff, 0xffffff, 0x000000 };
#ifdef __SDL_WRAPPER__
uint32 mappal[sizeof(pal)/sizeof(uint32)];
#endif
const TEXT *notenames[] = { "---",
"C-1", "C#1", "D-1", "D#1", "E-1", "F-1", "F#1", "G-1", "G#1", "A-1", "A#1", "B-1",
"C-2", "C#2", "D-2", "D#2", "E-2", "F-2", "F#2", "G-2", "G#2", "A-2", "A#2", "B-2",
"C-3", "C#3", "D-3", "D#3", "E-3", "F-3", "F#3", "G-3", "G#3", "A-3", "A#3", "B-3",
"C-4", "C#4", "D-4", "D#4", "E-4", "F-4", "F#4", "G-4", "G#4", "A-4", "A#4", "B-4",
"C-5", "C#5", "D-5", "D#5", "E-5", "F-5", "F#5", "G-5", "G#5", "A-5", "A#5", "B-5" };
const int32 posed_xoff[] = { 4*7, 5*7, 6*7, 8*7, 9*7,
11*7, 12*7, 13*7, 15*7, 16*7,
18*7, 19*7, 20*7, 22*7, 23*7,
25*7, 26*7, 27*7, 29*7, 30*7,
32*7, 33*7, 34*7, 36*7, 37*7,
39*7, 40*7, 41*7, 43*7, 44*7 };
const int32 tracked_xoff[] = { 3*8, 7*8, 8*8, 10*8, 11*8, 12*8, 14*8, 15*8, 16*8,
18*8, 22*8, 23*8, 25*8, 26*8, 27*8, 29*8, 30*8, 31*8,
33*8, 37*8, 38*8, 40*8, 41*8, 42*8, 44*8, 45*8, 46*8,
48*8, 52*8, 53*8, 55*8, 56*8, 57*8, 59*8, 60*8, 61*8,
63*8, 67*8, 68*8, 70*8, 71*8, 72*8, 74*8, 75*8, 76*8,
78*8, 82*8, 83*8, 85*8, 86*8, 87*8, 89*8, 90*8, 91*8 };
const int32 perf_xoff[] = { 4*8, 9*8, 11*8, 12*8, 13*8, 15*8, 16*8, 17*8 };
struct czone
{
int16 x;
int16 y;
int16 w;
int16 h;
};
#define NBB_ENABLED 0
#define NBF_ENABLED (1L<<NBB_ENABLED)
#define NBB_WAVELEN 1
#define NBF_WAVELEN (1L<<NBB_WAVELEN)
#define NBB_UDDURINGPLAY 2
#define NBF_UDDURINGPLAY (1L<<NBB_UDDURINGPLAY)
#define NBB_ONOFF 3
#define NBF_ONOFF (1L<<NBB_ONOFF)
struct numberbox
{
int16 x, y;
int16 w, h;
TEXT fmt[8];
int32 max, min;
int32 cnum;
uint16 flags;
int16 pressed;
};
#define TBB_ENABLED 0
#define TBF_ENABLED (1L<<TBB_ENABLED)
#define TBB_ACTIVE 1
#define TBF_ACTIVE (1L<<TBB_ACTIVE)
#define TBB_VISIBLE 2
#define TBF_VISIBLE (1L<<TBB_VISIBLE)
struct prefcycle
{
int16 x, y;
int32 copt;
int32 numopts;
int32 zone;
TEXT **options;
};
struct popup
{
int16 x, y;
};
enum
{
NB_POSNR = 0,
NB_LENGTH,
NB_RESPOS,
NB_TRKLEN,
NB_SSNR,
NB_CURSS,
NB_SSPOS,
NB_CHANS,
NB_MIXG,
NB_SPEEDMULT,
NB_DRUMPADMODE,
NB_END
};
enum
{
INB_INS = 0,
INB_VOL,
INB_WAVELEN,
INB_ATTACK,
INB_AVOL,
INB_DECAY,
INB_DVOL,
INB_SUSTAIN,
INB_RELEASE,
INB_RVOL,
INB_VIBDELAY,
INB_VIBDEPTH,
INB_VIBSPEED,
INB_SQRLOWER,
INB_SQRUPPER,
INB_SQRSPEED,
INB_FLTLOWER,
INB_FLTUPPER,
INB_FLTSPEED,
INB_PERFSPEED,
INB_PERFLEN,
INB_HARDCUT,
INB_RELCUT,
INB_END
};
enum
{
BBA_NOTHING = 0,
BBA_PLAYPOS,
BBA_PLAYSONG,
BBA_STOP,
BBA_ZAP,
BBA_NEWTAB,
BBA_CLONETAB,
BBA_LOADTUNE,
BBA_SAVEAHX,
BBA_SAVEHVL,
BBA_LOADINS,
BBA_SAVEINS,
BBA_CONTSONG,
BBA_CONTPOS,
BBA_INSEDIT,
BBA_PREFS,
BBA_AUTOGAIN,
BBA_ABOUT,
BBA_CUTTRK,
BBA_COPYTRK,
BBA_PASTE,
BBA_PASTECMDS,
BBA_NOTEUP,
BBA_NOTEDN,
BBA_SCRLUP,
BBA_SCRLDN,
BBA_REVERSE,
BBA_UNDO,
BBA_REDO,
BBA_OPTIMISE,
BBA_OPTIMISE_MORE,
BBA_ZAP_SONG,
BBA_ZAP_TRACKS,
BBA_ZAP_POSNS,
BBA_ZAP_INSTRS,
BBA_ZAP_ALL,
BBA_BACK,
BBA_END
};
enum
{
PTB_SONGDIR = 0,
PTB_INSTDIR,
PTB_SKINDIR,
PTB_END
};
enum
{
PP_SONGDIR = 0,
PP_INSTDIR,
PP_SKINDIR,
PP_END
};
struct buttonbank
{
int16 x, y;
int32 zone;
TEXT *name;
int32 action;
int32 raction;
int32 xo;
};
enum
{
BM_LOGO = 0,
BM_TAB_AREA,
BM_TAB_LEFT,
BM_TAB_MID,
BM_TAB_RIGHT,
BM_TAB_TEXT,
BM_ITAB_LEFT,
BM_ITAB_MID,
BM_ITAB_RIGHT,
BM_ITAB_TEXT,
BM_BUTBANKR,
BM_BUTBANKP,
BM_BG_TRACKER,
BM_BG_INSED,
BM_PLUSMINUS,
BM_POSED,
BM_TRACKED,
BM_TRACKBAR,
BM_PERF,
BM_VUMETER,
BM_WAVEMETERS,
BM_DEPTH,
BM_PRF_BG,
BM_PRF_CYCLE,
BM_INSLIST,
BM_INSLISTB,
BM_TRKBANKR,
BM_TRKBANKP,
BM_CHANMUTE,
BM_BLANK,
BM_DIRPOPUP,
BM_END
};
enum
{
PC_WMODE = 0,
PC_DEFSTEREO,
PC_BLANKZERO,
PC_MAXUNDOBUF,
PC_END
};
struct tunetab
{
struct ahx_tune *tune;
int32 zone;
};
TEXT fixfontname[256];
TEXT sfxfontname[256];
TEXT prpfontname[256];
TEXT skinext[32];
BOOL tabtextback = FALSE;
BOOL tabtextshad = TRUE;
BOOL posedadvance = TRUE;
int32 defnotejump = 1, definotejump = 1;
#ifndef __SDL_WRAPPER__
struct TextAttr fixfontattr = { fixfontname, 16, 0, 0 };
struct TextAttr sfxfontattr = { sfxfontname, 14, 0, 0 };
struct TextAttr prpfontattr = { prpfontname, 16, 0, 0 };
struct TextFont *fixfont = NULL;
struct TextFont *sfxfont = NULL;
struct TextFont *prpfont = NULL;
#else
TTF_Font *fixttf = NULL;
TTF_Font *sfxttf = NULL;
TTF_Font *prpttf = NULL;
BOOL prefwin_open = FALSE;
#endif
#define MAX_ZONES 100
#define MAX_PZONES 20
int32 last_tbox = -1;
struct rawbm mainbm, prefbm;
struct rawbm bitmaps[BM_END];
struct czone zones[MAX_ZONES], pzones[MAX_PZONES];
struct numberbox trk_nb[NB_END], ins_nb[INB_END];
struct textbox tbx[TB_END], ptb[PTB_END];
struct textbox *etbx = NULL, *ptbx = NULL;
struct popup pp[PP_END];
struct tunetab ttab[8];
struct buttonbank bbank[16];
struct buttonbank tbank[12];
struct prefcycle pcyc[PC_END];
TEXT *pc_wmode_opts[] = { "Windowed", "Fullscreen", NULL };
TEXT *pc_defst_opts[] = { "0% (mono)", "25%", "50%", "75%", "100% (paula)", NULL };
TEXT *pc_bzero_opts[] = { "No", "Yes", NULL };
TEXT *pc_mundo_opts[] = { "Unlimited", "256Kb", "512Kb", "1Mb", "2Mb", "4Mb", NULL };
struct ahx_tune *posed_lasttune = NULL;
int16 posed_lastposnr = 1000;
int16 posed_lastlchan = 0;
int16 posed_lastchans = 0;
struct ahx_tune *trked_lasttune = NULL;
int16 trked_lastposnr = 1000;
int16 trked_lastnotenr = 65;
int16 trked_lastchans = 4;
int16 trked_lastlchan = 0;
struct ahx_tune *insls_lasttune = NULL;
int16 insls_lastcuri = -1;
int16 insls_lasttopi = -1;
struct ahx_tune *inslsb_lasttune = NULL;
int16 inslsb_lastcuri = -1;
int16 inslsb_lasttopi = -1;
int32 numzones = 0;
int32 numpzones = 0;
int32 cz_lmb, cz_plmb;
int32 cz_rmb, cz_prmb;
int32 whichcyc = -1;
int32 whichpop = -1;
int32 zn_close = -1;
int32 zn_scrdep = -1;
int32 zn_mute[6];
#ifndef __SDL_WRAPPER__
struct FileRequester *ins_lreq;
struct FileRequester *ins_sreq;
struct FileRequester *sng_lreq;
struct FileRequester *sng_sreq;
struct FileRequester *dir_req;
#endif
#define CBB_NOTES 0
#define CBF_NOTES (1L<<CBB_NOTES)
#define CBB_CMD1 1
#define CBF_CMD1 (1L<<CBB_CMD1)
#define CBB_CMD2 2
#define CBF_CMD2 (1L<<CBB_CMD2)
struct ahx_step cb_content[64];
int32 cb_contains = 0;
int32 cb_length = 0;
TEXT songdir[512];
TEXT instdir[512];
TEXT skindir[512];
#ifdef __SDL_WRAPPER__
TEXT remsongdir[512];
TEXT reminstdir[512];
#ifdef WIN32
#define PATHSEP '\\'
#else
#define PATHSEP '/'
#endif
void setpathpart(char *path, const char *file)
{
int i;
i = strlen(file);
while (i>0)
{
if (file[i] == PATHSEP) break;
i--;
}
if (i>511) return;
strcpy(path, file);
path[i] = 0;
}
#endif
BOOL isws( TEXT c )
{
if( ( c == 9 ) || ( c == 32 ) ) return TRUE;
return FALSE;
}
BOOL isnum( TEXT c )
{
if( ( c >= '0' ) && ( c <= '9' ) ) return TRUE;
return FALSE;
}
BOOL ishex( TEXT c )
{
if( ( c >= '0' ) && ( c <= '9' ) ) return TRUE;
if( ( c >= 'A' ) && ( c <= 'F' ) ) return TRUE;
if( ( c >= 'a' ) && ( c <= 'f' ) ) return TRUE;
return FALSE;
}
#ifndef __SDL_WRAPPER__
int32 gui_req( uint32 img, const TEXT *title, const TEXT *reqtxt, const TEXT *buttons )
{
Object *req_obj;
int32 n;
req_obj = (Object *)IIntuition->NewObject( IRequester->REQUESTER_GetClass(), NULL,
REQ_TitleText, title,
REQ_BodyText, reqtxt,
REQ_GadgetText, buttons,
REQ_Image, img,
REQ_WrapBorder, 40,
TAG_DONE );
if( !req_obj ) return 1;
n = IIntuition->IDoMethod( req_obj, RM_OPENREQ, NULL, NULL, scr );
IIntuition->DisposeObject( req_obj );
return n;
}
#endif
void set_fpen(struct rawbm *bm, int pen)
{
if ((bm->fpenset) && (bm->fpen == pen))
return;
#ifndef __SDL_WRAPPER__
IGraphics->SetRPAttrs( &bm->rp, RPTAG_APenColor, pal[pen]|0xff000000, TAG_DONE );
#else
bm->fsc.r = pal[pen]>>16;
bm->fsc.g = pal[pen]>>8;
bm->fsc.b = pal[pen];
#endif
bm->fpen = pen;
bm->fpenset = TRUE;
}
void set_fcol(struct rawbm *bm, uint32 col)
{
#ifndef __SDL_WRAPPER__
IGraphics->SetRPAttrs( &bm->rp, RPTAG_APenColor, col|0xff000000, TAG_DONE );
#else
bm->fsc.r = col>>16;
bm->fsc.g = col>>8;
bm->fsc.b = col;
#endif
bm->fpenset = FALSE;
}
void set_bpen(struct rawbm *bm, int pen)
{
if ((bm->bpenset) && (bm->bpen == pen))
return;
#ifndef __SDL_WRAPPER__
IGraphics->SetRPAttrs( &bm->rp, RPTAG_BPenColor, pal[pen]|0xff000000, TAG_DONE );
#else
bm->bsc.r = pal[pen]>>16;
bm->bsc.g = pal[pen]>>8;
bm->bsc.b = pal[pen];
#endif
bm->bpen = pen;
bm->bpenset = TRUE;
}
void set_pens(struct rawbm *bm, int fpen, int bpen)
{
set_fpen(bm, fpen);
set_bpen(bm, bpen);
}
void fillrect_xy(struct rawbm *bm, int x, int y, int x2, int y2)
{
#ifndef __SDL_WRAPPER__
IGraphics->RectFill( &bm->rp, x, y, x2, y2 );
#else
SDL_Rect rect = { .x = x+bm->offx, .y = y+bm->offy, .w = (x2-x)+1, .h = (y2-y)+1 };
Uint32 col;
if (bm->fpenset)
col = mappal[bm->fpen];
else
#ifdef __APPLE__
// Work-around for SDL bug on OSX
col = SDL_MapRGB(bm->srf->format, bm->fsc.b, bm->fsc.g, bm->fsc.r) >> 8;
#else
col = SDL_MapRGB(bm->srf->format, bm->fsc.r, bm->fsc.g, bm->fsc.b);
#endif
SDL_FillRect(bm->srf, &rect, col);
#endif
}
void bm_to_bm(const struct rawbm *src, int sx, int sy, struct rawbm *dest, int dx, int dy, int w, int h)
{
#ifndef __SDL_WRAPPER__
IGraphics->BltBitMapRastPort(src->bm, sx, sy, &dest->rp, dx, dy, w, h, 0x0C0);
#else
SDL_Rect srect = { .x = sx+src->offx, .y = sy+src->offy, .w = w, .h = h };
SDL_Rect drect = { .x = dx+dest->offx, .y = dy+dest->offy, .w = w, .h = h };
SDL_BlitSurface(src->srf, &srect, dest->srf, &drect);
if (dest == &mainbm) needaflip = TRUE;
#endif
}
void set_font(struct rawbm *bm, int findex, BOOL jam2)
{
if ((bm->fontset) && (bm->findex == findex) && (bm->jam2 == jam2))
return;
#ifndef __SDL_WRAPPER__
struct TextFont *thefont;
switch (findex)
{
case FONT_SFX: thefont = sfxfont; break;
case FONT_PRP: thefont = prpfont; break;
default: thefont = fixfont; break;
}
IGraphics->SetRPAttrs( &bm->rp, RPTAG_DrMd, jam2 ? JAM2 : JAM1, RPTAG_Font, thefont, TAG_DONE );
bm->baseline = thefont->tf_Baseline;
#else
switch (findex)
{
case FONT_SFX: bm->font = sfxttf; break;
case FONT_PRP: bm->font = prpttf; break;
default: bm->font = fixttf; break;
}
#endif
bm->findex = findex;
bm->jam2 = jam2;
bm->fontset = TRUE;
}
void printstr(struct rawbm *bm, const char *str, int x, int y)
{
#ifndef __SDL_WRAPPER__
IGraphics->Move(&bm->rp, x, y+bm->baseline);
IGraphics->Text(&bm->rp, str, strlen(str));
#else
SDL_Surface *srf;
SDL_Rect rect = { .x = x+bm->offx, .y = y+bm->offy };
if (bm->jam2)
{
srf = TTF_RenderText_Shaded(bm->font, str, bm->fsc, bm->bsc);
}
else
{
srf = TTF_RenderText_Blended(bm->font, str, bm->fsc);
}
if (!srf) return;
SDL_BlitSurface(srf, NULL, bm->srf, &rect);
SDL_FreeSurface(srf);
#endif
}
void printstrlen(struct rawbm *bm, const char *str, int len, int x, int y)
{
#ifndef __SDL_WRAPPER__
IGraphics->Move(&bm->rp, x, y+bm->baseline);
IGraphics->Text(&bm->rp, str, len);
#else
char tmp[len+1];
SDL_Surface *srf;
SDL_Rect rect = { .x = x+bm->offx, .y = y+bm->offy };
strncpy(tmp, str, len);
tmp[len] = 0;
if (bm->jam2)
{
srf = TTF_RenderText_Shaded(bm->font, tmp, bm->fsc, bm->bsc);
}
else
{
srf = TTF_RenderText_Blended(bm->font, tmp, bm->fsc);
}
if (!srf) return;
SDL_BlitSurface(srf, NULL, bm->srf, &rect);
SDL_FreeSurface(srf);
#endif
}
int textfit( struct rawbm *bm, const char *str, int w )
{
#ifndef __SDL_WRAPPER__
struct TextExtent te;
return IGraphics->TextFit( &bm->rp, str, strlen(str), &te, NULL, 1, w, 24 );
#else
int tw, th, c;
char tmp[512];
strncpy(tmp, str, 512);
tmp[511] = 0;
c = strlen(tmp);
while (c>0)
{
TTF_SizeText(bm->font, tmp, &tw, &th);
if (tw <= w) break;
tmp[--c] = 0;
}
return c;
#endif
}
int32 gui_add_zone( struct czone *zn, int32 *numzn, int32 maxz, int16 x, int16 y, int16 w, int16 h )
{
int32 fz;
for( fz=0; fz<(*numzn); fz++ )
if( zn[fz].x == -1 ) break;
if( fz == *numzn )
{
if( (*numzn) == maxz )
return -1;
(*numzn)++;
}
zn[fz].x = x;
zn[fz].y = y;
zn[fz].w = w;
zn[fz].h = h;
// printf( "z: %ld = %d,%d,%d,%d\n", fz, x, y, w, h );
return fz;
}
void gui_set_nbox( struct numberbox *nb, int16 x, int16 y, int16 w, int16 h, int32 min, int32 max, int32 cnum, const TEXT *fmt, uint16 flags )
{
nb->x = x;
nb->y = y;
nb->w = w;
nb->h = h;
nb->min = min;
nb->max = max;
nb->cnum = cnum;
nb->flags = flags;
nb->pressed = 0;
if( fmt == NULL )
strcpy( nb->fmt, "%d" );
else
strcpy( nb->fmt, fmt );
}
void gui_zap_zone( struct czone *zn, int32 *numzn, int32 max, int32 *zone )
{
int32 tz;
tz = *zone;
*zone = -1;
if( ( tz < 0 ) || ( tz >= max ) )
return;
zn[tz].x = -1;
if( (*numzn) == 0 ) return;
while( (*numzn) > 0 )
{
if( zn[(*numzn)-1].x != -1 ) break;
(*numzn)--;
}
}
int32 gui_get_zone( struct czone *zn, int32 numz, int16 x, int16 y )
{
int32 i;
for( i=0; i<numz; i++ )
{
if( zn[i].x != -1 )
{
if( ( x >= zn[i].x ) &&
( y >= zn[i].y ) &&
( x < ( zn[i].x+zn[i].w ) ) &&
( y < ( zn[i].y+zn[i].h ) ) )
return i;
}
}
return -1;
}
BOOL make_image( struct rawbm *bm, uint16 w, uint16 h )
{
bm->w = w;
bm->h = h;
bm->fontset = FALSE;
bm->fpenset = FALSE;
bm->bpenset = FALSE;
#ifndef __SDL_WRAPPER__
IGraphics->InitRastPort( &bm->rp );
bm->bm = IGraphics->AllocBitMap( bm->w, bm->h, 8, 0, mainwin->RPort->BitMap );
if( !bm->bm )
{
printf( "Out of memory @ %s:%d\n", __FILE__, __LINE__ );
return FALSE;
}
bm->rp.BitMap = bm->bm;
#else
bm->offx = 0;
bm->offy = 0;
bm->srf = SDL_CreateRGBSurface(SRFTYPE, w, h, srfdepth, 0, 0, 0, 0);
if( !bm->srf )
{
printf( "Out of memory @ %s:%d\n", __FILE__, __LINE__ );
return FALSE;
}
#endif
return TRUE;
}
BOOL open_image( const TEXT *name, struct rawbm *bm )
{
#ifndef __SDL_WRAPPER__
uint8 *data;
Object *io = NULL;
struct BitMapHeader *bmh;
struct RenderInfo ri;
TEXT tmp[1024];
strcpy( tmp, skindir );
IDOS->AddPart( tmp, name, 1024 );
strcat( tmp, skinext );
io = IDataTypes->NewDTObject( tmp,
DTA_SourceType, DTST_FILE,
DTA_GroupID, GID_PICTURE,
PDTA_FreeSourceBitMap, TRUE,
PDTA_DestMode, PMODE_V43,
TAG_DONE );
if( !io )
{
printf( "Error opening '%s'\n", tmp );
return FALSE;
}
if( IDataTypes->GetDTAttrs( io,
PDTA_BitMapHeader, &bmh,
TAG_DONE ) == 0 )
{
IDataTypes->DisposeDTObject( io );
printf( "Unable to get information about '%s'\n", tmp );
return FALSE;
}
bm->w = bmh->bmh_Width;
bm->h = bmh->bmh_Height;
IGraphics->InitRastPort( &bm->rp );
bm->bm = IGraphics->AllocBitMap( bm->w, bm->h, 8, 0, mainwin->RPort->BitMap );
if( !bm->bm )
{
IDataTypes->DisposeDTObject( io );
printf( "Out of memory @ %s:%d\n", __FILE__, __LINE__ );
return FALSE;
}
bm->rp.BitMap = bm->bm;
data = IExec->AllocVecTags( bm->w*bm->h*4, TAG_DONE );
if( !data )
{
IDataTypes->DisposeDTObject( io );
IGraphics->FreeBitMap( bm->bm );
printf( "Out of memory @ %s:%d\n", __FILE__, __LINE__ );
return FALSE;
}
IIntuition->IDoMethod( io, PDTM_READPIXELARRAY, data, PBPAFMT_ARGB, bm->w<<2, 0, 0, bm->w,bm->h );
ri.Memory = data;
ri.BytesPerRow = bm->w<<2;
ri.RGBFormat = RGBFB_A8R8G8B8;
IP96->p96WritePixelArray( &ri, 0, 0, &bm->rp, 0, 0, bm->w, bm->h );
IExec->FreeVec( data );
IDataTypes->DisposeDTObject( io );
#else
SDL_Surface *tmpsrf;
TEXT tmp[1024];
#ifdef __APPLE__
if (strncmp(skindir, "Skins/", 6) == 0)
osxGetResourcesPath(tmp, skindir);
#else
strncpy( tmp, skindir, 1024 );
#endif
strncat( tmp, "/", 1024 );
strncat( tmp, name, 1024 );
strncat( tmp, skinext, 1024 );
tmpsrf = IMG_Load(tmp);
if (!tmpsrf)
{
printf("Error loading '%s': %s\n", tmp, IMG_GetError());
return FALSE;
}
if (!make_image(bm, tmpsrf->w, tmpsrf->h))
{
SDL_FreeSurface(tmpsrf);
return FALSE;
}
/* Convert to the screen surface format */
SDL_BlitSurface(tmpsrf, NULL, bm->srf, NULL);
SDL_FreeSurface(tmpsrf);
#endif
return TRUE;