31 #include <glm/vec2.hpp>
32 #include <glm/gtc/integer.hpp>
34 #include "eng3d/ui/widget.hpp"
35 #include "eng3d/ui/ui.hpp"
36 #include "eng3d/ui/waffle.hpp"
37 #include "eng3d/texture.hpp"
38 #include "eng3d/rectangle.hpp"
39 #include "eng3d/state.hpp"
48 this->data = new_data;
49 this->max = std::accumulate(this->data.begin(), this->data.end(), 0.f, [](
const auto a,
const auto& e) {
52 this->cols = this->width / 8.f;
53 this->rows = this->height / 8.f;
57 ctx.
obj_shader->set_uniform(
"diffuse_color", glm::vec4(1.f));
58 if(current_texture !=
nullptr)
59 draw_rectangle(0, 0, width, height, viewport, current_texture.get());
61 if(text_texture.get() !=
nullptr) {
62 ctx.
obj_shader->set_uniform(
"diffuse_color", glm::vec4(text_color.r, text_color.g, text_color.b, 1.f));
63 draw_rectangle(4, 2, text_texture->width, text_texture->height, viewport, text_texture.get());
69 const glm::vec2 scaling{ (1.f / this->cols) * this->width, (1.f / this->rows) * this->height };
70 const glm::vec2 square_size{ this->width / this->cols, this->height / this->rows };
71 const glm::vec2 aspect_ratio{ this->width / this->height, this->height / this->width };
73 size_t total_squares = this->cols * this->rows, rem_squares = 0;
74 auto it = this->data.cbegin();
75 for(
size_t sy = 0; sy < this->rows; sy++) {
76 for(
size_t sx = 0; sx < this->cols; sx++) {
77 if(!rem_squares && it != this->data.cend()) {
78 const auto& slice = *it++;
79 ctx.
obj_shader->set_uniform(
"diffuse_color", glm::vec4(slice.color.r, slice.color.g, slice.color.b, 1.f));
80 rem_squares = (slice.num / this->max) * total_squares;
83 const auto w = 0.8f, h = 0.8f;
85 mesh.buffer.resize(4);
86 mesh.buffer[0] =
Eng3D::MeshData(glm::vec2{ sx, sy + h } * scaling, glm::vec2(0.f));
87 mesh.buffer[1] =
Eng3D::MeshData(glm::vec2{ sx, sy } * scaling, glm::vec2(0.f));
88 mesh.buffer[2] =
Eng3D::MeshData(glm::vec2{ sx + w, sy + h } * scaling, glm::vec2(0.f));
89 mesh.buffer[3] =
Eng3D::MeshData(glm::vec2{ sx + w, sy } * scaling, glm::vec2(0.f));
static State & get_instance()
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.
void set_data(std::vector< UI::ChartData > data)
virtual void on_render(Context &ctx, Eng3D::Rect viewport) override
WaffleChart(int x, int y, unsigned w, unsigned h, Widget *_parent=nullptr)