The Battle for Wesnoth  1.17.8+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 ()
 
void set_blend_mode (SDL_BlendMode)
 Blend mode. More...
 
SDL_BlendMode get_blend_mode ()
 
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 ()
 
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(), 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_, texture_, and w_.

Referenced by clear_src().

◆ clear_src()

void texture::clear_src ( )
inline

◆ 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 video::force_render_target(), 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 operator bool(), reset(), and texture().

◆ get()

SDL_Texture* texture::get ( ) const
inline

Definition at line 196 of file texture.hpp.

References texture_.

Referenced by video::force_render_target(), 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_.

Referenced by get_info(), and draw::render_target_setter::render_target_setter().

◆ get_alpha_mod()

uint8_t texture::get_alpha_mod ( )

Definition at line 158 of file texture.cpp.

References a, and texture_.

Referenced by clear_src().

◆ get_blend_mode()

SDL_BlendMode texture::get_blend_mode ( )

Definition at line 198 of file texture.cpp.

References b, and texture_.

Referenced by clear_src().

◆ get_color_mod()

color_t texture::get_color_mod ( )

Definition at line 181 of file texture.cpp.

References c, and texture_.

Referenced by clear_src().

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

Referenced by get_info().

◆ 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 get_access(), get_format(), get_raw_size(), and texture::info::info().

◆ get_raw_size()

point texture::get_raw_size ( ) const

◆ h()

int texture::h ( ) const
inline

◆ operator bool()

texture::operator bool ( ) const
inlineexplicit

Definition at line 206 of file texture.hpp.

References finalize(), and 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().

◆ reset() [1/2]

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 clear_src(), display::fade_tod_mask(), gui::textbox::handle_event(), gui::button::load_images(), reset(), and texture().

◆ 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 clear_src(), font::floating_label::draw(), and gui::textbox::draw_contents().

◆ 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 clear_src(), and finalize().

◆ set_color_mod() [1/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_.

Referenced by clear_src().

◆ set_color_mod() [2/2]

void texture::set_color_mod ( color_t  c)

Definition at line 168 of file texture.cpp.

References 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 texture::info::h, and h_.

◆ set_draw_size() [1/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 texture::info::h, h_, p, texture::info::w, and w_.

Referenced by display::update_render_textures(), and font::pango_text::with_draw_scale().

◆ set_draw_size() [2/2]

void texture::set_draw_size ( const point p)

Definition at line 123 of file texture.cpp.

References h_, and w_.

◆ 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 texture::info::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 unit_drawer::draw_bar(), gui::textbox::draw_contents(), display::expose(), display::scroll(), and src().

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

Referenced by 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_, set_src(), set_src_raw(), and src_.

Referenced by draw::blit(), and draw::flipped().

◆ w()

int texture::w ( ) const
inline

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: