1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2025-01-31 12:31:45 +01:00

RSX: Add performance overlay colors to configs

use a string hex color code. Allowed string formats are:
#FFFFFF or #FFFFFFFF (or both without #)
This commit is contained in:
Megamouse 2018-07-21 23:07:47 +02:00
parent 2211e95e41
commit f82739afb0
3 changed files with 40 additions and 14 deletions

View File

@ -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)

View File

@ -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();

View File

@ -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};