lxgui
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
gui_sfml_material.hpp
1 #ifndef LXGUI_GUI_SFML_MATERIAL_HPP
2 #define LXGUI_GUI_SFML_MATERIAL_HPP
3 
4 #include "lxgui/gui_bounds2.hpp"
5 #include "lxgui/gui_color.hpp"
6 #include "lxgui/gui_material.hpp"
7 #include "lxgui/utils.hpp"
8 
9 #include <SFML/Graphics/Image.hpp>
10 #include <SFML/Graphics/RenderTexture.hpp>
11 #include <SFML/Graphics/Texture.hpp>
12 #include <memory>
13 #include <vector>
14 
15 namespace lxgui::gui::sfml {
16 
23 class material final : public gui::material {
24 public:
33  const vector2ui& dimensions,
34  bool is_render_target,
35  wrap wrp = wrap::repeat,
36  filter filt = filter::none);
37 
44  explicit material(const sf::Image& data, wrap wrp = wrap::repeat, filter filt = filter::none);
45 
52  explicit material(
53  const std::string& file_name, wrap wrp = wrap::repeat, filter filt = filter::none);
54 
61  explicit material(
62  const sf::Texture& texture, const bounds2f& location, filter filt = filter::none);
63 
64  material(const material& tex) = delete;
65  material(material&& tex) = delete;
66  material& operator=(const material& tex) = delete;
67  material& operator=(material&& tex) = delete;
68 
73  bounds2f get_rect() const override;
74 
86  vector2ui get_canvas_dimensions() const override;
87 
92  bool uses_same_texture(const gui::material& other) const override;
93 
100  bool set_dimensions(const vector2ui& dimensions);
101 
107  static void premultiply_alpha(sf::Image& data);
108 
113  void set_wrap(wrap wrp);
114 
121  void set_filter(filter filt);
122 
128 
133  void update_texture(const color32* data);
134 
139  sf::RenderTexture* get_render_texture();
140 
145  const sf::Texture* get_texture() const;
146 
147 private:
148  vector2ui dimensions_;
149  vector2ui canvas_dimensions_;
150  bounds2f rect_;
151  wrap wrap_ = wrap::repeat;
152  filter filter_ = filter::none;
153 
154  bool is_render_target_ = false;
155  sf::RenderTexture render_texture_;
156  sf::Texture texture_;
157  const sf::Texture* atlas_texture_ = nullptr;
158 
159  static const std::size_t maximum_size;
160 };
161 
162 } // namespace lxgui::gui::sfml
163 
164 #endif
A class that holds rendering data.
A class that holds rendering data This implementation can contain either a plain color or a real sf::...
static void premultiply_alpha(sf::Image &data)
Premultiplies an image by its alpha component.
material & operator=(material &&tex)=delete
bool set_dimensions(const vector2ui &dimensions)
Resizes this texture.
material(const sf::Texture &texture, const bounds2f &location, filter filt=filter::none)
Constructor for atlas textures.
void set_filter(filter filt)
Sets the filter mode of this texture.
bounds2f get_rect() const override
Returns the pixel rect in pixels of the canvas containing this texture (if any).
bool uses_same_texture(const gui::material &other) const override
Checks if another material is based on the same texture as the current material.
vector2ui get_canvas_dimensions() const override
Returns the physical dimensions (in pixels) of the canvas containing this texture (if any).
material(material &&tex)=delete
void update_texture(const color32 *data)
Updates the texture that is in GPU memory.
material(const vector2ui &dimensions, bool is_render_target, wrap wrp=wrap::repeat, filter filt=filter::none)
Constructor for textures.
filter get_filter() const
Returns the filter mode of this texture.
material(const std::string &file_name, wrap wrp=wrap::repeat, filter filt=filter::none)
Constructor for textures.
material(const material &tex)=delete
sf::RenderTexture * get_render_texture()
Returns the underlying SFML render texture object. return The underlying SFML render texture object.
material(const sf::Image &data, wrap wrp=wrap::repeat, filter filt=filter::none)
Constructor for textures.
void set_wrap(wrap wrp)
Sets the wrap mode of this texture.
const sf::Texture * get_texture() const
Returns the underlying SFML texture object. return The underlying SFML texture object.
material & operator=(const material &tex)=delete
A layered_region that can draw images and colored rectangles.
Definition: gui_texture.hpp:23
Holds a single color (byte RGBA, 32 bits)
Definition: gui_color.hpp:75