00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef SDLMANAGER_H
00023 #define SDLMANAGER_H
00024
00025 #include "SDL/SDL.h"
00026 #include "tinyxml.h"
00027 #include <list>
00028 #include "sdlsurface.h"
00029
00030 #define RGB( r,g,b ) SDL_MapRGB( SdlManager::the->getDisplay()->surf()->format, r, g, b )
00031
00032 using namespace std;
00033
00034 class SdlSurfaceContainer;
00035 class SdlAudio;
00036 class SdlMusicList;
00037
00069 class DECLSPEC SdlManager
00070 {
00071 public:
00072 DECLSPEC SdlManager();
00073 virtual DECLSPEC ~SdlManager();
00074
00080 DECLSPEC bool init();
00098 DECLSPEC bool init( TiXmlElement *el );
00109 DECLSPEC bool init( Uint32 width, Uint32 height, Uint32 &depth, bool fullscreen = true );
00114 DECLSPEC void destroy();
00115
00117 bool isAudioInited() { return bAudioInited; }
00119 bool isVideoInited() { return bVideoInited; }
00120
00125 DECLSPEC void refreshSoundVolumes();
00126
00133 DECLSPEC SdlAudio *getAudioByName( const char *name );
00140 DECLSPEC SdlSurface *getSurfaceByName( const char *name );
00147 DECLSPEC SdlSurfaceContainer *getSurfacesByName( const char *name );
00154 DECLSPEC SdlMusicList *getMusicsByName( const char *name );
00159 SdlSurface *getDisplay() { SDL_SetClipRect( surfDisplay->surf(), 0 ); return surfDisplay; }
00167 DECLSPEC bool getScreenSize( int &w, int &h );
00172 DECLSPEC SDL_Rect getScreenRect();
00173
00187 DECLSPEC bool screenShot( const char *fn = 0, bool nooverwrite = true );
00189 static void grabInput(void) {if(bGrabInputEnabled) SDL_WM_GrabInput( SDL_GRAB_ON );}
00191 static void ungrabInput(void) {SDL_WM_GrabInput( SDL_GRAB_OFF );}
00192
00196 static SdlManager *the;
00204 DECLSPEC static SdlManager *getThe();
00205
00207 static bool bGrabInputEnabled;
00208 private:
00209 bool initDisplay( Uint32 w, Uint32 h, Uint32 &d, bool fullscr = true );
00210 bool initAudio( Uint8 channels = 2, int freq = 22050, Uint16 format = AUDIO_S16SYS );
00211 SdlSurface *surfDisplay;
00212
00213 bool bVideoInited, bAudioInited;
00214 Uint32 nColorDepth;
00215 bool bFullScreen;
00216
00217 list<SdlAudio*> lAudios, lFailedAudios;
00218 list<SdlSurface*> lSurfaces, lFailedSurfaces;
00219 list<SdlSurfaceContainer*> lSurfaceContainers, lFailedSurfaceContainers;
00220 list<SdlMusicList*> lMusicLists;
00221 typedef list<SdlAudio*>::iterator AudioIter;
00222 typedef list<SdlSurface*>::iterator SurfaceIter;
00223 typedef list<SdlSurfaceContainer*>::iterator SurfacesIter;
00224 typedef list<SdlMusicList*>::iterator MusicsIter;
00225
00226 friend class SdlAudio;
00227 friend class SdlSurface;
00228 friend class SdlSurfaceContainer;
00229 friend class SdlMusicList;
00230 };
00231
00232 #endif