mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 17:25:07 +00:00
ProcessManager: Draw the graphs as lines.
This looks pretty neat. Also it exercises the diagonal line drawing code so we get 2-for-1. :^)
This commit is contained in:
parent
5b2e122624
commit
1598a0a5cb
2 changed files with 9 additions and 4 deletions
|
@ -30,12 +30,16 @@ void GraphWidget::paint_event(GPaintEvent& event)
|
||||||
auto inner_rect = frame_inner_rect();
|
auto inner_rect = frame_inner_rect();
|
||||||
float scale = (float)inner_rect.height() / (float)m_max;
|
float scale = (float)inner_rect.height() / (float)m_max;
|
||||||
|
|
||||||
|
Point prev_point;
|
||||||
for (int i = 0; i < m_values.size(); ++i) {
|
for (int i = 0; i < m_values.size(); ++i) {
|
||||||
int x = inner_rect.right() - i + 1;
|
int x = inner_rect.right() - (i * 2) + 1;
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
break;
|
break;
|
||||||
float scaled_value = (float)m_values.at(m_values.size() - i) * scale;
|
float scaled_value = (float)m_values.at(m_values.size() - i - 1) * scale;
|
||||||
painter.draw_line({ x, inner_rect.bottom() }, { x, inner_rect.bottom() - (int)scaled_value }, m_graph_color);
|
Point point = { x, inner_rect.bottom() - (int)scaled_value };
|
||||||
|
if (i != 0)
|
||||||
|
painter.draw_line(prev_point, point, m_graph_color);
|
||||||
|
prev_point = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_values.is_empty() && text_formatter) {
|
if (!m_values.is_empty() && text_formatter) {
|
||||||
|
|
|
@ -54,7 +54,6 @@ int main(int argc, char** argv)
|
||||||
auto* memory_graph_group_box = new GGroupBox("Memory usage", graphs_container);
|
auto* memory_graph_group_box = new GGroupBox("Memory usage", graphs_container);
|
||||||
memory_graph_group_box->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
memory_graph_group_box->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||||
memory_graph_group_box->layout()->set_margins({ 6, 16, 6, 6 });
|
memory_graph_group_box->layout()->set_margins({ 6, 16, 6, 6 });
|
||||||
tabwidget->add_widget("Graphs", graphs_container);
|
|
||||||
memory_graph_group_box->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
memory_graph_group_box->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||||
memory_graph_group_box->set_preferred_size({ 0, 120 });
|
memory_graph_group_box->set_preferred_size({ 0, 120 });
|
||||||
auto* memory_graph = new GraphWidget(memory_graph_group_box);
|
auto* memory_graph = new GraphWidget(memory_graph_group_box);
|
||||||
|
@ -64,6 +63,8 @@ int main(int argc, char** argv)
|
||||||
return String::format("%d / %d KB", value, max);
|
return String::format("%d / %d KB", value, max);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tabwidget->add_widget("Graphs", graphs_container);
|
||||||
|
|
||||||
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||||
|
|
||||||
auto* toolbar = new GToolBar(widget);
|
auto* toolbar = new GToolBar(widget);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue