overlays/perf: Graph label tune-up

Place graph text on top, split in 2 lines, center it horizontally.
Also if it's wider than the graph, match up graph's width to it.
This commit is contained in:
Nick Renieris 2020-01-24 14:55:03 +02:00 committed by Megamouse
parent 79216917b3
commit 1e69de1205
2 changed files with 23 additions and 13 deletions

View File

@ -1167,6 +1167,7 @@ namespace rsx
void set_count(u32 datapoint_count);
void set_color(color4f color);
void set_guide_interval(f32 guide_interval);
u16 get_height() const;
void record_datapoint(f32 datapoint);
void update();
compiled_resource& get_compiled() override;

View File

@ -146,20 +146,23 @@ namespace rsx
if (m_framerate_graph_enabled)
{
m_fps_graph.update();
m_fps_graph.set_pos(body_left, body_bottom);
m_fps_graph.set_size(graphs_width, fps_graph_h);
}
if (m_frametime_graph_enabled)
{
u16 padding = 0;
m_frametime_graph.update();
u16 y_offset{};
if (m_framerate_graph_enabled)
{
padding = m_fps_graph.h + graphs_padding;
y_offset = m_fps_graph.get_height();
}
m_frametime_graph.set_pos(body_left, body_bottom + padding);
m_frametime_graph.set_pos(body_left, body_bottom + y_offset);
m_frametime_graph.set_size(graphs_width, frametime_graph_h);
}
}
@ -213,7 +216,7 @@ namespace rsx
if (enabled)
{
m_fps_graph.set_title("Framerate");
m_fps_graph.set_title(" Framerate");
m_fps_graph.set_font_size(m_font_size * 0.8);
m_fps_graph.set_count(50);
m_fps_graph.set_color(convert_color_code(m_color_body, m_opacity));
@ -232,7 +235,7 @@ namespace rsx
if (enabled)
{
m_frametime_graph.set_title("Frametime");
m_frametime_graph.set_title(" Frametime");
m_frametime_graph.set_font_size(m_font_size * 0.8);
m_frametime_graph.set_count(170);
m_frametime_graph.set_color(convert_color_code(m_color_body, m_opacity));
@ -545,19 +548,17 @@ namespace rsx
void graph::set_pos(u16 _x, u16 _y)
{
overlay_element::set_pos(_x, _y);
m_label.set_pos(x, y + h);
m_label.set_pos(_x, _y);
overlay_element::set_pos(_x, _y + m_label.h);
}
void graph::set_size(u16 _w, u16 _h)
{
overlay_element::set_size(_w, _h);
set_padding(0, 0, h, 0);
m_label.set_size(w, m_label.h);
m_label.set_pos(x, y + h);
// Place label horizontally in the middle of the graph rect
const u16 label_x = std::max(x, u16(x + (w / 2) - (m_label.w / 2)));
m_label.set_pos(label_x, m_label.y);
}
void graph::set_title(const char* title)
@ -592,6 +593,11 @@ namespace rsx
m_guide_interval = guide_interval;
}
u16 graph::get_height() const
{
return h + m_label.h + m_label.padding_top + m_label.padding_bottom;
}
void graph::record_datapoint(f32 datapoint)
{
// std::dequeue is only faster for large sizes, so just use a std::vector and resize once in while
@ -614,11 +620,14 @@ namespace rsx
void graph::update()
{
m_label.set_text(fmt::format("%s min:%5.2f max:%6.2f", m_title.c_str(), m_min, m_max));
m_label.set_text(fmt::format("%s\nmn:%4.1f mx:%4.1f", m_title.c_str(), m_min, m_max));
m_label.set_padding(4, 4, 0, 4);
m_label.auto_resize();
m_label.refresh();
// If label horizontal end is larger, widen graph width to match it
set_size(std::max(m_label.w, w), h);
}
compiled_resource& graph::get_compiled()