opuntiaOS - an operating system targeting x86 and ARMv7
at master 40 lines 1.1 kB view raw
1#include "GraphView.h" 2#include <algorithm> 3#include <iostream> 4#include <libfoundation/EventLoop.h> 5#include <libfoundation/KeyboardMapping.h> 6#include <libg/Color.h> 7#include <libui/Context.h> 8 9GraphView::GraphView(UI::View* superview, const LG::Rect& frame, int data_size) 10 : UI::View(superview, frame) 11 , m_data(data_size) 12{ 13 for (int i = 0; i < data_size; i++) { 14 m_data.push_back(0); 15 } 16} 17 18void GraphView::display(const LG::Rect& rect) 19{ 20 LG::Context ctx = UI::graphics_current_context(); 21 ctx.add_clip(rect); 22 23 ctx.set_fill_color(LG::Color(233, 233, 233)); 24 ctx.fill(bounds()); 25 26 ctx.set_fill_color(LG::Color::LightSystemBlue); 27 28 size_t left_padding = bounds().width(); 29 size_t height = bounds().height(); 30 size_t column_width = 3; 31 32 for (int i = m_data.size() - 1; i >= 0; i--) { 33 left_padding -= column_width; 34 size_t column_height = (m_data[i] * height) / 100; 35 ctx.fill(LG::Rect(left_padding, height - column_height, column_width, column_height)); 36 if (left_padding < column_width) { 37 break; 38 } 39 } 40}