Arkanoid Remake
1.0
|
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 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 |
EventFunctor * | mEventCB |
bool | mAutoDeleteEventCB |
SDL application manager.
bool sdltk::SdlApp::ApplySurf | ( | int | x, |
int | y, | ||
const std::string & | source, | ||
const std::string & | destination = "" |
||
) |
Apply at the given coordinates the named surface
x | horizontal coordinate in pixels |
y | vertical coordinate in pixels |
source | name of the surface to be copied |
destination | name of the surface where to copy (if not specified it is the main window) |
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
surf_mat | name of the surface matrix used |
row,col | row and column of the matrix element to use |
x,y | where to appy the element (horizontal and vertical position in pixels) |
destination | name of the surface where to copy (if not specified it is the main window) |
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)
text_name | name used to identify the text |
font_name | name of the font used |
col | color of the text |
shadowcol | (optional) color of the shadow (default = no shadow) |
shadow_offset | offset of the shadow in pixels |
bool sdltk::SdlApp::DeleteSurface | ( | const std::string & | name | ) |
Delete an existing surface
bool sdltk::SdlApp::GetSurfMatrixElemSize | ( | const std::string & | surf_mat, |
int & | w, | ||
int & | h | ||
) |
Get the size of an element of the named matrix surface
surf_mat | name of the surface matrix | |
[out] | w | width of the element (not changed if the matrix was not found) |
[out] | h | height of the element (not changed if the matrix was not found) |
bool sdltk::SdlApp::LoadFont | ( | const std::string & | name, |
std::string | path, | ||
int | size | ||
) |
Load a font
name | name used to identify the font |
path | file path of the true type font to load |
size | chosen size for the font |
bool sdltk::SdlApp::LoadMusic | ( | const std::string & | name, |
std::string | path = "" |
||
) |
Load a named music from a WAV file
bool sdltk::SdlApp::LoadSound | ( | const std::string & | name, |
std::string | path = "" |
||
) |
Load a named sound from a WAV file
bool sdltk::SdlApp::LoadSurface | ( | const std::string & | name, |
const std::string & | filename | ||
) |
Create a surface loaded from a file
name | identifier that will be used for the new surface |
filename | name of the file to load ( |
bool sdltk::SdlApp::NewSurface | ( | const std::string & | name, |
int | width, | ||
int | height | ||
) |
Create a new surface with the given name and size
void sdltk::SdlApp::RenderText | ( | const std::string & | text_name, |
int | x, | ||
int | y, | ||
const std::string & | dest_surface = "" |
||
) |
Render the named text
text_name | name of the text to be rendered (not the text string itself) |
x,y | coordinates where to render the text |
dest_surface | (optional) destination surface (default = main window) |
|
inline |
Connect the events with the given handler (
func | handler for events ( |
auto_delete | automatically 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
surf_mat | name of the surface matrix to create or update |
filename | name of the file to load ( |
rows | number of rows in the loaded image (vertical subdivision) |
cols | number of columns in the loaded image (horizontal subdivision) |
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
u | horizontal offset of the tiles |
v | vertical offset of the tiles |
source | name of the surface used as tile |
destination | name of the surface that must be filled |