30 #include <glm/vec2.hpp>
32 #include "eng3d/ui/widget.hpp"
33 #include "eng3d/ui/ui.hpp"
34 #include "eng3d/ui/candle.hpp"
35 #include "eng3d/texture.hpp"
36 #include "eng3d/rectangle.hpp"
37 #include "eng3d/primitive.hpp"
38 #include "eng3d/state.hpp"
44 this->
current_texture = s.tex_man.load(s.package_man.get_unique(
"gfx/top_win_chart.png"));
48 this->data = new_data;
49 this->min = this->max = glm::epsilon<float>();
50 if(!this->data.empty())
52 for(
const auto& candle : this->data)
54 this->max = glm::max(this->max, candle.max);
55 this->min = glm::min(this->min, candle.min);
61 ctx.
obj_shader->set_uniform(
"diffuse_color", glm::vec4(1.f));
62 if(current_texture !=
nullptr)
63 draw_rectangle(0, 0, width, height, viewport, current_texture.get());
65 if(text_texture.get() !=
nullptr) {
66 ctx.
obj_shader->set_uniform(
"diffuse_color", glm::vec4(text_color.r, text_color.g, text_color.b, 1.f));
67 draw_rectangle(4, 2, text_texture->width, text_texture->height, viewport, text_texture.get());
72 const glm::vec2 scaling{ (1.f / this->data.size()) * this->width, (1.f / this->max) * this->height };
73 for(
size_t i = 0; i < this->data.size(); i++)
75 const auto& slice = this->data[i];
76 auto start = glm::vec2{ i, slice.open } * scaling;
77 start.y = this->height - start.y;
78 auto end = glm::vec2{ i + 1.f, slice.close } * scaling;
79 end.y = this->height - end.y;
82 const auto center = start + ((end - start) / 2.f);
86 ctx.
obj_shader->set_uniform(
"diffuse_color", glm::vec4(0.75f * (slice.close <= slice.open), 0.75f * (slice.close >= slice.open), 0.25f, 1.f));
90 line_mesh.buffer.resize(2);
91 line_mesh.buffer[0] =
Eng3D::MeshData(glm::vec2{ center.x, this->height - slice.max * scaling.y }, glm::vec2{});
92 line_mesh.buffer[1] =
Eng3D::MeshData(glm::vec2{ center.x, this->height - slice.min * scaling.y }, glm::vec2{});
98 candle_mesh.buffer.resize(4);
99 candle_mesh.buffer[0] =
Eng3D::MeshData(glm::vec2{ start.x, start.y }, glm::vec2{});
100 candle_mesh.buffer[1] =
Eng3D::MeshData(glm::vec2{ start.x, end.y }, glm::vec2{});
101 candle_mesh.buffer[2] =
Eng3D::MeshData(glm::vec2{ end.x, start.y }, glm::vec2{});
102 candle_mesh.buffer[3] =
Eng3D::MeshData(glm::vec2{ end.x, end.y }, glm::vec2{});
103 candle_mesh.upload();
static State & get_instance()
void set_data(std::vector< UI::CandleData > data)
CandleChart(int x, int y, unsigned w, unsigned h, Widget *_parent=nullptr)
virtual void on_render(Context &ctx, Eng3D::Rect viewport) override
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.