The Battle for Wesnoth  1.19.7+dev
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
texture Class Reference

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 rectsrc () 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ texture() [1/4]

texture::texture ( )
default

Default ctor.

Texture will be a nullptr.

◆ texture() [2/4]

texture::texture ( SDL_Texture *  txt)
explicit

Assigns the given texture to this one.

Definition at line 40 of file texture.cpp.

References finalize(), h_, and w_.

◆ texture() [3/4]

texture::texture ( const surface surf,
bool  linear_interpolation = false 
)
explicit

Construct a texture from a surface.

Parameters
surfThe surface to copy.
linear_interpolationIf 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() [4/4]

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().

Member Function Documentation

◆ assign()

void texture::assign ( SDL_Texture *  t)

Replaces ownership of the managed texture with the given one.

Definition at line 239 of file texture.cpp.

References h_, has_src_, t, texture_, and w_.

◆ clear_src()

void texture::clear_src ( )
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().

◆ draw_size()

point texture::draw_size ( ) const
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.

References h_, and w_.

Referenced by gui2::canvas::draw(), video::read_pixels(), set_src(), and display::update_render_textures().

◆ finalize()

void texture::finalize ( )
private

Definition at line 85 of file texture.cpp.

References set_blend_mode().

Referenced by reset(), and texture().

◆ get()

SDL_Texture* texture::get ( ) const
inline

Definition at line 196 of file texture.hpp.

References texture_.

Referenced by operator==(), and video::read_pixels().

◆ get_access()

int texture::get_access ( ) const

The texture access mode.

Equivalent to get_info().access.

Definition at line 101 of file texture.cpp.

References texture_.

◆ get_alpha_mod()

uint8_t texture::get_alpha_mod ( ) const

Definition at line 158 of file texture.cpp.

References texture_.

◆ get_blend_mode()

SDL_BlendMode texture::get_blend_mode ( ) const

Definition at line 198 of file texture.cpp.

References b, and texture_.

◆ get_color_mod()

color_t texture::get_color_mod ( ) const

Definition at line 181 of file texture.cpp.

References c, and texture_.

◆ get_format()

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_.

◆ get_info()

const info texture::get_info ( ) const
inline

Queries metadata about the texture, such as its dimensions.

Definition at line 78 of file texture.hpp.

References lg::info().

◆ get_raw_size()

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().

◆ h()

int texture::h ( ) const
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().

◆ operator bool()

texture::operator bool ( ) const
inlineexplicit

Definition at line 206 of file texture.hpp.

References texture_.

◆ operator SDL_Texture *()

texture::operator SDL_Texture * ( ) const
inline

Definition at line 201 of file texture.hpp.

References texture_.

◆ operator==()

bool texture::operator== ( const texture t) const
inline

Texture comparisons explicitly only care about the pointer value.

Definition at line 199 of file texture.hpp.

References get(), and t.

◆ reset() [1/2]

void texture::reset ( )

◆ reset() [2/2]

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_.

◆ set_alpha_mod()

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().

◆ set_blend_mode()

void texture::set_blend_mode ( SDL_BlendMode  b)

Blend mode.

Modifies how draw operations are applied.

Definition at line 191 of file texture.cpp.

References b, and texture_.

Referenced by finalize().

◆ set_color_mod() [1/2]

void texture::set_color_mod ( color_t  c)

Definition at line 168 of file texture.cpp.

References c, and texture_.

◆ set_color_mod() [2/2]

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.

References b, g, and texture_.

◆ set_draw_height()

void texture::set_draw_height ( int  h)
inline

Set the intended height of the texture, in draw-space.

Definition at line 128 of file texture.hpp.

References h(), and h_.

◆ set_draw_size() [1/2]

void texture::set_draw_size ( const point p)

Definition at line 123 of file texture.cpp.

References h_, p, and w_.

◆ set_draw_size() [2/2]

void texture::set_draw_size ( int  w,
int  h 
)
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().

◆ set_draw_width()

void texture::set_draw_width ( int  w)
inline

Set the intended width of the texture, in draw-space.

Definition at line 125 of file texture.hpp.

References w(), and w_.

◆ set_src()

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().

◆ set_src_raw()

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_.

◆ src()

const rect* texture::src ( ) const
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().

◆ w()

int texture::w ( ) const
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().

Member Data Documentation

◆ h_

int texture::h_ = 0
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().

◆ has_src_

bool texture::has_src_ = false
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().

◆ src_

rect texture::src_
private

uninitialized by default.

Definition at line 218 of file texture.hpp.

Referenced by set_src(), set_src_raw(), and src().

◆ texture_

std::shared_ptr<SDL_Texture> texture::texture_ = nullptr
private

◆ w_

int texture::w_ = 0
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().


The documentation for this class was generated from the following files: