SDL2lazy
Public Member Functions | Public Attributes | Protected Member Functions | Private Attributes | List of all members
SlTextureManager Class Reference
Collaboration diagram for SlTextureManager:
Collaboration graph
[legend]

Public Member Functions

 SlTextureManager (SlManager *manager)
 
 SlTextureManager (const SlTextureManager &)=delete
 
SlTextureManager & operator= (const SlTextureManager &)=delete
 
SlTexture * createTextureFromFile (const std::string &name, const std::string &filename)
 
SlTexture * createTextureFromRectangle (const std::string &name, int width, int height, uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha=0xFF)
 
SlTexture * createTextureFromSpriteOnTexture (const std::string &name, const std::string &backgroundTexture, const std::string &foregroundSprite)
 
SlTexture * createTextureFromText (const std::string &name, const std::string &fontname, const std::string &message, int width)
 
SlTexture * createTextureFromTile (const std::string &name, const std::string &sprite, int width, int height)
 
void deleteTexture (const std::string &name)
 
std::shared_ptr< SlFont > findFont (const std::string &name)
 
SlTexture * findTexture (const std::string &name)
 
std::shared_ptr< SlFont > parseFont (std::ifstream &input)
 
SlTexture * parseTexture (std::ifstream &input)
 

Public Attributes

SlValueParser * valParser = nullptr
 

Protected Member Functions

 SlTextureManager (void)
 
void addTexture (SlTexture *toAdd)
 
void clear ()
 

Private Attributes

std::vector< SlTexture * > textures_
 
SlManager * mngr_ = nullptr
 
std::vector< std::shared_ptr< SlFont > > fonts_
 

Constructor & Destructor Documentation

SlTextureManager::SlTextureManager ( SlManager *  manager)

Initializes SDL, creates window with name and width, height

SlTextureManager::SlTextureManager ( const SlTextureManager &  )
delete

Delete copy constructor. The manager owns the window, don't want copies of that.

SlTextureManager::SlTextureManager ( void  )
protected

Default constructor.

Member Function Documentation

void SlTextureManager::addTexture ( SlTexture *  toAdd)
protected

Adds toAdd to textures_ and creates SlSprite of same name.

void SlTextureManager::clear ( )
protected

Deletes all textures and sprites, empties render queue.

SlTexture * SlTextureManager::createTextureFromFile ( const std::string &  name,
const std::string &  filename 
)

Load texture from image filename

SlTexture * SlTextureManager::createTextureFromRectangle ( const std::string &  name,
int  width,
int  height,
uint8_t  red,
uint8_t  green,
uint8_t  blue,
uint8_t  alpha = 0xFF 
)

Creates SlTexture using a rectangle of dimension width x height filled with the specified colour.
Creates SlSprite of same name that holds the whole texture.

SlTexture * SlTextureManager::createTextureFromSpriteOnTexture ( const std::string &  name,
const std::string &  backgroundTexture,
const std::string &  foregroundSprite 
)

Create a new texture by rendering a sprite on this texture.
Creates SlSprite of same name that holds the whole texture.

SlTexture * SlTextureManager::createTextureFromText ( const std::string &  name,
const std::string &  fontname,
const std::string &  message,
int  width 
)

Create a new texture from the message using the specified font. The text will be wrapped to fit the width.

SlTexture * SlTextureManager::createTextureFromTile ( const std::string &  name,
const std::string &  sprite,
int  width,
int  height 
)

Creates a new texture with dimensions w x h and fills it with tiles of SlSprite tile.
Creates SlSprite of same name that holds the whole texture.

The SlRenderSettings::destinationRect at position 0 in the SlSprite::destinations_ is used to determine the width of the tile. If the SlSprite::destinations_ is empty, addDefaultDestination() is called which sets the destinationRect to equal the sourceRect.

void SlTextureManager::deleteTexture ( const std::string &  name)

Delete the specified texture and remove from textures_ .
Also deletes the SlSprite of same name that was created automatically with the texture.

std::shared_ptr< SlFont > SlTextureManager::findFont ( const std::string &  name)

Returns pointer to the named font.

Return values
nullptrif not found
SlTexture * SlTextureManager::findTexture ( const std::string &  name)

Returns pointer to the named texture.

Return values
nullptrif not found
SlTextureManager& SlTextureManager::operator= ( const SlTextureManager &  )
delete

Deleted, same reason as copy constructor.

std::shared_ptr< SlFont > SlTextureManager::parseFont ( std::ifstream &  input)

Read font file, size, colour from file

SlTexture * SlTextureManager::parseTexture ( std::ifstream &  input)

Read texture configurations from file

<- message[0] is space between token and beginning of text.

Member Data Documentation

std::vector<std::shared_ptr<SlFont> > SlTextureManager::fonts_
private

Font used for rendering. This is kept open until program exits to reduce overhead from opening and closing font file.

SlManager* SlTextureManager::mngr_ = nullptr
private

Pointer to the running SlManager that created this TextureManager.

std::vector<SlTexture*> SlTextureManager::textures_
private

Holds all SlTextures that were created using SlTextureManager methods. Texture will be deleted when the SlTextureManager instance is deleted.

SlValueParser* SlTextureManager::valParser = nullptr

Helper object to translate file input into values.


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