1 #include "lxgui/gui_animated_texture.hpp"
3 #include "lxgui/gui_layered_region.hpp"
4 #include "lxgui/gui_manager.hpp"
5 #include "lxgui/gui_material.hpp"
6 #include "lxgui/gui_out.hpp"
7 #include "lxgui/gui_region_tpl.hpp"
8 #include "lxgui/gui_renderer.hpp"
9 #include "lxgui/utils_file_system.hpp"
23 std::ostringstream str;
25 str << tab <<
" # File : " << file_ <<
"\n";
26 str << tab <<
" # Speed : " << speed_ <<
"\n";
27 str << tab <<
" # State : " << state_ <<
"\n";
28 str << tab <<
" # Paused : " << is_paused_ <<
"\n";
41 quad blended_quad = quad_;
42 for (std::size_t i = 0; i < 4; ++i)
43 blended_quad.
v[i].col.a *= alpha;
54 if (is_paused_ || !quad_.
mat)
57 int num_frames = quad_.
mat->get_rect().width() / quad_.
mat->get_rect().height();
60 std::clamp(
static_cast<int>(std::round(state_ * num_frames - 0.5)), 0, num_frames - 1);
62 state_ += delta * speed_ / num_frames;
63 state_ = std::fmod(state_, 1.0f);
66 std::clamp(
static_cast<int>(std::round(state_ * num_frames - 0.5)), 0, num_frames - 1);
68 if (old_frame != new_frame) {
106 <<
"Vertex index out of bound (" << index <<
")." << std::endl;
110 return quad_.
v[index].col;
122 update_tex_coords_();
137 std::shared_ptr<gui::material> mat;
144 quad_.
v[0].uvs = quad_.
mat->get_canvas_uv(
vector2f(0, 0),
true);
145 quad_.
v[1].uvs = quad_.
mat->get_canvas_uv(
vector2f(1, 0),
true);
146 quad_.
v[2].uvs = quad_.
mat->get_canvas_uv(
vector2f(1, 1),
true);
147 quad_.
v[3].uvs = quad_.
mat->get_canvas_uv(
vector2f(0, 1),
true);
156 <<
"Cannot load file \"" << file_ <<
"\" for \"" <<
name_
157 <<
"\". Using white animated_texture instead." << std::endl;
160 update_tex_coords_();
165 if (index == std::numeric_limits<std::size_t>::max()) {
166 for (std::size_t i = 0; i < 4; ++i)
175 <<
"Vertex index out of bound (" << index <<
")." << std::endl;
179 quad_.
v[index].col = c;
184 void animated_texture::update_tex_coords_() {
188 const int size =
static_cast<int>(quad_.
mat->get_rect().height());
189 const int steps =
static_cast<int>(quad_.
mat->get_rect().width()) / size;
191 int left = size * std::clamp(
static_cast<int>(std::round(state_ * steps - 0.5)), 0, steps - 1);
202 void animated_texture::update_borders_() {
211 const std::vector<std::string>& animated_texture::get_type_list_()
const {
212 return get_type_list_impl_<animated_texture>();
A layered_region that can draw animated sequences.
const std::string & get_texture_file() const
Returns this texture's texture file.
float get_state() const
Returns this animated_texture's state (0: begin, 1: end).
animated_texture(utils::control_block &block, manager &mgr, const region_core_attributes &attr)
Constructor.
std::string serialize(const std::string &tab) const override
Prints all relevant information about this region in a string.
void set_vertex_color(const color &c, std::size_t index=std::numeric_limits< std::size_t >::max())
Sets this texture's vertex color.
void update(float delta) override
Updates this region's logic.
color get_vertex_color(std::size_t index) const
Returns this texture's vertex color.
void set_state(float state)
Returns this animated_texture's state (0: begin, 1: end).
void set_texture(const std::string &file_name)
Sets this texture's texture file.
float get_speed() const
Returns this animated_texture's animation speed (frame per second).
void set_speed(float speed)
Set this animated_texture's animation speed (frame per second).
void set_paused(bool is_paused)
Play or pause this animated_texture.
void copy_from(const region &obj) override
Copies a region's parameters into this texture (inheritance).
float is_paused() const
Check if this animated_texture is paused.
void render() const override
Renders this region on the current render target.
Holds a single color (float RGBA, 128 bits)
A region that can be rendered in a layer.
void notify_renderer_need_redraw() override
Notifies the renderer of this region that it needs to be redrawn.
std::string serialize(const std::string &tab) const override
Prints all relevant information about this region in a string.
Manages the user interface.
const renderer & get_renderer() const
Returns the renderer implementation.
The base class of all elements in the GUI.
virtual void set_width(float abs_width)
Changes this region's absolute width (in pixels).
const std::string & get_region_type() const
Returns the type of this region.
void initialize_(T &self, const region_core_attributes &attr)
Set up function to call in all derived class constructors.
float get_effective_alpha() const
Returns this region's effective alpha (opacity).
bool is_apparent_width_defined() const
Checks if this region's apparent width is defined.
bool is_visible() const
Checks if this region can be seen on the screen.
manager & get_manager()
Returns this region's manager.
virtual void render() const
Renders this region on the current render target.
virtual void set_height(float abs_height)
Changes this region's absolute height (in pixels).
virtual void update(float delta)
Updates this region's logic.
bool is_apparent_height_defined() const
Checks if this region's apparent height is defined.
virtual void copy_from(const region &obj)
Copies a region's parameters into this region (inheritance).
std::string parse_file_name(const std::string &file_name) const
Convert an addon-relative file path to a application-relative path.
virtual void update_borders_()
Abstract type for implementation specific management.
std::shared_ptr< material > create_atlas_material(const std::string &atlas_category, const std::string &file_name, material::filter filt=material::filter::none)
Creates a new material from a texture file.
void render_quad(const quad &q)
Renders a quad.
vector2< float > vector2f
Holds 2D coordinates (as floats)
bool file_exists(const std::string &file)
vector2< T > bottom_left() const noexcept
vector2< T > bottom_right() const noexcept
vector2< T > top_right() const noexcept
vector2< T > top_left() const noexcept
Simple structure holding four vertices and a material.
std::shared_ptr< material > mat
std::array< vertex, 4 > v
Struct holding all the core information about a region necessary for its creation.