lxgui
gui_texture.hpp
1 #ifndef LXGUI_GUI_TEXTURE_HPP
2 #define LXGUI_GUI_TEXTURE_HPP
3 
4 #include "lxgui/gui_gradient.hpp"
5 #include "lxgui/gui_layered_region.hpp"
6 #include "lxgui/gui_quad.hpp"
7 #include "lxgui/lxgui.hpp"
8 #include "lxgui/utils.hpp"
9 
10 #include <limits>
11 #include <variant>
12 
13 namespace lxgui::gui {
14 
15 class renderer;
16 class render_target;
17 
23 class texture : public layered_region {
24 public:
26 
27  enum class blend_mode { none, blend, key, add, mod };
28 
30  explicit texture(utils::control_block& block, manager& mgr, const region_core_attributes& attr);
31 
37  std::string serialize(const std::string& tab) const override;
38 
40  void render() const override;
41 
46  void copy_from(const region& obj) override;
47 
52  blend_mode get_blend_mode() const;
53 
59 
64  bool has_solid_color() const;
65 
70  const color& get_solid_color() const;
71 
76  bool has_gradient() const;
77 
82  const gradient& get_gradient() const;
83 
92  std::array<float, 8> get_tex_coord() const;
93 
98  bool get_texture_stretching() const;
99 
104  bool has_texture_file() const;
105 
110  const std::string& get_texture_file() const;
111 
119  color get_vertex_color(std::size_t index) const;
120 
127  bool is_desaturated() const;
128 
133  void set_blend_mode(blend_mode mode);
134 
140 
145  void set_desaturated(bool is_desaturated);
146 
152  void set_gradient(const gradient& g);
153 
163  void set_tex_rect(const std::array<float, 4>& texture_rect);
164 
174  void set_tex_coord(const std::array<float, 8>& texture_coords);
175 
180  void set_texture_stretching(bool texture_stretching);
181 
189  void set_texture(const std::string& file_name);
190 
197  void set_texture(std::shared_ptr<render_target> target);
198 
205  void set_solid_color(const color& c);
206 
213  void set_quad(const quad& q);
214 
223  void
224  set_vertex_color(const color& c, std::size_t index = std::numeric_limits<std::size_t>::max());
225 
230  void parse_layout(const layout_node& node) override;
231 
233  static void register_on_lua(sol::state& lua);
234 
235  static constexpr const char* class_name = "Texture";
236 
237 private:
238  void parse_attributes_(const layout_node& node) override;
239  void parse_tex_coords_node_(const layout_node& node);
240  void parse_gradient_node_(const layout_node& node);
241 
242  const std::vector<std::string>& get_type_list_() const override;
243 
244  void update_dimensions_from_tex_coord_();
245  void update_borders_() override;
246 
247  using content = std::variant<color, std::string, gradient>;
248  content content_ = color::white;
249 
250  blend_mode blend_mode_ = blend_mode::blend;
252  bool is_desaturated_ = false;
253  bool is_texture_stretching_enabled_ = true;
254 
255  renderer& renderer_;
256  quad quad_;
257 };
258 
259 } // namespace lxgui::gui
260 
261 #endif
Holds a single color (float RGBA, 128 bits)
Definition: gui_color.hpp:12
static const color white
Definition: gui_color.hpp:43
A region that can be rendered in a layer.
layered_region(utils::control_block &block, manager &mgr, const region_core_attributes &attr)
Constructor.
An node in a layout file.
Manages the user interface.
Definition: gui_manager.hpp:44
The base class of all elements in the GUI.
Definition: gui_region.hpp:161
Abstract type for implementation specific management.
A layered_region that can draw images and colored rectangles.
Definition: gui_texture.hpp:23
bool get_texture_stretching() const
Checks if this texture can stretch to match the region dimensions.
std::string serialize(const std::string &tab) const override
Prints all relevant information about this region in a string.
Definition: gui_texture.cpp:22
void set_gradient(const gradient &g)
Adds a gradient effect to this texture.
void set_blend_mode(blend_mode mode)
Sets this texture's blending mode.
void copy_from(const region &obj) override
Copies a region's parameters into this texture (inheritance).
Definition: gui_texture.cpp:79
void set_tex_rect(const std::array< float, 4 > &texture_rect)
Sets this texture's texture coordinates.
static constexpr const char * class_name
const gradient & get_gradient() const
Returns this texture's gradient.
material::filter get_filter_mode() const
Returns this texture's filtering algorithm.
void set_solid_color(const color &c)
Sets this texture's color.
const color & get_solid_color() const
Returns this texture's color.
void set_desaturated(bool is_desaturated)
Makes this texture appear without any color.
void set_tex_coord(const std::array< float, 8 > &texture_coords)
Sets this texture's texture coordinates.
void set_texture_stretching(bool texture_stretching)
Sets whether this texture can stretch to match the region dimensions.
texture(utils::control_block &block, manager &mgr, const region_core_attributes &attr)
Constructor.
Definition: gui_texture.cpp:16
bool has_solid_color() const
Checks if this texture is defined as solid color.
color get_vertex_color(std::size_t index) const
Returns this texture's vertex color.
void set_filter_mode(material::filter filt)
Sets this texture's filtering mode.
blend_mode get_blend_mode() const
Returns this texture's blending mode.
Definition: gui_texture.cpp:99
const std::string & get_texture_file() const
Returns this texture's texture file.
void set_quad(const quad &q)
Directly sets this texture's underlying quad (vertices and material).
static void register_on_lua(sol::state &lua)
Registers this region class to the provided Lua state.
bool is_desaturated() const
Checks if this texture is desaturated.
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 parse_layout(const layout_node &node) override
Parses data from a layout_node.
std::array< float, 8 > get_tex_coord() const
Returns this texture's texture coordinates.
bool has_texture_file() const
Checks if this texture is defined as a texture file.
void render() const override
Renders this region on the current render target.
Definition: gui_texture.cpp:60
bool has_gradient() const
Checks if this texture is defined as a gradient.
void set_texture(const std::string &file_name)
Sets this texture's texture file.
blend_mode
Specifies the rendering mode of a quad.
Definition: gui_quad.hpp:15
Represents color gradients.
Simple structure holding four vertices and a material.
Definition: gui_quad.hpp:18
Struct holding all the core information about a region necessary for its creation.