mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:02:45 +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(); | ||||
|     float scale = (float)inner_rect.height() / (float)m_max; | ||||
| 
 | ||||
|     Point prev_point; | ||||
|     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) | ||||
|             break; | ||||
|         float scaled_value = (float)m_values.at(m_values.size() - i) * scale; | ||||
|         painter.draw_line({ x, inner_rect.bottom() }, { x, inner_rect.bottom() - (int)scaled_value }, m_graph_color); | ||||
|         float scaled_value = (float)m_values.at(m_values.size() - i - 1) * scale; | ||||
|         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) { | ||||
|  |  | |||
|  | @ -54,7 +54,6 @@ int main(int argc, char** argv) | |||
|     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->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_preferred_size({ 0, 120 }); | ||||
|     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); | ||||
|     }; | ||||
| 
 | ||||
|     tabwidget->add_widget("Graphs", graphs_container); | ||||
| 
 | ||||
|     widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); | ||||
| 
 | ||||
|     auto* toolbar = new GToolBar(widget); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling