(Menu widgets) Some architectural cleanups -

* Don't have all these manual setters
* Don't copy over the FPS text, instead make use
of video_info->fps_text
* Boolean checks always returned true anyway, so
avoid unnecessary conditional checks
This commit is contained in:
twinaphex 2019-08-15 15:13:07 +02:00
parent a500219d8c
commit 57df6dda82
4 changed files with 43 additions and 52 deletions

View File

@ -241,13 +241,6 @@ static float volume_text_alpha = 0.0f;
static menu_animation_ctx_tag volume_tag = (uintptr_t) &volume_alpha;
static bool volume_mute = false;
/* FPS */
static char menu_widgets_fps_text[255];
/* Status icons */
static bool menu_widgets_paused = false;
static bool menu_widgets_fast_forward = false;
static bool menu_widgets_rewinding = false;
/* Screenshot */
static float screenshot_alpha = 0.0f;
@ -309,12 +302,6 @@ static unsigned msg_queue_task_hourglass_x;
static unsigned generic_message_height; /* used for both generic and libretro messages */
bool menu_widgets_set_paused(bool is_paused)
{
menu_widgets_paused = is_paused;
return true;
}
static void msg_widget_msg_transition_animation_done(void *userdata)
{
menu_widget_msg_t *msg = (menu_widget_msg_t*) userdata;
@ -1641,10 +1628,10 @@ void menu_widgets_frame(video_frame_info_t *video_info)
/* FPS Counter */
if (video_info->fps_show || video_info->framecount_show)
{
const char *text = *menu_widgets_fps_text == '\0' ? "n/a" : menu_widgets_fps_text;
const char *text = *video_info->fps_text == '\0' ? "N/A" : video_info->fps_text;
int text_width = font_driver_get_message_width(font_regular, text, (unsigned)strlen(text), 1.0f);
int total_width = text_width + simple_widget_padding * 2;
int text_width = font_driver_get_message_width(font_regular, text, (unsigned)strlen(text), 1.0f);
int total_width = text_width + simple_widget_padding * 2;
menu_display_set_alpha(menu_widgets_backdrop_orig, DEFAULT_BACKDROP);
@ -1666,17 +1653,17 @@ void menu_widgets_frame(video_frame_info_t *video_info)
}
/* Indicators */
if (menu_widgets_paused)
if (video_info->widgets_is_paused)
top_right_x_advance -= menu_widgets_draw_indicator(video_info,
menu_widgets_icons_textures[MENU_WIDGETS_ICON_PAUSED], (video_info->fps_show ? simple_widget_height : 0), top_right_x_advance,
MSG_PAUSED);
if (menu_widgets_fast_forward)
if (video_info->widgets_is_fast_forwarding)
top_right_x_advance -= menu_widgets_draw_indicator(video_info,
menu_widgets_icons_textures[MENU_WIDGETS_ICON_FAST_FORWARD], (video_info->fps_show ? simple_widget_height : 0), top_right_x_advance,
MSG_PAUSED);
if (menu_widgets_rewinding)
if (video_info->widgets_is_rewinding)
top_right_x_advance -= menu_widgets_draw_indicator(video_info,
menu_widgets_icons_textures[MENU_WIDGETS_ICON_REWIND], (video_info->fps_show ? simple_widget_height : 0), top_right_x_advance,
MSG_REWINDING);
@ -1720,8 +1707,6 @@ bool menu_widgets_init(bool video_is_threaded)
menu_widgets_frame_count = 0;
menu_widgets_fps_text[0] = '\0';
msg_queue = fifo_new(MSG_QUEUE_PENDING_MAX * sizeof(menu_widget_msg_t*));
if (!msg_queue)
@ -2023,27 +2008,6 @@ bool menu_widgets_volume_update_and_show(void)
return true;
}
bool menu_widgets_set_fps_text(char *new_fps_text)
{
strlcpy(menu_widgets_fps_text,
new_fps_text, sizeof(menu_widgets_fps_text));
return true;
}
bool menu_widgets_set_fast_forward(bool is_fast_forward)
{
menu_widgets_fast_forward = is_fast_forward;
return true;
}
bool menu_widgets_set_rewind(bool is_rewind)
{
menu_widgets_rewinding = is_rewind;
return true;
}
static void menu_widgets_screenshot_fadeout(void *userdata)
{
menu_animation_ctx_entry_t entry;

View File

@ -51,8 +51,6 @@ bool menu_widgets_msg_queue_push(
bool menu_widgets_volume_update_and_show(void);
bool menu_widgets_set_fps_text(char *fps_text);
void menu_widgets_iterate(unsigned width, unsigned height);
bool menu_widgets_set_paused(bool is_paused);

View File

@ -959,6 +959,11 @@ extern void libnx_apply_overclock(void);
#ifdef HAVE_MENU_WIDGETS
static bool menu_widgets_inited = false;
menu_animation_ctx_tag menu_widgets_generic_tag = (uintptr_t) &menu_widgets_inited;
/* Status icons */
static bool menu_widgets_paused = false;
static bool menu_widgets_fast_forward = false;
static bool menu_widgets_rewinding = false;
#endif
bool menu_widgets_ready(void)
@ -3766,11 +3771,17 @@ static void retroarch_pause_checks(void)
command_event(CMD_EVENT_AUDIO_STOP, NULL);
#if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS)
if (!menu_widgets_inited || !menu_widgets_set_paused(is_paused))
if (!menu_widgets_inited)
#endif
{
#if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS)
menu_widgets_paused = is_paused;
#endif
runloop_msg_queue_push(msg_hash_to_str(MSG_PAUSED), 1,
1, true,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
}
if (!is_idle)
video_driver_cached_frame();
@ -3784,7 +3795,7 @@ static void retroarch_pause_checks(void)
{
#if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS)
if (menu_widgets_inited)
menu_widgets_set_paused(is_paused);
menu_widgets_paused = is_paused;
#endif
RARCH_LOG("%s\n", msg_hash_to_str(MSG_UNPAUSED));
command_event(CMD_EVENT_AUDIO_START, NULL);
@ -18315,9 +18326,11 @@ void video_driver_frame(const void *data, unsigned width,
if (video_info.fps_show || video_info.framecount_show)
{
#if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS)
if (!menu_widgets_inited || !menu_widgets_set_fps_text(video_info.fps_text))
if (!menu_widgets_inited)
#endif
{
runloop_msg_queue_push(video_info.fps_text, 2, 1, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
}
}
/* trigger set resolution*/
@ -18470,9 +18483,15 @@ void video_driver_build_info(video_frame_info_t *video_info)
video_info->fps_text[0] = '\0';
#ifdef HAVE_MENU_WIDGETS
video_info->widgets_inited = menu_widgets_inited;
video_info->widgets_inited = menu_widgets_inited;
video_info->widgets_is_paused = menu_widgets_paused;
video_info->widgets_is_fast_forwarding = menu_widgets_fast_forward;
video_info->widgets_is_rewinding = menu_widgets_rewinding;
#else
video_info->widgets_inited = false;
video_info->widgets_inited = false;
video_info->widgets_is_paused = false;
video_info->widgets_is_fast_forwarding = false;
video_info->widgets_is_rewinding = false;
#endif
video_info->width = video_driver_width;
@ -19823,7 +19842,9 @@ static void drivers_init(int flags)
&& video_driver_has_widgets())
{
if (!menu_widgets_inited)
{
menu_widgets_inited = menu_widgets_init(video_is_threaded);
}
if (menu_widgets_inited)
menu_widgets_context_reset(video_is_threaded,
@ -23180,16 +23201,21 @@ static void update_fastforwarding_state(void)
if (runloop_fastmotion)
{
#if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS)
if (!menu_widgets_inited || !menu_widgets_set_fast_forward(true))
if (!menu_widgets_inited)
#endif
{
#if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS)
menu_widgets_fast_forward = true;
#endif
runloop_msg_queue_push(
msg_hash_to_str(MSG_FAST_FORWARD), 1, 1, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
}
}
#if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS)
else
{
if (menu_widgets_inited)
menu_widgets_set_fast_forward(false);
menu_widgets_fast_forward = false;
}
#endif
}
@ -23892,7 +23918,7 @@ static enum runloop_state runloop_check_state(void)
#if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS)
if (menu_widgets_inited)
menu_widgets_set_rewind(rewinding);
menu_widgets_rewinding = rewinding;
#endif
}

View File

@ -1123,6 +1123,9 @@ typedef struct video_info
typedef struct video_frame_info
{
bool widgets_inited;
bool widgets_is_paused;
bool widgets_is_fast_forwarding;
bool widgets_is_rewinding;
bool input_menu_swap_ok_cancel_buttons;
bool input_driver_nonblock_state;
bool shared_context;