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

Public Member Functions

 SlSpriteManager (SlManager *mngr)
 
 SlSpriteManager (const SlSpriteManager &)=delete
 
SlSpriteManager & operator= (const SlSpriteManager &)=delete
 
void centerSpriteInSprite (const std::string &toCenter, const std::string &target, unsigned int destinationThis=0, unsigned int destinationOther=0)
 
bool checkSpriteName (const std::string &name)
 
std::shared_ptr< SlSprite > createSprite (SlTexture *texture, int x=0, int y=0, int width=0, int height=0)
 
std::shared_ptr< SlSprite > createSprite (const std::string &name, const std::string &textureName, int x=0, int y=0, int width=0, int height=0)
 
void deleteSprite (const std::string &name)
 
void deleteSprites (const std::string &textureName)
 
std::shared_ptr< SlSprite > findSprite (const std::string &name)
 
void initialize (SlValueParser *valPars)
 
std::map< std::string, SlManipulation * > manipulations ()
 
void parseSprite (std::ifstream &input)
 
void parseSpriteManipulation (std::ifstream &input)
 
void setSpriteColor (const std::string &name, uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha=0xFF, unsigned int destination=0)
 
void setSpriteDestinationOrigin (const std::string &name, int x, int y, unsigned int destination=0)
 
void setSpriteRenderOptions (const std::string &name, uint32_t renderOptions, unsigned int destination=0)
 

Public Attributes

SlValueParser * valParser = nullptr
 

Protected Member Functions

 SlSpriteManager ()
 
void clear ()
 
void manipulateSprite (const std::string &name, unsigned int destination, const std::string &whatToDo, const std::vector< std::string > &parameters)
 

Private Attributes

std::vector< std::shared_ptr< SlSprite > > sprites_
 
SlManager * mngr_ = nullptr
 
std::map< std::string, SlManipulation * > manipulations_
 

Constructor & Destructor Documentation

SlSpriteManager::SlSpriteManager ( SlManager *  mngr)

Initializes SDL, creates window with name and width, height

SlSpriteManager::SlSpriteManager ( const SlSpriteManager &  )
delete

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

SlSpriteManager::SlSpriteManager ( )
protected

Default constructor.

Member Function Documentation

void SlSpriteManager::centerSpriteInSprite ( const std::string &  toCenter,
const std::string &  target,
unsigned int  destinationThis = 0,
unsigned int  destinationOther = 0 
)

Centers the destination of the sprite in the destinationRect of the target sprite.
Note that if the destination dimensions are changed afterwards, the sprite will no longer be centered.

bool SlSpriteManager::checkSpriteName ( const std::string &  name)

Checks if a sprite of the given name already exists. Calls findSprite(const std::string& name).

Return values
trueis sprite exists.
falseif no sprite of that name exists.
void SlSpriteManager::clear ( )
protected

Deletes all sprites.

std::shared_ptr< SlSprite > SlSpriteManager::createSprite ( SlTexture *  texture,
int  x = 0,
int  y = 0,
int  width = 0,
int  height = 0 
)

Creates sprite based on the texture textureName.

If either width or height are 0, the texture's width and height will be used.
The default values will use the whole texture as a sprite. Calls SlSprite::addDefaultDestination(), so if you don't want to use that, either delete or adjust that destination.

std::shared_ptr< SlSprite > SlSpriteManager::createSprite ( const std::string &  name,
const std::string &  textureName,
int  x = 0,
int  y = 0,
int  width = 0,
int  height = 0 
)

Creates sprite based on the texture textureName.

If either width or height are 0, the texture's width and height will be used.
The default values will use the whole texture as a sprite. Calls SlSprite::addDefaultDestination(), so if you don't want to use that, either delete or adjust that destination.

void SlSpriteManager::deleteSprite ( const std::string &  name)

Delete the specified sprite and remove from sprites_ .

void SlSpriteManager::deleteSprites ( const std::string &  textureName)

Delete the sprite that are based on the named SlTexture.

std::shared_ptr< SlSprite > SlSpriteManager::findSprite ( const std::string &  name)

Returns pointer to the sprite, nullptr if not found.

void SlSpriteManager::initialize ( SlValueParser *  valPars)

set valParser and load manipulations.

void SlSpriteManager::manipulateSprite ( const std::string &  name,
unsigned int  destination,
const std::string &  whatToDo,
const std::vector< std::string > &  parameters 
)
protected

Move the sprite based on configuration file.\ Currently implemented whatToDo:
setOrigin, centerAt, centerIn, setOptions

std::map<std::string, SlManipulation*> SlSpriteManager::manipulations ( )
inline

Get the map of SlManipulations.

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

Deleted, same reason as copy constructor.

void SlSpriteManager::parseSprite ( std::ifstream &  input)

Read sprite configurations from file

void SlSpriteManager::parseSpriteManipulation ( std::ifstream &  input)

Read sprite placement from file.

void SlSpriteManager::setSpriteColor ( const std::string &  name,
uint8_t  red,
uint8_t  green,
uint8_t  blue,
uint8_t  alpha = 0xFF,
unsigned int  destination = 0 
)

Sets color for SlSprite name at position i of SlSprite::destinations_.

Color is use when using color mod to render, and when creating a texture from a rectangle.

void SlSpriteManager::setSpriteDestinationOrigin ( const std::string &  name,
int  x,
int  y,
unsigned int  destination = 0 
)

Changes destinationRect for SlSprite name at position destination of SlSprite::destinations_.

Sets where the sprite will be rendered.

void SlSpriteManager::setSpriteRenderOptions ( const std::string &  name,
uint32_t  renderOptions,
unsigned int  destination = 0 
)

Sets SlRenderOptions for SlSprite name at position i of SlSprite::destinations_.

Return values
falseif i > SlSprite::destinations_ size.

Member Data Documentation

std::map<std::string, SlManipulation*> SlSpriteManager::manipulations_
private

Holds the various SlSpriteManipulations for the different tasks. The map key is the name of the manipulation, which is also the keyword used in the configuration file, the mapped value is the object that will do the actual work.

SlManager* SlSpriteManager::mngr_ = nullptr
private

The running SlManager that called the constructor.

std::vector<std::shared_ptr<SlSprite> > SlSpriteManager::sprites_
private

Holds all SlSprites that were created using SlSpriteManager methods. Sprites will be deleted when the SlSpriteManager instance is deleted.

SlValueParser* SlSpriteManager::valParser = nullptr

Helper object to translate file input into values.


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