Add option to automatically rotate overlays

This commit is contained in:
jdgleaver 2019-10-04 12:15:05 +01:00
parent 9ea18c433b
commit 1df3e20bdd
13 changed files with 202 additions and 23 deletions

View File

@ -321,6 +321,12 @@
#define DEFAULT_INPUT_OVERLAY_OPACITY 0.7f #define DEFAULT_INPUT_OVERLAY_OPACITY 0.7f
#endif #endif
#if defined(RARCH_MOBILE)
#define DEFAULT_OVERLAY_AUTO_ROTATE true
#else
#define DEFAULT_OVERLAY_AUTO_ROTATE false
#endif
#ifdef HAVE_MENU #ifdef HAVE_MENU
#include "menu/menu_driver.h" #include "menu/menu_driver.h"
#include "menu/menu_animation.h" #include "menu/menu_animation.h"

View File

@ -1589,6 +1589,7 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings,
SETTING_BOOL("input_overlay_show_physical_inputs", &settings->bools.input_overlay_show_physical_inputs, true, false, false); SETTING_BOOL("input_overlay_show_physical_inputs", &settings->bools.input_overlay_show_physical_inputs, true, false, false);
SETTING_BOOL("input_overlay_hide_in_menu", &settings->bools.input_overlay_hide_in_menu, true, DEFAULT_OVERLAY_HIDE_IN_MENU, false); SETTING_BOOL("input_overlay_hide_in_menu", &settings->bools.input_overlay_hide_in_menu, true, DEFAULT_OVERLAY_HIDE_IN_MENU, false);
SETTING_BOOL("input_overlay_show_mouse_cursor", &settings->bools.input_overlay_show_mouse_cursor, true, DEFAULT_OVERLAY_SHOW_MOUSE_CURSOR, false); SETTING_BOOL("input_overlay_show_mouse_cursor", &settings->bools.input_overlay_show_mouse_cursor, true, DEFAULT_OVERLAY_SHOW_MOUSE_CURSOR, false);
SETTING_BOOL("input_overlay_auto_rotate", &settings->bools.input_overlay_auto_rotate, true, DEFAULT_OVERLAY_AUTO_ROTATE, false);
#endif #endif
#ifdef HAVE_VIDEO_LAYOUT #ifdef HAVE_VIDEO_LAYOUT
SETTING_BOOL("video_layout_enable", &settings->bools.video_layout_enable, true, true, false); SETTING_BOOL("video_layout_enable", &settings->bools.video_layout_enable, true, true, false);

View File

@ -130,6 +130,7 @@ typedef struct settings
bool input_overlay_hide_in_menu; bool input_overlay_hide_in_menu;
bool input_overlay_show_physical_inputs; bool input_overlay_show_physical_inputs;
bool input_overlay_show_mouse_cursor; bool input_overlay_show_mouse_cursor;
bool input_overlay_auto_rotate;
bool input_descriptor_label_show; bool input_descriptor_label_show;
bool input_descriptor_hide_unbound; bool input_descriptor_hide_unbound;
bool input_all_users_control_menu; bool input_all_users_control_menu;

View File

@ -96,6 +96,13 @@ enum overlay_visibility
OVERLAY_VISIBILITY_HIDDEN OVERLAY_VISIBILITY_HIDDEN
}; };
enum overlay_orientation
{
OVERLAY_ORIENTATION_NONE = 0,
OVERLAY_ORIENTATION_LANDSCAPE,
OVERLAY_ORIENTATION_PORTRAIT
};
struct overlay struct overlay
{ {
bool full_screen; bool full_screen;

View File

@ -611,6 +611,8 @@ MSG_HASH(MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT,
"overlay_show_physical_inputs_port") "overlay_show_physical_inputs_port")
MSG_HASH(MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_MOUSE_CURSOR, MSG_HASH(MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_MOUSE_CURSOR,
"overlay_show_mouse_cursor") "overlay_show_mouse_cursor")
MSG_HASH(MENU_ENUM_LABEL_INPUT_OVERLAY_AUTO_ROTATE,
"input_overlay_auto_rotate")
MSG_HASH(MENU_ENUM_LABEL_INPUT_PLAYER_ANALOG_DPAD_MODE, MSG_HASH(MENU_ENUM_LABEL_INPUT_PLAYER_ANALOG_DPAD_MODE,
"input_player%u_analog_dpad_mode") "input_player%u_analog_dpad_mode")
MSG_HASH(MENU_ENUM_LABEL_INPUT_POLL_TYPE_BEHAVIOR, MSG_HASH(MENU_ENUM_LABEL_INPUT_POLL_TYPE_BEHAVIOR,

View File

@ -1454,6 +1454,14 @@ MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_SHOW_MOUSE_CURSOR, MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_SHOW_MOUSE_CURSOR,
"Show Mouse Cursor With Overlay" "Show Mouse Cursor With Overlay"
) )
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_AUTO_ROTATE,
"Auto-Rotate Overlay"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_OVERLAY_AUTO_ROTATE,
"If supported by current overlay, automatically rotate layout to match screen orientation/aspect ratio."
)
MSG_HASH( MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT, MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT,
"Show Inputs Listen Port" "Show Inputs Listen Port"

View File

@ -173,7 +173,7 @@ static char *strip_comment(char *str)
else if (!cut_comment && literal) else if (!cut_comment && literal)
{ {
cut_comment = true; cut_comment = true;
str = literal + 1; str = (literal < string_end) ? literal + 1 : string_end;
} }
else else
{ {

View File

@ -286,6 +286,7 @@ default_sublabel_macro(action_bind_sublabel_video_message_pos_y, MENU_
default_sublabel_macro(action_bind_sublabel_video_font_size, MENU_ENUM_SUBLABEL_VIDEO_FONT_SIZE) default_sublabel_macro(action_bind_sublabel_video_font_size, MENU_ENUM_SUBLABEL_VIDEO_FONT_SIZE)
default_sublabel_macro(action_bind_sublabel_input_overlay_hide_in_menu, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_HIDE_IN_MENU) default_sublabel_macro(action_bind_sublabel_input_overlay_hide_in_menu, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_HIDE_IN_MENU)
default_sublabel_macro(action_bind_sublabel_input_overlay_show_mouse_cursor, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_SHOW_MOUSE_CURSOR) default_sublabel_macro(action_bind_sublabel_input_overlay_show_mouse_cursor, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_SHOW_MOUSE_CURSOR)
default_sublabel_macro(action_bind_sublabel_input_overlay_auto_rotate, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_AUTO_ROTATE)
default_sublabel_macro(action_bind_sublabel_content_collection_list, MENU_ENUM_SUBLABEL_PLAYLISTS_TAB) default_sublabel_macro(action_bind_sublabel_content_collection_list, MENU_ENUM_SUBLABEL_PLAYLISTS_TAB)
default_sublabel_macro(action_bind_sublabel_video_scale_integer, MENU_ENUM_SUBLABEL_VIDEO_SCALE_INTEGER) default_sublabel_macro(action_bind_sublabel_video_scale_integer, MENU_ENUM_SUBLABEL_VIDEO_SCALE_INTEGER)
default_sublabel_macro(action_bind_sublabel_video_gpu_screenshot, MENU_ENUM_SUBLABEL_VIDEO_GPU_SCREENSHOT) default_sublabel_macro(action_bind_sublabel_video_gpu_screenshot, MENU_ENUM_SUBLABEL_VIDEO_GPU_SCREENSHOT)
@ -2290,6 +2291,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_MOUSE_CURSOR: case MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_MOUSE_CURSOR:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_overlay_show_mouse_cursor); BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_overlay_show_mouse_cursor);
break; break;
case MENU_ENUM_LABEL_INPUT_OVERLAY_AUTO_ROTATE:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_overlay_auto_rotate);
break;
case MENU_ENUM_LABEL_VIDEO_FONT_SIZE: case MENU_ENUM_LABEL_VIDEO_FONT_SIZE:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_video_font_size); BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_video_font_size);
break; break;

View File

@ -4736,6 +4736,7 @@ unsigned menu_displaylist_build_list(file_list_t *list, enum menu_displaylist_ct
{MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS, PARSE_ONLY_BOOL }, {MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS, PARSE_ONLY_BOOL },
{MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT,PARSE_ONLY_BOOL }, {MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT,PARSE_ONLY_BOOL },
{MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_MOUSE_CURSOR, PARSE_ONLY_BOOL }, {MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_MOUSE_CURSOR, PARSE_ONLY_BOOL },
{MENU_ENUM_LABEL_INPUT_OVERLAY_AUTO_ROTATE, PARSE_ONLY_BOOL },
{MENU_ENUM_LABEL_OVERLAY_PRESET, PARSE_ONLY_PATH }, {MENU_ENUM_LABEL_OVERLAY_PRESET, PARSE_ONLY_PATH },
{MENU_ENUM_LABEL_OVERLAY_OPACITY, PARSE_ONLY_FLOAT }, {MENU_ENUM_LABEL_OVERLAY_OPACITY, PARSE_ONLY_FLOAT },
{MENU_ENUM_LABEL_OVERLAY_SCALE, PARSE_ONLY_FLOAT }, {MENU_ENUM_LABEL_OVERLAY_SCALE, PARSE_ONLY_FLOAT },

View File

@ -6421,6 +6421,32 @@ static void overlay_enable_toggle_change_handler(rarch_setting_t *setting)
else else
command_event(CMD_EVENT_OVERLAY_DEINIT, NULL); command_event(CMD_EVENT_OVERLAY_DEINIT, NULL);
} }
static void overlay_auto_rotate_toggle_change_handler(rarch_setting_t *setting)
{
settings_t *settings = config_get_ptr();
if (!setting || !settings)
return;
/* This is very simple...
* The menu is currently active, so if:
* - Overlays are enabled
* - Overlays are not hidden in menus
* ...we just need to de-initialise then
* initialise the current overlay and the
* auto-rotate setting will be applied
* (i.e. There's no need to explicitly
* call the internal 'rotate overlay'
* function - saves having to expose it
* via the API) */
if (settings->bools.input_overlay_enable &&
!settings->bools.input_overlay_hide_in_menu)
{
command_event(CMD_EVENT_OVERLAY_DEINIT, NULL);
command_event(CMD_EVENT_OVERLAY_INIT, NULL);
}
}
#endif #endif
#ifdef HAVE_VIDEO_LAYOUT #ifdef HAVE_VIDEO_LAYOUT
@ -11434,6 +11460,23 @@ static bool setting_append_list(
SD_FLAG_NONE SD_FLAG_NONE
); );
CONFIG_BOOL(
list, list_info,
&settings->bools.input_overlay_auto_rotate,
MENU_ENUM_LABEL_INPUT_OVERLAY_AUTO_ROTATE,
MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_AUTO_ROTATE,
DEFAULT_OVERLAY_AUTO_ROTATE,
MENU_ENUM_LABEL_VALUE_OFF,
MENU_ENUM_LABEL_VALUE_ON,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler,
SD_FLAG_NONE
);
(*list)[list_info->index - 1].change_handler = overlay_auto_rotate_toggle_change_handler;
CONFIG_PATH( CONFIG_PATH(
list, list_info, list, list_info,
settings->paths.path_overlay, settings->paths.path_overlay,

View File

@ -788,6 +788,7 @@ enum msg_hash_enums
MENU_LABEL(INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS), MENU_LABEL(INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS),
MENU_LABEL(INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT), MENU_LABEL(INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT),
MENU_LABEL(INPUT_OVERLAY_SHOW_MOUSE_CURSOR), MENU_LABEL(INPUT_OVERLAY_SHOW_MOUSE_CURSOR),
MENU_LABEL(INPUT_OVERLAY_AUTO_ROTATE),
MENU_LABEL(INPUT_KEYBOARD_GAMEPAD_MAPPING_TYPE), MENU_LABEL(INPUT_KEYBOARD_GAMEPAD_MAPPING_TYPE),
MENU_LABEL(INPUT_SMALL_KEYBOARD_ENABLE), MENU_LABEL(INPUT_SMALL_KEYBOARD_ENABLE),
MENU_LABEL(INPUT_TOUCH_ENABLE), MENU_LABEL(INPUT_TOUCH_ENABLE),

View File

@ -1965,6 +1965,7 @@ static int16_t input_state(unsigned port, unsigned device,
static void input_overlay_set_alpha_mod(input_overlay_t *ol, float mod); static void input_overlay_set_alpha_mod(input_overlay_t *ol, float mod);
static void input_overlay_set_scale_factor(input_overlay_t *ol, float scale); static void input_overlay_set_scale_factor(input_overlay_t *ol, float scale);
static void input_overlay_load_active(input_overlay_t *ol, float opacity); static void input_overlay_load_active(input_overlay_t *ol, float opacity);
static void input_overlay_auto_rotate(input_overlay_t *ol);
#endif #endif
static void bsv_movie_deinit(void); static void bsv_movie_deinit(void);
@ -5055,19 +5056,27 @@ TODO: Add a setting for these tweaks */
case CMD_EVENT_OVERLAY_NEXT: case CMD_EVENT_OVERLAY_NEXT:
/* Switch to the next available overlay screen. */ /* Switch to the next available overlay screen. */
#ifdef HAVE_OVERLAY #ifdef HAVE_OVERLAY
if (!overlay_ptr)
return false;
overlay_ptr->index = overlay_ptr->next_index;
overlay_ptr->active = &overlay_ptr->overlays[overlay_ptr->index];
{ {
settings_t *settings = configuration_settings; settings_t *settings = configuration_settings;
input_overlay_load_active(overlay_ptr, settings->floats.input_overlay_opacity); bool *check_rotation = (bool*)data;
}
overlay_ptr->blocked = true; if (!overlay_ptr)
overlay_ptr->next_index = (unsigned)((overlay_ptr->index + 1) % overlay_ptr->size); return false;
overlay_ptr->index = overlay_ptr->next_index;
overlay_ptr->active = &overlay_ptr->overlays[overlay_ptr->index];
input_overlay_load_active(overlay_ptr, settings->floats.input_overlay_opacity);
overlay_ptr->blocked = true;
overlay_ptr->next_index = (unsigned)((overlay_ptr->index + 1) % overlay_ptr->size);
/* Check orientation, if required */
if (settings->bools.input_overlay_auto_rotate)
if (check_rotation)
if (*check_rotation)
input_overlay_auto_rotate(overlay_ptr);
}
#endif #endif
break; break;
case CMD_EVENT_DSP_FILTER_INIT: case CMD_EVENT_DSP_FILTER_INIT:
@ -10844,6 +10853,86 @@ static void input_overlay_load_active(input_overlay_t *ol, float opacity)
ol->iface->full_screen(ol->iface_data, ol->active->full_screen); ol->iface->full_screen(ol->iface_data, ol->active->full_screen);
} }
/* Attempts to automatically rotate the specified overlay.
* Depends upon proper naming conventions in overlay
* config file. */
static void input_overlay_auto_rotate(input_overlay_t *ol)
{
settings_t *settings = configuration_settings;
enum overlay_orientation screen_orientation = OVERLAY_ORIENTATION_NONE;
enum overlay_orientation active_overlay_orientation = OVERLAY_ORIENTATION_NONE;
bool next_overlay_found = false;
bool tmp = false;
unsigned next_overlay_index;
size_t i;
/* Sanity check */
if (!ol || !settings)
return;
if (!ol->alive || !settings->bools.input_overlay_enable)
return;
/* Get current screen orientation */
if (video_driver_width > video_driver_height)
screen_orientation = OVERLAY_ORIENTATION_LANDSCAPE;
else
screen_orientation = OVERLAY_ORIENTATION_PORTRAIT;
/* 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 < overlay_ptr->active->size; i++)
{
overlay_desc_t *desc = &overlay_ptr->active->descs[i];
if (!desc)
continue;
if (!string_is_empty(desc->next_index_name))
{
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)
{
next_overlay_index = desc->next_index;
break;
}
}
}
/* Sanity check */
if (!next_overlay_found)
return;
/* 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 = next_overlay_index;
command_event(CMD_EVENT_OVERLAY_NEXT, &tmp);
}
/** /**
* inside_hitbox: * inside_hitbox:
* @desc : Overlay descriptor handle. * @desc : Overlay descriptor handle.
@ -11140,6 +11229,10 @@ static void input_overlay_loaded(retro_task_t *task,
if (!settings->bools.input_overlay_show_mouse_cursor) if (!settings->bools.input_overlay_show_mouse_cursor)
video_driver_hide_mouse(); video_driver_hide_mouse();
/* Attempt to automatically rotate overlay, if required */
if (settings->bools.input_overlay_auto_rotate)
input_overlay_auto_rotate(overlay_ptr);
return; return;
abort_load: abort_load:
@ -24670,11 +24763,6 @@ static enum runloop_state runloop_check_state(void)
BIT256_CLEAR_ALL(current_bits); BIT256_CLEAR_ALL(current_bits);
#endif #endif
#ifdef HAVE_OVERLAY
/* Check next overlay */
HOTKEY_CHECK(RARCH_OVERLAY_NEXT, CMD_EVENT_OVERLAY_NEXT, true, NULL);
#endif
/* Check fullscreen toggle */ /* Check fullscreen toggle */
{ {
bool fullscreen_toggled = !runloop_paused bool fullscreen_toggled = !runloop_paused
@ -24691,19 +24779,38 @@ static enum runloop_state runloop_check_state(void)
HOTKEY_CHECK(RARCH_GRAB_MOUSE_TOGGLE, CMD_EVENT_GRAB_MOUSE_TOGGLE, true, NULL); HOTKEY_CHECK(RARCH_GRAB_MOUSE_TOGGLE, CMD_EVENT_GRAB_MOUSE_TOGGLE, true, NULL);
#ifdef HAVE_OVERLAY #ifdef HAVE_OVERLAY
if (settings->bools.input_overlay_enable)
{ {
static char prev_overlay_restore = false; static char prev_overlay_restore = false;
bool check_next_rotation = true;
static unsigned last_width = 0;
static unsigned last_height = 0;
/* Check next overlay */
HOTKEY_CHECK(RARCH_OVERLAY_NEXT, CMD_EVENT_OVERLAY_NEXT, true, &check_next_rotation);
/* Ensure overlay is restored after displaying osk */
if (input_driver_keyboard_linefeed_enable) if (input_driver_keyboard_linefeed_enable)
{ prev_overlay_restore = true;
prev_overlay_restore = false;
retroarch_overlay_init();
}
else if (prev_overlay_restore) else if (prev_overlay_restore)
{ {
if (!settings->bools.input_overlay_hide_in_menu) if (!settings->bools.input_overlay_hide_in_menu)
retroarch_overlay_init(); retroarch_overlay_init();
prev_overlay_restore = false; prev_overlay_restore = false;
} }
/* If video aspect ratio has changed, check overlay
* rotation (if required) */
if (settings->bools.input_overlay_auto_rotate)
{
if ((video_driver_width != last_width) ||
(video_driver_height != last_height))
{
input_overlay_auto_rotate(overlay_ptr);
last_width = video_driver_width;
last_height = video_driver_height;
}
}
} }
#endif #endif

View File

@ -760,8 +760,6 @@ bool task_push_overlay_load_default(
return false; return false;
} }
conf->path = strdup(overlay_path);
if (!config_get_uint(conf, "overlays", &loader->size)) if (!config_get_uint(conf, "overlays", &loader->size))
{ {
/* Error - overlays varaible not defined in config. */ /* Error - overlays varaible not defined in config. */