30 #include <glm/vec2.hpp>
32 #include "eng3d/ui/widget.hpp"
33 #include "eng3d/ui/ui.hpp"
34 #include "eng3d/ui/chart.hpp"
35 #include "eng3d/texture.hpp"
36 #include "eng3d/rectangle.hpp"
37 #include "eng3d/state.hpp"
43 this->
current_texture = s.tex_man.load(s.package_man.get_unique(
"gfx/top_win_chart.png"));
47 this->data = new_data;
48 this->min = this->max = glm::epsilon<float>();
49 if(!this->data.empty())
51 const auto [it1, it2] = std::minmax_element(this->data.cbegin(), this->data.cend());
58 ctx.
obj_shader->set_uniform(
"diffuse_color", glm::vec4(1.f));
59 if(current_texture !=
nullptr)
60 draw_rectangle(0, 0, width, height, viewport, current_texture.get());
62 if(text_texture.get() !=
nullptr) {
63 ctx.
obj_shader->set_uniform(
"diffuse_color", glm::vec4(text_color.r, text_color.g, text_color.b, 1.f));
64 draw_rectangle(4, 2, text_texture->width, text_texture->height, viewport, text_texture.get());
67 ctx.
obj_shader->set_uniform(
"diffuse_color", glm::vec4(1.f, 0.f, 0.f, 1.f));
72 mesh.buffer.resize(this->data.size());
74 const glm::vec2 scaling{ (1.f / (this->data.size() - 1)) * this->width, (1.f / this->max) * this->height };
75 for(
size_t i = 0; i < this->data.size(); i++)
77 const auto& slice = this->data[i];
78 auto slice_pos = glm::vec2{ i, slice } * scaling;
79 slice_pos.y = this->height - slice_pos.y;
static State & get_instance()
Chart(int x, int y, unsigned w, unsigned h, Widget *_parent=nullptr)
virtual void on_render(Context &ctx, Eng3D::Rect viewport) override
void set_data(std::vector< float > data)
The UI context that handles all the ui widgets.
std::unique_ptr< Eng3D::OpenGL::Program > obj_shader
WidgetType
The type of the widget, some widgets share types between them to keep simplicity.
Packed model - packs both vertices and texcoords into the same buffer.