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
00026
00027
00028
00034 #ifndef PG_APPLICATION_H
00035 #define PG_APPLICATION_H
00036
00037 #include "pgmessageobject.h"
00038 #include "pgfilearchive.h"
00039 #include "pgfont.h"
00040 #include "pgdraw.h"
00041
00042 class PG_EventSupplier;
00043
00044 class PG_Theme;
00045 class PG_Widget;
00046
00095 class PG_XMLTag;
00096
00097 class DECLSPEC PG_Application : public PG_MessageObject, public PG_FileArchive, public PG_FontEngine {
00098 public:
00099
00101 typedef enum {
00102 QUERY,
00103 NONE,
00104 HARDWARE,
00105 SOFTWARE
00106 } CursorMode;
00107
00108 enum {
00109 IDAPPLICATION = PG_WIDGETID_INTERNAL + 100
00110 };
00111
00116 template<class datatype = PG_Pointer>
00117 class SignalXMLTag : public PG_Signal1<PG_XMLTag*, datatype> {}
00118 ;
00119 template<class datatype = PG_Pointer>
00120 class SignalAppIdle : public PG_Signal1<PG_MessageObject*, datatype> {}
00121 ;
00122
00124 PG_Application();
00125
00127 ~PG_Application();
00128
00137 bool InitScreen(int w, int h, int depth=0, Uint32 flags = SDL_SWSURFACE | SDL_HWPALETTE);
00138
00146 PG_Theme* LoadTheme(const std::string& xmltheme, bool asDefault = true, const std::string& searchpath = PG_NULLSTR);
00147
00154 void Run();
00155
00159 virtual void RunEventLoop();
00160
00164 void Quit();
00165
00172 SDL_Surface* SetScreen(SDL_Surface* screen, bool initialize = true);
00173
00179 static inline SDL_Surface* GetScreen() {
00180 return screen;
00181 }
00182
00188 inline static bool LockScreen() {
00189 return SDL_mutexP(mutexScreen) == 0;
00190 }
00191
00192
00198 inline static bool UnlockScreen() {
00199 return (SDL_mutexV(mutexScreen) == 0);
00200 }
00201
00209 bool SetBackground(const std::string& filename, PG_Draw::BkMode mode=PG_Draw::TILE);
00210
00219 bool SetBackground(SDL_Surface* surface, PG_Draw::BkMode mode=PG_Draw::TILE, bool freeBackground = false );
00220
00226 static void RedrawBackground(const PG_Rect& rect);
00227
00233 void SetEmergencyQuit(bool esc);
00234
00241 static const std::string& GetRelativePath(const std::string& file);
00242
00248 static int GetScreenHeight();
00249
00255 static int GetScreenWidth();
00256
00260 static void FlipPage();
00261
00266 void PrintVideoTest();
00267
00273 static PG_Theme* GetTheme();
00274
00281 static bool GetBulkMode();
00282
00293 static void SetBulkMode(bool bulk = true);
00294
00295
00296
00297 void EnableBackground(bool enable = true);
00298
00299 void DeleteBackground();
00300
00312 void EnableAppIdleCalls(bool enable = true);
00313
00323 void SetIcon(const std::string& filename);
00324
00332 void SetCaption(const std::string& title, const std::string& icon = PG_NULLSTR);
00333
00341 void GetCaption(std::string& title, std::string& icon);
00342
00349 int Iconify(void);
00350
00356 static bool LoadLayout(const std::string& name);
00357
00364 static bool LoadLayout(const std::string& name, void (* WorkCallback)(int now, int max));
00365
00373 static bool LoadLayout(const std::string& name, void (* WorkCallback)(int now, int max), void *UserSpace);
00374
00380 static PG_Widget *GetWidgetByName(const std::string& Name);
00381
00382 template<class T>
00383 static T* GetWidget(const std::string& Name) {
00384 return static_cast<T*>(GetWidgetByName(Name));
00385 }
00386
00387 template<class T>
00388 static T* GetWidget(int id) {
00389 return static_cast<T*>(GetWidgetById(id));
00390 }
00391
00397 static PG_Widget *GetWidgetById(int id);
00398
00404 static void SetFontColor(const PG_Color& Color);
00405
00411 static void SetFontAlpha(int Alpha);
00412
00418 static void SetFontStyle(PG_Font::Style Style);
00419
00425 static void SetFontSize(int Size);
00426
00432 static void SetFontIndex(int Index);
00433
00439 static void SetFontName(const std::string& Name);
00440
00442
00462 static void SetCursor(SDL_Surface *image);
00463
00465
00470 static void DrawCursor(bool update = true);
00471
00473
00479 static CursorMode ShowCursor(CursorMode mode);
00480
00482
00491 static void DisableDirtyUpdates(bool disable);
00492
00494
00497 static bool GetDirtyUpdatesDisabled();
00498
00499 static PG_Application* GetApp();
00500
00501 static PG_Font* DefaultFont;
00502
00508 bool GetAppIdleCallsEnabled();
00509
00511
00512
00513
00514
00515
00516
00517 static void FlushEventQueue();
00518
00520
00526 static void ClearOldMousePosition();
00527
00533 static void TranslateNumpadKeys(SDL_KeyboardEvent *key);
00534
00541 bool PumpIntoEventQueue(const SDL_Event* event);
00542
00543
00552 static void SetEventSupplier( PG_EventSupplier* eventSupplier );
00553
00559 static PG_EventSupplier* GetEventSupplier();
00560
00569 static void SetUpdateOverlappingSiblings(bool update = true);
00570
00575 static bool GetUpdateOverlappingSiblings();
00576
00577 static void SetHighlightingTag( PG_Char c );
00578
00579 static PG_Char GetHighlightingTag();
00580
00581 static void UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Sint32 w, Sint32 h);
00582 static void UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects);
00583
00584 SignalXMLTag<> sigXMLTag;
00585 SignalAppIdle<> sigAppIdle;
00586
00587
00588 class BulkModeActivator {
00589 bool active;
00590 public:
00591 BulkModeActivator() {
00592 active = PG_Application::GetBulkMode();
00593 if ( !active )
00594 PG_Application::SetBulkMode( true );
00595 };
00596 void disable() {
00597 if ( !active )
00598 PG_Application::SetBulkMode( false );
00599 active = true;
00600 }
00601 ~BulkModeActivator() {
00602 disable();
00603 };
00604 };
00605
00606 class ScreenLocker {
00607 bool active;
00608 public:
00609 ScreenLocker() {
00610 active = false;
00611 };
00612 ScreenLocker( bool doLock) {
00613 active = false;
00614 if ( doLock )
00615 lock();
00616 };
00617 void lock() {
00618 if ( !active ) {
00619 LockScreen();
00620 active = true;
00621 }
00622 }
00623 void unlock() {
00624 if ( active ) {
00625 UnlockScreen();
00626 active = false;
00627 }
00628 }
00629 ~ScreenLocker() {
00630 unlock();
00631 };
00632 };
00633
00634
00635
00636 protected:
00637
00641 void Shutdown();
00642
00644 bool eventKeyUp(const SDL_KeyboardEvent* key);
00645
00647 bool eventKeyDown(const SDL_KeyboardEvent* key);
00648
00650 bool eventQuit(int id, PG_MessageObject* widget, unsigned long data);
00651
00653 bool eventResize(const SDL_ResizeEvent* event);
00654
00656 virtual void eventInit();
00657
00659 virtual void eventIdle();
00660
00661 bool my_quitEventLoop;
00662
00663
00664
00665 private:
00666
00667
00668 PG_Application(const PG_Application&);
00669 PG_Application& operator=(const PG_Application&);
00670
00671 bool my_freeBackground;
00672 static SDL_Surface* my_background;
00673 static SDL_Surface* my_scaled_background;
00674 static PG_Color my_backcolor;
00675 static PG_Draw::BkMode my_backmode;
00676
00677 static PG_Theme* my_Theme;
00678
00679
00680
00681 static PG_Application* pGlobalApp;
00682 static SDL_Surface* screen;
00683
00684 static bool bulkMode;
00685
00686 bool emergencyQuit;
00687 static bool enableBackground;
00688 bool enableAppIdleCalls;
00689 static PG_EventSupplier* my_eventSupplier;
00690 static PG_EventSupplier* my_defaultEventSupplier;
00691
00692 static SDL_Surface* my_mouse_pointer;
00693 static SDL_Surface* my_mouse_backingstore;
00694 static PG_Rect my_mouse_position;
00695 static CursorMode my_mouse_mode;
00696 static SDL_mutex* mutexScreen;
00697 static bool disableDirtyUpdates;
00698 static bool defaultUpdateOverlappingSiblings;
00699
00700 static PG_Char highlightingTag;
00701 };
00702
00713 int PG_main(int argc, char **argv, PG_Application *app);
00714
00715 #endif // PG_APPLICATION_H