lxgui
Loading...
Searching...
No Matches
gui_sdl_material.hpp
1#ifndef LXGUI_GUI_SDL_MATERIAL_HPP
2#define LXGUI_GUI_SDL_MATERIAL_HPP
3
4#include "lxgui/gui_color.hpp"
5#include "lxgui/gui_material.hpp"
6#include "lxgui/utils.hpp"
7
8#include <memory>
9#include <variant>
10#include <vector>
11
12struct SDL_Renderer;
13struct SDL_Surface;
14struct SDL_Texture;
15
16namespace lxgui::gui::sdl {
17
24class material final : public gui::material {
25public:
35 SDL_Renderer* rdr,
36 const vector2ui& dimensions,
37 bool is_render_target = false,
38 wrap wrp = wrap::repeat,
39 filter filt = filter::none);
40
50 SDL_Renderer* rdr,
51 const std::string& file_name,
52 bool is_pre_multiplied_alpha_supported,
53 wrap wrp = wrap::repeat,
54 filter filt = filter::none);
55
63 material(SDL_Renderer* rdr, SDL_Texture* tex, const bounds2f& rect, filter filt = filter::none);
64
65 material(const material& tex) = delete;
66 material(material&& tex) = delete;
67 material& operator=(const material& tex) = delete;
68 material& operator=(material&& tex) = delete;
69
71 ~material() noexcept override;
72
77 bounds2f get_rect() const override;
78
91
96 bool uses_same_texture(const gui::material& other) const override;
97
104 bool set_dimensions(const vector2ui& dimensions);
105
111 static void premultiply_alpha(SDL_Surface* data);
112
118
123 void set_wrap(wrap wrp);
124
131 void set_filter(filter filt);
132
138
143 wrap get_wrap() const;
144
149 SDL_Texture* get_texture() const;
150
155 SDL_Texture* get_render_texture();
156
161 SDL_Renderer* get_renderer();
162
170 color32* lock_pointer(std::size_t* pitch = nullptr);
171
173 const color32* lock_pointer(std::size_t* pitch = nullptr) const;
174
176 void unlock_pointer() const;
177
178private:
179 SDL_Renderer* renderer_ = nullptr;
180
181 vector2ui dimensions_;
182 vector2ui canvas_dimensions_;
183 bounds2f rect_;
184 wrap wrap_ = wrap::repeat;
185 filter filter_ = filter::none;
186 bool is_render_target_ = false;
187
188 SDL_Texture* texture_ = nullptr;
189 bool is_owner_ = false;
190};
191
192} // namespace lxgui::gui::sdl
193
194#endif
A class that holds rendering data.
A class that holds rendering data This implementation can contain either a plain color or a real SDL_...
static void premultiply_alpha(SDL_Surface *data)
Premultiplies an image by its alpha component.
material(SDL_Renderer *rdr, SDL_Texture *tex, const bounds2f &rect, filter filt=filter::none)
Constructor for atlas textures.
material(const material &tex)=delete
void unlock_pointer() const
Stops modifying the texture data and update the texture in GPU memory.
void set_filter(filter filt)
Sets the filter mode of this texture.
bool uses_same_texture(const gui::material &other) const override
Checks if another material is based on the same texture as the current material.
material(material &&tex)=delete
material(SDL_Renderer *rdr, const std::string &file_name, bool is_pre_multiplied_alpha_supported, wrap wrp=wrap::repeat, filter filt=filter::none)
Constructor for textures.
material & operator=(const material &tex)=delete
filter get_filter() const
Returns the filter mode of this texture.
vector2ui get_canvas_dimensions() const override
Returns the physical dimensions (in pixels) of the canvas containing this texture (if any).
material(SDL_Renderer *rdr, const vector2ui &dimensions, bool is_render_target=false, wrap wrp=wrap::repeat, filter filt=filter::none)
Constructor for textures.
material & operator=(material &&tex)=delete
static int get_premultiplied_alpha_blend_mode()
Returns the SDL blend mode corresponding to pre-multiplied alpha.
color32 * lock_pointer(std::size_t *pitch=nullptr)
Returns a pointer to the texture data, which can be modified.
void set_wrap(wrap wrp)
Sets the wrap mode of this texture.
SDL_Texture * get_texture() const
Returns the underlying SDL texture object. return The underlying SDL texture object.
bounds2f get_rect() const override
Returns the pixel rect in pixels of the canvas containing this texture (if any).
bool set_dimensions(const vector2ui &dimensions)
Resizes this texture.
~material() noexcept override
Destructor.
wrap get_wrap() const
Return the wrap mode of this texture.
SDL_Renderer * get_renderer()
Returns the SDL renderer object that this material was created on. return The SDL renderer object tha...
SDL_Texture * get_render_texture()
Returns the underlying SDL texture object (for render target). return The underlying SDL texture obje...
STL namespace.
Holds a single color (byte RGBA, 32 bits)
Definition gui_color.hpp:76