SDL2lazy
Public Member Functions | Public Attributes | Protected Attributes | List of all members
SlTexture Class Reference

#include <SlTexture.h>

Public Member Functions

 SlTexture (const std::string &name)
 
 ~SlTexture ()
 
 SlTexture (const SlTexture &)=delete
 
SlTexture & operator= (const SlTexture &)=delete
 
SlTexture * createFromRectangle (SDL_Renderer *renderer, int width, int height, uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
 
SlTexture * createFromSpriteOnTexture (SDL_Renderer *renderer, SlTexture *backgroundTexture, const std::shared_ptr< SlSprite > foregroundSprite)
 
SlTexture * createFromText (SDL_Renderer *renderer, const std::shared_ptr< SlFont > font, const std::string &message, int width)
 
SlTexture * createFromTile (SDL_Renderer *renderer, const std::shared_ptr< SlSprite > tile, int width, int height)
 
void dimensions (int &width, int &height)
 
SlTexture * loadFromFile (SDL_Renderer *renderer, const std::string &fileName)
 
std::string name () const
 
SDL_Texture * texture ()
 

Public Attributes

bool alphaModIsSet = false
 
bool colorModIsSet = false
 

Protected Attributes

std::string name_ = "unnamedTexture"
 
SDL_Texture * texture_
 

Detailed Description

Main class for textures.

Constructor & Destructor Documentation

SlTexture::SlTexture ( const std::string &  name)

Constructor with texture name.

All textures have a name. Remember to create the actual texture!

SlTexture::~SlTexture ( )

deletes texture_

SlTexture::SlTexture ( const SlTexture &  )
delete

Delete copy constructor. There's no reason to copy the texture, if the goal is to render different parts of it or with different options create a SlSprite.

Member Function Documentation

SlTexture * SlTexture::createFromRectangle ( SDL_Renderer *  renderer,
int  width,
int  height,
uint8_t  red,
uint8_t  green,
uint8_t  blue,
uint8_t  alpha 
)

createFromRectangle uses SDL_FillRect to create a texture based on the given geometry and the color defined in SlTextureInfo.

Exceptions
std::runtime_errorif texture can't be created or rectangle can't be rendered.
SlTexture * SlTexture::createFromSpriteOnTexture ( SDL_Renderer *  renderer,
SlTexture *  backgroundTexture,
const std::shared_ptr< SlSprite >  foregroundSprite 
)

Create a new texture by rendering a sprite on this texture. Calls SlSprite::render() for the sprite.

Exceptions
std::runtime_errorif texture can't be created or rendered.
SlTexture * SlTexture::createFromText ( SDL_Renderer *  renderer,
const std::shared_ptr< SlFont >  font,
const std::string &  message,
int  width 
)

Create a new texture from the message using the specified SlFont.

Exceptions
std::runtime_errorif surface or texture can't be created.
SlTexture * SlTexture::createFromTile ( SDL_Renderer *  renderer,
const std::shared_ptr< SlSprite >  tile,
int  width,
int  height 
)

Creates a new texture with dimensions w x h and fills it with tiles of SlSprite tile.
The SlRenderSettings::destinationRect at position 0 in the sprite's lSprite::destinations_ is used to determine the width of the tile.
If the sprite's SlSprite::destinations_ is empty, addDefaultDestination() is called which sets the destinationRect to equal the sourceRect.

Exceptions
std::runtime_errorif the texture can't be created or the step size for placing the tiles it <= 0.
void SlTexture::dimensions ( int &  width,
int &  height 
)

Returns the dimensions of the SDL_Texture.

SlTexture * SlTexture::loadFromFile ( SDL_Renderer *  renderer,
const std::string &  fileName 
)

uses IMG_LoadTexture to get texture from png image file

Exceptions
std::runtime_errorif object already has a texture or texture can't be loaded.
std::string SlTexture::name ( ) const
inline

Returns the name of the texture. Changing the name after creation is not allowed.

SlTexture& SlTexture::operator= ( const SlTexture &  )
delete

Deleted, same reason as copy constructor.

SDL_Texture* SlTexture::texture ( )
inline

Returns the SDL_texture. Changing the texture is not allowed.

Member Data Documentation

bool SlTexture::alphaModIsSet = false

alphaModIsSet stores whether SDL_SetTextureAlphaMod has been applied. If true but the RenderOptions for the next render call don't request the mod anymore, the texture is reset to default.

bool SlTexture::colorModIsSet = false

colorModIsSet stores whether SDL_SetTextureColorMod has been applied. If true but the RenderOptions for the next render call don't request the mod anymore, the texture is reset to default.

std::string SlTexture::name_ = "unnamedTexture"
protected

The object's name. Cannot be changed.

SDL_Texture* SlTexture::texture_
protected

The actual SDL_Texture.


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