forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgfx_widgets.c
2541 lines (2078 loc) · 75.1 KB
/
gfx_widgets.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) 2014-2017 - Jean-André Santoni
* Copyright (C) 2015-2018 - Andre Leiradella
* Copyright (C) 2018-2020 - natinusala
*
* 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 <retro_miscellaneous.h>
#include <retro_inline.h>
#include <lists/file_list.h>
#include <queues/fifo_queue.h>
#include <file/file_path.h>
#include <streams/file_stream.h>
#include <string/stdstring.h>
#include <retro_math.h>
#ifdef HAVE_THREADS
#include <rthreads/rthreads.h>
#define SLOCK_LOCK(x) slock_lock(x)
#define SLOCK_UNLOCK(x) slock_unlock(x)
#else
#define SLOCK_LOCK(x)
#define SLOCK_UNLOCK(x)
#endif
#include "gfx_widgets.h"
#include "gfx_display.h"
#include "font_driver.h"
#include "../msg_hash.h"
#include "../tasks/task_content.h"
#ifdef HAVE_CHEEVOS
#include "../cheevos-new/badges.h"
#endif
static bool widgets_inited = false;
static bool widgets_active = false;
bool gfx_widgets_active(void)
{
return widgets_active;
}
static bool widgets_persisting = false;
void gfx_widgets_set_persistence(bool persist)
{
widgets_persisting = persist;
}
static float msg_queue_background[16] = COLOR_HEX_TO_FLOAT(0x3A3A3A, 1.0f);
static float msg_queue_info[16] = COLOR_HEX_TO_FLOAT(0x12ACF8, 1.0f);
static float msg_queue_task_progress_1[16] = COLOR_HEX_TO_FLOAT(0x397869, 1.0f); /* Color of first progress bar in a task message */
static float msg_queue_task_progress_2[16] = COLOR_HEX_TO_FLOAT(0x317198, 1.0f); /* Color of second progress bar in a task message (for multiple tasks with same message) */
#if 0
static float color_task_progress_bar[16] = COLOR_HEX_TO_FLOAT(0x22B14C, 1.0f);
#endif
static uint64_t gfx_widgets_frame_count = 0;
/* Font data */
typedef struct
{
gfx_widget_font_data_t regular;
gfx_widget_font_data_t bold;
gfx_widget_font_data_t msg_queue;
} gfx_widget_fonts_t;
static gfx_widget_fonts_t gfx_widget_fonts;
gfx_widget_font_data_t* gfx_widgets_get_font_regular(void)
{
return &gfx_widget_fonts.regular;
}
gfx_widget_font_data_t* gfx_widgets_get_font_bold(void)
{
return &gfx_widget_fonts.bold;
}
gfx_widget_font_data_t* gfx_widgets_get_font_msg_queue(void)
{
return &gfx_widget_fonts.msg_queue;
}
static float gfx_widgets_pure_white[16] = {
1.00, 1.00, 1.00, 1.00,
1.00, 1.00, 1.00, 1.00,
1.00, 1.00, 1.00, 1.00,
1.00, 1.00, 1.00, 1.00,
};
float* gfx_widgets_get_pure_white(void)
{
return gfx_widgets_pure_white;
}
/* FPS */
static char gfx_widgets_fps_text[255] = {0};
#ifdef HAVE_CHEEVOS
/* Achievement notification */
typedef struct cheevo_popup
{
char* title;
uintptr_t badge;
} cheevo_popup;
#define CHEEVO_QUEUE_SIZE 8
static cheevo_popup cheevo_popup_queue[CHEEVO_QUEUE_SIZE];
static int cheevo_popup_queue_read_index = -1;
static int cheevo_popup_queue_write_index = 0;
#ifdef HAVE_THREADS
slock_t* cheevo_popup_queue_lock = NULL;
#endif
static float cheevo_unfold = 0.0f;
static gfx_timer_t cheevo_timer;
static float cheevo_y = 0.0f;
static unsigned cheevo_width = 0;
static unsigned cheevo_height = 0;
static void gfx_widgets_start_achievement_notification(void);
#endif
#ifdef HAVE_MENU
/* Load content animation */
#define ANIMATION_LOAD_CONTENT_DURATION 333
#define LOAD_CONTENT_ANIMATION_INITIAL_ICON_SIZE 320
#define LOAD_CONTENT_ANIMATION_TARGET_ICON_SIZE 240
static bool load_content_animation_running = false;
static char *load_content_animation_content_name = NULL;
static char *load_content_animation_playlist_name = NULL;
static uintptr_t load_content_animation_icon = 0;
static float load_content_animation_icon_color[16];
static float load_content_animation_icon_size;
static float load_content_animation_icon_alpha;
static float load_content_animation_fade_alpha;
static float load_content_animation_final_fade_alpha;
static gfx_timer_t load_content_animation_end_timer;
static unsigned load_content_animation_icon_size_initial;
static unsigned load_content_animation_icon_size_target;
#endif
static float gfx_widgets_backdrop_orig[16] = {
0.00, 0.00, 0.00, 0.75,
0.00, 0.00, 0.00, 0.75,
0.00, 0.00, 0.00, 0.75,
0.00, 0.00, 0.00, 0.75,
};
float* gfx_widgets_get_backdrop_orig(void)
{
return gfx_widgets_backdrop_orig;
}
static float gfx_widgets_backdrop[16] = {
0.00, 0.00, 0.00, 0.75,
0.00, 0.00, 0.00, 0.75,
0.00, 0.00, 0.00, 0.75,
0.00, 0.00, 0.00, 0.75,
};
/* Messages queue */
typedef struct menu_widget_msg
{
char *msg;
char *msg_new;
float msg_transition_animation;
unsigned msg_len;
unsigned duration;
unsigned text_height;
float offset_y;
float alpha;
/* Is it currently doing the fade out animation ? */
bool dying;
/* Has the timer expired ? if so, should be set to dying */
bool expired;
unsigned width;
gfx_timer_t expiration_timer;
bool expiration_timer_started;
retro_task_t *task_ptr;
/* Used to detect title change */
char *task_title_ptr;
/* How many tasks have used this notification? */
uint8_t task_count;
int8_t task_progress;
bool task_finished;
bool task_error;
bool task_cancelled;
uint32_t task_ident;
/* Unfold animation */
bool unfolded;
bool unfolding;
float unfold;
float hourglass_rotation;
gfx_timer_t hourglass_timer;
} menu_widget_msg_t;
static fifo_buffer_t *msg_queue = NULL;
static file_list_t *current_msgs = NULL;
static unsigned msg_queue_kill = 0;
/* Count of messages bound to a task in current_msgs */
static unsigned msg_queue_tasks_count = 0;
static uintptr_t msg_queue_icon = 0;
static uintptr_t msg_queue_icon_outline = 0;
static uintptr_t msg_queue_icon_rect = 0;
static bool msg_queue_has_icons = false;
static gfx_animation_ctx_tag gfx_widgets_generic_tag = (uintptr_t)&widgets_active;
gfx_animation_ctx_tag gfx_widgets_get_generic_tag(void)
{
return gfx_widgets_generic_tag;
}
/* There can only be one message animation at a time to
* avoid confusing users */
static bool widgets_moving = false;
/* Icons */
enum gfx_widgets_icon
{
MENU_WIDGETS_ICON_PAUSED = 0,
MENU_WIDGETS_ICON_FAST_FORWARD,
MENU_WIDGETS_ICON_REWIND,
MENU_WIDGETS_ICON_SLOW_MOTION,
MENU_WIDGETS_ICON_HOURGLASS,
MENU_WIDGETS_ICON_CHECK,
MENU_WIDGETS_ICON_INFO,
MENU_WIDGETS_ICON_ACHIEVEMENT,
MENU_WIDGETS_ICON_LAST
};
static const char *gfx_widgets_icons_names[MENU_WIDGETS_ICON_LAST] = {
"menu_pause.png",
"menu_frameskip.png",
"menu_rewind.png",
"resume.png",
"menu_hourglass.png",
"menu_check.png",
"menu_info.png",
"menu_achievements.png"
};
static uintptr_t gfx_widgets_icons_textures[
MENU_WIDGETS_ICON_LAST] = {0};
#ifdef HAVE_TRANSLATE
/* AI Service Overlay */
static int ai_service_overlay_state = 0;
static unsigned ai_service_overlay_width = 0;
static unsigned ai_service_overlay_height = 0;
static uintptr_t ai_service_overlay_texture = 0;
#endif
/* Metrics */
#define BASE_FONT_SIZE 32.0f
#define MSG_QUEUE_FONT_SIZE (BASE_FONT_SIZE * 0.69f)
static float last_scale_factor = 0.0f;
static unsigned simple_widget_padding = 0;
static unsigned simple_widget_height = 0;
unsigned gfx_widgets_get_padding(void)
{
return simple_widget_padding;
}
unsigned gfx_widgets_get_height(void)
{
return simple_widget_height;
}
static unsigned msg_queue_height;
static unsigned msg_queue_icon_size_x;
static unsigned msg_queue_icon_size_y;
static unsigned msg_queue_spacing;
static unsigned msg_queue_rect_start_x;
static unsigned msg_queue_internal_icon_size;
static unsigned msg_queue_internal_icon_offset;
static unsigned msg_queue_icon_offset_y;
static unsigned msg_queue_scissor_start_x;
static unsigned msg_queue_default_rect_width_menu_alive;
static unsigned msg_queue_default_rect_width;
static unsigned msg_queue_task_text_start_x;
static unsigned msg_queue_regular_padding_x;
static unsigned msg_queue_regular_text_start;
static unsigned msg_queue_task_rect_start_x;
static unsigned msg_queue_task_hourglass_x;
/* Used for both generic and libretro messages */
static unsigned generic_message_height;
unsigned gfx_widgets_get_generic_message_height(void)
{
return generic_message_height;
}
static unsigned divider_width_1px = 1;
static unsigned last_video_width = 0;
static unsigned last_video_height = 0;
unsigned gfx_widgets_get_last_video_width(void)
{
return last_video_width;
}
unsigned gfx_widgets_get_last_video_height(void)
{
return last_video_height;
}
/* Widgets list */
const static gfx_widget_t* const widgets[] = {
&gfx_widget_screenshot,
&gfx_widget_volume,
&gfx_widget_generic_message,
&gfx_widget_libretro_message
};
static const size_t widgets_len = sizeof(widgets) / sizeof(widgets[0]);
static void msg_widget_msg_transition_animation_done(void *userdata)
{
menu_widget_msg_t *msg = (menu_widget_msg_t*)userdata;
if (msg->msg)
free(msg->msg);
msg->msg = NULL;
if (msg->msg_new)
msg->msg = strdup(msg->msg_new);
msg->msg_transition_animation = 0.0f;
}
void gfx_widgets_msg_queue_push(
retro_task_t *task, const char *msg,
unsigned duration,
char *title,
enum message_queue_icon icon,
enum message_queue_category category,
unsigned prio, bool flush,
bool menu_is_alive)
{
menu_widget_msg_t* msg_widget = NULL;
if (!widgets_active)
return;
if (fifo_write_avail(msg_queue) > 0)
{
/* Get current msg if it exists */
if (task && task->frontend_userdata)
{
msg_widget = (menu_widget_msg_t*)task->frontend_userdata;
/* msg_widgets can be passed between tasks */
msg_widget->task_ptr = task;
}
/* Spawn a new notification */
if (!msg_widget)
{
const char *title = msg;
msg_widget = (menu_widget_msg_t*)calloc(1, sizeof(*msg_widget));
if (task)
title = task->title;
msg_widget->duration = duration;
msg_widget->offset_y = 0;
msg_widget->alpha = 1.0f;
msg_widget->dying = false;
msg_widget->expired = false;
msg_widget->expiration_timer = 0;
msg_widget->task_ptr = task;
msg_widget->expiration_timer_started = false;
msg_widget->msg_new = NULL;
msg_widget->msg_transition_animation = 0.0f;
msg_widget->text_height = 0;
if (msg_queue_has_icons)
{
msg_widget->unfolded = false;
msg_widget->unfolding = false;
msg_widget->unfold = 0.0f;
}
else
{
msg_widget->unfolded = true;
msg_widget->unfolding = false;
msg_widget->unfold = 1.0f;
}
if (task)
{
msg_widget->msg = strdup(title);
msg_widget->msg_new = strdup(title);
msg_widget->msg_len = (unsigned)strlen(title);
msg_widget->task_error = !string_is_empty(task->error);
msg_widget->task_cancelled = task->cancelled;
msg_widget->task_finished = task->finished;
msg_widget->task_progress = task->progress;
msg_widget->task_ident = task->ident;
msg_widget->task_title_ptr = task->title;
msg_widget->task_count = 1;
msg_widget->unfolded = true;
msg_widget->width = font_driver_get_message_width(
gfx_widget_fonts.msg_queue.font, title, msg_widget->msg_len, 1) +
simple_widget_padding/2;
task->frontend_userdata = msg_widget;
msg_widget->hourglass_rotation = 0;
}
else
{
/* Compute rect width, wrap if necessary */
/* Single line text > two lines text > two lines
* text with expanded width */
unsigned title_length = (unsigned)strlen(title);
char *msg = strdup(title);
unsigned width = menu_is_alive
? msg_queue_default_rect_width_menu_alive
: msg_queue_default_rect_width;
unsigned text_width = font_driver_get_message_width(
gfx_widget_fonts.msg_queue.font, title, title_length, 1);
msg_widget->text_height = gfx_widget_fonts.msg_queue.line_height;
/* Text is too wide, split it into two lines */
if (text_width > width)
{
/* If the second line is too short, the widget may
* look unappealing - ensure that second line is at
* least 25% of the total width */
if ((text_width - (text_width >> 2)) < width)
width = text_width - (text_width >> 2);
word_wrap(msg, msg, (title_length * width) / text_width,
false, 2);
msg_widget->text_height *= 2;
}
else
width = text_width;
msg_widget->msg = msg;
msg_widget->msg_len = (unsigned)strlen(msg);
msg_widget->width = width + simple_widget_padding/2;
}
fifo_write(msg_queue, &msg_widget, sizeof(msg_widget));
}
/* Update task info */
else
{
if (msg_widget->expiration_timer_started)
{
gfx_timer_kill(&msg_widget->expiration_timer);
msg_widget->expiration_timer_started = false;
}
if (!string_is_equal(task->title, msg_widget->msg_new))
{
unsigned len = (unsigned)strlen(task->title);
unsigned new_width = font_driver_get_message_width(
gfx_widget_fonts.msg_queue.font, task->title, len, 1);
if (msg_widget->msg_new)
{
free(msg_widget->msg_new);
msg_widget->msg_new = NULL;
}
msg_widget->msg_new = strdup(task->title);
msg_widget->msg_len = len;
msg_widget->task_title_ptr = task->title;
msg_widget->msg_transition_animation = 0;
if (!task->alternative_look)
{
gfx_animation_ctx_entry_t entry;
entry.easing_enum = EASING_OUT_QUAD;
entry.tag = (uintptr_t)msg_widget;
entry.duration = MSG_QUEUE_ANIMATION_DURATION*2;
entry.target_value = msg_queue_height/2.0f;
entry.subject = &msg_widget->msg_transition_animation;
entry.cb = msg_widget_msg_transition_animation_done;
entry.userdata = msg_widget;
gfx_animation_push(&entry);
}
else
{
msg_widget_msg_transition_animation_done(msg_widget);
}
msg_widget->task_count++;
msg_widget->width = new_width;
}
msg_widget->task_error = !string_is_empty(task->error);
msg_widget->task_cancelled = task->cancelled;
msg_widget->task_finished = task->finished;
msg_widget->task_progress = task->progress;
}
}
}
static void gfx_widgets_unfold_end(void *userdata)
{
menu_widget_msg_t *unfold = (menu_widget_msg_t*)userdata;
unfold->unfolding = false;
widgets_moving = false;
}
static void gfx_widgets_move_end(void *userdata)
{
if (userdata)
{
gfx_animation_ctx_entry_t entry;
menu_widget_msg_t *unfold = (menu_widget_msg_t*)userdata;
entry.cb = gfx_widgets_unfold_end;
entry.duration = MSG_QUEUE_ANIMATION_DURATION;
entry.easing_enum = EASING_OUT_QUAD;
entry.subject = &unfold->unfold;
entry.tag = (uintptr_t)unfold;
entry.target_value = 1.0f;
entry.userdata = unfold;
gfx_animation_push(&entry);
unfold->unfolded = true;
unfold->unfolding = true;
}
else
widgets_moving = false;
}
static void gfx_widgets_msg_queue_expired(void *userdata)
{
menu_widget_msg_t *msg = (menu_widget_msg_t *)userdata;
if (msg && !msg->expired)
msg->expired = true;
}
static void gfx_widgets_msg_queue_move(void)
{
int i;
float y = 0;
/* there should always be one and only one unfolded message */
menu_widget_msg_t *unfold = NULL;
if (current_msgs->size == 0)
return;
for (i = (int)(current_msgs->size-1); i >= 0; i--)
{
menu_widget_msg_t *msg = (menu_widget_msg_t*)
current_msgs->list[i].userdata;
if (!msg || msg->dying)
continue;
y += msg_queue_height / (msg->task_ptr ? 2 : 1) + msg_queue_spacing;
if (!msg->unfolded)
unfold = msg;
if (msg->offset_y != y)
{
gfx_animation_ctx_entry_t entry;
entry.cb = (i == 0) ? gfx_widgets_move_end : NULL;
entry.duration = MSG_QUEUE_ANIMATION_DURATION;
entry.easing_enum = EASING_OUT_QUAD;
entry.subject = &msg->offset_y;
entry.tag = (uintptr_t)msg;
entry.target_value = y;
entry.userdata = unfold;
gfx_animation_push(&entry);
widgets_moving = true;
}
}
}
static void gfx_widgets_msg_queue_free(
menu_widget_msg_t *msg, bool touch_list)
{
size_t i;
gfx_animation_ctx_tag tag = (uintptr_t)msg;
if (msg->task_ptr)
{
/* remove the reference the task has of ourself
only if the task is not finished already
(finished tasks are freed before the widget) */
if (!msg->task_finished && !msg->task_error && !msg->task_cancelled)
msg->task_ptr->frontend_userdata = NULL;
/* update tasks count */
msg_queue_tasks_count--;
}
/* Kill all animations */
gfx_timer_kill(&msg->hourglass_timer);
gfx_animation_kill_by_tag(&tag);
/* Kill all timers */
if (msg->expiration_timer_started)
gfx_timer_kill(&msg->expiration_timer);
/* Free it */
if (msg->msg)
free(msg->msg);
if (msg->msg_new)
free(msg->msg_new);
/* Remove it from the list */
if (touch_list)
{
file_list_free_userdata(current_msgs, msg_queue_kill);
for (i = msg_queue_kill; i < current_msgs->size-1; i++)
current_msgs->list[i] = current_msgs->list[i+1];
current_msgs->size--;
}
widgets_moving = false;
}
static void gfx_widgets_msg_queue_kill_end(void *userdata)
{
menu_widget_msg_t *msg = (menu_widget_msg_t*)
current_msgs->list[msg_queue_kill].userdata;
if (!msg)
return;
gfx_widgets_msg_queue_free(msg, true);
}
static void gfx_widgets_msg_queue_kill(unsigned idx)
{
gfx_animation_ctx_entry_t entry;
menu_widget_msg_t *msg = (menu_widget_msg_t*)
current_msgs->list[idx].userdata;
if (!msg)
return;
widgets_moving = true;
msg->dying = true;
msg_queue_kill = idx;
/* Drop down */
entry.cb = NULL;
entry.duration = MSG_QUEUE_ANIMATION_DURATION;
entry.easing_enum = EASING_OUT_QUAD;
entry.tag = (uintptr_t)msg;
entry.userdata = NULL;
entry.subject = &msg->offset_y;
entry.target_value = msg->offset_y - msg_queue_height/4;
gfx_animation_push(&entry);
/* Fade out */
entry.cb = gfx_widgets_msg_queue_kill_end;
entry.subject = &msg->alpha;
entry.target_value = 0.0f;
gfx_animation_push(&entry);
/* Move all messages back to their correct position */
gfx_widgets_msg_queue_move();
}
void gfx_widgets_draw_icon(
void *userdata,
unsigned video_width,
unsigned video_height,
unsigned icon_width,
unsigned icon_height,
uintptr_t texture,
float x, float y,
unsigned width, unsigned height,
float rotation, float scale_factor,
float *color)
{
gfx_display_ctx_rotate_draw_t rotate_draw;
gfx_display_ctx_draw_t draw;
struct video_coords coords;
math_matrix_4x4 mymat;
if (!texture)
return;
rotate_draw.matrix = &mymat;
rotate_draw.rotation = rotation;
rotate_draw.scale_x = scale_factor;
rotate_draw.scale_y = scale_factor;
rotate_draw.scale_z = 1;
rotate_draw.scale_enable = true;
gfx_display_rotate_z(&rotate_draw, userdata);
coords.vertices = 4;
coords.vertex = NULL;
coords.tex_coord = NULL;
coords.lut_tex_coord = NULL;
coords.color = color;
draw.x = x;
draw.y = height - y - icon_height;
draw.width = icon_width;
draw.height = icon_height;
draw.scale_factor = scale_factor;
draw.rotation = rotation;
draw.coords = &coords;
draw.matrix_data = &mymat;
draw.texture = texture;
draw.prim_type = GFX_DISPLAY_PRIM_TRIANGLESTRIP;
draw.pipeline.id = 0;
gfx_display_draw(&draw, userdata,
video_width, video_height);
}
#ifdef HAVE_TRANSLATE
static void gfx_widgets_draw_icon_blend(
void *userdata,
unsigned video_width,
unsigned video_height,
unsigned icon_width,
unsigned icon_height,
uintptr_t texture,
float x, float y,
unsigned width, unsigned height,
float rotation, float scale_factor,
float *color)
{
gfx_display_ctx_rotate_draw_t rotate_draw;
gfx_display_ctx_draw_t draw;
struct video_coords coords;
math_matrix_4x4 mymat;
if (!texture)
return;
rotate_draw.matrix = &mymat;
rotate_draw.rotation = rotation;
rotate_draw.scale_x = scale_factor;
rotate_draw.scale_y = scale_factor;
rotate_draw.scale_z = 1;
rotate_draw.scale_enable = true;
gfx_display_rotate_z(&rotate_draw, userdata);
coords.vertices = 4;
coords.vertex = NULL;
coords.tex_coord = NULL;
coords.lut_tex_coord = NULL;
coords.color = color;
draw.x = x;
draw.y = height - y - icon_height;
draw.width = icon_width;
draw.height = icon_height;
draw.scale_factor = scale_factor;
draw.rotation = rotation;
draw.coords = &coords;
draw.matrix_data = &mymat;
draw.texture = texture;
draw.prim_type = GFX_DISPLAY_PRIM_TRIANGLESTRIP;
draw.pipeline.id = 0;
gfx_display_draw_blend(&draw, userdata,
video_width, video_height);
}
#endif
void gfx_widgets_draw_text(
gfx_widget_font_data_t* font_data,
const char *text,
float x, float y,
int width, int height,
uint32_t color,
enum text_alignment text_align,
bool draw_outside)
{
if (!font_data || string_is_empty(text))
return;
gfx_display_draw_text(
font_data->font,
text,
x, y,
width, height,
color,
text_align,
1.0f,
false,
0.0f,
draw_outside);
font_data->usage_count++;
}
void gfx_widgets_flush_text(
unsigned video_width, unsigned video_height,
gfx_widget_font_data_t* font_data)
{
/* Flushing is slow - only do it if font
* has actually been used */
if (!font_data || (font_data->usage_count == 0))
return;
font_driver_flush(video_width, video_height, font_data->font);
font_data->raster_block.carr.coords.vertices = 0;
font_data->usage_count = 0;
}
float gfx_widgets_get_thumbnail_scale_factor(
const float dst_width, const float dst_height,
const float image_width, const float image_height)
{
float dst_ratio = dst_width / dst_height;
float image_ratio = image_width / image_height;
if (dst_ratio > image_ratio)
return (dst_height / image_height);
return (dst_width / image_width);
}
static void gfx_widgets_start_msg_expiration_timer(menu_widget_msg_t *msg_widget, unsigned duration)
{
gfx_timer_ctx_entry_t timer;
if (msg_widget->expiration_timer_started)
return;
timer.cb = gfx_widgets_msg_queue_expired;
timer.duration = duration;
timer.userdata = msg_widget;
gfx_timer_start(&msg_widget->expiration_timer, &timer);
msg_widget->expiration_timer_started = true;
}
static void gfx_widgets_hourglass_tick(void *userdata);
static void gfx_widgets_hourglass_end(void *userdata)
{
gfx_timer_ctx_entry_t timer;
menu_widget_msg_t *msg = (menu_widget_msg_t*)userdata;
msg->hourglass_rotation = 0.0f;
timer.cb = gfx_widgets_hourglass_tick;
timer.duration = HOURGLASS_INTERVAL;
timer.userdata = msg;
gfx_timer_start(&msg->hourglass_timer, &timer);
}
static void gfx_widgets_hourglass_tick(void *userdata)
{
gfx_animation_ctx_entry_t entry;
menu_widget_msg_t *msg = (menu_widget_msg_t*)userdata;
gfx_animation_ctx_tag tag = (uintptr_t)msg;
entry.easing_enum = EASING_OUT_QUAD;
entry.tag = tag;
entry.duration = HOURGLASS_DURATION;
entry.target_value = -(2 * M_PI);
entry.subject = &msg->hourglass_rotation;
entry.cb = gfx_widgets_hourglass_end;
entry.userdata = msg;
gfx_animation_push(&entry);
}
/* Forward declarations */
static void gfx_widgets_context_reset(bool is_threaded,
unsigned width, unsigned height, bool fullscreen,
const char *dir_assets, char *font_path);
static void gfx_widgets_context_destroy(void);
static void gfx_widgets_free(void);
static void gfx_widgets_layout(
bool is_threaded, const char *dir_assets, char *font_path);
#ifdef HAVE_MENU
bool menu_driver_get_load_content_animation_data(
uintptr_t *icon, char **playlist_name);
#endif
void gfx_widgets_iterate(
unsigned width, unsigned height, bool fullscreen,
const char *dir_assets, char *font_path,
bool is_threaded)
{
size_t i;
float scale_factor;
if (!widgets_active)
return;
/* Check whether screen dimensions or menu scale
* factor have changed */
scale_factor = (gfx_display_get_driver_id() == MENU_DRIVER_ID_XMB) ?
gfx_display_get_widget_pixel_scale(width, height, fullscreen) :
gfx_display_get_widget_dpi_scale(width, height, fullscreen);
if ((scale_factor != last_scale_factor) ||
(width != last_video_width) ||
(height != last_video_height))
{
last_scale_factor = scale_factor;
last_video_width = width;
last_video_height = height;
/* Note: We don't need a full context reset here
* > Just rescale layout, and reset frame time counter */
gfx_widgets_layout(is_threaded, dir_assets, font_path);
video_driver_monitor_reset();
}
for (i = 0; i < widgets_len; i++)
{
const gfx_widget_t* widget = widgets[i];
if (widget->iterate)
widget->iterate(width, height, fullscreen, dir_assets, font_path, is_threaded);
}
/* Messages queue */
/* Consume one message if available */
if ((fifo_read_avail(msg_queue) > 0)