forked from TnA-Plastic/FreeMcBoot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgui.c
1923 lines (1653 loc) · 57.1 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
/*
_____ ___ ____
____| | ____| PS2 Open Source Project
| ___| |____
---------------------------------------------------------------------------
Copyright (C) 2008 - Neme & jimmikaelkael (www.psx-scene.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the Free McBoot License.
This program and any related documentation is provided "as is"
WITHOUT ANY WARRANTIES, either express or implied, including, but not
limited to, implied warranties of fitness for a particular purpose. The
entire risk arising out of use or performance of the software remains
with you.
In no event shall the author be liable for any damages whatsoever
(including, without limitation, damages to your hardware or equipment,
environmental damage, loss of health, or any kind of pecuniary loss)
arising out of the use of or inability to use this software or
documentation, even if the author has been advised of the possibility of
such damages.
You should have received a copy of the Free McBoot License along with
this program; if not, please report at psx-scene :
http://psx-scene.com/forums/freevast/
---------------------------------------------------------------------------
GUI source file
---------------------------------------------------------------------------
*/
#include "fmcb.h"
#include "sjpcm.h"
// include font specific datas
#include "font_verdana.h"
//#define DEBUG
void Setup_GS(int gs_vmode);
void gfx_set_defaults(void);
void load_Textures(void);
void Clear_Screen(void);
int Draw_INTRO(void);
int Draw_GUI(int logo, int selected_button, int highlight_pulse, int highlight_blw, int log, int dialog);
int Draw_OUTRO(void);
void Render_GUI(void);
void Play_Sound(void);
GSGLOBAL *gsGlobal;
GSTEXTURE tex_bar_up, tex_bar_down, tex_bar_delimiter, tex_highlight, tex_highlight_bw;
GSTEXTURE tex_background, tex_logo;
GSTEXTURE tex_credits_coded, tex_credits_gui;
GSTEXTURE tex_option[6];
GSTEXTURE tex_font_verdana;
GSTEXTURE tex_icon_ok, tex_icon_warning, tex_icon_error;
// screen defaults for NTSC, just in case
int TV_mode = 2;
int SCREEN_WIDTH = 640;
int SCREEN_HEIGHT = 448;
int SCREEN_X = 632;
int SCREEN_Y = 50;
int FONT_WIDTH = 16;
int FONT_HEIGHT = 15;
int FONT_SPACING = 1;
int FONT_Y = 75;
// define colors
#define Black GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00)
#define Blue GS_SETREG_RGBAQ(0x18,0x23,0xFF,0x80,0x00)
#define White GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x80,0x00)
#define Gray GS_SETREG_RGBAQ(0x33,0x33,0x33,0x80,0x00)
#define TexCol GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00)
// sounds related
static short snd_buf_L[1024] __attribute__((aligned (64)));
static short snd_buf_R[1024] __attribute__((aligned (64)));
u16 *pSampleBuf;
int nSizeSample;
int snd_pos;
int snd_finished;
int SAMPLES_TICK = 800; // default to NTSC, PAL must use 960
// Common to both GUI & INTRO
int bar_delimiter_x[7];
int option_x[6];
// For GUI
int logo_alpha;
int highlight_alpha;
int amount;
int pause_pulse;
int stop_pulse_done;
int log_alpha;
int dialog_alpha;
int control_alpha;
int control_amount;
int pause_control_pulse;
// For both INTRO & OUTRO
int up_panel_y;
int down_panel_y;
int background_alpha;
// For INTRO only
float logo_width;
float logo_height;
float logo_accel;
// For dialogs
#define DIALOG_YES_NO 1
#define DIALOG_OK 2
#define DIALOG_OK_CANCEL 3
#define DIALOG_ABORT 4
#define DIALOG_1_2 5
#define DIALOG_NONE 6
#define ICON_DIALOG_OK 1
#define ICON_DIALOG_WARNING 2
#define ICON_DIALOG_ERROR 3
#define ICON_DIALOG_NONE 4
#define MAX_DIALOG_LINES 14
// to be filled before opening a dialog :
int dialog_type;
int dialog_icon;
char* dialog_buffer[MAX_DIALOG_LINES];
int selected_dialog_button;
int internal_dialog_type; // only for internal use !!!
#define MAX_LOG_LINES 22
// to be filled before to print a log
char* log_job_buffer[MAX_LOG_LINES];
int log_result[MAX_LOG_LINES];
//--------------------------------------------------------------
// PNG handling code: from MyPS2 by ntba2
//
typedef struct {
int width;
int height;
int bit_depth;
void *priv;
} pngData;
typedef struct {
png_structp png_ptr;
png_infop info_ptr, end_info;
u8 *buf;
int pos;
u8 *data;
} pngPrivate;
//--------------------------------------------------------------
static void read_data_fn(png_structp png_ptr, png_bytep buf, png_size_t size)
{
pngPrivate *priv = (pngPrivate*)png_get_io_ptr(png_ptr);
memcpy(buf, priv->buf + priv->pos, size);
priv->pos += size;
}
//--------------------------------------------------------------
pngData *pngOpenRAW(u8 *data, int size)
{
pngData *png;
pngPrivate *priv;
if (png_sig_cmp( data, 0, 8 ) != 0)
return NULL;
if ((png = malloc(sizeof(pngData))) == NULL)
return NULL;
memset (png, 0, sizeof(pngData));
if ((priv = malloc(sizeof(pngPrivate))) == NULL)
return NULL;
png->priv = priv;
priv->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!priv->png_ptr) {
#ifdef DEBUG
printf("PNG Read Struct Init Failed\n");
#endif
free(png);
return NULL;
}
priv->info_ptr = png_create_info_struct(priv->png_ptr);
if (!priv->info_ptr) {
#ifdef DEBUG
printf("PNG Info Struct Init Failed\n");
#endif
free(png);
png_destroy_read_struct(&priv->png_ptr, NULL, NULL);
return NULL;
}
priv->end_info = png_create_info_struct(priv->png_ptr);
if (!priv->end_info) {
free(png);
png_destroy_read_struct(&priv->png_ptr, &priv->info_ptr, NULL);
return NULL;
}
priv->buf = data;
priv->pos = 0;
png_set_read_fn(priv->png_ptr, (png_voidp)priv, read_data_fn);
png_read_png(priv->png_ptr, priv->info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
png->width = priv->info_ptr->width;
png->height = priv->info_ptr->height;
png->bit_depth = priv->info_ptr->channels * 8;
#ifdef DEBUG
printf("PNG info: width=%3d ", png->width);
printf("height=%3d ", png->height);
printf("bit depth=%2d ", png->bit_depth);
printf("color type=%2d\n", priv->png_ptr->color_type);
#endif
return png;
}
//--------------------------------------------------------------
int pngReadImage(pngData *png, u8 *dest)
{
pngPrivate *priv = png->priv;
u8 **row_pointers;
int i, row_ptr;
int y;
row_pointers = png_get_rows(priv->png_ptr, priv->info_ptr);
row_ptr = 0;
for (i = 0; i < priv->info_ptr->height; i++) {
memcpy(dest + row_ptr, row_pointers[i], priv->info_ptr->rowbytes);
// need to normalize alpha channel to ps2 range
if (priv->info_ptr->channels == 4) {
for (y = 3; y < priv->info_ptr->rowbytes; y += 4)
*(dest + row_ptr + y ) /= 2;
}
row_ptr += priv->info_ptr->rowbytes;
}
return 1;
}
//--------------------------------------------------------------
void pngClose(pngData *png)
{
pngPrivate *priv = png->priv;
png_destroy_read_struct(&priv->png_ptr, &priv->info_ptr, &priv->end_info);
if (priv->data)
free(priv->data);
free(priv);
free(png);
}
//----------------------------------------------------
void Play_Sound(void)
{
// TO BE CALLED ONCE PER VERTICAL SYNC PERIOD !!!
// Uses :
// - pSampleBuf (u16 *) as sound buffer
// - nSizeSample (int) as sound buffer size
// - SAMPLES_TICK (int) : 800 for NTSC, 960 for PAL
// - snd_pos (int) as position in sound buffer
// - snd_finished (int) as flag if sound finished playing : 0 or 1
// Sounds must be 48kHZ 16bit mono uncompressed PCM
// The mono channel is send on both R & L
//
// Example of use :
// pSampleBuf = (u16 *)&option_snd;
// nSizeSample = size_option_snd;
// snd_pos = 0;
// while (1) {
// Play_Sound();
// gsKit_vsync();
// }
int i;
int buffered;
// Skip audio file header (to avoid it to be put in sound buffer and be played,
// producing crackling effect at begining of sample)
if (snd_pos == 0) {
snd_pos += 22; // Skip audio file header (in short int indexing !)
snd_finished = 0;
#ifdef DEBUG
printf("Starting new sound\n");
#endif
}
// fill left & right sound buffer
for (i=0; i<SAMPLES_TICK; i++) {
// If were are not at end of sound buffer, fills with datas
if ((snd_pos + i) <= (nSizeSample / 2)) {
snd_buf_L[i] = pSampleBuf[snd_pos + i];
snd_buf_R[i] = snd_buf_L[i];
//if (((snd_pos + i) * 2 + 1) <= (nSizeSample / 2)) { // stereo
//snd_buf_L[i] = pSampleBuf[(snd_pos + i) * 2 + 0]; // stereo
//snd_buf_R[i] = pSampleBuf[(snd_pos + i) * 2 + 1]; // stereo
}
else {
// if no more datas available, then clear left & right buffer
snd_buf_L[i] = 0;
snd_buf_R[i] = 0;
}
}
// Enqueue "SAMPLES_TICK" left & right samples
buffered = SjPCM_Buffered();
if (buffered < 1*SAMPLES_TICK)
SjPCM_Enqueue(snd_buf_L, snd_buf_R, SAMPLES_TICK, 0); // avoid underrun
if (buffered < 2*SAMPLES_TICK)
SjPCM_Enqueue(snd_buf_L, snd_buf_R, SAMPLES_TICK, 0); // regular buffer fill
// Update sound position
if (snd_pos < (nSizeSample / 2)) {
snd_pos += SAMPLES_TICK;
//if (snd_pos < (nSizeSample / 4)) { // stereo
//snd_pos += SAMPLES_TICK; // stereo
}
else {
snd_finished = 1;
#ifdef DEBUG
printf("Sound position = %d\n", snd_pos);
#endif
}
}
//----------------------------------------------------
void drawChar_verdana(u32 x, u32 y, u32 width, u32 height, u64 color, u32 c)
{
// Draw a character with verdana font
int x1, x2, y1, y2;
int u1, u2, v1, v2;
x1 = x;
x2 = x1 + width;
y1 = y;
y2 = y1 + height;
// Calculate char coordinates int verdana texture
u1 = (c % (tex_font_verdana.Width/16)) * (tex_font_verdana.Width/16);
u2 = u1 + 16;
v1 = c - (c % (tex_font_verdana.Height/8)); // careful: 8 rows only !!!
v2 = v1 + 16;
// Draw a char using verdana texture
gsKit_prim_sprite_texture(gsGlobal, &tex_font_verdana,
x1, // X1
y1, // Y1
u1, // U1
v1, // V1
x2, // X2
y2, // Y2
u2, // U2
v2, // V2
0,
color);
}
//--------------------------------------------------------------
void drawString_verdana(u32 x, u32 y, u64 color, const char *string)
{
// Draw a string with verdana font
int l, i, cx;
int c;
cx = x;
l = strlen(string);
for( i = 0; i < l; i++ )
{
c = (u8)string[i];
if (c > 127) c = 127; // security check as the font is incomplete
// Draw the string character by character
drawChar_verdana(cx, y, FONT_WIDTH, FONT_HEIGHT, color, c);
// Uses width informations for verdana font
cx += font_verdana_width[c] + FONT_SPACING;
}
}
//--------------------------------------------------------------
int getStringWidth_verdana(const char *string)
{
// Calculate and return width in pixels of a string using verdana font
int i, l, c, size;
l = strlen(string);
size = 0;
for( i = 0; i < l; i++ )
{
c = (u8)string[i];
if (c >= 128) c = 127; // security check as the font is incomplete
size += font_verdana_width[c] + FONT_SPACING;
}
return size;
}
//--------------------------------------------------------------
void draw_log(int alpha)
{
// Draw the log
int i;
int pos_x = 40; // log lines x
int pos_x2 = 370; // log result x
int pos_y = FONT_Y;
for (i=0; i<MAX_LOG_LINES; i++) {
if ((log_job_buffer[i] != NULL) && (strlen(log_job_buffer[i]) > 0)) {
drawString_verdana(pos_x, pos_y, GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,alpha,0x00), log_job_buffer[i]);
}
if (log_result[i] == 0) {
// Draw icon error
gsKit_prim_sprite_texture(gsGlobal, &tex_icon_error,
pos_x2, // X1
pos_y, // Y1
0, // U1
0, // V1
pos_x2 + FONT_WIDTH + 1, // X2
pos_y + FONT_HEIGHT, // Y2
tex_icon_error.Width, // U2
tex_icon_error.Height, // V2
0,
GS_SETREG_RGBAQ(0x80,0x80,0x80, alpha,0x00));
}
else if (log_result[i] == 1) {
// Draw icon OK
gsKit_prim_sprite_texture(gsGlobal, &tex_icon_ok,
pos_x2, // X1
pos_y, // Y1
0, // U1
0, // V1
pos_x2 + FONT_WIDTH + 1, // X2
pos_y + FONT_HEIGHT,// Y2
tex_icon_ok.Width, // U2
tex_icon_ok.Height, // V2
0,
GS_SETREG_RGBAQ(0x80,0x80,0x80, alpha,0x00));
}
else if (log_result[i] == 2) {
// do nothing
}
pos_y += FONT_HEIGHT;
}
}
//--------------------------------------------------------------
void draw_dialog(int alpha_dialog, int alpha_control)
{
// log must be faded before to call this
// Draw a dialog using dialog_type, dialog_icon, dialog_buffer vars
int x1, x2, y1, y2;
int y;
int i;
char *msg;
char *msg1, *msg2;
u64 color_text, color_texture, color_selected, color_unselected;
int dialog_start_y = 0;
int spacing = 12;
int width = 0;
int height = 0;
int control_spacing = 25;
// Set all needed colors and transparency
color_text = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF, alpha_dialog,0x00);
color_texture = GS_SETREG_RGBAQ(0x80,0x80,0x80, alpha_dialog,0x00);
if (dialog_icon == ICON_DIALOG_ERROR)
color_selected = GS_SETREG_RGBAQ(0x92,0x00,0x00, alpha_control,0x00);
else
color_selected = GS_SETREG_RGBAQ(0x18,0x23,0xFF, alpha_control,0x00);
color_unselected = GS_SETREG_RGBAQ(0x33,0x33,0x33, alpha_dialog,0x00);
y2 = 0;
// Calculate height needed for dialog to center it in height
if (dialog_icon == ICON_DIALOG_OK)
height += tex_icon_ok.Height;
else if (dialog_icon == ICON_DIALOG_WARNING)
height += tex_icon_warning.Height;
else if (dialog_icon == ICON_DIALOG_ERROR)
height += tex_icon_error.Height;
height += spacing;
for (i=0; i<MAX_DIALOG_LINES; i++) {
if ((dialog_buffer[i] != NULL) && (strlen(dialog_buffer[i]) > 0))
height += FONT_HEIGHT;
}
height += spacing;
if (dialog_type != DIALOG_NONE)
height += FONT_HEIGHT;
dialog_start_y = ((SCREEN_HEIGHT - height) / 2) - 20;
// Draw dialog Icon
if (dialog_icon == ICON_DIALOG_OK) {
// Calculates coordinates to center the dialog icon OK
x1 = (SCREEN_WIDTH - tex_icon_ok.Width) / 2;
x2 = x1 + tex_icon_ok.Width;
y1 = dialog_start_y;
y2 = y1 + tex_icon_ok.Height;
// Draw icon OK
gsKit_prim_sprite_texture(gsGlobal, &tex_icon_ok,
x1, // X1
y1, // Y1
0, // U1
0, // V1
x2, // X2
y2, // Y2
tex_icon_ok.Width, // U2
tex_icon_ok.Height, // V2
0,
color_texture);
}
else if (dialog_icon == ICON_DIALOG_WARNING) {
// Calculates coordinates to center the dialog icon warning
x1 = (SCREEN_WIDTH - tex_icon_warning.Width) / 2;
x2 = x1 + tex_icon_warning.Width;
y1 = dialog_start_y;
y2 = y1 + tex_icon_warning.Height;
// Draw icon warning
gsKit_prim_sprite_texture(gsGlobal, &tex_icon_warning,
x1, // X1
y1, // Y1
0, // U1
0, // V1
x2, // X2
y2, // Y2
tex_icon_warning.Width, // U2
tex_icon_warning.Height, // V2
0,
color_texture);
}
else if (dialog_icon == ICON_DIALOG_ERROR) {
// Calculates coordinates to center the dialog icon warning
x1 = (SCREEN_WIDTH - tex_icon_error.Width) / 2;
x2 = x1 + tex_icon_error.Width;
y1 = dialog_start_y;
y2 = y1 + tex_icon_error.Height;
// Draw icon error
gsKit_prim_sprite_texture(gsGlobal, &tex_icon_error,
x1, // X1
y1, // Y1
0, // U1
0, // V1
x2, // X2
y2, // Y2
tex_icon_error.Width, // U2
tex_icon_error.Height, // V2
0,
color_texture);
}
else if (dialog_icon == ICON_DIALOG_NONE) {
y2 = dialog_start_y;
}
// Spacing from icon
y = y2 + spacing;
// Printing dialog buffer
for (i=0; i<MAX_DIALOG_LINES; i++) {
if ((dialog_buffer[i] != NULL) && (strlen(dialog_buffer[i]) > 0)) {
msg = dialog_buffer[i];
// Print centered string
drawString_verdana(((
SCREEN_WIDTH - getStringWidth_verdana(msg)) / 2), // X
y, // Y
color_text, // color
msg); // string
y += FONT_HEIGHT;
}
}
// Spacing from dialog text
y += spacing;
// Drawing dialog controls
if (internal_dialog_type == DIALOG_OK) {
// set default selected control
if (selected_dialog_button == 0) selected_dialog_button = 1;
// Draw centered controls
msg1 = "OK";
width = getStringWidth_verdana(msg1);
x1 = (SCREEN_WIDTH - width) / 2;
//if (selected_dialog_button == 1)
drawString_verdana(x1, y, color_selected, msg1);
}
else if (internal_dialog_type == DIALOG_YES_NO) {
// set default selected control
if (selected_dialog_button == 0) selected_dialog_button = 2;
// Draw centered controls
msg1 = "YES";
msg2 = "NO";
width = getStringWidth_verdana(msg1) + getStringWidth_verdana(msg2) + control_spacing;
x1 = (SCREEN_WIDTH - width) / 2;
x2 = x1 + width - getStringWidth_verdana(msg2);
if (selected_dialog_button == 1)
drawString_verdana(x1, y, color_selected, msg1);
else drawString_verdana(x1, y, color_unselected, msg1);
if (selected_dialog_button == 2)
drawString_verdana(x2, y, color_selected, msg2);
else drawString_verdana(x2, y, color_unselected, msg2);
}
else if (internal_dialog_type == DIALOG_OK_CANCEL) {
// set default selected control
if (selected_dialog_button == 0) selected_dialog_button = 2;
// Draw centered controls
msg1 = "OK";
msg2 = "CANCEL";
width = getStringWidth_verdana(msg1) + getStringWidth_verdana(msg2) + control_spacing;
x1 = (SCREEN_WIDTH - width) / 2;
x2 = x1 + width - getStringWidth_verdana(msg2);
if (selected_dialog_button == 1)
drawString_verdana(x1, y, color_selected, msg1);
else drawString_verdana(x1, y, color_unselected, msg1);
if (selected_dialog_button == 2)
drawString_verdana(x2, y, color_selected, msg2);
else drawString_verdana(x2, y, color_unselected, msg2);
}
else if (internal_dialog_type == DIALOG_ABORT) {
// set default selected control
if (selected_dialog_button == 0) selected_dialog_button = 1;
// Draw centered controls
msg1 = "ABORT";
width = getStringWidth_verdana(msg1);
x1 = (SCREEN_WIDTH - width) / 2;
//if (selected_dialog_button == 1)
drawString_verdana(x1, y, color_selected, msg1);
}
else if (internal_dialog_type == DIALOG_1_2) {
// set default selected control
if (selected_dialog_button == 0) selected_dialog_button = 1;
// Draw centered controls
msg1 = "SLOT 1";
msg2 = "SLOT 2";
width = getStringWidth_verdana(msg1) + getStringWidth_verdana(msg2) + control_spacing;
x1 = (SCREEN_WIDTH - width) / 2;
x2 = x1 + width - getStringWidth_verdana(msg2);
if (selected_dialog_button == 1)
drawString_verdana(x1, y, color_selected, msg1);
else drawString_verdana(x1, y, color_unselected, msg1);
if (selected_dialog_button == 2)
drawString_verdana(x2, y, color_selected, msg2);
else drawString_verdana(x2, y, color_unselected, msg2);
}
else if (internal_dialog_type == DIALOG_NONE) {
// do nothing
}
}
//--------------------------------------------------------------
void draw_background(int alpha)
{
// Draw background texture
gsKit_prim_sprite_texture(gsGlobal, &tex_background,
0, // X1
0, // Y1
0, // U1
0, // V1
SCREEN_WIDTH, // X2
SCREEN_HEIGHT, // Y2
tex_background.Width, // U2
tex_background.Height, // V2
0,
GS_SETREG_RGBAQ(0x80, 0x80, 0x80, alpha, 0x00));
}
//--------------------------------------------------------------
void draw_up_panel(int y, int selected_button, int highlight_pulse, int highlight_blw)
{
// Draw a complete Up panel including bar, separators, buttons texts and highlight (with pulse control)
int i;
// Draw up bar
gsKit_prim_sprite_texture(gsGlobal, &tex_bar_up,
0, // X1
y, // Y1
0, // U1
0, // V1
SCREEN_WIDTH, // X2
y + tex_bar_up.Height, // Y2
tex_bar_up.Width, // U2
tex_bar_up.Height, // V2
0,
TexCol);
// Draw delimiters
for (i=1; i<6; i++) { //skip 1st and last up panel delimiters
gsKit_prim_sprite_texture(gsGlobal, &tex_bar_delimiter,
bar_delimiter_x[i], // X1
y, // Y1
0, // U1
0, // V1
bar_delimiter_x[i] + tex_bar_delimiter.Width, // X2
y + tex_bar_delimiter.Height, // Y2
tex_bar_delimiter.Width, // U2
tex_bar_delimiter.Height, // V2
0,
TexCol);
}
// Draw buttons text
for (i=0; i<6; i++) {
gsKit_prim_sprite_texture(gsGlobal, &tex_option[i],
option_x[i],// X1
y + 10, // Y1
0, // U1
0, // V1
option_x[i] + tex_option[i].Width, // X2
y + 10 + tex_option[i].Height, // Y2
tex_option[i].Width, // U2
tex_option[i].Height, // V2
0,
TexCol);
}
// Alpha calculation to control Highlight pulse
if (highlight_pulse) {
highlight_alpha += amount;
if (highlight_alpha >= 0xff) {
highlight_alpha = 0xff;
pause_pulse++;
if (pause_pulse >= 12) {
amount = -6;
pause_pulse = 0;
}
} else if (highlight_alpha <= 0x40) {
amount = 6;
highlight_alpha = 0x40;
}
}
else {
if (highlight_blw) {
stop_pulse_done = 1;
highlight_alpha = 0x80;
}
else {
stop_pulse_done = 0;
if (highlight_alpha <= 0xff) {
amount = 6;
highlight_alpha += amount;
if (highlight_alpha >= 0xff) {
highlight_alpha = 0xff;
stop_pulse_done = 1;
}
}
}
}
if (!highlight_pulse && highlight_blw && stop_pulse_done) {
// Draw highlighting on up panel selected button if needed
if (selected_button > 0) {
gsKit_prim_sprite_texture(gsGlobal, &tex_highlight_bw,
bar_delimiter_x[selected_button-1]+1,// X1
y, // Y1
0, // U1
0, // V1
bar_delimiter_x[selected_button], // X2
y + tex_highlight_bw.Height, // Y2
tex_highlight_bw.Width, // U2
tex_highlight_bw.Height, // V2
0,
GS_SETREG_RGBAQ(0x80, 0x80, 0x80, highlight_alpha, 0x00));
}
}
else {
// Draw highlighting on up panel selected button if needed
if (selected_button > 0) {
gsKit_prim_sprite_texture(gsGlobal, &tex_highlight,
bar_delimiter_x[selected_button-1]+1,// X1
y, // Y1
0, // U1
0, // V1
bar_delimiter_x[selected_button], // X2
y + tex_highlight.Height, // Y2
tex_highlight.Width, // U2
tex_highlight.Height, // V2
0,
GS_SETREG_RGBAQ(0x80, 0x80, 0x80, highlight_alpha, 0x00));
}
}
}
//--------------------------------------------------------------
void draw_down_panel(int y2) // careful : y2 !!!
{
// Draw a complete down panel including down bar, credits for code & gfx
// Draw down bar
gsKit_prim_sprite_texture(gsGlobal, &tex_bar_down,
0, // X1
y2 - tex_bar_down.Height, // Y1
0, // U1
0, // V1
SCREEN_WIDTH, // X2
y2, // Y2
tex_bar_down.Width, // U2
tex_bar_down.Height, // V2
0,
TexCol);
// Draw credits for code
gsKit_prim_sprite_texture(gsGlobal, &tex_credits_coded,
8, // X1
y2 - 4 - tex_credits_coded.Height, // Y1
0, // U1
0, // V1
8 + tex_credits_coded.Width, // X2
y2 - 4, // Y2
tex_credits_coded.Width, // U2
tex_credits_coded.Height, // V2
0,
TexCol);
// Draw credits for gfx
gsKit_prim_sprite_texture(gsGlobal, &tex_credits_gui,
SCREEN_WIDTH - 12 - tex_credits_gui.Width, // X1
y2 - 4 - tex_credits_gui.Height, // Y1
0, // U1
0, // V1
SCREEN_WIDTH - 12, // X2
y2 - 4, // Y2
tex_credits_gui.Width, // U2
tex_credits_gui.Height, // V2
0,
TexCol);
}
//--------------------------------------------------------------
void draw_logo(int width, int height, int alpha)
{
// Draw FMCB logo
int x1, x2, y1, y2;
// Calculates coordinates to center the logo
x1 = (SCREEN_WIDTH - width) / 2;
x2 = x1 + width;
y1 = (SCREEN_HEIGHT - height) / 2;
y2 = y1 + height;
// Draw logo
gsKit_prim_sprite_texture(gsGlobal, &tex_logo,
x1, // X1
y1, // Y1
0, // U1
0, // V1
x2, // X2
y2, // Y2
tex_logo.Width, // U2
tex_logo.Height, // V2
0,
GS_SETREG_RGBAQ(0x80, 0x80, 0x80, alpha, 0x00));
}
//----------------------------------------------------
void load_Textures(void)
{
// Load permanently needed textures into VRAM
pngData *pPng;
u8 *pImgData;
#ifdef DEBUG
printf("1st VRAM Pointer = %08x \n", gsGlobal->CurrentPointer);
#endif
//gsGlobal->CurrentPointer = vram_pointer;
if ((pPng = pngOpenRAW(&background, size_background)) > 0) { // tex size = 0x140000
if ((pImgData = malloc(pPng->width * pPng->height * (pPng->bit_depth / 8))) > 0) {
if (pngReadImage( pPng, pImgData ) != -1) {
tex_background.PSM = GS_PSM_CT32;
tex_background.Mem = (u32 *)pImgData;
tex_background.VramClut = 0;
tex_background.Clut = NULL;
tex_background.Width = pPng->width;
tex_background.Height = pPng->height;
tex_background.Filter = GS_FILTER_NEAREST;
#ifdef DEBUG
printf("VRAM Pointer = %08x ", gsGlobal->CurrentPointer);
printf("texture size = %x\n", gsKit_texture_size(pPng->width, pPng->height, GS_PSM_CT32));
#endif
tex_background.Vram = gsKit_vram_alloc(gsGlobal,
gsKit_texture_size(tex_background.Width, tex_background.Height, tex_background.PSM),
GSKIT_ALLOC_USERBUFFER);
gsKit_texture_upload(gsGlobal, &tex_background);
}
pngClose(pPng);
free(pImgData);
}
}
if ((pPng = pngOpenRAW(&bar_up, size_bar_up)) > 0) { // tex size = 0x8000
if ((pImgData = malloc(pPng->width * pPng->height * (pPng->bit_depth / 8))) > 0) {
if (pngReadImage( pPng, pImgData ) != -1) {
tex_bar_up.PSM = GS_PSM_CT32;
tex_bar_up.Mem = (u32 *)pImgData;
tex_bar_up.VramClut = 0;
tex_bar_up.Clut = NULL;
tex_bar_up.Width = pPng->width;
tex_bar_up.Height = pPng->height;
tex_bar_up.Filter = GS_FILTER_NEAREST;
#ifdef DEBUG
printf("VRAM Pointer = %08x ", gsGlobal->CurrentPointer);
printf("texture size = %x\n", gsKit_texture_size(pPng->width, pPng->height, GS_PSM_CT32));
#endif
tex_bar_up.Vram = gsKit_vram_alloc(gsGlobal,
gsKit_texture_size(tex_bar_up.Width, tex_bar_up.Height, tex_bar_up.PSM),
GSKIT_ALLOC_USERBUFFER);
gsKit_texture_upload(gsGlobal, &tex_bar_up);
}
pngClose(pPng);
free(pImgData);
}
}
if ((pPng = pngOpenRAW(&bar_down, size_bar_down)) > 0) { // tex size = 0x8000
if ((pImgData = malloc(pPng->width * pPng->height * (pPng->bit_depth / 8))) > 0) {
if (pngReadImage( pPng, pImgData ) != -1) {