From 6c79cebc6ebd0257f2b336a829dc2f32ec0e233d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 9 Sep 2021 14:24:42 +0200 Subject: [PATCH] Move input_overlay_auto_rotate_ out of retroarch.c and into input_driver.c --- input/input_driver.c | 69 ++++++++++++++++++++++++++++++++++++ input/input_driver.h | 2 +- input/input_overlay.h | 9 +++++ retroarch.c | 82 +++++-------------------------------------- retroarch_fwd_decls.h | 2 -- 5 files changed, 88 insertions(+), 76 deletions(-) diff --git a/input/input_driver.c b/input/input_driver.c index 9e4e923014..21e2a14aab 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -29,6 +29,7 @@ #include #endif +#include "../command.h" #include "../retroarch.h" #include "../verbosity.h" #include "../configuration.h" @@ -1713,6 +1714,74 @@ void input_overlay_free(input_overlay_t *ol) free(ol); } + +void input_overlay_auto_rotate_( + unsigned video_driver_width, + unsigned video_driver_height, + bool input_overlay_enable, + input_overlay_t *ol) +{ + size_t i; + enum overlay_orientation screen_orientation = OVERLAY_ORIENTATION_PORTRAIT; + enum overlay_orientation active_overlay_orientation = OVERLAY_ORIENTATION_NONE; + bool tmp = false; + + /* Sanity check */ + if (!ol || !ol->alive || !input_overlay_enable) + return; + + /* Get current screen orientation */ + if (video_driver_width > video_driver_height) + screen_orientation = OVERLAY_ORIENTATION_LANDSCAPE; + + /* Get orientation of active overlay */ + if (!string_is_empty(ol->active->name)) + { + if (strstr(ol->active->name, "landscape")) + active_overlay_orientation = OVERLAY_ORIENTATION_LANDSCAPE; + else if (strstr(ol->active->name, "portrait")) + active_overlay_orientation = OVERLAY_ORIENTATION_PORTRAIT; + } + + /* Sanity check */ + if (active_overlay_orientation == OVERLAY_ORIENTATION_NONE) + return; + + /* If screen and overlay have the same orientation, + * no action is required */ + if (screen_orientation == active_overlay_orientation) + return; + + /* Attempt to find index of overlay corresponding + * to opposite orientation */ + for (i = 0; i < ol->active->size; i++) + { + overlay_desc_t *desc = &ol->active->descs[i]; + + if (!desc) + continue; + + if (!string_is_empty(desc->next_index_name)) + { + bool next_overlay_found = false; + if (active_overlay_orientation == OVERLAY_ORIENTATION_LANDSCAPE) + next_overlay_found = (strstr(desc->next_index_name, "portrait") != 0); + else + next_overlay_found = (strstr(desc->next_index_name, "landscape") != 0); + + if (next_overlay_found) + { + /* We have a valid target overlay + * > Trigger 'overly next' command event + * Note: tmp == false. This prevents CMD_EVENT_OVERLAY_NEXT + * from calling input_overlay_auto_rotate_() again */ + ol->next_index = desc->next_index; + command_event(CMD_EVENT_OVERLAY_NEXT, &tmp); + break; + } + } + } +} #endif /** diff --git a/input/input_driver.h b/input/input_driver.h index 3d26e1bb76..151f33aa28 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -23,7 +23,7 @@ #include #ifdef HAVE_CONFIG_H -#include "config.h" +#include "../config.h" #endif /* HAVE_CONFIG_H */ #include diff --git a/input/input_overlay.h b/input/input_overlay.h index e1e2db48be..102fab5290 100644 --- a/input/input_overlay.h +++ b/input/input_overlay.h @@ -316,6 +316,15 @@ bool input_overlay_add_inputs_inner(overlay_desc_t *desc, bool input_overlay_add_inputs(input_overlay_t *ol, bool show_touched, unsigned port); +/* Attempts to automatically rotate the specified overlay. + * Depends upon proper naming conventions in overlay + * config file. */ +void input_overlay_auto_rotate_( + unsigned video_driver_width, + unsigned video_driver_height, + bool input_overlay_enable, + input_overlay_t *ol); + void input_overlay_poll( input_overlay_t *ol, input_overlay_state_t *out, diff --git a/retroarch.c b/retroarch.c index e1466c09c8..74408b5fe4 100644 --- a/retroarch.c +++ b/retroarch.c @@ -12364,7 +12364,9 @@ bool command_event(enum event_command cmd, void *data) if (inp_overlay_auto_rotate) if (check_rotation) if (*check_rotation) - input_overlay_auto_rotate_(p_rarch, + input_overlay_auto_rotate_( + p_rarch->video_driver_width, + p_rarch->video_driver_height, settings->bools.input_overlay_enable, p_rarch->overlay_ptr); } @@ -18656,76 +18658,6 @@ static bool bsv_movie_check(struct rarch_state *p_rarch, static bool video_driver_overlay_interface( const video_overlay_interface_t **iface); -/* Attempts to automatically rotate the specified overlay. - * Depends upon proper naming conventions in overlay - * config file. */ -static void input_overlay_auto_rotate_( - struct rarch_state *p_rarch, - bool input_overlay_enable, - input_overlay_t *ol) -{ - size_t i; - enum overlay_orientation screen_orientation = OVERLAY_ORIENTATION_PORTRAIT; - enum overlay_orientation active_overlay_orientation = OVERLAY_ORIENTATION_NONE; - bool tmp = false; - - /* Sanity check */ - if (!ol || !ol->alive || !input_overlay_enable) - return; - - /* Get current screen orientation */ - if (p_rarch->video_driver_width > p_rarch->video_driver_height) - screen_orientation = OVERLAY_ORIENTATION_LANDSCAPE; - - /* Get orientation of active overlay */ - if (!string_is_empty(ol->active->name)) - { - if (strstr(ol->active->name, "landscape")) - active_overlay_orientation = OVERLAY_ORIENTATION_LANDSCAPE; - else if (strstr(ol->active->name, "portrait")) - active_overlay_orientation = OVERLAY_ORIENTATION_PORTRAIT; - } - - /* Sanity check */ - if (active_overlay_orientation == OVERLAY_ORIENTATION_NONE) - return; - - /* If screen and overlay have the same orientation, - * no action is required */ - if (screen_orientation == active_overlay_orientation) - return; - - /* Attempt to find index of overlay corresponding - * to opposite orientation */ - for (i = 0; i < p_rarch->overlay_ptr->active->size; i++) - { - overlay_desc_t *desc = &p_rarch->overlay_ptr->active->descs[i]; - - if (!desc) - continue; - - if (!string_is_empty(desc->next_index_name)) - { - bool next_overlay_found = false; - if (active_overlay_orientation == OVERLAY_ORIENTATION_LANDSCAPE) - next_overlay_found = (strstr(desc->next_index_name, "portrait") != 0); - else - next_overlay_found = (strstr(desc->next_index_name, "landscape") != 0); - - if (next_overlay_found) - { - /* We have a valid target overlay - * > Trigger 'overly next' command event - * Note: tmp == false. This prevents CMD_EVENT_OVERLAY_NEXT - * from calling input_overlay_auto_rotate_() again */ - ol->next_index = desc->next_index; - command_event(CMD_EVENT_OVERLAY_NEXT, &tmp); - break; - } - } - } -} - /* task_data = overlay_task_data_t* */ static void input_overlay_loaded(retro_task_t *task, void *task_data, void *user_data, const char *err) @@ -18805,7 +18737,9 @@ static void input_overlay_loaded(retro_task_t *task, /* Attempt to automatically rotate overlay, if required */ if (inp_overlay_auto_rotate) - input_overlay_auto_rotate_(p_rarch, + input_overlay_auto_rotate_( + p_rarch->video_driver_width, + p_rarch->video_driver_height, input_overlay_enable, p_rarch->overlay_ptr); @@ -33404,7 +33338,9 @@ static enum runloop_state runloop_check_state( /* Check overlay rotation, if required */ if (input_overlay_auto_rotate) - input_overlay_auto_rotate_(p_rarch, + input_overlay_auto_rotate_( + p_rarch->video_driver_width, + p_rarch->video_driver_height, settings->bools.input_overlay_enable, p_rarch->overlay_ptr); diff --git a/retroarch_fwd_decls.h b/retroarch_fwd_decls.h index 75547b4dd7..7cafd88d06 100644 --- a/retroarch_fwd_decls.h +++ b/retroarch_fwd_decls.h @@ -101,8 +101,6 @@ static bool recording_deinit(struct rarch_state *p_rarch); #ifdef HAVE_OVERLAY static void retroarch_overlay_init(struct rarch_state *p_rarch); static void retroarch_overlay_deinit(struct rarch_state *p_rarch); -static void input_overlay_auto_rotate_(struct rarch_state *p_rarch, - bool input_overlay_enable, input_overlay_t *ol); #endif #ifdef HAVE_AUDIOMIXER