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

Public Member Functions

 SlManager ()
 
 SlManager (const std::string &name, int width, int height)
 
 SlManager (const SlManager &)=delete
 
SlManager & operator= (const SlManager &)=delete
 
bool appendToRenderQueue (const std::string &name, unsigned int destination=0)
 
SlRenderItem * createRenderItem (const std::string &name, unsigned int destination)
 
void deleteRenderItem (const std::string &name)
 
void deleteSprite (const std::string &name)
 
void deleteTexture (const std::string &name)
 
std::shared_ptr< SlSprite > findSprite (const std::string &name)
 
SlTexture * findTexture (const std::string &name)
 
void handleEvent (const SDL_Event &event)
 
void insertInRenderQueueAfter (const std::string &toAdd, const std::string &afterThis, unsigned int destToAdd=0, unsigned int destAfterThis=0)
 
void insertInRenderQueueBefore (const std::string &toAdd, const std::string &beforeThis, unsigned int destToAdd=0, unsigned int destBeforeThis=0)
 
bool moveInRenderQueueBefore (const std::string &toAdd, const std::string &beforeThis, unsigned int destToAdd=0, unsigned int destBeforeThis=0)
 
bool moveInRenderQueueAfter (const std::string &toAdd, const std::string &afterThis, unsigned int destToAdd=0, unsigned int destAfterThis=0)
 
void manipulateRenderQueue (const std::string &name, unsigned int destination, const std::string &whatToDo, const std::vector< std::string > &parameters)
 
void parseRenderQueueManipulation (std::ifstream &input)
 
bool parseConfigurationFile (const std::string &filename="SlTextureConfig.ini")
 
void parseIniFile (const std::string &filename="SlApplication.ini")
 
void render ()
 
SDL_Renderer * renderer ()
 
void run ()
 
int screenWidth ()
 
int screenHeight ()
 
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)
 
void swapInRenderQueue (const std::string &toAdd, const std::string &toRemove, unsigned int destToAdd=0, unsigned int destToRemove=0)
 
void swapInRenderQueueAtPosition (const std::string &toAdd, unsigned int destToAdd, unsigned int position)
 
void swapInRenderQueueLastPosition (const std::string &toAdd, unsigned int destToAdd=0)
 
void toggleRender (const std::string &toToggle, unsigned int destination=0, int onOrOff=-1)
 
void toggleRenderOff (const std::string &toToggle, unsigned int destination=0)
 
void toggleRenderOn (const std::string &toToggle, unsigned int destination=0)
 

Protected Member Functions

void clear ()
 
void initialize ()
 
void initializeWindow (const std::string &name, int width, int height)
 
bool moveInRenderQueue (const std::string &toMoveName, const std::string &targetName, unsigned int destToMove=0, unsigned int targetDest=0, int beforeOrAfter=0)
 

Protected Attributes

SDL_Window * window_ = nullptr
 
SDL_Renderer * renderer_ = nullptr
 

Private Attributes

std::vector< SlRenderItem * > renderQueue_
 
std::unique_ptr< SlTextureManager > tmngr_ = nullptr
 
std::shared_ptr< SlSpriteManager > smngr_ = nullptr
 
std::unique_ptr< SlEventHandler > eventHandler_ = nullptr
 
int screen_width_
 
int screen_height_
 
SlValueParser valParser_
 
std::map< std::string, SlManipulation * > renderManip_
 

Constructor & Destructor Documentation

SlManager::SlManager ( )

Default constructor. Parses "SlApplication.ini" for window name and dimensions, and configuration file names.

SlManager::SlManager ( const std::string &  name,
int  width,
int  height 
)

Initializes SDL, creates window with name and width, height

SlManager::SlManager ( const SlManager &  )
delete

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

Member Function Documentation

bool SlManager::appendToRenderQueue ( const std::string &  name,
unsigned int  destination = 0 
)

Adds the sprite 'name' to the end of the renderQueue_ .

Return values
falseif sprite not found or destination out of bounds.
void SlManager::clear ( )
protected

Deletes all textures and sprites, empties render queue.

SlRenderItem * SlManager::createRenderItem ( const std::string &  name,
unsigned int  destination 
)

Creates new SlRenderItem for the specified sprite.

Return values
nullptrif sprite not found or destination out of bounds.
void SlManager::deleteRenderItem ( const std::string &  name)

Delete all render items with the specified name from the renderQueue_ . Should be called before deleteSprite(const std::string& name).

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

Tells smngr_ to delete the specified sprite. Also deletes all associated entries in renderQueue_ .

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

Tells tmngr_ to delete the specified texture and remove from SlTextureManager::textures_ . Also deletes all associates SlSprites.

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

Returns pointer to the sprite, nullptr if not found.

SlTexture * SlManager::findTexture ( const std::string &  name)

Returns pointer to the texture, nullptr if not found. Calls SlTextureManager tmngr_ .

void SlManager::handleEvent ( const SDL_Event &  event)
inline

Pass event on to SlEventHandler eventHandler_ . Deprecated, just call run().

void SlManager::initialize ( )
protected

Initializes SDL

< Needs to be shared with SlRenderQueueManipulation items.

void SlManager::initializeWindow ( const std::string &  name,
int  width,
int  height 
)
protected

Initializes window

void SlManager::insertInRenderQueueAfter ( const std::string &  toAdd,
const std::string &  afterThis,
unsigned int  destToAdd = 0,
unsigned int  destAfterThis = 0 
)

Inserts the sprite into the renderQueue_ after the specified sprite.

void SlManager::insertInRenderQueueBefore ( const std::string &  toAdd,
const std::string &  beforeThis,
unsigned int  destToAdd = 0,
unsigned int  destBeforeThis = 0 
)

Inserts the sprite into the renderQueue_ before the specified sprite.

void SlManager::manipulateRenderQueue ( const std::string &  name,
unsigned int  destination,
const std::string &  whatToDo,
const std::vector< std::string > &  parameters 
)

Move the render item based on configuration file.\ Currently implemented whatToDo:
append

bool SlManager::moveInRenderQueue ( const std::string &  toMoveName,
const std::string &  targetName,
unsigned int  destToMove = 0,
unsigned int  targetDest = 0,
int  beforeOrAfter = 0 
)
protected

Moves a SlRenderItem's position in the renderQueue_ to before of after the target item.
beforeOrAfter is 0 for before, 1 for after. Larger (smaller) values will result in the target item begin inserted further upstream (downstream) of the target. (Handle with care, currently no test for valid iterators beyond +1...)

bool SlManager::moveInRenderQueueAfter ( const std::string &  toAdd,
const std::string &  afterThis,
unsigned int  destToAdd = 0,
unsigned int  destAfterThis = 0 
)

Moves the render item into the renderQueue_ after the specified sprite.

bool SlManager::moveInRenderQueueBefore ( const std::string &  toAdd,
const std::string &  beforeThis,
unsigned int  destToAdd = 0,
unsigned int  destBeforeThis = 0 
)

Moves the render item into the renderQueue_ before the specified sprite.

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

Deleted, same reason as copy constructor.

bool SlManager::parseConfigurationFile ( const std::string &  filename = "SlTextureConfig.ini")

Read texture and sprite definitions from configuration file.
Default file name: "SlTextures.ini".

void SlManager::parseIniFile ( const std::string &  filename = "SlApplication.ini")

Reads application name, screen dimensions and config file names from from ini file "SlApplication.ini".

void SlManager::parseRenderQueueManipulation ( std::ifstream &  input)

Add sprites to render queue, change to order of the queue. (Currently only implemented: append.)

void SlManager::render ( )

Render all items in the renderQueue_ .

Return values
0if all renders well.
SDL_Renderer* SlManager::renderer ( )
inline

Temporary solution until all rendering related stuff happens in SlManager methods.

void SlManager::run ( )

Run the event - render loop.

int SlManager::screenHeight ( )
inline

Returns the screen_height_ of the window.

int SlManager::screenWidth ( )
inline

Returns the screen_width_ of the window.

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

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 SlManager::setSpriteDestinationOrigin ( const std::string &  name,
int  x,
int  y,
unsigned int  destination = 0 
)
inline

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

Sets where the sprite will be rendered.

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

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

Return values
falseif i > SlSprite::destinations_ size.
void SlManager::swapInRenderQueue ( const std::string &  toAdd,
const std::string &  toRemove,
unsigned int  destToAdd = 0,
unsigned int  destToRemove = 0 
)

Replaces the sprite 'toRemove' in the renderQueue_ with sprite 'toAdd' .

Return values
falseif sprite not found or destination out of bounds.
void SlManager::swapInRenderQueueAtPosition ( const std::string &  toAdd,
unsigned int  destToAdd,
unsigned int  position 
)

Replaces the SlRenderItem at 'position' in the renderQueue_ with sprite 'toAdd'.
Note that the first item is in position 0.

void SlManager::swapInRenderQueueLastPosition ( const std::string &  toAdd,
unsigned int  destToAdd = 0 
)

Replaces the last item in the renderQueue_ with sprite toAdd.

void SlManager::toggleRender ( const std::string &  toToggle,
unsigned int  destination = 0,
int  onOrOff = -1 
)

Toggles rendering of an item in the renderQueue_ on and off. onOrOff is -1 to toggle, 0 to turn off, 1 to turn on.

void SlManager::toggleRenderOff ( const std::string &  toToggle,
unsigned int  destination = 0 
)
inline

Turns off rendering for the specified SlRenderItem in the renderQueue_ .

void SlManager::toggleRenderOn ( const std::string &  toToggle,
unsigned int  destination = 0 
)
inline

Turns on rendering for the specified SlRenderItem in the renderQueue_ .

Member Data Documentation

std::unique_ptr<SlEventHandler> SlManager::eventHandler_ = nullptr
private

Event handler, parses events in configuration file, triggers SlManipulation on key input.

SDL_Renderer* SlManager::renderer_ = nullptr
protected

The renderer tied to the main window.

std::map<std::string, SlManipulation*> SlManager::renderManip_
private

Holds the various SlRenderQueueManipulations 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.

std::vector<SlRenderItem*> SlManager::renderQueue_
private

Holds the items to be rendered. The front of the queue is rendered first (background) the last element is rendered last (foreground).

int SlManager::screen_height_
private

Window height

int SlManager::screen_width_
private

Window width.

std::shared_ptr<SlSpriteManager> SlManager::smngr_ = nullptr
private

Sprite manager, creates, stores, manipulates, and deletes SlSprite objects.

std::unique_ptr<SlTextureManager> SlManager::tmngr_ = nullptr
private

Texture manager, creates, stores, deletes SlTexture objects.

SlValueParser SlManager::valParser_
private

Helper object to translate file input into values.

SDL_Window* SlManager::window_ = nullptr
protected

The main (and only) window.


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