From cfaaa5eeffe19fdede3233cc639b9dfc51d61d96 Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Fri, 7 Jun 2019 16:38:17 +0100 Subject: [PATCH] (XMB) Add optional thumbnail scaling --- config.def.h | 2 + configuration.c | 1 + configuration.h | 1 + intl/msg_hash_lbl.h | 2 + intl/msg_hash_us.h | 8 +++ menu/cbs/menu_cbs_sublabel.c | 4 ++ menu/drivers/xmb.c | 126 ++++++++++++++++++++++++----------- menu/menu_displaylist.c | 1 + menu/menu_setting.c | 15 +++++ msg_hash.h | 1 + 10 files changed, 121 insertions(+), 40 deletions(-) diff --git a/config.def.h b/config.def.h index ca556e9caa..d2b136935e 100644 --- a/config.def.h +++ b/config.def.h @@ -827,6 +827,8 @@ static const unsigned menu_timedate_style = 5; static const bool xmb_vertical_thumbnails = false; +static const unsigned xmb_thumbnail_scale_factor = 100; + #ifdef IOS static const bool ui_companion_start_on_boot = false; #else diff --git a/configuration.c b/configuration.c index 2652479c65..f7f561e769 100644 --- a/configuration.c +++ b/configuration.c @@ -1777,6 +1777,7 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings, SETTING_UINT("menu_font_color_red", &settings->uints.menu_font_color_red, true, menu_font_color_red, false); SETTING_UINT("menu_font_color_green", &settings->uints.menu_font_color_green, true, menu_font_color_green, false); SETTING_UINT("menu_font_color_blue", &settings->uints.menu_font_color_blue, true, menu_font_color_blue, false); + SETTING_UINT("menu_xmb_thumbnail_scale_factor", &settings->uints.menu_xmb_thumbnail_scale_factor, true, xmb_thumbnail_scale_factor, false); #endif SETTING_UINT("materialui_menu_color_theme", &settings->uints.menu_materialui_color_theme, true, MATERIALUI_THEME_BLUE, false); SETTING_UINT("menu_shader_pipeline", &settings->uints.menu_xmb_shader_pipeline, true, menu_shader_pipeline, false); diff --git a/configuration.h b/configuration.h index 2f31620021..c3cbfd1825 100644 --- a/configuration.h +++ b/configuration.h @@ -473,6 +473,7 @@ typedef struct settings unsigned menu_xmb_alpha_factor; unsigned menu_xmb_theme; unsigned menu_xmb_color_theme; + unsigned menu_xmb_thumbnail_scale_factor; unsigned menu_materialui_color_theme; unsigned menu_ozone_color_theme; unsigned menu_font_color_red; diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index 8cc91688c5..597f5c561c 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -1151,6 +1151,8 @@ MSG_HASH(MENU_ENUM_LABEL_LEFT_THUMBNAILS, "left thumbnails") MSG_HASH(MENU_ENUM_LABEL_XMB_VERTICAL_THUMBNAILS, "xmb_vertical_thumbnails") +MSG_HASH(MENU_ENUM_LABEL_MENU_XMB_THUMBNAIL_SCALE_FACTOR, + "menu_xmb_thumbnail_scale_factor") MSG_HASH(MENU_ENUM_LABEL_MENU_THUMBNAIL_UPSCALE_THRESHOLD, "menu_thumbnail_upscale_threshold") MSG_HASH(MENU_ENUM_LABEL_MENU_RGUI_THUMBNAIL_DOWNSCALER, diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index f6cfdc807d..ac5060a9e7 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -3034,6 +3034,14 @@ MSG_HASH( MENU_ENUM_LABEL_VALUE_XMB_VERTICAL_THUMBNAILS, "Thumbnails Vertical Disposition" ) +MSG_HASH( + MENU_ENUM_LABEL_VALUE_MENU_XMB_THUMBNAIL_SCALE_FACTOR, + "Thumbnail Scale Factor" + ) +MSG_HASH( + MENU_ENUM_SUBLABEL_MENU_XMB_THUMBNAIL_SCALE_FACTOR, + "Reduce thumbnail display size by scaling maximum allowed width." + ) MSG_HASH( MENU_ENUM_LABEL_VALUE_MENU_THUMBNAIL_UPSCALE_THRESHOLD, "Thumbnail Upscaling Threshold" diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index da17b32fa0..6ca417fb60 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -440,6 +440,7 @@ default_sublabel_macro(action_bind_sublabel_xmb_layout, default_sublabel_macro(action_bind_sublabel_xmb_icon_theme, MENU_ENUM_SUBLABEL_XMB_THEME) default_sublabel_macro(action_bind_sublabel_xmb_shadows_enable, MENU_ENUM_SUBLABEL_XMB_SHADOWS_ENABLE) default_sublabel_macro(action_bind_sublabel_xmb_vertical_thumbnails, MENU_ENUM_SUBLABEL_XMB_VERTICAL_THUMBNAILS) +default_sublabel_macro(action_bind_sublabel_menu_xmb_thumbnail_scale_factor, MENU_ENUM_SUBLABEL_MENU_XMB_THUMBNAIL_SCALE_FACTOR) default_sublabel_macro(action_bind_sublabel_menu_color_theme, MENU_ENUM_SUBLABEL_MATERIALUI_MENU_COLOR_THEME) default_sublabel_macro(action_bind_sublabel_ozone_menu_color_theme, MENU_ENUM_SUBLABEL_OZONE_MENU_COLOR_THEME) default_sublabel_macro(action_bind_sublabel_ozone_collapse_sidebar, MENU_ENUM_SUBLABEL_OZONE_COLLAPSE_SIDEBAR) @@ -1466,6 +1467,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_XMB_VERTICAL_THUMBNAILS: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_xmb_vertical_thumbnails); break; + case MENU_ENUM_LABEL_MENU_XMB_THUMBNAIL_SCALE_FACTOR: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_menu_xmb_thumbnail_scale_factor); + break; case MENU_ENUM_LABEL_XMB_LAYOUT: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_xmb_layout); break; diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 0afd29078e..9fd07d56d4 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -2942,7 +2942,15 @@ static int xmb_draw_item( && xmb->left_thumbnail && settings->bools.menu_xmb_vertical_thumbnails) ) + { ticker_limit = 40 * scale_mod[1]; + + /* Can increase text length if thumbnail is downscaled */ + if (settings->uints.menu_xmb_thumbnail_scale_factor < 100) + ticker_limit += + (unsigned)((1.0f - ((float)settings->uints.menu_xmb_thumbnail_scale_factor / 100.0f)) * + 15.0f * scale_mod[1]); + } else ticker_limit = 70 * scale_mod[2]; } @@ -3401,6 +3409,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) unsigned height = video_info->height; const float under_thumb_margin = 0.96; float scale_factor = 0.0f; + float thumbnail_scale_factor = 0.0f; float pseudo_font_length = 0.0f; xmb_handle_t *xmb = (xmb_handle_t*)data; settings_t *settings = config_get_ptr(); @@ -3411,6 +3420,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) return; scale_factor = (settings->uints.menu_xmb_scale_factor * (float)width) / (1920.0 * 100); + thumbnail_scale_factor = ((float)settings->uints.menu_xmb_thumbnail_scale_factor / 100.0f); pseudo_font_length = xmb->icon_spacing_horizontal * 4 - xmb->icon_size / 4; msg[0] = '\0'; @@ -3484,15 +3494,50 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) /* Save State thumbnail, right side */ if (xmb->savestate_thumbnail) + { + float thumb_width = 0.0f; + float thumb_height = 0.0f; + float thumb_max_width = (float)width - (xmb->icon_size / 6) + - (xmb->margins_screen_left * scale_mod[5]) - + xmb->icon_spacing_horizontal - pseudo_font_length; + float thumb_max_width_scaled = thumb_max_width * thumbnail_scale_factor; + + /* Limit thumbnail width */ + if (xmb->savestate_thumbnail_width * scale_mod[4] > thumb_max_width_scaled) + { + thumb_width = (xmb->savestate_thumbnail_width * scale_mod[4]) * + (thumb_max_width_scaled / (xmb->savestate_thumbnail_width * scale_mod[4])); + thumb_height = (xmb->savestate_thumbnail_height * scale_mod[4]) * + (thumb_max_width_scaled / (xmb->savestate_thumbnail_width * scale_mod[4])); + } + else + { + thumb_width = xmb->savestate_thumbnail_width * scale_mod[4]; + thumb_height = xmb->savestate_thumbnail_height * scale_mod[4]; + } + + /* Limit thumbnail height to screen height + margin. */ + if (xmb->margins_screen_top + xmb->icon_size + thumb_height >= + ((float)height * under_thumb_margin)) + { + thumb_width = thumb_width * + ((((float)height * under_thumb_margin) - + xmb->margins_screen_top - xmb->icon_size) / + thumb_height); + thumb_height = thumb_height * + ((((float)height * under_thumb_margin) - + xmb->margins_screen_top - xmb->icon_size) / + thumb_height); + } + xmb_draw_thumbnail(video_info, xmb, &coord_white[0], width, height, - xmb->margins_screen_left * scale_mod[5] + - xmb->icon_spacing_horizontal + pseudo_font_length, - xmb->margins_screen_top + xmb->icon_size + - xmb->savestate_thumbnail_height * scale_mod[4], - xmb->savestate_thumbnail_width * scale_mod[4], - xmb->savestate_thumbnail_height * scale_mod[4], + (float)width - (xmb->icon_size / 6) - thumb_max_width + + ((thumb_max_width - thumb_width) / 2), + xmb->margins_screen_top + xmb->icon_size + thumb_height, + thumb_width, thumb_height, xmb->savestate_thumbnail); + } /* This is used for hiding thumbnails when going into sub-levels in the * Quick Menu as well as when selecting "Information" for a playlist entry. @@ -3522,6 +3567,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) float thumb_max_width = (float)width - (xmb->icon_size / 6) - (xmb->margins_screen_left * scale_mod[5]) - xmb->icon_spacing_horizontal - pseudo_font_length; + float thumb_max_width_scaled = thumb_max_width * thumbnail_scale_factor; #ifdef XMB_DEBUG RARCH_LOG("[XMB thumbnail] width: %.2f, height: %.2f\n", @@ -3529,12 +3575,12 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) RARCH_LOG("[XMB thumbnail] w: %.2f, h: %.2f\n", width, height); #endif - if (xmb->thumbnail_width * scale_mod[4] > thumb_max_width) + if (xmb->thumbnail_width * scale_mod[4] > thumb_max_width_scaled) { thumb_width = (xmb->thumbnail_width * scale_mod[4]) * - (thumb_max_width / (xmb->thumbnail_width * scale_mod[4])); + (thumb_max_width_scaled / (xmb->thumbnail_width * scale_mod[4])); thumb_height = (xmb->thumbnail_height * scale_mod[4]) * - (thumb_max_width / (xmb->thumbnail_width * scale_mod[4])); + (thumb_max_width_scaled / (xmb->thumbnail_width * scale_mod[4])); } else { @@ -3584,7 +3630,12 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) float left_thumb_width = 0.0f; float left_thumb_height = 0.0f; - float thumb_max_width = xmb->icon_size * 3.4; + float thumb_max_width = xmb->icon_size * 3.4; + float thumb_max_width_scaled = thumb_max_width * thumbnail_scale_factor; + float y_offset_factor = !(xmb->depth == 1) ? 2.1 : 1; + float thumb_max_height = ((float)height - (96.0 * scale_factor)) - + xmb->margins_screen_top - + (xmb->icon_size * y_offset_factor); #ifdef XMB_DEBUG RARCH_LOG("[XMB left thumbnail] width: %.2f, height: %.2f\n", @@ -3592,12 +3643,12 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) RARCH_LOG("[XMB left thumbnail] w: %.2f, h: %.2f\n", width, height); #endif - if (xmb->left_thumbnail_width * scale_mod[4] > thumb_max_width) + if (xmb->left_thumbnail_width * scale_mod[4] > thumb_max_width_scaled) { left_thumb_width = (xmb->left_thumbnail_width * scale_mod[4]) * - (thumb_max_width / (xmb->left_thumbnail_width * scale_mod[4])); + (thumb_max_width_scaled / (xmb->left_thumbnail_width * scale_mod[4])); left_thumb_height = (xmb->left_thumbnail_height * scale_mod[4]) * - (thumb_max_width / (xmb->left_thumbnail_width * scale_mod[4])); + (thumb_max_width_scaled / (xmb->left_thumbnail_width * scale_mod[4])); } else { @@ -3606,30 +3657,21 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) } /* Limit left thumbnail height to screen height + margin. */ - if (xmb->margins_screen_top + xmb->icon_size * - (!(xmb->depth == 1)? 2.1 : 1) + - left_thumb_height >= - ((float)height - (96.0 * scale_factor))) + if (left_thumb_height >= thumb_max_height) { left_thumb_width = left_thumb_width * - ((((float)height - (96.0 * scale_factor)) - - xmb->margins_screen_top - - (xmb->icon_size * (!(xmb->depth == 1)? 2.1 : 1))) / - left_thumb_height); + (thumb_max_height / left_thumb_height); - left_thumb_height = left_thumb_height * - ((((float)height - (96.0 * scale_factor)) - - xmb->margins_screen_top - - (xmb->icon_size * (!(xmb->depth == 1)? 2.1 : 1))) / - left_thumb_height); + left_thumb_height = thumb_max_height; } xmb_draw_thumbnail(video_info, xmb, &coord_white[0], width, height, (xmb->icon_size / 6) + ((thumb_max_width - left_thumb_width) / 2), - xmb->margins_screen_top + xmb->icon_size * - (!(xmb->depth == 1)? 2.1 : 1) + left_thumb_height, + xmb->margins_screen_top + (xmb->icon_size * y_offset_factor) + + left_thumb_height + (!(xmb->depth == 1) ? + (1.0f - thumbnail_scale_factor) * 0.5f * (thumb_max_height - left_thumb_height) : 0), left_thumb_width, left_thumb_height, xmb->left_thumbnail); } @@ -3656,6 +3698,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) float thumb_max_width = (float)width - (xmb->icon_size / 6) - (xmb->margins_screen_left * scale_mod[5]) - xmb->icon_spacing_horizontal - pseudo_font_length; + float thumb_max_width_scaled = thumb_max_width * thumbnail_scale_factor; #ifdef XMB_DEBUG RARCH_LOG("[XMB thumbnail] width: %.2f, height: %.2f\n", @@ -3663,12 +3706,12 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) RARCH_LOG("[XMB thumbnail] w: %.2f, h: %.2f\n", width, height); #endif - if (xmb->left_thumbnail_width * scale_mod[4] > thumb_max_width) + if (xmb->left_thumbnail_width * scale_mod[4] > thumb_max_width_scaled) { left_thumb_width = (xmb->left_thumbnail_width * scale_mod[4]) * - (thumb_max_width / (xmb->left_thumbnail_width * scale_mod[4])); + (thumb_max_width_scaled / (xmb->left_thumbnail_width * scale_mod[4])); left_thumb_height = (xmb->left_thumbnail_height * scale_mod[4]) * - (thumb_max_width / (xmb->left_thumbnail_width * scale_mod[4])); + (thumb_max_width_scaled / (xmb->left_thumbnail_width * scale_mod[4])); } else { @@ -3717,6 +3760,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) float left_thumb_width = 0.0f; float left_thumb_height = 0.0f; float thumb_max_width = xmb->icon_size * 2.4; + float thumb_max_width_scaled = thumb_max_width * thumbnail_scale_factor; #ifdef XMB_DEBUG RARCH_LOG("[XMB left thumbnail] width: %.2f, height: %.2f\n", @@ -3724,12 +3768,12 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) RARCH_LOG("[XMB left thumbnail] w: %.2f, h: %.2f\n", width, height); #endif - if (xmb->left_thumbnail_width > thumb_max_width) + if (xmb->left_thumbnail_width > thumb_max_width_scaled) { left_thumb_width = xmb->left_thumbnail_width * - (thumb_max_width / xmb->left_thumbnail_width); + (thumb_max_width_scaled / xmb->left_thumbnail_width); left_thumb_height = xmb->left_thumbnail_height * - (thumb_max_width / xmb->left_thumbnail_width); + (thumb_max_width_scaled / xmb->left_thumbnail_width); } else { @@ -3960,6 +4004,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) float thumb_max_width = (float)width - (xmb->icon_size / 6) - (xmb->margins_screen_left * scale_mod[5]) - xmb->icon_spacing_horizontal - pseudo_font_length; + float thumb_max_width_scaled = thumb_max_width * thumbnail_scale_factor; #ifdef XMB_DEBUG RARCH_LOG("[XMB thumbnail] width: %.2f, height: %.2f\n", @@ -3967,12 +4012,12 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) RARCH_LOG("[XMB thumbnail] w: %.2f, h: %.2f\n", width, height); #endif - if (xmb->thumbnail_width * scale_mod[4] > thumb_max_width) + if (xmb->thumbnail_width * scale_mod[4] > thumb_max_width_scaled) { thumb_width = (xmb->thumbnail_width * scale_mod[4]) * - (thumb_max_width / (xmb->thumbnail_width * scale_mod[4])); + (thumb_max_width_scaled / (xmb->thumbnail_width * scale_mod[4])); thumb_height = (xmb->thumbnail_height * scale_mod[4]) * - (thumb_max_width / (xmb->thumbnail_width * scale_mod[4])); + (thumb_max_width_scaled / (xmb->thumbnail_width * scale_mod[4])); } else { @@ -4022,6 +4067,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) float thumb_max_width = (float)width - (xmb->icon_size / 6) - (xmb->margins_screen_left * scale_mod[5]) - xmb->icon_spacing_horizontal - pseudo_font_length; + float thumb_max_width_scaled = thumb_max_width * thumbnail_scale_factor; #ifdef XMB_DEBUG RARCH_LOG("[XMB left thumbnail] width: %.2f, height: %.2f\n", @@ -4029,12 +4075,12 @@ static void xmb_frame(void *data, video_frame_info_t *video_info) RARCH_LOG("[XMB left thumbnail] w: %.2f, h: %.2f\n", width, height); #endif - if (xmb->left_thumbnail_width * scale_mod[4] > thumb_max_width) + if (xmb->left_thumbnail_width * scale_mod[4] > thumb_max_width_scaled) { left_thumb_width = (xmb->left_thumbnail_width * scale_mod[4]) * - (thumb_max_width / (xmb->left_thumbnail_width * scale_mod[4])); + (thumb_max_width_scaled / (xmb->left_thumbnail_width * scale_mod[4])); left_thumb_height = (xmb->left_thumbnail_height * scale_mod[4]) * - (thumb_max_width / (xmb->left_thumbnail_width * scale_mod[4])); + (thumb_max_width_scaled / (xmb->left_thumbnail_width * scale_mod[4])); } else { diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 9188faf6bc..991d976c6a 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -4462,6 +4462,7 @@ unsigned menu_displaylist_build_list(file_list_t *list, enum menu_displaylist_ct {MENU_ENUM_LABEL_THUMBNAILS, PARSE_ONLY_UINT }, {MENU_ENUM_LABEL_LEFT_THUMBNAILS, PARSE_ONLY_UINT }, {MENU_ENUM_LABEL_XMB_VERTICAL_THUMBNAILS, PARSE_ONLY_BOOL }, + {MENU_ENUM_LABEL_MENU_XMB_THUMBNAIL_SCALE_FACTOR, PARSE_ONLY_UINT }, {MENU_ENUM_LABEL_MENU_THUMBNAIL_UPSCALE_THRESHOLD, PARSE_ONLY_UINT }, {MENU_ENUM_LABEL_MENU_RGUI_SWAP_THUMBNAILS, PARSE_ONLY_BOOL }, {MENU_ENUM_LABEL_MENU_RGUI_THUMBNAIL_DOWNSCALER, PARSE_ONLY_UINT }, diff --git a/menu/menu_setting.c b/menu/menu_setting.c index a20374b5de..f409b56254 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -12287,6 +12287,21 @@ static bool setting_append_list( general_write_handler, general_read_handler, SD_FLAG_NONE); + + CONFIG_UINT( + list, list_info, + &settings->uints.menu_xmb_thumbnail_scale_factor, + MENU_ENUM_LABEL_MENU_XMB_THUMBNAIL_SCALE_FACTOR, + MENU_ENUM_LABEL_VALUE_MENU_XMB_THUMBNAIL_SCALE_FACTOR, + xmb_thumbnail_scale_factor, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler); + (*list)[list_info->index - 1].action_ok = &setting_action_ok_uint; + (*list)[list_info->index - 1].offset_by = 30; + menu_settings_list_current_add_range(list, list_info, (*list)[list_info->index - 1].offset_by, 100, 1, true, true); } if (string_is_equal(settings->arrays.menu_driver, "xmb") || string_is_equal(settings->arrays.menu_driver, "ozone")) diff --git a/msg_hash.h b/msg_hash.h index 7291224d9e..9d35ea4e5a 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -936,6 +936,7 @@ enum msg_hash_enums MENU_LABEL(LEFT_THUMBNAILS_RGUI), MENU_LABEL(LEFT_THUMBNAILS_OZONE), MENU_LABEL(XMB_VERTICAL_THUMBNAILS), + MENU_LABEL(MENU_XMB_THUMBNAIL_SCALE_FACTOR), MENU_LABEL(MENU_THUMBNAIL_UPSCALE_THRESHOLD), MENU_LABEL(MENU_RGUI_INLINE_THUMBNAILS), MENU_LABEL(MENU_RGUI_SWAP_THUMBNAILS),