-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmenu.c
1960 lines (1600 loc) · 55.7 KB
/
menu.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
// Temper menu code
#include "common.h"
#define menu_line(line) \
(line * 8) \
#define make_color16(r, g, b) \
(b | (g << 5) | (r << 11)) \
void gui_wait_for_input(gui_input_struct *gui_input)
{
do
{
get_gui_input(gui_input);
} while(gui_input->action_type == CURSOR_NONE);
}
#define FILE_LIST_ROWS ((int)((240 - 40) / 10))
#define FILE_LIST_CHARS 36
#define DIR_LIST_CHARS 16
#define FILE_LIST_POSITION 6
#define DIR_LIST_POSITION (FILE_LIST_POSITION + (FILE_LIST_CHARS * 6) + 1)
int sort_function(const void *dest_str_ptr, const void *src_str_ptr)
{
char *dest_str = *((char **)dest_str_ptr);
char *src_str = *((char **)src_str_ptr);
if(src_str[0] == '.')
return 1;
if(dest_str[0] == '.')
return -1;
return strcasecmp(dest_str, src_str);
}
#define move_cursor_down() \
if(current_column == 0) \
{ \
if(current_file_selection < (num_files - 1)) \
{ \
current_file_selection++; \
if(current_file_in_scroll == (FILE_LIST_ROWS - 1)) \
current_file_scroll_value++; \
else \
current_file_in_scroll++; \
} \
} \
else \
{ \
if(current_dir_selection < (num_dirs - 1)) \
{ \
current_dir_selection++; \
if(current_dir_in_scroll == (FILE_LIST_ROWS - 1)) \
current_dir_scroll_value++; \
else \
current_dir_in_scroll++; \
} \
} \
#define move_cursor_up() \
if(current_column == 0) \
{ \
if(current_file_selection) \
{ \
current_file_selection--; \
if(current_file_in_scroll == 0) \
current_file_scroll_value--; \
else \
current_file_in_scroll--; \
} \
} \
else \
{ \
if(current_dir_selection) \
{ \
current_dir_selection--; \
if(current_dir_in_scroll == 0) \
current_dir_scroll_value--; \
else \
current_dir_in_scroll--; \
} \
} \
const u32 cursor_page_rate = FILE_LIST_ROWS;
#define SEEK_TICKS_THRESHOLD (500 * 1000)
#define SEEK_MAX_CHARACTERS 6
s32 load_file(char **wildcards, char *result, u16 *screen_bg)
{
DIR *current_dir;
struct dirent *current_file;
struct stat file_info;
char current_dir_name[MAX_PATH];
char current_dir_short[81];
u32 current_dir_length;
u32 total_filenames_allocated;
u32 total_dirnames_allocated;
char **file_list;
char **dir_list;
u32 num_files;
u32 num_dirs;
char *file_name;
u32 file_name_length;
u32 ext_pos = -1;
u32 chosen_file, chosen_dir;
s32 return_value = 1;
u32 current_file_selection;
u32 current_file_scroll_value;
u32 current_dir_selection;
u32 current_dir_scroll_value;
u32 current_file_in_scroll;
u32 current_dir_in_scroll;
u32 current_file_number, current_dir_number;
u32 current_column = 0;
u32 repeat;
u32 i;
char seek_string[SEEK_MAX_CHARACTERS + 1];
u32 seek_characters = 0;
u64 last_seek_ticks = 0;
gui_input_struct gui_input;
char name_buffer[FILE_LIST_CHARS + 1];
char *name_buffer_ptr;
blit_screen(screen_bg);
set_font_narrow();
while(return_value == 1)
{
current_file_selection = 0;
current_file_scroll_value = 0;
current_dir_selection = 0;
current_dir_scroll_value = 0;
current_file_in_scroll = 0;
current_dir_in_scroll = 0;
total_filenames_allocated = 32;
total_dirnames_allocated = 32;
file_list = malloc(sizeof(char *) * 32);
dir_list = malloc(sizeof(char *) * 32);
memset(file_list, 0, sizeof(char *) * 32);
memset(dir_list, 0, sizeof(char *) * 32);
num_files = 0;
num_dirs = 0;
chosen_file = 0;
chosen_dir = 0;
getcwd(current_dir_name, MAX_PATH);
current_dir = opendir(current_dir_name);
do
{
if(current_dir)
current_file = readdir(current_dir);
else
current_file = NULL;
if(current_file)
{
file_name = current_file->d_name;
file_name_length = strlen(file_name);
if((stat(file_name, &file_info) >= 0) &&
((file_name[0] != '.') || (file_name[1] == '.')))
{
if(S_ISDIR(file_info.st_mode))
{
dir_list[num_dirs] =
malloc(file_name_length + 1);
sprintf(dir_list[num_dirs], "%s", file_name);
num_dirs++;
}
else
{
// Must match one of the wildcards, also ignore the .
if(file_name_length >= 4)
{
if(file_name[file_name_length - 4] == '.')
ext_pos = file_name_length - 4;
else
if(file_name[file_name_length - 3] == '.')
ext_pos = file_name_length - 3;
else
ext_pos = 0;
for(i = 0; wildcards[i] != NULL; i++)
{
if(strstr((file_name + ext_pos),
wildcards[i]))
{
file_list[num_files] =
malloc(file_name_length + 1);
sprintf(file_list[num_files], "%s", file_name);
num_files++;
break;
}
}
}
}
}
if(num_files == total_filenames_allocated)
{
file_list = realloc(file_list, sizeof(char *) *
total_filenames_allocated * 2);
memset(file_list + total_filenames_allocated, 0,
sizeof(char *) * total_filenames_allocated);
total_filenames_allocated *= 2;
}
if(num_dirs == total_dirnames_allocated)
{
dir_list = realloc(dir_list, sizeof(char *) *
total_dirnames_allocated * 2);
memset(dir_list + total_dirnames_allocated, 0,
sizeof(char *) * total_dirnames_allocated);
total_dirnames_allocated *= 2;
}
}
} while(current_file);
qsort((void *)file_list, num_files, sizeof(char *), sort_function);
qsort((void *)dir_list, num_dirs, sizeof(char *), sort_function);
closedir(current_dir);
current_dir_length = strlen(current_dir_name);
if(current_dir_length > 80)
{
snprintf(current_dir_short, 80,
"...%s", current_dir_name + current_dir_length - 77);
}
else
{
snprintf(current_dir_short, 80, "%s", current_dir_name);
}
repeat = 1;
if(num_files == 0)
current_column = 1;
while(repeat)
{
print_string_bg(current_dir_short, make_color16(0x1F, 0x3F, 0x1F),
screen_bg, 6, 4, RESOLUTION_WIDTH);
print_string_bg(control_config_exit_string,
make_color16(0x1F, 0x3F, 0x1F), screen_bg, 20, 228, RESOLUTION_WIDTH);
for(i = 0, current_file_number = i + current_file_scroll_value;
i < FILE_LIST_ROWS; i++, current_file_number++)
{
if(current_file_number < num_files)
{
name_buffer_ptr = file_list[current_file_number];
if(strlen(name_buffer_ptr) >= FILE_LIST_CHARS)
{
memcpy(name_buffer, name_buffer_ptr, FILE_LIST_CHARS);
name_buffer_ptr = name_buffer;
name_buffer_ptr[FILE_LIST_CHARS] = 0;
}
if((current_file_number == current_file_selection) &&
(current_column == 0))
{
print_string(name_buffer_ptr, make_color16(0x1F, 0x3F, 0x1F),
make_color16(0x0, 0x0, 0x17), FILE_LIST_POSITION, (i * 10) + 20,
RESOLUTION_WIDTH);
}
else
{
print_string_bg(name_buffer_ptr, make_color16(0x1F, 0x3F, 0x1F),
screen_bg, FILE_LIST_POSITION, (i * 10) + 20, RESOLUTION_WIDTH);
}
}
}
for(i = 0, current_dir_number = i + current_dir_scroll_value;
i < FILE_LIST_ROWS; i++, current_dir_number++)
{
if(current_dir_number < num_dirs)
{
name_buffer_ptr = dir_list[current_dir_number];
if(strlen(name_buffer_ptr) >= DIR_LIST_CHARS)
{
memcpy(name_buffer, name_buffer_ptr, DIR_LIST_CHARS);
name_buffer_ptr = name_buffer;
name_buffer_ptr[DIR_LIST_CHARS] = 0;
}
if((current_dir_number == current_dir_selection) &&
(current_column == 1))
{
print_string(name_buffer_ptr, make_color16(0x1F, 0x3F, 0x1F),
make_color16(0x0, 0x0, 0x17), DIR_LIST_POSITION, (i * 10) + 20,
RESOLUTION_WIDTH);
}
else
{
print_string_bg(name_buffer_ptr, make_color16(0x1F, 0x3F, 0x1F),
screen_bg, DIR_LIST_POSITION, (i * 10) + 20, RESOLUTION_WIDTH);
}
}
}
update_screen();
gui_wait_for_input(&gui_input);
switch(gui_input.action_type)
{
case CURSOR_DOWN:
move_cursor_down();
break;
case CURSOR_UP:
move_cursor_up();
break;
// Cheap but effective.
case CURSOR_PAGE_UP:
for(i = 0; i < cursor_page_rate; i++)
{
move_cursor_up();
}
break;
case CURSOR_PAGE_DOWN:
for(i = 0; i < cursor_page_rate; i++)
{
move_cursor_down();
}
break;
case CURSOR_RIGHT:
if(current_column == 0)
{
if(num_dirs != 0)
current_column = 1;
}
break;
case CURSOR_LEFT:
if(current_column == 1)
{
if(num_files != 0)
current_column = 0;
}
break;
case CURSOR_SELECT:
if(current_column == 1)
{
repeat = 0;
chdir(dir_list[current_dir_selection]);
}
else
{
if(num_files != 0)
{
repeat = 0;
return_value = 0;
strcpy(result, file_list[current_file_selection]);
}
}
break;
case CURSOR_BACK:
repeat = 0;
chdir("..");
break;
case CURSOR_EXIT:
return_value = -1;
repeat = 0;
break;
case CURSOR_LETTER:
{
char **select_list = file_list;
u32 num_items = num_files;
u64 current_ticks;
get_ticks_us(¤t_ticks);
if((current_ticks - last_seek_ticks) > SEEK_TICKS_THRESHOLD)
seek_characters = 0;
last_seek_ticks = current_ticks;
if(seek_characters < SEEK_MAX_CHARACTERS)
{
seek_string[seek_characters] = gui_input.key_letter;
seek_characters++;
seek_string[seek_characters + 1] = 0;
if(current_column == 1)
{
select_list = dir_list;
num_items = num_dirs;
}
for(i = 0; i < num_items; i++)
{
if(!strncasecmp(select_list[i], seek_string, seek_characters))
break;
}
if(i != num_items)
{
s32 scroll_offset = i - (FILE_LIST_ROWS / 2);
s32 in_scroll = FILE_LIST_ROWS / 2;
if(scroll_offset < 0)
{
scroll_offset = 0;
in_scroll = i;
}
if(current_column == 0)
{
current_file_selection = i;
current_file_scroll_value = scroll_offset;
current_file_in_scroll = in_scroll;
}
else
{
current_dir_selection = i;
current_dir_scroll_value = scroll_offset;
current_dir_in_scroll = in_scroll;
}
}
}
break;
}
default:
break;
}
blit_screen(screen_bg);
}
for(i = 0; i < num_files; i++)
{
free(file_list[i]);
}
free(file_list);
for(i = 0; i < num_dirs; i++)
{
free(dir_list[i]);
}
free(dir_list);
}
set_font_wide();
return return_value;
}
char *pce_ext[] = { ".pce", ".bz2", ".cue", ".sgx", NULL };
void modify_snapshot_bg(menu_state_struct *menu_state,
menu_option_struct *menu_option)
{
if(config.rom_filename[0])
{
u32 load_state_flags;
char state_name[MAX_PATH];
char state_date[256];
sprintf(state_name, "%s_%d.svs", config.rom_filename,
config.savestate_number);
menu_state->current_bg = menu_state->load_state_snapshot_bg;
load_state_flags = load_state_snapshot(state_name,
menu_state->load_state_snapshot_bg, state_date);
if(load_state_flags & SS_EXT_SNAPSHOT)
{
buffer_half_intensity(menu_state->current_bg,
menu_state->current_bg, 320);
}
else
{
memset(menu_state->current_bg, 0, 320 * 240 * sizeof(u16));
}
if(load_state_flags & SS_EXT_INVALID)
sprintf(menu_state->bg_info_string, "(savestate does not exist)");
else
sprintf(menu_state->bg_info_string, "state saved at: %s", state_date);
}
}
void draw_menu_option_string(menu_state_struct *menu_state,
menu_option_struct *menu_option, char *display_str, u32 selected)
{
u32 column_start = menu_state->current_menu->column_start;
if(selected)
{
print_string(display_str, make_color16(0x1F, 0x3F, 0x1F),
make_color16(0x0, 0x0, 0x17), column_start, menu_option->line_number * 8,
RESOLUTION_WIDTH);
}
else
{
print_string_bg(display_str, make_color16(0x1F, 0x3F, 0x1F),
menu_state->current_bg, column_start, menu_option->line_number * 8,
RESOLUTION_WIDTH);
}
}
void draw_menu_option(menu_state_struct *menu_state,
menu_option_struct *menu_option, u32 selected)
{
draw_menu_option_string(menu_state, menu_option, menu_option->name,
selected);
}
void draw_numeric(menu_state_struct *menu_state,
menu_option_struct *menu_option, u32 selected)
{
u32 numeric_limit = 1;
char display_str[256];
menu_option_numeric_struct *numeric =
(menu_option_numeric_struct *)menu_option;
if(numeric->upper_limit > 10000)
numeric_limit = 5;
else
if(numeric->upper_limit > 1000)
numeric_limit = 4;
else
if(numeric->upper_limit > 100)
numeric_limit = 3;
else
if(numeric->upper_limit > 10)
numeric_limit = 2;
sprintf(display_str, "%s%*d", menu_option->name, numeric_limit,
*(numeric->value));
draw_menu_option_string(menu_state, menu_option, display_str,
selected);
}
void draw_numeric_labeled(menu_state_struct *menu_state,
menu_option_struct *menu_option, u32 selected)
{
char display_str[64];
menu_option_numeric_struct *numeric =
(menu_option_numeric_struct *)menu_option;
menu_option_numeric_labeled_struct *numeric_labeled =
(menu_option_numeric_labeled_struct *)menu_option;
snprintf(display_str, sizeof(display_str), "%s%s", menu_option->name,
numeric_labeled->labels[*(numeric->value)]);
draw_menu_option_string(menu_state, menu_option, display_str,
selected);
}
void draw_input_str(menu_state_struct *menu_state,
menu_option_input_struct *input, u32 draw_offset, u32 selected,
u32 highlight_current)
{
u32 y_offset = input->base.line_number * 8;
u32 space_length = input->num_segments - input->num_segments_active;
if(selected)
{
char spacer_str[256];
s8 selected_char[2];
memset(spacer_str, ' ', space_length);
spacer_str[space_length] = 0;
print_string(spacer_str, make_color16(0x1F, 0x3F, 0x1F),
make_color16(0x0, 0x00, 0x17), draw_offset, y_offset, RESOLUTION_WIDTH);
draw_offset += space_length * 8;
selected_char[0] = input->segment_values[input->segment_position];
selected_char[1] = 0;
print_string((char *)input->segment_values, make_color16(0x1F, 0x3F, 0x1F),
make_color16(0x0, 0x10, 0x1A), draw_offset, y_offset, RESOLUTION_WIDTH);
if(highlight_current)
{
print_string((char *)selected_char, make_color16(0x1F, 0x3F, 0x1F),
make_color16(0x0, 0x30, 0x0), draw_offset +
(input->segment_position * 8), y_offset, RESOLUTION_WIDTH);
}
}
else
{
draw_offset += space_length * 8;
print_string_bg((char *)input->segment_values,
make_color16(0x1F, 0x3F, 0x1F), menu_state->current_bg, draw_offset,
y_offset, RESOLUTION_WIDTH);
}
}
void draw_input(menu_state_struct *menu_state,
menu_option_struct *menu_option, u32 selected)
{
menu_option_input_struct *input = (menu_option_input_struct *)menu_option;
u32 display_input_offset;
draw_menu_option_string(menu_state, menu_option, menu_option->name,
selected);
display_input_offset = strlen(menu_option->name);
draw_input_str(menu_state, input, menu_state->current_menu->column_start +
(display_input_offset * 8), selected, 1);
}
void draw_multi_input_int(menu_state_struct *menu_state,
menu_option_struct *menu_option, u32 selected)
{
menu_option_multi_input_int_struct *multi_input_int =
(menu_option_multi_input_int_struct *)menu_option;
menu_option_input_int_struct *current_input_int;
u32 display_input_offset;
s32 i;
draw_menu_option_string(menu_state, menu_option, menu_option->name,
selected);
display_input_offset = strlen(menu_option->name);
for(i = 0; i < multi_input_int->num_input_ints; i++)
{
char separator_str[2];
separator_str[0] = multi_input_int->separator;
separator_str[0] = '.';
separator_str[1] = 0;
current_input_int = multi_input_int->input_ints[i];
draw_input_str(menu_state, (menu_option_input_struct *)current_input_int,
menu_state->current_menu->column_start + (display_input_offset * 8),
selected, i == multi_input_int->current_input_int);
display_input_offset += multi_input_int->spacing;
if(separator_str[0] && (i != multi_input_int->num_input_ints - 1) )
{
if(selected)
{
print_string(separator_str, make_color16(0x1F, 0x3F, 0x1F),
make_color16(0x0, 0x0, 0x17), menu_state->current_menu->column_start +
(display_input_offset * 8), menu_option->line_number * 8,
RESOLUTION_WIDTH);
}
else
{
print_string_bg(separator_str, make_color16(0x1F, 0x3F, 0x1F),
menu_state->current_bg, menu_state->current_menu->column_start +
(display_input_offset * 8), menu_option->line_number * 8,
RESOLUTION_WIDTH);
}
display_input_offset++;
}
}
}
u32 action_numeric(menu_state_struct *menu_state,
menu_option_struct *menu_option, gui_input_struct *gui_input)
{
menu_option_numeric_struct *numeric =
(menu_option_numeric_struct *)menu_option;
s32 value = *(numeric->value);
u32 numeric_range = (numeric->upper_limit - numeric->lower_limit) + 1;
s32 value_mod = 0;
switch(gui_input->action_type)
{
case CURSOR_LEFT:
value_mod = -1;
break;
case CURSOR_RIGHT:
value_mod = 1;
break;
case CURSOR_PAGE_DOWN:
value_mod = -10;
break;
case CURSOR_PAGE_UP:
value_mod = 10;
break;
default:
return gui_input->action_type;
}
value += value_mod;
while(value < numeric->lower_limit)
value += numeric_range;
while(value > numeric->upper_limit)
value -= numeric_range;
*(numeric->value) = value;
return CURSOR_NONE;
}
u32 action_select(menu_state_struct *menu_state,
menu_option_struct *menu_option, gui_input_struct *gui_input)
{
menu_option_select_struct *select = (menu_option_select_struct *)menu_option;
switch(gui_input->action_type)
{
case CURSOR_SELECT:
select->select_function(menu_state, menu_option);
break;
default:
return gui_input->action_type;
}
return CURSOR_NONE;
}
u32 action_select_menu(menu_state_struct *menu_state,
menu_option_struct *menu_option, gui_input_struct *gui_input)
{
menu_option_select_menu_struct *select_menu =
(menu_option_select_menu_struct *)menu_option;
switch(gui_input->action_type)
{
case CURSOR_SELECT:
{
menu_struct *target_menu = select_menu->target_menu;
menu_struct *current_menu = menu_state->current_menu;
menu_state->current_menu = target_menu;
if(current_menu->focus_function)
current_menu->focus_function(menu_state, target_menu, FOCUS_TYPE_EXIT);
if(target_menu->focus_function)
target_menu->focus_function(menu_state, target_menu, FOCUS_TYPE_ENTER);
break;
}
default:
return gui_input->action_type;
}
return CURSOR_NONE;
}
u32 action_numeric_select(menu_state_struct *menu_state,
menu_option_struct *menu_option, gui_input_struct *gui_input)
{
menu_option_numeric_select_struct *numeric_select =
(menu_option_numeric_select_struct *)menu_option;
u32 new_gui_action = action_numeric(menu_state, menu_option, gui_input);
switch(gui_input->action_type)
{
case CURSOR_LEFT:
case CURSOR_RIGHT:
case CURSOR_PAGE_UP:
case CURSOR_PAGE_DOWN:
case CURSOR_BACK:
if(numeric_select->modify_function)
numeric_select->modify_function(menu_state, menu_option);
break;
case CURSOR_SELECT:
numeric_select->select_function(menu_state, menu_option);
break;
default:
break;
}
return new_gui_action;
}
u32 action_input(menu_state_struct *menu_state,
menu_option_struct *menu_option, gui_input_struct *gui_input)
{
menu_option_input_struct *input = (menu_option_input_struct *)menu_option;
s32 segment_position = input->segment_position;
s32 segment_position_mod = 0;
s32 segment_value = input->segment_values[segment_position];
s32 segment_value_mod = 0;
switch(gui_input->action_type)
{
#ifdef KEYBOARD_SUPPORT
case CURSOR_PAGE_UP:
segment_value_mod = -1;
break;
case CURSOR_PAGE_DOWN:
segment_value_mod = 1;
break;
case CURSOR_LEFT:
segment_position_mod = -1;
break;
case CURSOR_RIGHT:
segment_position_mod = 1;
break;
#else
case CURSOR_LEFT:
segment_value_mod = -1;
break;
case CURSOR_RIGHT:
segment_value_mod = 1;
break;
case CURSOR_PAGE_UP:
segment_position_mod = -1;
break;
case CURSOR_PAGE_DOWN:
segment_position_mod = 1;
break;
#endif
case CURSOR_BACK:
if(input->num_segments_active > 1)
{
(input->num_segments_active)--;
if(segment_position < input->num_segments_active)
{
memmove(&(input->segment_values[segment_position]),
&(input->segment_values[segment_position + 1]),
(input->num_segments_active - segment_position));
}
else
{
input->segment_position = segment_position - 1;
}
if(segment_position)
segment_position_mod = -1;
}
break;
case CURSOR_SELECT:
if(input->num_segments_active < input->num_segments)
{
memmove(&(input->segment_values[segment_position + 1]),
&(input->segment_values[segment_position]),
input->num_segments_active - segment_position);
(input->num_segments_active)++;
if(input->segment_insert_value != -1)
{
input->segment_values[segment_position + 1] =
input->segment_insert_value;
}
segment_position_mod = 1;
}
break;
case CURSOR_LETTER:
if((gui_input->key_letter >= input->segment_lower_limit) &&
(gui_input->key_letter <= input->segment_upper_limit))
{
input->segment_values[segment_position] = gui_input->key_letter;
segment_position_mod = 1;
}
break;
default:
return gui_input->action_type;
}
if(segment_value_mod)
{
segment_value += segment_value_mod;
if(segment_value < input->segment_lower_limit)
segment_value = input->segment_upper_limit;
if(segment_value > input->segment_upper_limit)
segment_value = input->segment_lower_limit;
input->segment_values[segment_position] = segment_value;
}
if(segment_position_mod)
{
segment_position += segment_position_mod;
if(input->wrap_position)
{
if(segment_position < 0)
segment_position = input->num_segments_active - 1;
if(segment_position >= input->num_segments_active)
segment_position = 0;
}
else
{
if((segment_position < 0) ||
(segment_position >= input->num_segments_active))
{
return gui_input->action_type;
}
}
input->segment_position = segment_position;
}
input->segment_values[input->num_segments_active] = 0;
return CURSOR_NONE;
}
u32 action_multi_input_int(menu_state_struct *menu_state,
menu_option_struct *menu_option, gui_input_struct *gui_input)
{
menu_option_multi_input_int_struct *multi_input_int =
(menu_option_multi_input_int_struct *)menu_option;
menu_option_input_int_struct *current_input_int =
multi_input_int->input_ints[multi_input_int->current_input_int];
gui_action_type gui_action = action_input(menu_state,
(menu_option_struct *)current_input_int, gui_input);
switch(gui_action)
{
#ifdef KEYBOARD_SUPPORT
case CURSOR_RIGHT:
#else
case CURSOR_PAGE_DOWN:
#endif
if(multi_input_int->current_input_int <
multi_input_int->num_input_ints - 1)
{
(multi_input_int->current_input_int)++;
}
break;
#ifdef KEYBOARD_SUPPORT
case CURSOR_LEFT:
#else
case CURSOR_PAGE_UP:
#endif
if(multi_input_int->current_input_int > 0)
(multi_input_int->current_input_int)--;
break;
default:
return gui_action;
}
return CURSOR_NONE;
}
void focus_input_int(menu_state_struct *menu_state,
menu_option_struct *menu_option, u32 focus_type)
{
if(focus_type == FOCUS_TYPE_EXIT)
{
s32 value;
menu_option_input_int_struct *input_int =
(menu_option_input_int_struct *)menu_option;
sscanf((char *)input_int->segment_values, "%d", &value);