lxgui
Loading...
Searching...
No Matches
gui_material.cpp
1#include "lxgui/gui_material.hpp"
2
3namespace lxgui::gui {
4
5material::material(bool is_atlas) : is_atlas_(is_atlas) {}
6
7vector2f material::get_canvas_uv(const vector2f& texture_uv, bool from_normalized) const {
8 const bounds2f quad = get_rect();
9
10 vector2f pixel_uv = texture_uv;
11 if (from_normalized)
12 pixel_uv *= quad.dimensions();
13
14 pixel_uv += quad.top_left();
15 pixel_uv /= vector2f(get_canvas_dimensions());
16
17 return pixel_uv;
18}
19
20vector2f material::get_local_uv(const vector2f& canvas_uv, bool as_normalized) const {
21 const bounds2f quad = get_rect();
22
23 vector2f pixel_uv = canvas_uv;
24 pixel_uv *= vector2f(get_canvas_dimensions());
25 pixel_uv -= quad.top_left();
26
27 if (as_normalized)
28 pixel_uv /= quad.dimensions();
29
30 return pixel_uv;
31}
32
34 return is_atlas_;
35}
36
37} // namespace lxgui::gui
material(bool is_atlas)
Constructor.
vector2f get_local_uv(const vector2f &canvas_uv, bool as_normalized) const
Returns local UV coordinates on the texture, given canvas UV coordinates.
virtual bounds2f get_rect() const =0
Returns the pixel rect in pixels of the canvas containing this texture (if any).
vector2f get_canvas_uv(const vector2f &texture_uv, bool from_normalized) const
Returns normalized UV coordinates on the canvas, given local UV coordinates.
bool is_in_atlas() const
Checks if the material is embedded in an atlas.
virtual vector2ui get_canvas_dimensions() const =0
Returns the physical dimensions (in pixels) of the canvas containing this texture (if any).
vector2< float > vector2f
Holds 2D coordinates (as floats)
Simple structure holding four vertices and a material.
Definition gui_quad.hpp:18