51 struct SDL_PixelFormat;
56 typedef struct _TTF_Font TTF_Font;
59 typedef struct _Mix_Music Mix_Music;
147 unsigned int mStartMs;
178 ColorRGBA(
unsigned char r=0,
unsigned char g=0,
unsigned char b=0,
unsigned char a=0)
199 SDL_Surface *mSdlWinSurf;
200 SDL_PixelFormat *mPixelFormat;
205 bool Create(std::string title,
bool fullscreen,
int width,
int height,
int x=-1,
int y=-1);
212 SDL_Surface* mMatrixSurf;
219 SurfaceMatrix(SDL_Surface* surf=
nullptr,
int rows=0,
int cols=0);
220 void SetSdlSurface(SDL_Surface* surf,
int row,
int col);
221 void ApplySdlSurface(
int row,
int col, SDL_Surface * dst,
int dst_x,
int dst_y);
222 int GetElemW() {
return mElemW; }
223 int GetElemH() {
return mElemH; }
231 SDL_Surface* mTextSurf;
232 SDL_Surface* mTextShadowSurf;
236 std::string mTextString;
242 void UpdateAlignment();
245 enum {TOP=-1,
MIDDLE=0,BOTTOM=1};
247 void Render(SDL_Surface* surf,
int x,
int y);
248 void SetText(
const std::string& text);
249 void SetFont(TTF_Font* font);
250 void SetAlignment(
int horiz,
int vert);
262 bool CreateWindow(std::string title,
bool fullscreen=
true,
int width=-1,
int height=-1,
int x=-1,
int y=-1);
276 mAutoDeleteEventCB = auto_delete;
308 bool NewSurface(
const std::string& name,
int width,
int height);
317 bool LoadSurface(
const std::string& name,
const std::string& filename);
331 bool ApplySurf(
int x,
int y,
const std::string& source,
const std::string& destination=
"");
338 bool TileSurf(
int u,
int v,
const std::string& source,
const std::string& destination);
349 bool SetupSurfMatrix(
const std::string& surf_mat,
const std::string& filename,
int rows,
int cols);
357 bool ApplySurfMatrixElem(
const std::string& surf_mat,
int row,
int col,
int x,
int y,
const std::string& destination=
"");
373 bool ExistsFont(
const std::string& name);
380 bool LoadFont(
const std::string& name, std::string path,
int size);
383 bool ExistsText(
const std::string& name);
393 const std::string& text_name,
394 const std::string& font_name,
397 int shadow_offset=1);
400 void SetText(
const std::string& text_name,
const std::string& text);
406 void RenderText(
const std::string& text_name,
int x,
int y,
const std::string& dest_surface=
"");
410 bool LoadSound(
const std::string& name, std::string path=
"");
423 bool LoadMusic(
const std::string& name, std::string path=
"");
444 void Delay(
unsigned int ms);
454 std::string mFontsPath;
455 std::string mImagesPath;
456 std::string mSoundPath;
457 std::string mMusicPath;
464 std::map<std::string,TTF_Font*> mFont;
467 std::map<std::string,SDL_Surface*> mSurface;
470 std::map<std::string,SurfaceMatrix*> mSurfaceMatrix;
473 std::map<std::string,Mix_Chunk*> mSoundFx;
477 std::vector<Mix_Music*> mPlaylist;
480 std::map<std::string,Text> mText;
485 bool mAutoDeleteEventCB;
489 SDL_Surface* CreateSdlSurface(
int w,
int h);
490 SDL_Surface* LoadImageAsSurface(
const std::string& filename);
491 void ApplySdlSurface(
int x,
int y, SDL_Surface* source, SDL_Surface* destination=
nullptr, SDL_Rect *src_rect=
nullptr);
492 void TileSdlSurface(
int u,
int v, SDL_Surface* source, SDL_Surface* destination);
493 void DestroySdlSurface(SDL_Surface*& surf);
bool ApplySurf(int x, int y, const std::string &source, const std::string &destination="")
int GetSoundsVolume(int vol)
Get the volume for sounds (0 to 128)
bool AudioEnabled()
Check if the audio is on (true) or off (false)
Definition: sdltk.h:441
Application event.
Definition: sdltk.h:70
Mouse event.
Definition: sdltk.h:71
unsigned char R
Red component (0..255)
Definition: sdltk.h:168
bool HandleEvents()
Handle events (mouse, keyboard)
ColorRGBA(unsigned char r=0, unsigned char g=0, unsigned char b=0, unsigned char a=0)
Definition: sdltk.h:178
bool SetupSurfMatrix(const std::string &surf_mat, const std::string &filename, int rows, int cols)
virtual ~SdlApp()
Just trace the deletion of this message with a message.
int WinHeight()
Get the height of the window surface.
void PlaySound(const std::string &name)
Play the named sound.
std::string & ImagesPath()
Access (read/change) the path containing the image files.
Definition: sdltk.h:283
Keyboard event.
Definition: sdltk.h:72
int GetSurfWidth(const std::string &name)
Get the width of the named surface.
EventType Type
Event type (see EventType)
Definition: sdltk.h:115
Mouse middle button.
Definition: sdltk.h:89
EventType
Event type (see EventData)
Definition: sdltk.h:67
int WinWidth()
Get the width of the window surface.
SDL application manager.
Definition: sdltk.h:188
int Button
Mouse/keyboard button (see Button)
Definition: sdltk.h:121
Color data structure (red, green, blue, alpha=opacity)
Definition: sdltk.h:166
std::string & FontsPath()
Access (read/change) the path containing the font files.
Definition: sdltk.h:280
void DestroySurface(const std::string &name)
Destroy a previously created surface.
bool ExistsSurfaceMatrix(const std::string &name) const
Check if a named surface matrix exists.
Event not defined.
Definition: sdltk.h:69
int GetMusicVolume()
Get the music volume (0 to 128)
Delete key (ASCII code)
Definition: sdltk.h:94
void SetText(const std::string &text_name, const std::string &text)
Set the text content for the named text.
int GetSurfHeight(const std::string &name)
Get the width of the named surface.
EventData()
Constructor: set class attributes to default values.
Definition: sdltk.h:127
bool LoadFont(const std::string &name, std::string path, int size)
Mouse left button.
Definition: sdltk.h:88
unsigned char B
Blue component (0..255)
Definition: sdltk.h:170
void DestroySurfaceMatrix(const std::string &name)
Destroy a previously created surface matrix.
bool TileSurf(int u, int v, const std::string &source, const std::string &destination)
bool ApplySurfMatrixElem(const std::string &surf_mat, int row, int col, int x, int y, const std::string &destination="")
bool DeleteSurface(const std::string &name)
bool LoadSurface(const std::string &name, const std::string &filename)
Application quit.
Definition: sdltk.h:82
Button/key up.
Definition: sdltk.h:80
bool CreateWindow(std::string title, bool fullscreen=true, int width=-1, int height=-1, int x=-1, int y=-1)
Create teh application window.
Backspace key (ASCII code)
Definition: sdltk.h:95
bool CreateText(const std::string &text_name, const std::string &font_name, const ColorRGBA &col, const ColorRGBA &shadowcol=ColorRGBA(), int shadow_offset=1)
Coords Point
Coordinates at which the event occurred (see Point)
Definition: sdltk.h:118
Functor class for events handling.
Definition: sdltk.h:136
unsigned char G
Green component (0..255)
Definition: sdltk.h:169
virtual bool operator()(const sdltk::EventData &evt_data)=0
Functor operator.
bool GetSurfMatrixElemSize(const std::string &surf_mat, int &w, int &h)
void SetSoundsVolume(int vol)
Set the volume for sounds (0 to 128)
Coordinates at which the event occurred (see EventData)
Definition: sdltk.h:101
void UpdateWindow()
Redraw window surface.
void Delay(unsigned int ms)
Delay (suspend) the execution for the given milliseconds.
SdlApp()
Constructor: just initialize data members.
Button
Mouse/keyboard button (see EventData)
Definition: sdltk.h:86
Mouse move.
Definition: sdltk.h:81
void ExitSdl()
Destroy all and quit SDL library.
Tabulation key (ASCII code)
Definition: sdltk.h:96
bool NewSurface(const std::string &name, int width, int height)
bool LoadMusic(const std::string &name, std::string path="")
Mouse right button.
Definition: sdltk.h:90
std::string & MusicPath()
Access (read/change) the path containing the music files.
Definition: sdltk.h:289
bool InitSdl()
Initialize SDL library.
EventAction
Event action type (see EventData)
Definition: sdltk.h:76
EventAction Action
Event action type (see EventAction)
Definition: sdltk.h:124
Utility timer (e.g. for dynamics calculations)
Definition: sdltk.h:144
void SetMusicVolume(int vol)
Set the music volume (0 to 128)
std::string & SoundsPath()
Access (read/change) the path containing the sound files.
Definition: sdltk.h:286
Event data structure.
Definition: sdltk.h:112
void PlayMusic()
Play the music (start playing, continue, cycle thruogh the playlist)
void SwitchAudio(bool on)
Switch the audio on (true) or off (false)
bool LoadSound(const std::string &name, std::string path="")
void SetEventFunc(EventFunctor *func, bool auto_delete=true)
Definition: sdltk.h:273
Enter key (ASCII code)
Definition: sdltk.h:93
bool ExistsSurface(const std::string &name) const
Check if a named surface exists.
void RenderText(const std::string &text_name, int x, int y, const std::string &dest_surface="")
Escape key (ASCII code)
Definition: sdltk.h:92
unsigned char A
Alpha (opacity) component (0..255)
Definition: sdltk.h:171
void Stop()
Stop the timer.
unsigned int GetTimeMs()
Get the elapsed time in milliseconds.
void Start()
Start the timer.
No action.
Definition: sdltk.h:78
Button/key down.
Definition: sdltk.h:79