00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _WG_APPLICATION_H_
00026 #define _WG_APPLICATION_H_
00027
00028 #include "SDL.h"
00029 #include <list>
00030 #include <string>
00031 #include <map>
00032 #include <memory>
00033 #include "wg_window.h"
00034 #include "wg_message_server.h"
00035 #include "wg_message_client.h"
00036 #include "wg_fontengine.h"
00037 #include "wg_resources.h"
00038 #include "wutil_config_store.h"
00039 #include "wutil_log.h"
00040 #include "std_ex.h"
00041
00042
00043 namespace
00044 {
00045 const int DEFAULT_BPP = 32;
00046 }
00047
00048
00049 namespace wGui
00050 {
00051
00053 enum EAppLogSeverity
00054 {
00055 APP_LOG_CRITICAL = 1,
00056 APP_LOG_ERROR = 3,
00057 APP_LOG_WARNING = 5,
00058 APP_LOG_INFO = 8
00059 };
00060
00061
00063
00067
00068 class CApplication : public CMessageClient
00069 {
00070 public:
00076 CApplication(int argc, char** argv, std::wstring sFontFileName = L"Vera.ttf", bool bHandleExceptionsInternally = true);
00077
00079 virtual ~CApplication(void);
00080
00083 static CApplication* Instance(void) { return m_pInstance; }
00084
00087 virtual const std::wstring& GetDefaultFontFileName(void) const { return m_sFontFileName; }
00088
00091 virtual int ExitCode(void) const { return m_iExitCode; }
00092
00095 virtual bool IsRunning(void) const { return m_bRunning; }
00096
00099 virtual bool HandleExceptions(void) const { return m_bHandleExceptionsInternally; }
00100
00103 virtual bool IsInitialized(void) const { return m_bInited; }
00104
00108 virtual void SetKeyFocus(CWindow* pWindow);
00109
00112 virtual CWindow* GetKeyFocus(void) const { return m_pKeyFocusWindow; }
00113
00117 virtual void SetMouseFocus(CWindow* pWindow);
00118
00121 virtual CWindow* GetMouseFocus(void) const { return m_pMouseFocusWindow; }
00122
00125 virtual void Init(void);
00126
00128 virtual void Exec(void);
00129
00132 virtual void ApplicationExit(int iExitCode = EXIT_SUCCESS);
00133
00139 virtual CFontEngine* GetFontEngine(std::wstring sFontFileName, unsigned char iFontSize = 12);
00140
00143 virtual void SetDefaultFontEngine(CFontEngine* pFontEngine) { m_pDefaultFontEngine = pFontEngine; }
00144
00147 virtual CFontEngine* GetDefaultFontEngine(void) const { return m_pDefaultFontEngine; }
00148
00151 virtual int GetBitsPerPixel(void) const { return m_iBitsPerPixel; }
00152
00155 virtual CRGBColor GetDefaultBackgroundColor(void) const { return m_DefaultBackgroundColor; }
00156
00159 virtual CRGBColor GetDefaultForegroundColor(void) const { return m_DefaultForegroundColor; }
00160
00163 virtual CRGBColor GetDefaultSelectionColor(void) const { return m_DefaultSelectionColor; }
00164
00169 virtual void EnableResourcePool(bool bEnable);
00170
00175 virtual bool AddToResourcePool(CResourceHandle& ResourceHandle);
00176
00179 virtual void SetMouseCursor(CCursorResourceHandle* pCursorResourceHandle = 0);
00180
00184 virtual void SetMousePosition( const CPoint& Point )
00185 { SDL_WarpMouse(stdex::safe_static_cast<Uint16>(Point.XPos()), stdex::safe_static_cast<Uint16>(Point.YPos())); }
00186
00189 virtual void SetMouseVisibility( bool bVisible ) { SDL_ShowCursor(bVisible); }
00190
00200 virtual const wUtil::CConfigStore& GetGlobalConfig(void) { return m_GlobalConfig; }
00201
00204 virtual wUtil::CLog& GetApplicationLog(void) { return m_AppLog; }
00205
00206
00207
00210 virtual bool HandleMessage(CMessage* pMessage);
00211
00212
00213 protected:
00214
00218 virtual void HandleSDLEvent(SDL_Event event);
00219
00220 static CApplication* m_pInstance;
00221 int m_argc;
00222 char** m_argv;
00223 std::wstring m_sFontFileName;
00224 int m_iExitCode;
00225 bool m_bRunning;
00226 bool m_bInited;
00227 CWindow* m_pKeyFocusWindow;
00228 CWindow* m_pMouseFocusWindow;
00229
00230 typedef std::pair<std::wstring, unsigned char> t_FontEngineMapKey;
00231 typedef std::map<t_FontEngineMapKey, CFontEngine*> t_FontEngineMap;
00232 t_FontEngineMap m_FontEngines;
00233 CFontEngine* m_pDefaultFontEngine;
00234
00235 int m_iBitsPerPixel;
00236 CRGBColor m_DefaultBackgroundColor;
00237 CRGBColor m_DefaultForegroundColor;
00238 CRGBColor m_DefaultSelectionColor;
00239
00240 bool m_bHandleExceptionsInternally;
00241 bool m_bResourcePoolEnabled;
00242 std::list<CResourceHandle> m_ResourceHandlePool;
00243 std::auto_ptr<CCursorResourceHandle> m_pCurrentCursorResourceHandle;
00244 SDL_Cursor* m_pSystemDefaultCursor;
00245 wUtil::CConfigStore m_GlobalConfig;
00246 wUtil::CLog m_AppLog;
00247 };
00248
00249
00250 }
00251
00252
00253 #include "unit_tests/wg_application_unittests.h"
00254
00255 #endif // _WG_APPLICATION_H_