From f82739afb02883f05affb75cd80d8fbd577736eb Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 21 Jul 2018 23:07:47 +0200 Subject: [PATCH] RSX: Add performance overlay colors to configs use a string hex color code. Allowed string formats are: #FFFFFF or #FFFFFFFF (or both without #) --- .../Emu/RSX/Overlays/overlay_perf_metrics.cpp | 45 +++++++++++++++---- rpcs3/Emu/RSX/Overlays/overlays.h | 5 --- rpcs3/Emu/System.h | 4 ++ 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp b/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp index cdce9a0caa..12e9e7f5e3 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp @@ -11,6 +11,38 @@ namespace rsx { namespace overlays { + inline color4f convert_color_code(std::string hex_color, f32 opacity = 1.0f) + { + if (hex_color.length() > 0 && hex_color[0] == '#') + { + hex_color.erase(0, 1); + } + + unsigned long hexval; + const int len = hex_color.length(); + + try + { + if (len != 6 && len != 8) + { + fmt::throw_exception("wrong length: %d", len); + } + hexval = std::stoul(hex_color, nullptr, 16); + } + catch (const std::exception& e) + { + LOG_ERROR(RSX, "Overlays: tried to convert incompatible color code: '%s' exception: '%s'", hex_color, e.what()); + return color4f(0.0f, 0.0f, 0.0f, 0.0f); + } + + const int r = (len == 8 ? (hexval >> 24) : (hexval >> 16)) & 0xff; + const int g = (len == 8 ? (hexval >> 16) : (hexval >> 8)) & 0xff; + const int b = (len == 8 ? (hexval >> 8) : (hexval >> 0)) & 0xff; + const int a = len == 8 ? ((hexval >> 0) & 0xff) : 255; + + return color4f(r / 255.f, g / 255.f, b / 255.f, a / 255.f * opacity); + } + void perf_metrics_overlay::reset_transform(label& elm) const { const u32 text_padding = m_font_size / 2; @@ -65,22 +97,17 @@ namespace rsx void perf_metrics_overlay::reset_body() { - const float text_opacity = get_text_opacity(); - const float bg_opacity = m_opacity; - m_body.set_font(m_font.c_str(), m_font_size); - m_body.fore_color = {0xFF / 255.f, 0xE1 / 255.f, 0x38 / 255.f, text_opacity}; - m_body.back_color = {0x00 / 255.f, 0x23 / 255.f, 0x39 / 255.f, bg_opacity}; + m_body.fore_color = convert_color_code(g_cfg.video.perf_overlay.color_body, m_opacity); + m_body.back_color = convert_color_code(g_cfg.video.perf_overlay.background_body, m_opacity); reset_transform(m_body); } void perf_metrics_overlay::reset_titles() { - const float text_opacity = get_text_opacity(); - m_titles.set_font(m_font.c_str(), m_font_size); - m_titles.fore_color = {0xF2 / 256.0, 0x6C / 256.0, 0x24 / 256.0, text_opacity}; - m_titles.back_color = {0.0f, 0.0f, 0.0f, 0.0f}; + m_titles.fore_color = convert_color_code(g_cfg.video.perf_overlay.color_title, m_opacity); + m_titles.back_color = convert_color_code(g_cfg.video.perf_overlay.background_title, m_opacity); reset_transform(m_titles); switch (m_detail) diff --git a/rpcs3/Emu/RSX/Overlays/overlays.h b/rpcs3/Emu/RSX/Overlays/overlays.h index cf80e16af1..5389b03229 100644 --- a/rpcs3/Emu/RSX/Overlays/overlays.h +++ b/rpcs3/Emu/RSX/Overlays/overlays.h @@ -449,11 +449,6 @@ namespace rsx void reset_titles(); void reset_text(); - f32 get_text_opacity() const - { - return std::clamp(m_opacity + 0.3f, 0.3f, 1.0f); - } - public: void init(); diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index ab0f3d70b3..e9ecb108a0 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -461,6 +461,10 @@ struct cfg_root : cfg::node cfg::_bool center_x{ this, "Center Horizontally", false }; cfg::_bool center_y{ this, "Center Vertically", false }; cfg::_int<0, 100> opacity{this, "Opacity (%)", 70}; + cfg::string color_body{ this, "Body Color (hex)", "#FFE138FF" }; + cfg::string background_body{ this, "Body Background (hex)", "#002339FF" }; + cfg::string color_title{ this, "Title Color (hex)", "#F26C24FF" }; + cfg::string background_title{ this, "Title Background (hex)", "#00000000" }; } perf_overlay{this};