Arkanoid Remake  1.0
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
sdltk::SdlApp Class Reference

SDL application manager. More...

#include <sdltk.h>

Public Member Functions

 SdlApp ()
 Constructor: just initialize data members.
 
virtual ~SdlApp ()
 Just trace the deletion of this message with a message.
 
bool CreateWindow (std::string title, bool fullscreen=true, int width=-1, int height=-1, int x=-1, int y=-1)
 Create teh application window.
 
void UpdateWindow ()
 Redraw window surface.
 
bool HandleEvents ()
 Handle events (mouse, keyboard)
 
void SetEventFunc (EventFunctor *func, bool auto_delete=true)
 
std::string & FontsPath ()
 Access (read/change) the path containing the font files.
 
std::string & ImagesPath ()
 Access (read/change) the path containing the image files.
 
std::string & SoundsPath ()
 Access (read/change) the path containing the sound files.
 
std::string & MusicPath ()
 Access (read/change) the path containing the music files.
 
int WinWidth ()
 Get the width of the window surface.
 
int WinHeight ()
 Get the height of the window surface.
 
bool InitSdl ()
 Initialize SDL library.
 
void ExitSdl ()
 Destroy all and quit SDL library.
 
bool ExistsSurface (const std::string &name) const
 Check if a named surface exists.
 
bool NewSurface (const std::string &name, int width, int height)
 
bool DeleteSurface (const std::string &name)
 
bool LoadSurface (const std::string &name, const std::string &filename)
 
int GetSurfWidth (const std::string &name)
 Get the width of the named surface.
 
int GetSurfHeight (const std::string &name)
 Get the width of the named surface.
 
bool ApplySurf (int x, int y, const std::string &source, const std::string &destination="")
 
bool TileSurf (int u, int v, const std::string &source, const std::string &destination)
 
void DestroySurface (const std::string &name)
 Destroy a previously created surface.
 
bool SetupSurfMatrix (const std::string &surf_mat, const std::string &filename, int rows, int cols)
 
bool ApplySurfMatrixElem (const std::string &surf_mat, int row, int col, int x, int y, const std::string &destination="")
 
bool GetSurfMatrixElemSize (const std::string &surf_mat, int &w, int &h)
 
bool ExistsSurfaceMatrix (const std::string &name) const
 Check if a named surface matrix exists.
 
void DestroySurfaceMatrix (const std::string &name)
 Destroy a previously created surface matrix.
 
bool ExistsFont (const std::string &name)
 
bool LoadFont (const std::string &name, std::string path, int size)
 
bool ExistsText (const std::string &name)
 
bool CreateText (const std::string &text_name, const std::string &font_name, const ColorRGBA &col, const ColorRGBA &shadowcol=ColorRGBA(), int shadow_offset=1)
 
void SetText (const std::string &text_name, const std::string &text)
 Set the text content for the named text.
 
void RenderText (const std::string &text_name, int x, int y, const std::string &dest_surface="")
 
bool LoadSound (const std::string &name, std::string path="")
 
void PlaySound (const std::string &name)
 Play the named sound.
 
void SetSoundsVolume (int vol)
 Set the volume for sounds (0 to 128)
 
int GetSoundsVolume (int vol)
 Get the volume for sounds (0 to 128)
 
bool LoadMusic (const std::string &name, std::string path="")
 
void PlayMusic (unsigned int index)
 Play the music with the given index.
 
void PlayMusic ()
 Play the music (start playing, continue, cycle thruogh the playlist)
 
void SetMusicVolume (int vol)
 Set the music volume (0 to 128)
 
int GetMusicVolume ()
 Get the music volume (0 to 128)
 
void SwitchAudio (bool on)
 Switch the audio on (true) or off (false)
 
bool AudioEnabled ()
 Check if the audio is on (true) or off (false)
 
void Delay (unsigned int ms)
 Delay (suspend) the execution for the given milliseconds.
 

Protected Member Functions

SDL_Surface * CreateSdlSurface (int w, int h)
 
SDL_Surface * LoadImageAsSurface (const std::string &filename)
 
void ApplySdlSurface (int x, int y, SDL_Surface *source, SDL_Surface *destination=nullptr, SDL_Rect *src_rect=nullptr)
 
void TileSdlSurface (int u, int v, SDL_Surface *source, SDL_Surface *destination)
 
void DestroySdlSurface (SDL_Surface *&surf)
 

Protected Attributes

Window mWin
 
std::string mFontsPath
 
std::string mImagesPath
 
std::string mSoundPath
 
std::string mMusicPath
 
bool mAudioEnabled
 
std::map< std::string, TTF_Font * > mFont
 
std::map< std::string,
SDL_Surface * > 
mSurface
 
std::map< std::string,
SurfaceMatrix * > 
mSurfaceMatrix
 
std::map< std::string,
Mix_Chunk * > 
mSoundFx
 
unsigned mMusic
 
std::vector< Mix_Music * > mPlaylist
 
std::map< std::string, Text > mText
 
EventFunctormEventCB
 
bool mAutoDeleteEventCB
 

Detailed Description

SDL application manager.

Member Function Documentation

bool sdltk::SdlApp::ApplySurf ( int  x,
int  y,
const std::string &  source,
const std::string &  destination = "" 
)

Apply at the given coordinates the named surface

Parameters
xhorizontal coordinate in pixels
yvertical coordinate in pixels
sourcename of the surface to be copied
destinationname of the surface where to copy (if not specified it is the main window)
Returns
Return true on success, false if something went wrong
bool sdltk::SdlApp::ApplySurfMatrixElem ( const std::string &  surf_mat,
int  row,
int  col,
int  x,
int  y,
const std::string &  destination = "" 
)

Apply a matrix element (sub-image) of the named surface matrix

Parameters
surf_matname of the surface matrix used
row,colrow and column of the matrix element to use
x,ywhere to appy the element (horizontal and vertical position in pixels)
destinationname of the surface where to copy (if not specified it is the main window)
Returns
Return true on success, false the named surface does't exist
bool sdltk::SdlApp::CreateText ( const std::string &  text_name,
const std::string &  font_name,
const ColorRGBA col,
const ColorRGBA shadowcol = ColorRGBA(),
int  shadow_offset = 1 
)

Create a new text (object)

Parameters
text_namename used to identify the text
font_namename of the font used
colcolor of the text
shadowcol(optional) color of the shadow (default = no shadow)
shadow_offsetoffset of the shadow in pixels
Returns
Return true on success, false on error
bool sdltk::SdlApp::DeleteSurface ( const std::string &  name)

Delete an existing surface

Returns
Return true on success, false the named surface does't exist
bool sdltk::SdlApp::GetSurfMatrixElemSize ( const std::string &  surf_mat,
int &  w,
int &  h 
)

Get the size of an element of the named matrix surface

Parameters
surf_matname of the surface matrix
[out]wwidth of the element (not changed if the matrix was not found)
[out]hheight of the element (not changed if the matrix was not found)
Returns
Return true on success, false the named surface does't exist
bool sdltk::SdlApp::LoadFont ( const std::string &  name,
std::string  path,
int  size 
)

Load a font

Parameters
namename used to identify the font
pathfile path of the true type font to load
sizechosen size for the font
Returns
Return true on success, false on error
bool sdltk::SdlApp::LoadMusic ( const std::string &  name,
std::string  path = "" 
)

Load a named music from a WAV file

Returns
Return true on success, false on error
bool sdltk::SdlApp::LoadSound ( const std::string &  name,
std::string  path = "" 
)

Load a named sound from a WAV file

Returns
Return true on success, false on error
bool sdltk::SdlApp::LoadSurface ( const std::string &  name,
const std::string &  filename 
)

Create a surface loaded from a file

Parameters
nameidentifier that will be used for the new surface
filenamename of the file to load (
See also
ImagesPath())
bool sdltk::SdlApp::NewSurface ( const std::string &  name,
int  width,
int  height 
)

Create a new surface with the given name and size

Returns
Return true on success, false on error
void sdltk::SdlApp::RenderText ( const std::string &  text_name,
int  x,
int  y,
const std::string &  dest_surface = "" 
)

Render the named text

Parameters
text_namename of the text to be rendered (not the text string itself)
x,ycoordinates where to render the text
dest_surface(optional) destination surface (default = main window)
void sdltk::SdlApp::SetEventFunc ( EventFunctor func,
bool  auto_delete = true 
)
inline

Connect the events with the given handler (

See also
HandleEvents())
Parameters
funchandler for events (
See also
EventFunctor)
Parameters
auto_deleteautomatically delete the given functor along with the application
bool sdltk::SdlApp::SetupSurfMatrix ( const std::string &  surf_mat,
const std::string &  filename,
int  rows,
int  cols 
)

Create or setup a surface matrix using an image table stored in the given file

Parameters
surf_matname of the surface matrix to create or update
filenamename of the file to load (
See also
ImagesPath())
Parameters
rowsnumber of rows in the loaded image (vertical subdivision)
colsnumber of columns in the loaded image (horizontal subdivision)
Returns
Return true on success, false the named file can't be loaded
bool sdltk::SdlApp::TileSurf ( int  u,
int  v,
const std::string &  source,
const std::string &  destination 
)

Fill a surface using the given surface as tile

Parameters
uhorizontal offset of the tiles
vvertical offset of the tiles
sourcename of the surface used as tile
destinationname of the surface that must be filled

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