Wrapper class to encapsulate creation and management of an SDL_Texture. More...
#include <texture.hpp>
Classes | |
struct | info |
Small wrapper that queries metadata about the provided texture. More... | |
Public Member Functions | |
texture ()=default | |
Default ctor. More... | |
texture (SDL_Texture *txt) | |
Assigns the given texture to this one. More... | |
texture (const surface &surf, bool linear_interpolation=false) | |
Construct a texture from a surface. More... | |
texture (int w, int h, SDL_TextureAccess access) | |
Construct a texture of the specified size and access type. More... | |
const info | get_info () const |
Queries metadata about the texture, such as its dimensions. More... | |
uint32_t | get_format () const |
The internal texture format. More... | |
int | get_access () const |
The texture access mode. More... | |
point | get_raw_size () const |
The raw internal texture size. More... | |
int | w () const |
The draw-space width of the texture, in pixels. More... | |
int | h () const |
The draw-space height of the texture, in pixels. More... | |
point | draw_size () const |
The size of the texture in draw-space. More... | |
void | set_draw_width (int w) |
Set the intended width of the texture, in draw-space. More... | |
void | set_draw_height (int h) |
Set the intended height of the texture, in draw-space. More... | |
void | set_draw_size (int w, int h) |
Set the intended size of the texture, in draw-space. More... | |
void | set_draw_size (const point &p) |
const rect * | src () const |
A pointer to a rect indicating the source region of the underlying SDL_Texture to be used when drawing. More... | |
void | set_src (const rect &r) |
Set the source region of the texture used for drawing operations. More... | |
void | set_src_raw (const rect &r) |
Set the source region of the texture used for drawing operations. More... | |
void | clear_src () |
Clear the source region. More... | |
void | set_alpha_mod (uint8_t alpha) |
Alpha modifier. More... | |
uint8_t | get_alpha_mod () const |
void | set_blend_mode (SDL_BlendMode) |
Blend mode. More... | |
SDL_BlendMode | get_blend_mode () const |
void | set_color_mod (uint8_t r, uint8_t g, uint8_t b) |
Colour modifier. More... | |
void | set_color_mod (color_t) |
color_t | get_color_mod () const |
void | reset () |
Releases ownership of the managed texture and resets the ptr to null. More... | |
void | reset (int width, int height, SDL_TextureAccess access) |
Releases ownership of the managed texture and creates a new one. More... | |
void | assign (SDL_Texture *t) |
Replaces ownership of the managed texture with the given one. More... | |
SDL_Texture * | get () const |
bool | operator== (const texture &t) const |
Texture comparisons explicitly only care about the pointer value. More... | |
operator SDL_Texture * () const | |
operator bool () const | |
Private Member Functions | |
void | finalize () |
Private Attributes | |
std::shared_ptr< SDL_Texture > | texture_ = nullptr |
int | w_ = 0 |
int | h_ = 0 |
bool | has_src_ = false |
true iff the source rect is valid More... | |
rect | src_ |
uninitialized by default. More... | |
Wrapper class to encapsulate creation and management of an SDL_Texture.
Supports free creation and creation from a surface.
Definition at line 32 of file texture.hpp.
|
default |
Default ctor.
Texture will be a nullptr.
|
explicit |
Assigns the given texture to this one.
Definition at line 40 of file texture.cpp.
References finalize(), h_, and w_.
|
explicit |
Construct a texture from a surface.
surf | The surface to copy. |
linear_interpolation | If true this texture will use linear interpolation when drawing. Otherwise nearest-neighbour interpolation is used. This does not affect texture creation, only later application. |
Definition at line 49 of file texture.cpp.
References ERR_SDL, finalize(), video::get_renderer(), h_, renderer(), surf, texture_, and w_.
texture::texture | ( | int | w, |
int | h, | ||
SDL_TextureAccess | access | ||
) |
Construct a texture of the specified size and access type.
Definition at line 79 of file texture.cpp.
References reset().
void texture::assign | ( | SDL_Texture * | t | ) |
|
inline |
Clear the source region.
Definition at line 167 of file texture.hpp.
References has_src_.
Referenced by gui::textbox::draw_contents(), display::expose(), and display::scroll().
|
inline |
The size of the texture in draw-space.
This may differ from the raw texture size. To get that in stead, use get_info() or get_raw_size().
Definition at line 122 of file texture.hpp.
Referenced by gui2::canvas::draw(), video::read_pixels(), set_src(), and display::update_render_textures().
|
private |
Definition at line 85 of file texture.cpp.
References set_blend_mode().
|
inline |
Definition at line 196 of file texture.hpp.
References texture_.
Referenced by operator==(), and video::read_pixels().
int texture::get_access | ( | ) | const |
The texture access mode.
Equivalent to get_info().access.
Definition at line 101 of file texture.cpp.
References texture_.
uint8_t texture::get_alpha_mod | ( | ) | const |
Definition at line 158 of file texture.cpp.
References texture_.
SDL_BlendMode texture::get_blend_mode | ( | ) | const |
Definition at line 198 of file texture.cpp.
color_t texture::get_color_mod | ( | ) | const |
Definition at line 181 of file texture.cpp.
uint32_t texture::get_format | ( | ) | const |
The internal texture format.
Equivalent to get_info().format.
Definition at line 90 of file texture.cpp.
References texture_.
|
inline |
Queries metadata about the texture, such as its dimensions.
Definition at line 78 of file texture.hpp.
References lg::info().
point texture::get_raw_size | ( | ) | const |
The raw internal texture size.
Equivalent to point{get_info().w, get_info().h}
Definition at line 112 of file texture.cpp.
References texture_.
Referenced by image::prep_minimap_for_rendering(), video::read_pixels(), set_src(), set_src_raw(), draw::tiled_highres(), and display::update_render_textures().
|
inline |
The draw-space height of the texture, in pixels.
This will usually be the real texture height in pixels, but may differ in some situations. For high-DPI text, for example, it will usually be equal to get_info().h / pixel_scale.
Definition at line 114 of file texture.hpp.
References h_.
Referenced by gui::button::calculate_size(), gui2::image_shape::draw(), gui2::text_shape::draw(), gui::button::draw_contents(), gui::scrollbar::draw_contents(), gui::textbox::draw_contents(), font::floating_label::get_draw_size(), gui::button::load_images(), set_draw_height(), set_draw_size(), draw::tiled(), gui::tristate_button::tristate_button(), font::floating_label::update(), and gui::textbox::update_text_cache().
|
inlineexplicit |
Definition at line 206 of file texture.hpp.
References texture_.
|
inline |
Definition at line 201 of file texture.hpp.
References texture_.
|
inline |
Texture comparisons explicitly only care about the pointer value.
Definition at line 199 of file texture.hpp.
void texture::reset | ( | ) |
Releases ownership of the managed texture and resets the ptr to null.
Definition at line 208 of file texture.cpp.
References h_, has_src_, texture_, and w_.
Referenced by editor::editor_display::clear_mouseover_hex_overlay(), font::floating_label::clear_texture(), display::fade_tod_mask(), gui::textbox::handle_event(), gui::button::load_images(), gui2::canvas::queue_reblur(), reset(), texture(), and gui2::canvas::update_blur().
void texture::reset | ( | int | width, |
int | height, | ||
SDL_TextureAccess | access | ||
) |
Releases ownership of the managed texture and creates a new one.
Definition at line 217 of file texture.cpp.
References ERR_SDL, finalize(), video::get_renderer(), h_, has_src_, renderer(), reset(), texture_, and w_.
void texture::set_alpha_mod | ( | uint8_t | alpha | ) |
Alpha modifier.
Multiplies alpha when drawing.
Definition at line 151 of file texture.cpp.
References texture_.
Referenced by font::floating_label::draw(), gui::textbox::draw_contents(), display::draw_hex(), and editor::editor_display::draw_hex().
void texture::set_blend_mode | ( | SDL_BlendMode | b | ) |
Blend mode.
Modifies how draw operations are applied.
Definition at line 191 of file texture.cpp.
Referenced by finalize().
void texture::set_color_mod | ( | color_t | c | ) |
Definition at line 168 of file texture.cpp.
void texture::set_color_mod | ( | uint8_t | r, |
uint8_t | g, | ||
uint8_t | b | ||
) |
Colour modifier.
Multiplies each colour component when drawing.
Definition at line 174 of file texture.cpp.
|
inline |
Set the intended height of the texture, in draw-space.
Definition at line 128 of file texture.hpp.
void texture::set_draw_size | ( | const point & | p | ) |
Definition at line 123 of file texture.cpp.
|
inline |
Set the intended size of the texture, in draw-space.
Definition at line 131 of file texture.hpp.
References h(), h_, w(), and w_.
Referenced by display::update_render_textures(), and font::pango_text::with_draw_scale().
|
inline |
Set the intended width of the texture, in draw-space.
Definition at line 125 of file texture.hpp.
void texture::set_src | ( | const rect & | r | ) |
Set the source region of the texture used for drawing operations.
This function operates in draw-space, and will be clipped to {0, 0, w(), h()}.
Definition at line 129 of file texture.cpp.
References draw_size(), get_raw_size(), h_, has_src_, rect::intersect(), src_, and w_.
Referenced by gui::textbox::draw_contents(), display::expose(), and display::scroll().
void texture::set_src_raw | ( | const rect & | r | ) |
Set the source region of the texture used for drawing operations.
This function operates in texture-space, and will be clipped to {0, 0, get_raw_size().x, get_raw_size().y}.
Definition at line 144 of file texture.cpp.
References get_raw_size(), has_src_, rect::intersect(), and src_.
|
inline |
A pointer to a rect indicating the source region of the underlying SDL_Texture to be used when drawing.
If null, the whole SDL_Texture should be used.
It should generally not be queried directly. Set it using set_src() or set_src_raw(). Clear it using clear_src().
Definition at line 148 of file texture.hpp.
References has_src_, and src_.
Referenced by draw::blit(), and draw::flipped().
|
inline |
The draw-space width of the texture, in pixels.
This will usually be the real texture width in pixels, but may differ in some situations. For high-DPI text, for example, it will usually be equal to get_info().w / pixel_scale.
Definition at line 105 of file texture.hpp.
References w_.
Referenced by gui::button::calculate_size(), gui2::image_shape::draw(), gui2::text_shape::draw(), gui::button::draw_contents(), gui::scrollbar::draw_contents(), gui::textbox::draw_contents(), font::floating_label::get_draw_size(), font::floating_label::get_pos(), gui::button::load_images(), set_draw_size(), set_draw_width(), draw::tiled(), gui::tristate_button::tristate_button(), and font::floating_label::update().
|
private |
Definition at line 216 of file texture.hpp.
Referenced by assign(), draw_size(), h(), reset(), set_draw_height(), set_draw_size(), set_src(), and texture().
|
private |
true iff the source rect is valid
Definition at line 217 of file texture.hpp.
Referenced by assign(), clear_src(), reset(), set_src(), set_src_raw(), and src().
|
private |
uninitialized by default.
Definition at line 218 of file texture.hpp.
Referenced by set_src(), set_src_raw(), and src().
|
private |
Definition at line 214 of file texture.hpp.
Referenced by assign(), get(), get_access(), get_alpha_mod(), get_blend_mode(), get_color_mod(), get_format(), get_raw_size(), operator bool(), operator SDL_Texture *(), reset(), set_alpha_mod(), set_blend_mode(), set_color_mod(), and texture().
|
private |
Definition at line 215 of file texture.hpp.
Referenced by assign(), draw_size(), reset(), set_draw_size(), set_draw_width(), set_src(), texture(), and w().