-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathxmb.c
More file actions
10031 lines (8854 loc) · 353 KB
/
xmb.c
File metadata and controls
10031 lines (8854 loc) · 353 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
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) 2011-2017 - Daniel De Matteis
* Copyright (C) 2014-2017 - Jean-André Santoni
* Copyright (C) 2016-2019 - Brad Parker
* Copyright (C) 2018 - Alfredo Monclús
*
* 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/>.
*/
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <limits.h>
#include <file/file_path.h>
#include <compat/posix_string.h>
#include <compat/strl.h>
#include <formats/image.h>
#include <string/stdstring.h>
#include <lists/string_list.h>
#include <gfx/math/matrix_4x4.h>
#include <streams/file_stream.h>
#include <encodings/utf.h>
#include <features/features_cpu.h>
#include <array/rhmap.h>
#include <retro_math.h>
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
#include "../../frontend/frontend_driver.h"
#include "../menu_driver.h"
#include "../menu_entries.h"
#include "../menu_screensaver.h"
#include "../../gfx/gfx_animation.h"
#include "../../gfx/gfx_thumbnail_path.h"
#include "../../gfx/gfx_thumbnail.h"
#include "../../configuration.h"
#include "../../content.h"
#include "../../core_info.h"
#include "../../file_path_special.h"
#include "../../input/input_osk.h"
#include "../../tasks/tasks_internal.h"
#ifdef HAVE_AUDIOMIXER
#include "../../audio/audio_driver.h"
#endif
#ifdef HAVE_CHEEVOS
#include "../../cheevos/cheevos_menu.h"
#endif
#define XMB_RIBBON_ROWS 64
#define XMB_RIBBON_COLS 64
#define XMB_RIBBON_VERTICES (XMB_RIBBON_ROWS * (2 * XMB_RIBBON_COLS)) - (2 * XMB_RIBBON_COLS)
#define XMB_TAB_MAX_LENGTH 255
#define XMB_DELAY 166.66667f
#define XMB_EASING_ALPHA EASING_OUT_CIRC
#define XMB_EASING_XY EASING_OUT_QUAD
/* Specifies minimum period (in usec) between
* tab switch events when input repeat is
* active (i.e. when navigating between top level
* menu categories by *holding* left/right on
* RetroPad or keyboard)
* > Note: We want to set a value of 100 ms
* here, but doing so leads to bad pacing when
* running at 60 Hz (due to random frame time
* deviations - input repeat cycles always take
* slightly more or less than 100 ms, so tab
* switches occur every n or (n + 1) frames,
* which gives the appearance of stuttering).
* Reducing the delay by 1 ms accommodates
* any timing fluctuations, resulting in
* smooth motion */
#define XMB_TAB_SWITCH_REPEAT_DELAY 99000
/* XMB does not have a clean colour theme
* implementation. Until this is available,
* the menu screensaver tint will be set to
* a fixed colour: HTML WhiteSmoke */
#define XMB_SCREENSAVER_TINT 0xF5F5F5
/* Mean human reading speed for all western languages,
* characters per minute */
#define TICKER_CPM 1000.0f
/* Base time for which a line should be shown, in us */
#define TICKER_LINE_DURATION_US(line_len) ((line_len * 60.0f * 1000.0f * 1000.0f) / TICKER_CPM)
/* Base time for which a line should be shown, in ms */
#define TICKER_LINE_DURATION_MS(line_len) ((line_len * 60.0f * 1000.0f) / TICKER_CPM)
/* Ticker updates (nominally) once every TICKER_SPEED us
* > Base number of ticks for which line should be shown */
#define TICKER_LINE_DISPLAY_TICKS(line_len) ((size_t)(TICKER_LINE_DURATION_US(line_len) / (float)TICKER_SPEED))
/* Smooth ticker updates (nominally) once every TICKER_PIXEL_PERIOD ms
* > Base number of ticks for which text should scroll
* from one line to the next */
#define TICKER_LINE_SMOOTH_SCROLL_TICKS(line_len) ((size_t)(TICKER_LINE_DURATION_MS(line_len) / TICKER_PIXEL_PERIOD))
enum
{
XMB_TEXTURE_MAIN_MENU = 0,
XMB_TEXTURE_SETTINGS,
XMB_TEXTURE_HISTORY,
XMB_TEXTURE_FAVORITES,
#ifdef HAVE_IMAGEVIEWER
XMB_TEXTURE_IMAGES,
#endif
XMB_TEXTURE_MUSICS,
#if defined(HAVE_FFMPEG) || defined(HAVE_MPV)
XMB_TEXTURE_MOVIES,
#endif
#ifdef HAVE_NETWORKING
XMB_TEXTURE_NETPLAY,
XMB_TEXTURE_NETPLAY_ALT,
XMB_TEXTURE_ROOM,
XMB_TEXTURE_ROOM_LAN,
XMB_TEXTURE_ROOM_RELAY,
#endif
XMB_TEXTURE_SETTING,
XMB_TEXTURE_SUBSETTING,
XMB_TEXTURE_ARROW,
XMB_TEXTURE_RUN,
XMB_TEXTURE_CLOSE,
XMB_TEXTURE_RESUME,
XMB_TEXTURE_SAVESTATE,
XMB_TEXTURE_LOADSTATE,
XMB_TEXTURE_RECORDREPLAY,
XMB_TEXTURE_PLAYREPLAY,
XMB_TEXTURE_HALTREPLAY,
XMB_TEXTURE_UNDO,
XMB_TEXTURE_CORE_INFO,
XMB_TEXTURE_BLUETOOTH,
XMB_TEXTURE_WIFI,
XMB_TEXTURE_CORE_OPTIONS,
XMB_TEXTURE_INPUT_REMAPPING_OPTIONS,
XMB_TEXTURE_CHEAT_OPTIONS,
XMB_TEXTURE_DISK_OPTIONS,
XMB_TEXTURE_SHADER_OPTIONS,
XMB_TEXTURE_ACHIEVEMENT_LIST,
XMB_TEXTURE_SCREENSHOT,
XMB_TEXTURE_RELOAD,
XMB_TEXTURE_RENAME,
XMB_TEXTURE_FILE,
XMB_TEXTURE_FOLDER,
XMB_TEXTURE_ZIP,
XMB_TEXTURE_FAVORITE,
XMB_TEXTURE_ADD_FAVORITE,
XMB_TEXTURE_IMAGE,
XMB_TEXTURE_MUSIC,
XMB_TEXTURE_MOVIE,
XMB_TEXTURE_CORE,
XMB_TEXTURE_RDB,
XMB_TEXTURE_CURSOR,
XMB_TEXTURE_SWITCH_ON,
XMB_TEXTURE_SWITCH_OFF,
XMB_TEXTURE_CLOCK,
XMB_TEXTURE_BATTERY_FULL,
XMB_TEXTURE_BATTERY_CHARGING,
XMB_TEXTURE_BATTERY_80,
XMB_TEXTURE_BATTERY_60,
XMB_TEXTURE_BATTERY_40,
XMB_TEXTURE_BATTERY_20,
XMB_TEXTURE_POINTER,
XMB_TEXTURE_ADD,
XMB_TEXTURE_KEY,
XMB_TEXTURE_KEY_HOVER,
XMB_TEXTURE_DIALOG_SLICE,
XMB_TEXTURE_ACHIEVEMENTS,
XMB_TEXTURE_AUDIO,
XMB_TEXTURE_EXIT,
XMB_TEXTURE_FRAMESKIP,
XMB_TEXTURE_INFO,
XMB_TEXTURE_HELP,
XMB_TEXTURE_NETWORK,
XMB_TEXTURE_POWER,
XMB_TEXTURE_SAVING,
XMB_TEXTURE_UPDATER,
XMB_TEXTURE_VIDEO,
XMB_TEXTURE_RECORD,
XMB_TEXTURE_INPUT_SETTINGS,
XMB_TEXTURE_MIXER,
XMB_TEXTURE_LOG,
XMB_TEXTURE_OSD,
XMB_TEXTURE_UI,
XMB_TEXTURE_USER,
XMB_TEXTURE_PRIVACY,
XMB_TEXTURE_LATENCY,
XMB_TEXTURE_DRIVERS,
XMB_TEXTURE_PLAYLIST,
XMB_TEXTURE_QUICKMENU,
XMB_TEXTURE_REWIND,
XMB_TEXTURE_OVERLAY,
XMB_TEXTURE_OVERRIDE,
XMB_TEXTURE_NOTIFICATIONS,
XMB_TEXTURE_STREAM,
XMB_TEXTURE_SHUTDOWN,
XMB_TEXTURE_INPUT_DPAD_U,
XMB_TEXTURE_INPUT_DPAD_D,
XMB_TEXTURE_INPUT_DPAD_L,
XMB_TEXTURE_INPUT_DPAD_R,
XMB_TEXTURE_INPUT_STCK_U,
XMB_TEXTURE_INPUT_STCK_D,
XMB_TEXTURE_INPUT_STCK_L,
XMB_TEXTURE_INPUT_STCK_R,
XMB_TEXTURE_INPUT_STCK_P,
XMB_TEXTURE_INPUT_SELECT,
XMB_TEXTURE_INPUT_START,
XMB_TEXTURE_INPUT_BTN_U,
XMB_TEXTURE_INPUT_BTN_D,
XMB_TEXTURE_INPUT_BTN_L,
XMB_TEXTURE_INPUT_BTN_R,
XMB_TEXTURE_INPUT_LB,
XMB_TEXTURE_INPUT_RB,
XMB_TEXTURE_INPUT_LT,
XMB_TEXTURE_INPUT_RT,
XMB_TEXTURE_INPUT_ADC,
XMB_TEXTURE_INPUT_BIND_ALL,
XMB_TEXTURE_INPUT_MOUSE,
XMB_TEXTURE_INPUT_LGUN,
XMB_TEXTURE_INPUT_TURBO,
XMB_TEXTURE_CHECKMARK,
XMB_TEXTURE_MENU_ADD,
XMB_TEXTURE_BRIGHTNESS,
XMB_TEXTURE_PAUSE,
XMB_TEXTURE_DEFAULT,
XMB_TEXTURE_DEFAULT_CONTENT,
XMB_TEXTURE_MENU_APPLY_TOGGLE,
XMB_TEXTURE_MENU_APPLY_COG,
XMB_TEXTURE_DISC,
XMB_TEXTURE_LAST
};
enum
{
XMB_SYSTEM_TAB_MAIN = 0,
XMB_SYSTEM_TAB_SETTINGS,
XMB_SYSTEM_TAB_HISTORY,
XMB_SYSTEM_TAB_FAVORITES,
XMB_SYSTEM_TAB_MUSIC,
#if defined(HAVE_FFMPEG) || defined(HAVE_MPV)
XMB_SYSTEM_TAB_VIDEO,
#endif
#ifdef HAVE_IMAGEVIEWER
XMB_SYSTEM_TAB_IMAGES,
#endif
#ifdef HAVE_NETWORKING
XMB_SYSTEM_TAB_NETPLAY,
#endif
XMB_SYSTEM_TAB_ADD,
XMB_SYSTEM_TAB_CONTENTLESS_CORES,
#if defined(HAVE_LIBRETRODB)
XMB_SYSTEM_TAB_EXPLORE,
#endif
/* End of this enum - use the last one to determine num of possible tabs */
XMB_SYSTEM_TAB_MAX_LENGTH
};
enum xmb_pending_thumbnail_type
{
XMB_PENDING_THUMBNAIL_NONE = 0,
XMB_PENDING_THUMBNAIL_RIGHT,
XMB_PENDING_THUMBNAIL_LEFT,
XMB_PENDING_THUMBNAIL_BOTH,
XMB_PENDING_THUMBNAIL_ICONS
};
typedef struct
{
gfx_thumbnail_path_data_t thumbnail_path_data;
gfx_thumbnail_t icon;
} xmb_icons_t;
/* NOTE: If you change this you HAVE to update
* xmb_alloc_node() */
typedef struct
{
char *fullpath;
char *console_name;
uintptr_t icon;
uintptr_t content_icon;
xmb_icons_t thumbnail_icon;
float alpha;
float label_alpha;
float zoom;
float x;
float y;
bool icon_hide;
} xmb_node_t;
enum xmb_drag_mode
{
XMB_DRAG_NONE = 0,
XMB_DRAG_DETECTING,
XMB_DRAG_HORIZONTAL,
XMB_DRAG_VERTICAL
};
typedef struct xmb_handle
{
/* Keeps track of the last time tabs were switched
* via a MENU_ACTION_LEFT/MENU_ACTION_RIGHT event */
retro_time_t last_tab_switch_time; /* uint64_t alignment */
char *box_message;
char *bg_file_path;
file_list_t horizontal_list; /* ptr alignment */
/* Maps console tabs to playlist database names */
xmb_node_t **playlist_db_node_map;
xmb_node_t main_menu_node;
#ifdef HAVE_IMAGEVIEWER
xmb_node_t images_tab_node;
#endif
xmb_node_t music_tab_node;
#if defined(HAVE_FFMPEG) || defined(HAVE_MPV)
xmb_node_t video_tab_node;
#endif
xmb_node_t settings_tab_node;
xmb_node_t history_tab_node;
xmb_node_t favorites_tab_node;
xmb_node_t add_tab_node;
xmb_node_t contentless_cores_tab_node;
#if defined(HAVE_LIBRETRODB)
xmb_node_t explore_tab_node;
#endif
xmb_node_t netplay_tab_node;
menu_input_pointer_t pointer;
/* Touch drag state for direction locking */
enum xmb_drag_mode drag_mode;
float drag_start_x;
float drag_start_y;
float categories_drag_start_pos;
size_t drag_start_selection;
font_data_t *font;
font_data_t *font2;
video_font_raster_block_t raster_block;
video_font_raster_block_t raster_block2;
size_t (*word_wrap)(
char *s, size_t len,
const char *src, size_t src_len,
int line_width, int wideglyph_width, unsigned max_lines);
menu_screensaver_t *screensaver;
struct {
gfx_thumbnail_t right;
gfx_thumbnail_t left;
gfx_thumbnail_t icon;
gfx_thumbnail_t savestate;
enum xmb_pending_thumbnail_type pending;
enum xmb_pending_thumbnail_type pending_icons;
} thumbnails;
struct
{
uintptr_t bg;
uintptr_t list[XMB_TEXTURE_LAST];
} textures;
uintptr_t current_menu_icon;
size_t categories_selection_ptr;
size_t categories_selection_ptr_old;
size_t selection_ptr_old;
size_t fullscreen_thumbnail_selection;
/* size of the current list */
size_t list_size;
size_t tab_selection[XMB_TAB_MAX_LENGTH];
int depth;
int old_depth;
int icon_size;
int cursor_size;
int wideglyph_width;
unsigned categories_active_idx;
unsigned categories_active_idx_old;
unsigned ticker_limit;
unsigned draw_entry_delay;
float fullscreen_thumbnail_alpha;
float x;
float alpha;
float alpha_list;
float above_subitem_offset;
float above_item_offset;
float active_item_factor;
float under_item_offset;
float shadow_offset;
float font_size;
float font2_size;
float last_scale_factor;
float margins_screen_left;
float margins_screen_top;
float margins_setting_left;
float margins_title_left;
float margins_title_top;
float margins_title_bottom;
float margins_title;
float margins_title_horizontal_offset;
float last_margins_title;
float last_margins_title_horizontal_offset;
float margins_label_left;
float margins_label_top;
float icon_spacing_horizontal;
float icon_spacing_vertical;
float items_active_alpha;
float items_active_zoom;
float items_passive_alpha;
float items_passive_zoom;
float margins_dialog;
float margins_slice;
float categories_x_pos;
float categories_passive_alpha;
float categories_passive_zoom;
float categories_active_zoom;
float categories_active_alpha;
uint8_t system_tab_end;
uint8_t tabs[XMB_SYSTEM_TAB_MAX_LENGTH];
char title_name[NAME_MAX_LENGTH];
char title_name_alt[NAME_MAX_LENGTH];
/* Cached texts showing current entry index / current list size */
char entry_index_str[32];
char entry_index_offset;
/* These have to be huge, because runloop_st->name.savestate
* has a hard-coded size of (PATH_MAX_LENGTH * 2)... */
char savestate_thumbnail_file_path[PATH_MAX_LENGTH * 2];
char prev_savestate_thumbnail_file_path[PATH_MAX_LENGTH * 2];
char fullscreen_thumbnail_label[NAME_MAX_LENGTH];
char thumbnails_left_status_prev;
char thumbnails_right_status_prev;
bool allow_horizontal_animation;
bool allow_dynamic_wallpaper;
bool fullscreen_thumbnails_available;
bool show_fullscreen_thumbnails;
bool want_fullscreen_thumbnails;
bool skip_thumbnail_reset;
bool show_thumbnails;
bool show_mouse;
bool show_screensaver;
bool show_playlist_tabs;
bool use_ps3_layout;
bool last_use_ps3_layout;
bool assets_missing;
/* Favorites, History, Images, Music, Videos, user generated */
bool is_playlist;
bool is_playlist_tab;
bool is_playlist_information;
bool is_db_manager_list;
bool is_explore_list;
bool is_contentless_cores;
/* Load Content file browser */
bool is_file_list;
bool is_quick_menu;
bool is_state_slot;
bool libretro_running;
/* Whether to show entry index for current list */
bool entry_idx_enabled;
} xmb_handle_t;
static float xmb_scale_mod[8] = {
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f
};
static float xmb_coord_shadow[] = {
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
};
static float xmb_coord_black[] = {
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
};
static float xmb_coord_white[] = {
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
};
static float xmb_item_color[] = {
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
};
/* Forward declarations */
extern int action_switch_thumbnail(const char *path,
const char *label, unsigned type, size_t idx);
static int xmb_menu_entry_action(void *userdata,
menu_entry_t *entry, size_t i, enum menu_action action);
static bool xmb_load_image(void *userdata, void *data,
enum menu_image_type type);
static void xmb_navigation_set(void *data, bool scroll);
static uintptr_t xmb_icon_get_id(xmb_handle_t *xmb,
xmb_node_t *core_node, xmb_node_t *node,
enum msg_hash_enums enum_idx, const char *enum_path,
const char *enum_label, unsigned type, bool active,
bool checked);
static INLINE float xmb_item_y(const xmb_handle_t *xmb,
int i, size_t current)
{
float icon_spacing_vertical = xmb->icon_spacing_vertical;
if (i < (int)current)
{
if (xmb->depth > 1)
return icon_spacing_vertical * (i - (int)current + xmb->above_subitem_offset);
return icon_spacing_vertical * (i - (int)current + xmb->above_item_offset);
}
else if (i == (int)current)
return icon_spacing_vertical * xmb->active_item_factor;
return icon_spacing_vertical * (i - (int)current + xmb->under_item_offset);
}
static void xmb_calculate_visible_range(const xmb_handle_t *xmb,
unsigned height, size_t list_size, unsigned current,
unsigned *first, unsigned *last)
{
unsigned j;
float base_y = xmb->margins_screen_top;
*first = 0;
*last = (unsigned)(list_size ? list_size - 1 : 0);
if (current)
{
for (j = current; j-- > 0;)
{
float bottom = xmb_item_y(xmb, j, current) + base_y + xmb->icon_size;
if (bottom < 0)
break;
*first = j;
}
}
for (j = current + 1; j < list_size; j++)
{
float top = xmb_item_y(xmb, j, current) + base_y;
if (top > height)
break;
*last = j;
}
}
const char* xmb_theme_ident(void)
{
unsigned menu_xmb_theme = config_get_ptr()->uints.menu_xmb_theme;
switch (menu_xmb_theme)
{
case XMB_ICON_THEME_FLATUI:
return "flatui";
case XMB_ICON_THEME_FLATUX:
return "flatux";
case XMB_ICON_THEME_RETROSYSTEM:
return "retrosystem";
case XMB_ICON_THEME_PIXEL:
return "pixel";
case XMB_ICON_THEME_SYSTEMATIC:
return "systematic";
case XMB_ICON_THEME_DOTART:
return "dot-art";
case XMB_ICON_THEME_CUSTOM:
return "custom";
case XMB_ICON_THEME_MONOCHROME_INVERTED:
return "monochrome";
case XMB_ICON_THEME_AUTOMATIC:
return "automatic";
case XMB_ICON_THEME_AUTOMATIC_INVERTED:
return "automatic";
case XMB_ICON_THEME_DAITE:
return "daite";
case XMB_ICON_THEME_MONOCHROME:
default:
break;
}
return "monochrome";
}
/* NOTE: This exists because calloc()ing xmb_node_t is expensive
* when you can have big lists like MAME and fba playlists */
static xmb_node_t *xmb_alloc_node(void)
{
xmb_node_t *node = (xmb_node_t*)malloc(sizeof(*node));
if (!node)
return NULL;
node->alpha = node->label_alpha = 0;
node->zoom = node->x = node->y = 0;
node->icon = node->content_icon = 0;
node->thumbnail_icon.icon.texture = 0;
node->fullpath = NULL;
node->console_name = NULL;
node->icon_hide = false;
return node;
}
static void xmb_free_node(xmb_node_t *node)
{
if (!node)
return;
if (node->fullpath)
free(node->fullpath);
node->fullpath = NULL;
gfx_thumbnail_reset(&node->thumbnail_icon.icon);
free(node);
}
/**
* @brief frees all xmb_node_t in a file_list_t
*
* file_list_t assumes userdata holds a simple structure and
* free()'s it. Can't change this at the time because other
* code depends on this behavior.
*
* @param list
* @param actiondata whether to free actiondata too
*/
static void xmb_free_list_nodes(file_list_t *list, bool actiondata)
{
unsigned i;
unsigned size = list ? (unsigned)list->size : 0;
for (i = 0; i < size; ++i)
{
xmb_free_node((xmb_node_t*)file_list_get_userdata_at_offset(list, i));
list->list[i].userdata = NULL;
if (actiondata)
file_list_free_actiondata(list, i);
}
}
static float *xmb_gradient_ident(unsigned xmb_color_theme)
{
static float gradient_golden[16] = {
174/255.0, 123/255.0, 44/255.0, 1.0,
205/255.0, 174/255.0, 84/255.0, 1.0,
58/255.0, 43/255.0, 24/255.0, 1.0,
58/255.0, 43/255.0, 24/255.0, 1.0,
};
static float gradient_legacy_red[16] = {
171/255.0, 70/255.0, 59/255.0, 1.0,
171/255.0, 70/255.0, 59/255.0, 1.0,
190/255.0, 80/255.0, 69/255.0, 1.0,
190/255.0, 80/255.0, 69/255.0, 1.0,
};
static float gradient_electric_blue[16] = {
1/255.0, 2/255.0, 67/255.0, 1.0,
1/255.0, 73/255.0, 183/255.0, 1.0,
1/255.0, 93/255.0, 194/255.0, 1.0,
3/255.0, 162/255.0, 254/255.0, 1.0,
};
static float gradient_dark_purple[16] = {
20/255.0, 13/255.0, 20/255.0, 1.0,
20/255.0, 13/255.0, 20/255.0, 1.0,
92/255.0, 44/255.0, 92/255.0, 1.0,
148/255.0, 90/255.0, 148/255.0, 1.0,
};
static float gradient_midnight_blue[16] = {
44/255.0, 62/255.0, 80/255.0, 1.0,
44/255.0, 62/255.0, 80/255.0, 1.0,
44/255.0, 62/255.0, 80/255.0, 1.0,
44/255.0, 62/255.0, 80/255.0, 1.0,
};
static float gradient_apple_green[16] = {
102/255.0, 134/255.0, 58/255.0, 1.0,
122/255.0, 131/255.0, 52/255.0, 1.0,
82/255.0, 101/255.0, 35/255.0, 1.0,
63/255.0, 95/255.0, 30/255.0, 1.0,
};
static float gradient_undersea[16] = {
23/255.0, 18/255.0, 41/255.0, 1.0,
30/255.0, 72/255.0, 114/255.0, 1.0,
52/255.0, 88/255.0, 110/255.0, 1.0,
69/255.0, 125/255.0, 140/255.0, 1.0,
};
static float gradient_morning_blue[16] = {
221/255.0, 241/255.0, 254/255.0, 1.0,
135/255.0, 206/255.0, 250/255.0, 1.0,
0.7, 0.7, 0.7, 1.0,
170/255.0, 200/255.0, 252/255.0, 1.0,
};
static float gradient_sunbeam[16] = {
20/255.0, 13/255.0, 20/255.0, 1.0,
30/255.0, 72/255.0, 114/255.0, 1.0,
0.7, 0.7, 0.7, 1.0,
0.1, 0.0, 0.1, 1.0,
};
static float gradient_lime_green[16] = {
209/255.0, 255/255.0, 82/255.0, 1.0,
146/255.0, 232/255.0, 66/255.0, 1.0,
82/255.0, 101/255.0, 35/255.0, 1.0,
63/255.0, 95/255.0, 30/255.0, 1.0,
};
static float gradient_pikachu_yellow[16] = {
63/255.0, 63/255.0, 1/255.0, 1.0,
174/255.0, 174/255.0, 1/255.0, 1.0,
191/255.0, 194/255.0, 1/255.0, 1.0,
254/255.0, 221/255.0, 3/255.0, 1.0,
};
static float gradient_gamecube_purple[16] = {
40/255.0, 20/255.0, 91/255.0, 1.0,
160/255.0, 140/255.0, 211/255.0, 1.0,
107/255.0, 92/255.0, 177/255.0, 1.0,
84/255.0, 71/255.0, 132/255.0, 1.0,
};
static float gradient_famicom_red[16] = {
255/255.0, 191/255.0, 171/255.0, 1.0,
119/255.0, 49/255.0, 28/255.0, 1.0,
148/255.0, 10/255.0, 36/255.0, 1.0,
206/255.0, 126/255.0, 110/255.0, 1.0,
};
static float gradient_flaming_hot[16] = {
231/255.0, 53/255.0, 53/255.0, 1.0,
242/255.0, 138/255.0, 97/255.0, 1.0,
236/255.0, 97/255.0, 76/255.0, 1.0,
255/255.0, 125/255.0, 3/255.0, 1.0,
};
static float gradient_ice_cold[16] = {
66/255.0, 183/255.0, 229/255.0, 1.0,
29/255.0, 164/255.0, 255/255.0, 1.0,
176/255.0, 255/255.0, 247/255.0, 1.0,
174/255.0, 240/255.0, 255/255.0, 1.0,
};
static float gradient_midgar[16] = {
255/255.0, 0/255.0, 0/255.0, 1.0,
0/255.0, 0/255.0, 255/255.0, 1.0,
0/255.0, 255/255.0, 0/255.0, 1.0,
32/255.0, 32/255.0, 32/255.0, 1.0,
};
static float gradient_volcanic_red[16] = {
1.0, 0.0, 0.1, 1.0,
1.0, 0.1, 0.0, 1.0,
0.1, 0.0, 0.1, 1.0,
0.1, 0.0, 0.1, 1.0,
};
static float gradient_dark[16] = {
0.05, 0.05, 0.05, 1.0,
0.05, 0.05, 0.05, 1.0,
0.05, 0.05, 0.05, 1.0,
0.05, 0.05, 0.05, 1.0,
};
static float gradient_light[16] = {
0.50, 0.50, 0.50, 1.0,
0.50, 0.50, 0.50, 1.0,
0.50, 0.50, 0.50, 1.0,
0.50, 0.50, 0.50, 1.0,
};
static float gradient_gray_dark[16] = {
16/255.0, 16/255.0, 16/255.0, 1.0,
16/255.0, 16/255.0, 16/255.0, 1.0,
16/255.0, 16/255.0, 16/255.0, 1.0,
16/255.0, 16/255.0, 16/255.0, 1.0,
};
static float gradient_gray_light[16] = {
32/255.0, 32/255.0, 32/255.0, 1.0,
32/255.0, 32/255.0, 32/255.0, 1.0,
32/255.0, 32/255.0, 32/255.0, 1.0,
32/255.0, 32/255.0, 32/255.0, 1.0,
};
switch (xmb_color_theme)
{
case XMB_THEME_DARK_PURPLE:
return &gradient_dark_purple[0];
case XMB_THEME_MIDNIGHT_BLUE:
return &gradient_midnight_blue[0];
case XMB_THEME_GOLDEN:
return &gradient_golden[0];
case XMB_THEME_ELECTRIC_BLUE:
return &gradient_electric_blue[0];
case XMB_THEME_APPLE_GREEN:
return &gradient_apple_green[0];
case XMB_THEME_UNDERSEA:
return &gradient_undersea[0];
case XMB_THEME_VOLCANIC_RED:
return &gradient_volcanic_red[0];
case XMB_THEME_DARK:
return &gradient_dark[0];
case XMB_THEME_LIGHT:
return &gradient_light[0];
case XMB_THEME_MORNING_BLUE:
return &gradient_morning_blue[0];
case XMB_THEME_SUNBEAM:
return &gradient_sunbeam[0];
case XMB_THEME_LIME:
return &gradient_lime_green[0];
case XMB_THEME_MIDGAR:
return &gradient_midgar[0];
case XMB_THEME_PIKACHU_YELLOW:
return &gradient_pikachu_yellow[0];
case XMB_THEME_GAMECUBE_PURPLE:
return &gradient_gamecube_purple[0];
case XMB_THEME_FAMICOM_RED:
return &gradient_famicom_red[0];
case XMB_THEME_FLAMING_HOT:
return &gradient_flaming_hot[0];
case XMB_THEME_ICE_COLD:
return &gradient_ice_cold[0];
case XMB_THEME_LEGACY_RED:
return &gradient_legacy_red[0];
case XMB_THEME_GRAY_DARK:
return &gradient_gray_dark[0];
case XMB_THEME_GRAY_LIGHT:
return &gradient_gray_light[0];
default:
return &gradient_dark[0];
}
}
static size_t xmb_list_get_selection(void *data)
{
xmb_handle_t *xmb = (xmb_handle_t*)data;
if (!xmb)
return 0;
return xmb->categories_selection_ptr;
}
static size_t xmb_list_get_size(void *data,
enum menu_list_type type)
{
xmb_handle_t *xmb = (xmb_handle_t*)data;
switch (type)
{
case MENU_LIST_PLAIN:
{
struct menu_state *menu_st = menu_state_get_ptr();
menu_list_t *menu_list = menu_st->entries.list;
if (menu_list)
return MENU_LIST_GET_STACK_SIZE(menu_list, 0);
}
break;
case MENU_LIST_HORIZONTAL:
return xmb->horizontal_list.size;
case MENU_LIST_TABS:
return xmb->system_tab_end;
default:
break;
}
return 0;
}
static void *xmb_list_get_entry(void *data,
enum menu_list_type type, unsigned i)
{
xmb_handle_t *xmb = (xmb_handle_t*)data;
size_t list_size = 0;
switch (type)
{
case MENU_LIST_PLAIN:
{
struct menu_state *menu_st = menu_state_get_ptr();
menu_list_t *menu_list = menu_st->entries.list;
file_list_t *menu_stack = MENU_LIST_GET_SELECTION(menu_list, 0);
list_size = MENU_LIST_GET_STACK_SIZE(menu_list, 0);
if (i < list_size)
return (void*)&menu_stack->list[i];
}
break;
case MENU_LIST_HORIZONTAL:
list_size = xmb->horizontal_list.size;
if (i < list_size)
return (void*)&xmb->horizontal_list.list[i];
break;
default:
break;
}
return NULL;
}
static void xmb_draw_icon(
void *userdata,
gfx_display_t *p_disp,
gfx_display_ctx_driver_t *dispctx,
unsigned video_width,
unsigned video_height,
bool shadows_enable,
int icon_size_x,
int icon_size_y,
uintptr_t texture,
float x,
float y,
unsigned width,
unsigned height,
float alpha,
float rotation,
float scale_factor,
float *color,
float shadow_offset,
math_matrix_4x4 *mymat)
{
gfx_display_ctx_draw_t draw;
struct video_coords coords;
math_matrix_4x4 mymat_tmp;
if ( (x < (-icon_size_x / 2.0f))
|| (x > width)
|| (y < (icon_size_y / 2.0f))
|| (y > height + icon_size_y)
)
return;
if (!p_disp->dispctx->handles_transform)
{
float radians = rotation * (M_PI / 2.0f);
float cosine = cosf(radians);
float sine = sinf(radians);
gfx_display_rotate_z(p_disp, &mymat_tmp, cosine, sine, userdata);
if (scale_factor != 1.0f)
{
math_matrix_4x4 matrix_scaled = {
{ 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f }
};
MAT_ELEM_4X4(matrix_scaled, 0, 0) = scale_factor;
MAT_ELEM_4X4(matrix_scaled, 1, 1) = scale_factor;
MAT_ELEM_4X4(matrix_scaled, 2, 2) = 1.0f;
matrix_4x4_multiply(mymat_tmp, matrix_scaled, mymat_tmp);
}
}
else if (mymat)
mymat_tmp = *mymat;
coords.vertices = 4;
coords.vertex = NULL;
coords.tex_coord = NULL;
coords.lut_tex_coord = NULL;
draw.width = icon_size_x;
draw.height = icon_size_y;
draw.rotation = rotation;
draw.scale_factor = scale_factor;
#if defined(VITA) || defined(WIIU) || defined(__PS3__)