Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgapplication.h

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka
00004  
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009  
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014  
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021  
00022     Last Update:      $Author: mbickel $
00023     Update Date:      $Date: 2008-04-20 16:44:33 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/include/pgapplication.h,v $
00025     CVS/RCS Revision: $Revision: 1.3 $
00026     Status:           $State: Exp $
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_FULLSCREEN*/ | 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         //static bool GetGLMode();
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         This function savely discards all events in the eventqueue.
00513         All pending messages will be deleted and the memory freed.
00514         \note Your memory will leak if you just do a SDL_PollEvent
00515         because this won't delete pending usermessages.
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         // disable the copy operators
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         //static std::string app_path;
00680 
00681         static PG_Application* pGlobalApp;
00682         static SDL_Surface* screen;
00683 
00684         static bool bulkMode;
00685         //static bool glMode;
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

Generated on Tue Jun 24 01:27:47 2008 for Advanced Strategic Command by  doxygen 1.4.2