Merge pull request #5527 from bparker06/osd_background

Add a configurable background color to OSD messages
This commit is contained in:
Twinaphex 2017-10-10 22:14:06 +02:00 committed by GitHub
commit eb3d8c8804
17 changed files with 305 additions and 5 deletions

View File

@ -5,6 +5,7 @@
- GUI: (XMB) Skip drawing the fading list when it is already transparent. Optimization.
- GUI: (XMB) Comment out visible item calculation in xmb_draw_items().
- GUI: (RGUI) Prevent crashes when using a non-English language reliant on UTF8.
- GUI: Add option for OSD background color.
- INPUT: Always show the controls menu even if descriptors are not set
- INPUT: Fix input descriptors not being set on cores that don't implement the controllers interface
- INPUT: Apply descriptors only for the amount of cores the core supports

View File

@ -373,6 +373,12 @@ static const float message_pos_offset_y = 0.05;
* RGB hex value. */
static const uint32_t message_color = 0xffff00;
static const bool message_bgcolor_enable = false;
static const uint32_t message_bgcolor_red = 0;
static const uint32_t message_bgcolor_green = 0;
static const uint32_t message_bgcolor_blue = 0;
static const float message_bgcolor_opacity = 1.0f;
/* Record post-filtered (CPU filter) video,
* rather than raw game output. */
static const bool post_filter_record = false;

View File

@ -1293,6 +1293,8 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings,
SETTING_BOOL("systemfiles_in_content_dir", &settings->bools.systemfiles_in_content_dir, true, default_systemfiles_in_content_dir, false);
SETTING_BOOL("screenshots_in_content_dir", &settings->bools.screenshots_in_content_dir, true, default_screenshots_in_content_dir, false);
SETTING_BOOL("video_msg_bgcolor_enable", &settings->bools.video_msg_bgcolor_enable, true, message_bgcolor_enable, false);
if (global)
{
SETTING_BOOL("custom_bgm_enable", &global->console.sound.system_bgm_enable, true, false, false);
@ -1331,6 +1333,7 @@ static struct config_float_setting *populate_settings_float(settings_t *settings
SETTING_FLOAT("fastforward_ratio", &settings->floats.fastforward_ratio, true, fastforward_ratio, false);
SETTING_FLOAT("slowmotion_ratio", &settings->floats.slowmotion_ratio, true, slowmotion_ratio, false);
SETTING_FLOAT("input_axis_threshold", input_driver_get_float(INPUT_ACTION_AXIS_THRESHOLD), true, axis_threshold, false);
SETTING_FLOAT("video_msg_bgcolor_opacity", &settings->floats.video_msg_bgcolor_opacity, true, message_bgcolor_opacity, false);
*size = count;
@ -1406,6 +1409,9 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings,
SETTING_UINT("bundle_assets_extract_version_current", &settings->uints.bundle_assets_extract_version_current, true, 0, false);
SETTING_UINT("bundle_assets_extract_last_version", &settings->uints.bundle_assets_extract_last_version, true, 0, false);
SETTING_UINT("input_overlay_show_physical_inputs_port", &settings->uints.input_overlay_show_physical_inputs_port, true, 0, false);
SETTING_UINT("video_msg_bgcolor_red", &settings->uints.video_msg_bgcolor_red, true, message_bgcolor_red, false);
SETTING_UINT("video_msg_bgcolor_green", &settings->uints.video_msg_bgcolor_green, true, message_bgcolor_green, false);
SETTING_UINT("video_msg_bgcolor_blue", &settings->uints.video_msg_bgcolor_blue, true, message_bgcolor_blue, false);
*size = count;

View File

@ -83,6 +83,7 @@ typedef struct settings
bool video_shared_context;
bool video_force_srgb_disable;
bool video_fps_show;
bool video_msg_bgcolor_enable;
/* Audio */
bool audio_enable;
@ -252,6 +253,7 @@ typedef struct settings
float video_msg_color_r;
float video_msg_color_g;
float video_msg_color_b;
float video_msg_bgcolor_opacity;
float menu_wallpaper_opacity;
float menu_framebuffer_opacity;
@ -320,6 +322,9 @@ typedef struct settings
unsigned video_viwidth;
unsigned video_aspect_ratio_idx;
unsigned video_rotation;
unsigned video_msg_bgcolor_red;
unsigned video_msg_bgcolor_green;
unsigned video_msg_bgcolor_blue;
unsigned menu_thumbnails;
unsigned menu_dpi_override_value;

View File

@ -941,6 +941,129 @@ static void gl_set_texture_enable(void *data, bool state, bool full_screen)
gl->menu_texture_full_screen = full_screen;
}
static void gl_render_osd_background(
gl_t *gl, video_frame_info_t *video_info,
const char *msg)
{
video_shader_ctx_mvp_t mvp;
video_shader_ctx_coords_t coords_data;
video_coords_t coords;
video_coord_array_t ca;
video_shader_ctx_info_t shader_info;
struct uniform_info uniform_param;
const unsigned vertices_total = 6;
float colors[4];
float *dummy = (float*)calloc(4 * vertices_total, sizeof(float));
float *verts = (float*)malloc(2 * vertices_total * sizeof(float));
int msg_width;
float x, x2, y, y2, width, height;
settings_t *settings = config_get_ptr();
if (!gl || !settings)
goto end;
msg_width = font_driver_get_message_width(NULL, msg, strlen(msg), 1.0f);
/* shader driver expects vertex coords as 0..1 */
x = video_info->font_msg_pos_x;
y = video_info->font_msg_pos_y;
width = msg_width / (float)video_info->width;
height = settings->floats.video_font_size / (float)video_info->height;
x2 = 0.005f; /* extend background around text */
y2 = 0.005f;
x -= x2;
y -= y2;
width += x2;
height += y2;
colors[0] = settings->uints.video_msg_bgcolor_red / 255.0f;
colors[1] = settings->uints.video_msg_bgcolor_green / 255.0f;
colors[2] = settings->uints.video_msg_bgcolor_blue / 255.0f;
colors[3] = settings->floats.video_msg_bgcolor_opacity;
/* triangle 1 */
verts[0] = x;
verts[1] = y; /* bottom-left */
verts[2] = x;
verts[3] = y + height; /* top-left */
verts[4] = x + width;
verts[5] = y + height; /* top-right */
/* triangle 2 */
verts[6] = x;
verts[7] = y; /* bottom-left */
verts[8] = x + width;
verts[9] = y + height; /* top-right */
verts[10] = x + width;
verts[11] = y; /* bottom-right */
coords.color = dummy;
coords.vertex = verts;
coords.tex_coord = dummy;
coords.lut_tex_coord = dummy;
coords.vertices = vertices_total;
coords_data.handle_data = NULL;
coords_data.data = &coords;
shader_info.data = NULL;
shader_info.idx = VIDEO_SHADER_STOCK_BLEND;
shader_info.set_active = true;
video_driver_set_viewport(video_info->width, video_info->height, true, false);
video_shader_driver_use(shader_info);
video_shader_driver_set_coords(coords_data);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
mvp.data = gl;
mvp.matrix = &gl->mvp_no_rot;
video_shader_driver_set_mvp(mvp);
uniform_param.type = UNIFORM_4F;
uniform_param.enabled = true;
uniform_param.location = 0;
uniform_param.count = 0;
uniform_param.lookup.type = SHADER_PROGRAM_FRAGMENT;
uniform_param.lookup.ident = "bgcolor";
uniform_param.lookup.idx = shader_info.idx;
uniform_param.lookup.add_prefix = true;
uniform_param.lookup.enable = true;
uniform_param.result.f.v0 = colors[0];
uniform_param.result.f.v1 = colors[1];
uniform_param.result.f.v2 = colors[2];
uniform_param.result.f.v3 = colors[3];
video_shader_driver_set_parameter(uniform_param);
glDrawArrays(GL_TRIANGLES, 0, coords.vertices);
end:
/* reset uniform back to zero so it is not used for anything else */
uniform_param.result.f.v0 = 0.0f;
uniform_param.result.f.v1 = 0.0f;
uniform_param.result.f.v2 = 0.0f;
uniform_param.result.f.v3 = 0.0f;
video_shader_driver_set_parameter(uniform_param);
free(dummy);
free(verts);
video_driver_set_viewport(video_info->width, video_info->height, false, true);
}
static void gl_set_osd_msg(void *data,
video_frame_info_t *video_info,
const char *msg,
@ -1068,8 +1191,9 @@ static bool gl_frame(void *data, const void *frame,
gl_t *gl = (gl_t*)data;
unsigned width = video_info->width;
unsigned height = video_info->height;
settings_t *settings = config_get_ptr();
if (!gl)
if (!gl || !settings)
return false;
context_bind_hw_render(false);
@ -1244,7 +1368,11 @@ static bool gl_frame(void *data, const void *frame,
#endif
if (!string_is_empty(msg))
{
if (settings->bools.video_msg_bgcolor_enable)
gl_render_osd_background(gl, video_info, msg);
font_driver_render_msg(video_info, NULL, msg, NULL);
}
#ifdef HAVE_OVERLAY
if (gl && gl->overlay_enable)

View File

@ -2,11 +2,15 @@
static const char *stock_fragment_core_blend = GLSL(
uniform sampler2D Texture;
uniform vec4 bgcolor;
in vec2 tex_coord;
in vec4 color;
out vec4 FragColor;
void main() {
FragColor = color * texture(Texture, tex_coord);
if (bgcolor.a > 0.0)
FragColor = bgcolor;
else
FragColor = color * texture(Texture, tex_coord);
}
);

View File

@ -2,9 +2,13 @@
static const char *stock_fragment_modern_blend = GLSL(
uniform sampler2D Texture;
uniform vec4 bgcolor;
varying vec2 tex_coord;
varying vec4 color;
void main() {
gl_FragColor = color * texture2D(Texture, tex_coord);
if (bgcolor.a > 0.0)
gl_FragColor = bgcolor;
else
gl_FragColor = color * texture2D(Texture, tex_coord);
}
);

View File

@ -475,7 +475,7 @@ static void gl_raster_font_render_msg(
else
gl_raster_font_setup_viewport(width, height, font, full_screen);
if (!string_is_empty(msg) && font->gl
if (!string_is_empty(msg) && font->gl
&& font->font_data && font->font_driver)
{
if (drop_x || drop_y)

View File

@ -75,7 +75,7 @@ bool video_coord_array_append(video_coord_array_t *ca,
base_size = count * sizeof(float);
offset = ca->coords.vertices;
/* XXX: I wish we used interlaced arrays so
/* XXX: I wish we used interlaced arrays so
* we could call memcpy only once. */
memcpy(ca->coords.vertex + offset * 2,
coords->vertex, base_size * 2);

View File

@ -3141,3 +3141,13 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_INFORMATION,
"Show Information")
MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_INFORMATION,
"Show/hide the 'Information' option.")
MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_ENABLE,
"OSDメッセージ背景を有効")
MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_RED,
"OSDメッセージ背景の赤色値")
MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_GREEN,
"OSDメッセージ背景の緑色値")
MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_BLUE,
"OSDメッセージ背景の青色値")
MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_OPACITY,
"OSDメッセージ背景の不透明性")

View File

@ -1343,3 +1343,13 @@ MSG_HASH(MENU_ENUM_LABEL_QUICK_MENU_SHOW_SAVE_GAME_OVERRIDES,
"quick_menu_show_save_game_overrides")
MSG_HASH(MENU_ENUM_LABEL_QUICK_MENU_SHOW_INFORMATION,
"quick_menu_show_information")
MSG_HASH(MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_ENABLE,
"video_msg_bgcolor_enable")
MSG_HASH(MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_RED,
"video_msg_bgcolor_red")
MSG_HASH(MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_GREEN,
"video_msg_bgcolor_green")
MSG_HASH(MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_BLUE,
"video_msg_bgcolor_blue")
MSG_HASH(MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_OPACITY,
"video_msg_bgcolor_opacity")

View File

@ -1991,6 +1991,26 @@ int menu_hash_get_help_us_enum(enum msg_hash_enums msg, char *s, size_t len)
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_HIDE_IN_MENU)
);
break;
case MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_ENABLE:
snprintf(s, len,
"Enables a background color for the OSD.");
break;
case MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_RED:
snprintf(s, len,
"Sets the red value of the OSD background color. Valid values are between 0 and 255.");
break;
case MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_GREEN:
snprintf(s, len,
"Sets the green value of the OSD background color. Valid values are between 0 and 255.");
break;
case MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_BLUE:
snprintf(s, len,
"Sets the blue value of the OSD background color. Valid values are between 0 and 255.");
break;
case MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_OPACITY:
snprintf(s, len,
"Sets the opacity of the OSD background color. Valid values are between 0.0 and 1.0.");
break;
default:
if (string_is_empty(s))
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_INFORMATION_AVAILABLE), len);

View File

@ -3227,3 +3227,13 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_SHOW_INFORMATION,
"Show Information")
MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_SHOW_INFORMATION,
"Show/hide the 'Information' option.")
MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_ENABLE,
"Onscreen Notification Background Enable")
MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_RED,
"Onscreen Notification Background Red Color")
MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_GREEN,
"Onscreen Notification Background Green Color")
MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_BLUE,
"Onscreen Notification Background Blue Color")
MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_OPACITY,
"Onscreen Notification Background Opacity")

View File

@ -5258,6 +5258,21 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_VIDEO_MESSAGE_POS_Y,
PARSE_ONLY_FLOAT, false);
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_ENABLE,
PARSE_ONLY_BOOL, false);
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_RED,
PARSE_ONLY_UINT, false);
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_GREEN,
PARSE_ONLY_UINT, false);
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_BLUE,
PARSE_ONLY_UINT, false);
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_OPACITY,
PARSE_ONLY_FLOAT, false);
info->need_refresh = true;
info->need_push = true;

View File

@ -4832,6 +4832,75 @@ static bool setting_append_list(
general_read_handler);
menu_settings_list_current_add_range(list, list_info, 0, 1, 0.01, true, true);
CONFIG_BOOL(
list, list_info,
&settings->bools.video_msg_bgcolor_enable,
MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_ENABLE,
MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_ENABLE,
message_bgcolor_enable,
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
);
CONFIG_UINT(
list, list_info,
&settings->uints.video_msg_bgcolor_red,
MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_RED,
MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_RED,
message_bgcolor_red,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler);
menu_settings_list_current_add_range(list, list_info, 0, 255, 1, true, true);
CONFIG_UINT(
list, list_info,
&settings->uints.video_msg_bgcolor_green,
MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_GREEN,
MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_GREEN,
message_bgcolor_green,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler);
menu_settings_list_current_add_range(list, list_info, 0, 255, 1, true, true);
CONFIG_UINT(
list, list_info,
&settings->uints.video_msg_bgcolor_blue,
MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_BLUE,
MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_BLUE,
message_bgcolor_blue,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler);
menu_settings_list_current_add_range(list, list_info, 0, 255, 1, true, true);
CONFIG_FLOAT(
list, list_info,
&settings->floats.video_msg_bgcolor_opacity,
MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_OPACITY,
MENU_ENUM_LABEL_VALUE_VIDEO_MESSAGE_BGCOLOR_OPACITY,
message_bgcolor_opacity,
"%.2f",
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler);
menu_settings_list_current_add_range(list, list_info, 0, 1, 0.01, true, true);
END_SUB_GROUP(list, list_info, parent_group);
END_GROUP(list, list_info, parent_group);
break;

View File

@ -625,6 +625,11 @@ enum msg_hash_enums
MENU_LABEL(VIDEO_FONT_SIZE),
MENU_LABEL(VIDEO_MESSAGE_POS_X),
MENU_LABEL(VIDEO_MESSAGE_POS_Y),
MENU_LABEL(VIDEO_MESSAGE_BGCOLOR_ENABLE),
MENU_LABEL(VIDEO_MESSAGE_BGCOLOR_RED),
MENU_LABEL(VIDEO_MESSAGE_BGCOLOR_GREEN),
MENU_LABEL(VIDEO_MESSAGE_BGCOLOR_BLUE),
MENU_LABEL(VIDEO_MESSAGE_BGCOLOR_OPACITY),
MENU_LABEL(VIDEO_FILTER_FLICKER),
MENU_LABEL(VIDEO_SOFT_FILTER),
MENU_LABEL(VIDEO_MAX_SWAPCHAIN_IMAGES),

View File

@ -262,6 +262,13 @@
# It is a regular RGB hex number, i.e. red is "ff0000".
# video_message_color = ffffff
# Background color for OSD messages. Red/Green/Blue values are from 0 to 255 and opacity is 0.0 to 1.0.
video_message_bgcolor_enable = false
video_message_bgcolor_red = 0
video_message_bgcolor_green = 0
video_message_bgcolor_blue = 0
video_message_bgcolor_opacity = 1.0
# Video refresh rate of your monitor.
# Used to calculate a suitable audio input rate.
# video_refresh_rate = 59.94