/
menu_setting.c
14963 lines (13388 loc) · 542 KB
/
menu_setting.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
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2014-2017 - Jean-André Santoni
* Copyright (C) 2016-2019 - Brad Parker
*
* RetroArch 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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 RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef _WIN32
#include <direct.h>
#else
#include <unistd.h>
#endif
#include <libretro.h>
#include <lists/file_list.h>
#include <file/file_path.h>
#include <string/stdstring.h>
#include <lists/string_list.h>
#include <streams/file_stream.h>
#include <audio/audio_resampler.h>
#include <compat/strl.h>
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#include "../config.def.h"
#include "../config.def.keybinds.h"
#if defined(__CELLOS_LV2__)
#include <sdk_version.h>
#if (CELL_SDK_VERSION > 0x340000)
#include <sysutil/sysutil_bgmplayback.h>
#endif
#endif
#ifdef HAVE_CHEEVOS
#include "../cheevos-new/cheevos.h"
#endif
#include "../frontend/frontend_driver.h"
#include "widgets/menu_input_bind_dialog.h"
#include "menu_setting.h"
#include "menu_cbs.h"
#include "menu_driver.h"
#include "menu_animation.h"
#include "menu_input.h"
#include "menu_shader.h"
#include "widgets/menu_input_dialog.h"
#include "widgets/menu_input_bind_dialog.h"
#include "../core.h"
#include "../configuration.h"
#include "../msg_hash.h"
#include "../defaults.h"
#include "../driver.h"
#include "../dirs.h"
#include "../paths.h"
#include "../dynamic.h"
#include "../list_special.h"
#include "../camera/camera_driver.h"
#include "../wifi/wifi_driver.h"
#include "../location/location_driver.h"
#include "../record/record_driver.h"
#include "../audio/audio_driver.h"
#include "../input/input_driver.h"
#include "../midi/midi_driver.h"
#include "../tasks/tasks_internal.h"
#include "../config.def.h"
#include "../ui/ui_companion_driver.h"
#include "../performance_counters.h"
#include "../setting_list.h"
#include "../lakka.h"
#include "../retroarch.h"
#include "../gfx/video_display_server.h"
#include "../managers/cheat_manager.h"
#include "../verbosity.h"
#include "../tasks/tasks_internal.h"
#ifdef HAVE_NETWORKING
#include "../network/netplay/netplay.h"
#endif
#ifdef HAVE_VIDEO_LAYOUT
#include "../gfx/video_layout.h"
#endif
/* Required for 3DS display mode setting */
#if defined(_3DS)
#include "gfx/common/ctr_common.h"
#include <3ds/services/cfgu.h>
#endif
enum settings_list_type
{
SETTINGS_LIST_NONE = 0,
SETTINGS_LIST_MAIN_MENU,
SETTINGS_LIST_DRIVERS,
SETTINGS_LIST_CORE,
SETTINGS_LIST_CONFIGURATION,
SETTINGS_LIST_LOGGING,
SETTINGS_LIST_SAVING,
SETTINGS_LIST_REWIND,
SETTINGS_LIST_CHEAT_DETAILS,
SETTINGS_LIST_CHEAT_SEARCH,
SETTINGS_LIST_CHEATS,
SETTINGS_LIST_VIDEO,
SETTINGS_LIST_CRT_SWITCHRES,
SETTINGS_LIST_AUDIO,
SETTINGS_LIST_INPUT,
SETTINGS_LIST_INPUT_HOTKEY,
SETTINGS_LIST_RECORDING,
SETTINGS_LIST_FRAME_THROTTLING,
SETTINGS_LIST_FONT,
SETTINGS_LIST_OVERLAY,
#ifdef HAVE_VIDEO_LAYOUT
SETTINGS_LIST_VIDEO_LAYOUT,
#endif
SETTINGS_LIST_MENU,
SETTINGS_LIST_MENU_FILE_BROWSER,
SETTINGS_LIST_MULTIMEDIA,
SETTINGS_LIST_USER_INTERFACE,
SETTINGS_LIST_POWER_MANAGEMENT,
SETTINGS_LIST_MENU_SOUNDS,
SETTINGS_LIST_PLAYLIST,
SETTINGS_LIST_CHEEVOS,
SETTINGS_LIST_CORE_UPDATER,
SETTINGS_LIST_NETPLAY,
SETTINGS_LIST_LAKKA_SERVICES,
SETTINGS_LIST_USER,
SETTINGS_LIST_USER_ACCOUNTS,
SETTINGS_LIST_USER_ACCOUNTS_CHEEVOS,
SETTINGS_LIST_USER_ACCOUNTS_YOUTUBE,
SETTINGS_LIST_USER_ACCOUNTS_TWITCH,
SETTINGS_LIST_DIRECTORY,
SETTINGS_LIST_PRIVACY,
SETTINGS_LIST_MIDI
};
struct bool_entry
{
bool default_value;
bool *target;
uint32_t flags;
enum msg_hash_enums name_enum_idx;
enum msg_hash_enums SHORT_enum_idx;
enum msg_hash_enums off_enum_idx;
enum msg_hash_enums on_enum_idx;
};
struct string_options_entry
{
enum msg_hash_enums name_enum_idx;
enum msg_hash_enums SHORT_enum_idx;
const char *default_value;
const char *values;
char *target;
size_t len;
};
/* SETTINGS LIST */
#define _3_SECONDS 3000000
#define _6_SECONDS 6000000
#define _9_SECONDS 9000000
#define _12_SECONDS 12000000
#define _15_SECONDS 15000000
#define _18_SECONDS 18000000
#define _21_SECONDS 21000000
#define CONFIG_SIZE(a, b, c, d, e, f, g, h, i, j, k, l) \
if (settings_list_append(a, b)) \
config_size(a, b, c, d, e, f, g, h, i, j, k, l)
#define CONFIG_BOOL_ALT(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
if (settings_list_append(a, b)) \
config_bool_alt(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
#define CONFIG_BOOL(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
if (settings_list_append(a, b)) \
config_bool(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
#define CONFIG_INT(a, b, c, d, e, f, g, h, i, j, k) \
if (settings_list_append(a, b)) \
config_int(a, b, c, d, e, f, g, h, i, j, k)
#define CONFIG_UINT_ALT(a, b, c, d, e, f, g, h, i, j, k) \
if (settings_list_append(a, b)) \
config_uint_alt(a, b, c, d, e, f, g, h, i, j, k)
#define CONFIG_UINT(a, b, c, d, e, f, g, h, i, j, k) \
if (settings_list_append(a, b)) \
config_uint(a, b, c, d, e, f, g, h, i, j, k)
#define CONFIG_STRING(a, b, c, d, e, f, g, h, i, j, k, l) \
if (settings_list_append(a, b)) \
config_string(a, b, c, d, e, f, g, h, i, j, k, l)
#define CONFIG_FLOAT(a, b, c, d, e, f, g, h, i, j, k, l) \
if (settings_list_append(a, b)) \
config_float(a, b, c, d, e, f, g, h, i, j, k, l)
#define CONFIG_DIR(a, b, c, d, e, f, g, h, i, j, k, l, m) \
if (settings_list_append(a, b)) \
config_dir(a, b, c, d, e, f, g, h, i, j, k, l, m)
#define CONFIG_PATH(a, b, c, d, e, f, g, h, i, j, k, l) \
if (settings_list_append(a, b)) \
config_path(a, b, c, d, e, f, g, h, i, j, k, l)
#define CONFIG_ACTION_ALT(a, b, c, d, e, f, g) \
if (settings_list_append(a, b)) \
config_action_alt(a, b, c, d, e, f, g)
#define CONFIG_ACTION(a, b, c, d, e, f, g) \
if (settings_list_append(a, b)) \
config_action(a, b, c, d, e, f, g)
#define END_GROUP(a, b, c) \
if (settings_list_append(a, b)) \
end_group(a, b, c)
#define START_SUB_GROUP(a, b, c, d, e, f) \
if (settings_list_append(a, b)) \
start_sub_group(a, b, c, d, e, f)
#define END_SUB_GROUP(a, b, c) \
if (settings_list_append(a, b)) \
end_sub_group(a, b, c)
#define CONFIG_STRING_OPTIONS(a, b, c, d, e, f, g, h, i, j, k, l, m) \
if (settings_list_append(a, b)) \
config_string_options(a, b, c, d, e, f, g, h, i, j, k, l, m)
#define CONFIG_HEX(a, b, c, d, e, f, g, h, i, j, k, l) \
if (settings_list_append(a, b)) \
config_hex(a, b, c, d, e, f, g, h, i, j, k, l)
#define CONFIG_BIND_ALT(a, b, c, d, e, f, g, h, i, j, k) \
if (settings_list_append(a, b)) \
config_bind_alt(a, b, c, d, e, f, g, h, i, j, k)
#define CONFIG_BIND(a, b, c, d, e, f, g, h, i, j, k, l) \
if (settings_list_append(a, b)) \
config_bind(a, b, c, d, e, f, g, h, i, j, k, l)
#define SETTINGS_DATA_LIST_CURRENT_ADD_FREE_FLAGS(a, b, c) \
(*a)[b->index - 1].free_flags |= c
#define MENU_SETTINGS_LIST_CURRENT_ADD_ENUM_IDX_PTR(a, b, c) \
(*a)[b->index - 1].enum_idx = c
#define MENU_SETTINGS_LIST_CURRENT_ADD_ENUM_VALUE_IDX(a, b, c) \
(*a)[b->index - 1].enum_value_idx = c
static void menu_input_st_uint_cb(void *userdata, const char *str)
{
if (str && *str)
{
const char *label = menu_input_dialog_get_label_setting_buffer();
rarch_setting_t *setting = menu_setting_find(label);
setting_set_with_string_representation(setting, str);
}
menu_input_dialog_end();
}
/* TODO/FIXME - get rid of this eventually */
static void *setting_get_ptr(rarch_setting_t *setting)
{
if (!setting)
return NULL;
switch (setting_get_type(setting))
{
case ST_BOOL:
return setting->value.target.boolean;
case ST_INT:
return setting->value.target.integer;
case ST_UINT:
return setting->value.target.unsigned_integer;
case ST_SIZE:
return setting->value.target.sizet;
case ST_FLOAT:
return setting->value.target.fraction;
case ST_BIND:
return setting->value.target.keybind;
case ST_STRING:
case ST_STRING_OPTIONS:
case ST_PATH:
case ST_DIR:
return setting->value.target.string;
default:
break;
}
return NULL;
}
static void menu_input_st_hex_cb(void *userdata, const char *str)
{
if (str && *str)
{
const char *label = menu_input_dialog_get_label_setting_buffer();
rarch_setting_t *setting = menu_setting_find(label);
if (setting)
{
unsigned *ptr = (unsigned*)setting_get_ptr(setting);
if (str[0] == '#')
str++;
if (ptr)
*ptr = (unsigned)strtoul(str, NULL, 16);
}
}
menu_input_dialog_end();
}
static void menu_input_st_string_cb(void *userdata, const char *str)
{
if (str && *str)
{
rarch_setting_t *setting = NULL;
const char *label = menu_input_dialog_get_label_setting_buffer();
if (!string_is_empty(label))
setting = menu_setting_find(label);
if (setting)
{
setting_set_with_string_representation(setting, str);
menu_setting_generic(setting, false);
}
}
menu_input_dialog_end();
}
static int setting_generic_action_ok_linefeed(rarch_setting_t *setting, bool wraparound)
{
menu_input_ctx_line_t line;
input_keyboard_line_complete_t cb = NULL;
if (!setting)
return -1;
(void)wraparound;
switch (setting_get_type(setting))
{
case ST_SIZE:
case ST_UINT:
cb = menu_input_st_uint_cb;
break;
case ST_HEX:
cb = menu_input_st_hex_cb;
break;
case ST_STRING:
case ST_STRING_OPTIONS:
cb = menu_input_st_string_cb;
break;
default:
break;
}
line.label = setting->short_description;
line.label_setting = setting->name;
line.type = 0;
line.idx = 0;
line.cb = cb;
if (!menu_input_dialog_start(&line))
return -1;
return 0;
}
static void setting_add_special_callbacks(
rarch_setting_t **list,
rarch_setting_info_t *list_info,
unsigned values)
{
unsigned idx = list_info->index - 1;
if (values & SD_FLAG_ALLOW_INPUT)
{
(*list)[idx].action_ok = setting_generic_action_ok_linefeed;
(*list)[idx].action_select = setting_generic_action_ok_linefeed;
switch ((*list)[idx].type)
{
case ST_SIZE:
case ST_UINT:
(*list)[idx].action_cancel = NULL;
break;
case ST_HEX:
(*list)[idx].action_cancel = NULL;
break;
case ST_STRING:
(*list)[idx].action_start = setting_string_action_start_generic;
(*list)[idx].action_cancel = NULL;
break;
default:
break;
}
}
}
#define SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(a, b, c) \
{ \
(*a)[b->index - 1].flags |= c; \
setting_add_special_callbacks(a, b, c); \
}
static bool settings_list_append_internal(
rarch_setting_t **list,
rarch_setting_info_t *list_info)
{
unsigned new_size = list_info->size * 2;
rarch_setting_t *list_settings = (rarch_setting_t*)
realloc(*list, sizeof(rarch_setting_t) * new_size);
if (!list_settings)
return false;
list_info->size = new_size;
*list = list_settings;
return true;
}
#define settings_list_append(a, b) ((a && *a && b) ? ((((b)->index == (b)->size)) ? settings_list_append_internal(a, b) : true) : false)
unsigned setting_get_bind_type(rarch_setting_t *setting)
{
if (!setting)
return 0;
return setting->bind_type;
}
static int setting_bind_action_ok(rarch_setting_t *setting, bool wraparound)
{
(void)wraparound; /* TODO/FIXME - handle this */
if (!menu_input_key_bind_set_mode(MENU_INPUT_BINDS_CTL_BIND_SINGLE, setting))
return -1;
return 0;
}
static int setting_int_action_right_default(rarch_setting_t *setting, bool wraparound)
{
double max = 0.0f;
if (!setting)
return -1;
max = setting->max;
(void)wraparound; /* TODO/FIXME - handle this */
*setting->value.target.integer =
*setting->value.target.integer + setting->step;
if (setting->enforce_maxrange)
{
if (*setting->value.target.integer > max)
{
settings_t *settings = config_get_ptr();
double min = setting->min;
if (settings && settings->bools.menu_navigation_wraparound_enable)
*setting->value.target.integer = min;
else
*setting->value.target.integer = max;
}
}
return 0;
}
static int setting_bind_action_start(rarch_setting_t *setting)
{
unsigned bind_type;
struct retro_keybind *keybind = NULL;
struct retro_keybind *def_binds = (struct retro_keybind *)retro_keybinds_1;
if (!setting)
return -1;
keybind = (struct retro_keybind*)setting->value.target.keybind;
if (!keybind)
return -1;
keybind->joykey = NO_BTN;
keybind->joyaxis = AXIS_NONE;
if (setting->index_offset)
def_binds = (struct retro_keybind*)retro_keybinds_rest;
bind_type = setting_get_bind_type(setting);
keybind->key = def_binds[bind_type - MENU_SETTINGS_BIND_BEGIN].key;
keybind->mbutton = NO_BTN;
return 0;
}
static void setting_get_string_representation_hex(rarch_setting_t *setting,
char *s, size_t len)
{
if (setting)
snprintf(s, len, "%08x",
*setting->value.target.unsigned_integer);
}
void setting_get_string_representation_hex_and_uint(rarch_setting_t *setting,
char *s, size_t len)
{
if (setting)
snprintf(s, len, "%u (%08X)",
*setting->value.target.unsigned_integer, *setting->value.target.unsigned_integer);
}
void setting_get_string_representation_uint(rarch_setting_t *setting,
char *s, size_t len)
{
if (setting)
snprintf(s, len, "%u",
*setting->value.target.unsigned_integer);
}
void setting_get_string_representation_size(rarch_setting_t *setting,
char *s, size_t len)
{
if (setting)
snprintf(s, len, "%" PRI_SIZET,
*setting->value.target.sizet);
}
void setting_get_string_representation_size_in_mb(rarch_setting_t *setting,
char *s, size_t len)
{
if (setting)
snprintf(s, len, "%" PRI_SIZET,
(*setting->value.target.sizet)/(1024*1024));
}
void setting_get_string_representation_uint_as_enum(rarch_setting_t *setting,
char *s, size_t len)
{
if (setting)
snprintf(s, len, "%s",
msg_hash_to_str((enum msg_hash_enums)(
setting->index_offset+(
*setting->value.target.unsigned_integer))));
}
static float recalc_step_based_on_length_of_action(rarch_setting_t *setting)
{
float step = setting->step;
global_t *global = global_get_ptr();
if ( global )
{
if ( global->menu.action_press_time > _21_SECONDS)
step = setting->step*1000000.0f ;
else if ( global->menu.action_press_time > _18_SECONDS)
step = setting->step*100000.0f ;
else if ( global->menu.action_press_time > _15_SECONDS)
step = setting->step*10000.0f ;
else if ( global->menu.action_press_time > _12_SECONDS)
step = setting->step*1000.0f ;
else if ( global->menu.action_press_time > _9_SECONDS)
step = setting->step*100.0f ;
else if ( global->menu.action_press_time > _6_SECONDS)
step = setting->step*10.0f ;
else if ( global->menu.action_press_time > _3_SECONDS)
step = setting->step*5.0f ;
else
step = setting->step ;
}
return step < setting->step ? setting->step : step ;
}
int setting_uint_action_left_default(rarch_setting_t *setting, bool wraparound)
{
double min = 0.0f;
bool overflowed = false;
float step = 0.0f ;
if (!setting)
return -1;
min = setting->min;
(void)wraparound; /* TODO/FIXME - handle this */
step = recalc_step_based_on_length_of_action(setting) ;
overflowed = step > *setting->value.target.unsigned_integer;
if (!overflowed)
*setting->value.target.unsigned_integer = *setting->value.target.unsigned_integer - step;
if (setting->enforce_minrange)
{
if (overflowed || *setting->value.target.unsigned_integer < min)
{
settings_t *settings = config_get_ptr();
double max = setting->max;
if (settings && settings->bools.menu_navigation_wraparound_enable)
*setting->value.target.unsigned_integer = max;
else
*setting->value.target.unsigned_integer = min;
}
}
return 0;
}
int setting_uint_action_right_default(rarch_setting_t *setting, bool wraparound)
{
double max = 0.0f;
float step = 0.0f ;
if (!setting)
return -1;
max = setting->max;
(void)wraparound; /* TODO/FIXME - handle this */
step = recalc_step_based_on_length_of_action(setting) ;
*setting->value.target.unsigned_integer =
*setting->value.target.unsigned_integer + step;
if (setting->enforce_maxrange)
{
if (*setting->value.target.unsigned_integer > max)
{
settings_t *settings = config_get_ptr();
double min = setting->min;
if (settings && settings->bools.menu_navigation_wraparound_enable)
*setting->value.target.unsigned_integer = min;
else
*setting->value.target.unsigned_integer = max;
}
}
return 0;
}
int setting_uint_action_right_with_refresh(rarch_setting_t *setting, bool wraparound)
{
int retval = setting_uint_action_right_default(setting, wraparound) ;
bool refresh = false;
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
return retval ;
}
int setting_uint_action_left_with_refresh(rarch_setting_t *setting, bool wraparound)
{
int retval = setting_uint_action_left_default(setting, wraparound) ;
bool refresh = false;
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
return retval ;
}
static int setting_size_action_left_default(rarch_setting_t *setting, bool wraparound)
{
double min = 0.0f;
bool overflowed = false;
float step = 0.0f ;
if (!setting)
return -1;
min = setting->min;
(void)wraparound; /* TODO/FIXME - handle this */
step = recalc_step_based_on_length_of_action(setting) ;
overflowed = step > *setting->value.target.sizet;
if (!overflowed)
*setting->value.target.sizet = *setting->value.target.sizet - step;
if (setting->enforce_minrange)
{
if (overflowed || *setting->value.target.sizet < min)
{
settings_t *settings = config_get_ptr();
double max = setting->max;
if (settings && settings->bools.menu_navigation_wraparound_enable)
*setting->value.target.sizet = max;
else
*setting->value.target.sizet = min;
}
}
return 0;
}
static int setting_size_action_right_default(rarch_setting_t *setting, bool wraparound)
{
double max = 0.0f;
float step = 0.0f ;
if (!setting)
return -1;
max = setting->max;
(void)wraparound; /* TODO/FIXME - handle this */
step = recalc_step_based_on_length_of_action(setting) ;
*setting->value.target.sizet =
*setting->value.target.sizet + step;
if (setting->enforce_maxrange)
{
if (*setting->value.target.sizet > max)
{
settings_t *settings = config_get_ptr();
double min = setting->min;
if (settings && settings->bools.menu_navigation_wraparound_enable)
*setting->value.target.sizet = min;
else
*setting->value.target.sizet = max;
}
}
return 0;
}
int setting_generic_action_ok_default(rarch_setting_t *setting, bool wraparound)
{
if (!setting)
return -1;
(void)wraparound; /* TODO/FIXME - handle this */
if (setting->cmd_trigger.idx != CMD_EVENT_NONE)
setting->cmd_trigger.triggered = true;
return 0;
}
static void setting_get_string_representation_int(rarch_setting_t *setting,
char *s, size_t len)
{
if (setting)
snprintf(s, len, "%d", *setting->value.target.integer);
}
/**
* setting_set_with_string_representation:
* @setting : pointer to setting
* @value : value for the setting (string)
*
* Set a settings' value with a string. It is assumed
* that the string has been properly formatted.
**/
int setting_set_with_string_representation(rarch_setting_t* setting,
const char* value)
{
double min, max;
uint64_t flags;
if (!setting || !value)
return -1;
min = setting->min;
max = setting->max;
flags = setting->flags;
switch (setting_get_type(setting))
{
case ST_INT:
sscanf(value, "%d", setting->value.target.integer);
if (flags & SD_FLAG_HAS_RANGE)
{
if (setting->enforce_minrange && *setting->value.target.integer < min)
*setting->value.target.integer = min;
if (setting->enforce_maxrange && *setting->value.target.integer > max)
{
settings_t *settings = config_get_ptr();
if (settings && settings->bools.menu_navigation_wraparound_enable)
*setting->value.target.integer = min;
else
*setting->value.target.integer = max;
}
}
break;
case ST_UINT:
sscanf(value, "%u", setting->value.target.unsigned_integer);
if (flags & SD_FLAG_HAS_RANGE)
{
if (setting->enforce_minrange && *setting->value.target.unsigned_integer < min)
*setting->value.target.unsigned_integer = min;
if (setting->enforce_maxrange && *setting->value.target.unsigned_integer > max)
{
settings_t *settings = config_get_ptr();
if (settings && settings->bools.menu_navigation_wraparound_enable)
*setting->value.target.unsigned_integer = min;
else
*setting->value.target.unsigned_integer = max;
}
}
break;
case ST_SIZE:
sscanf(value, "%" PRI_SIZET, setting->value.target.sizet);
if (flags & SD_FLAG_HAS_RANGE)
{
if (setting->enforce_minrange && *setting->value.target.sizet < min)
*setting->value.target.sizet = min;
if (setting->enforce_maxrange && *setting->value.target.sizet > max)
{
settings_t *settings = config_get_ptr();
if (settings && settings->bools.menu_navigation_wraparound_enable)
*setting->value.target.sizet = min;
else
*setting->value.target.sizet = max;
}
}
break;
case ST_FLOAT:
sscanf(value, "%f", setting->value.target.fraction);
if (flags & SD_FLAG_HAS_RANGE)
{
if (setting->enforce_minrange && *setting->value.target.fraction < min)
*setting->value.target.fraction = min;
if (setting->enforce_maxrange && *setting->value.target.fraction > max)
{
settings_t *settings = config_get_ptr();
if (settings && settings->bools.menu_navigation_wraparound_enable)
*setting->value.target.fraction = min;
else
*setting->value.target.fraction = max;
}
}
break;
case ST_PATH:
case ST_DIR:
case ST_STRING:
case ST_STRING_OPTIONS:
case ST_ACTION:
if ( setting->value.target.string != NULL)
strlcpy(setting->value.target.string, value, setting->size);
break;
case ST_BOOL:
if (string_is_equal(value, "true"))
*setting->value.target.boolean = true;
else if (string_is_equal(value, "false"))
*setting->value.target.boolean = false;
break;
default:
break;
}
if (setting->change_handler)
setting->change_handler(setting);
return 0;
}
static int setting_fraction_action_left_default(
rarch_setting_t *setting, bool wraparound)
{
double min = 0.0f;
if (!setting)
return -1;
min = setting->min;
(void)wraparound; /* TODO/FIXME - handle this */
*setting->value.target.fraction = *setting->value.target.fraction - setting->step;
if (setting->enforce_minrange)
{
if (*setting->value.target.fraction < min)
{
settings_t *settings = config_get_ptr();
double max = setting->max;
if (settings && settings->bools.menu_navigation_wraparound_enable)
*setting->value.target.fraction = max;
else
*setting->value.target.fraction = min;
}
}
return 0;
}
static int setting_fraction_action_right_default(
rarch_setting_t *setting, bool wraparound)
{
double max = 0.0f;
if (!setting)
return -1;
max = setting->max;
(void)wraparound; /* TODO/FIXME - handle this */
*setting->value.target.fraction =
*setting->value.target.fraction + setting->step;
if (setting->enforce_maxrange)
{
if (*setting->value.target.fraction > max)
{
settings_t *settings = config_get_ptr();
double min = setting->min;
if (settings && settings->bools.menu_navigation_wraparound_enable)
*setting->value.target.fraction = min;
else
*setting->value.target.fraction = max;
}
}
return 0;
}
/**
* setting_reset_setting:
* @setting : pointer to setting
*
* Reset a setting's value to its defaults.
**/
static void setting_reset_setting(rarch_setting_t* setting)
{
if (!setting)
return;
switch (setting_get_type(setting))
{
case ST_BOOL:
*setting->value.target.boolean = setting->default_value.boolean;
break;
case ST_INT:
*setting->value.target.integer = setting->default_value.integer;
break;
case ST_UINT:
*setting->value.target.unsigned_integer = setting->default_value.unsigned_integer;
break;
case ST_SIZE:
*setting->value.target.sizet = setting->default_value.sizet;
break;
case ST_FLOAT:
*setting->value.target.fraction = setting->default_value.fraction;
break;
case ST_BIND:
*setting->value.target.keybind = *setting->default_value.keybind;
break;
case ST_STRING:
case ST_STRING_OPTIONS:
case ST_PATH: