GUIApp.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2002-2007 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifndef GUIAPP_H
00020 #define GUIAPP_H
00021 
00022 #include <vector>
00023 #include <stack>
00024 #include <list>
00025 
00026 #include "SDL_events.h"
00027 #include "intrinsics.h"
00028 #include "Args.h"
00029 
00030 #include "CoreApp.h"
00031 #include "Mouse.h"
00032 
00033 class Kernel;
00034 class UCMachine;
00035 class Game;
00036 class Gump;
00037 class ConsoleGump;
00038 class GameMapGump;
00039 class ScalerGump;
00040 class InverterGump;
00041 class RenderSurface;
00042 class PaletteManager;
00043 class GameData;
00044 class World;
00045 class ObjectManager;
00046 class FontManager;
00047 class HIDManager;
00048 class AvatarMoverProcess;
00049 class IDataSource;
00050 class ODataSource;
00051 struct Texture;
00052 
00053 namespace Pentagram {
00054         class AudioMixer;
00055 
00056         const unsigned int savegame_version = 4;
00057 };
00058 
00059 // Hack alert
00060 struct HWMouseCursor;
00061 #if defined(WIN32) && defined(I_AM_COLOURLESS_EXPERIMENTING_WITH_HW_CURSORS)
00062 #include <windows.h>
00063 #endif
00064 
00065 class GUIApp : public CoreApp
00066 {
00067 public:
00068         ENABLE_RUNTIME_CLASSTYPE();
00069         
00070         GUIApp(int argc, const char* const* argv);
00071         virtual ~GUIApp();
00072         
00073         static GUIApp* get_instance()
00074                 { return p_dynamic_cast<GUIApp*>(application); }
00075         
00076         void startup();
00077         void shutdown();
00078 
00079         void startupGame();
00080         void startupPentagramMenu();
00081         void shutdownGame(bool reloading=true);
00082         void changeGame(Pentagram::istring newgame);
00083 
00084         void changeVideoMode(int width, int height, int fullscreen=-1); // -1 = no change, -2 = fullscreen toggle
00085         RenderSurface *getScreen() { return screen; }
00086 
00087         virtual void run();
00088         virtual void handleEvent(const SDL_Event& event);
00089         
00090         virtual void paint();
00091         virtual bool isPainting() { return painting; }
00092         
00093         
00094         INTRINSIC(I_getCurrentTimerTick);
00095         INTRINSIC(I_setAvatarInStasis);
00096         INTRINSIC(I_getAvatarInStasis);
00097         INTRINSIC(I_getTimeInGameHours);
00098         INTRINSIC(I_getTimeInMinutes);
00099         INTRINSIC(I_getTimeInSeconds);
00100         INTRINSIC(I_setTimeInGameHours);
00101         INTRINSIC(I_makeAvatarACheater);
00102         INTRINSIC(I_closeItemGumps);
00103 
00104         void setAvatarInStasis(bool stat) { avatarInStasis = stat; }
00105         bool isAvatarInStasis() const { return avatarInStasis; }
00106         void toggleAvatarInStasis() { avatarInStasis = !avatarInStasis; }
00107         bool isPaintEditorItems() const { return paintEditorItems; }
00108         void togglePaintEditorItems() { paintEditorItems = !paintEditorItems; }
00109         bool isShowTouchingItems() const { return showTouching; }
00110         void toggleShowTouchingItems() { showTouching = !showTouching; }
00111 
00112         uint32 getGameTimeInSeconds();
00113         
00114         GameMapGump* getGameMapGump() { return gameMapGump; }
00115         ConsoleGump* getConsoleGump() { return consoleGump; }
00116         Gump* getDesktopGump() { return desktopGump; }
00117         Gump* getGump(uint16 gumpid);
00118 
00121         void addGump(Gump* gump);
00122 
00123         AvatarMoverProcess* getAvatarMoverProcess() { return avatarMoverProcess; }
00124 
00128         bool saveGame(std::string filename, std::string desc,
00129                                   bool ignore_modals=false);
00130 
00134         bool loadGame(std::string filename);
00135 
00138         bool newGame();
00139 
00141         int getMouseLength(int mx, int my);
00142 
00144         int getMouseDirection(int mx, int my);
00145 
00147         void getMouseCoords(int& mx, int& my) { mx = mouseX; my = mouseY; }
00148 
00150         void setMouseCoords(int mx, int my);
00151 
00152         bool isMouseDown(MouseButton button);
00153 
00154         enum MouseCursor {
00155                 MOUSE_NORMAL = 0,
00156                 MOUSE_NONE = 1,
00157                 MOUSE_TARGET = 2,
00158                 MOUSE_PENTAGRAM = 3,
00159                 MOUSE_HAND = 4,
00160                 MOUSE_QUILL = 5,
00161                 MOUSE_MAGGLASS = 6,
00162                 MOUSE_CROSS = 7
00163         };
00164 
00166         void setMouseCursor(MouseCursor cursor);
00167 
00169         void flashCrossCursor();
00170 
00172         void pushMouseCursor();
00173 
00175         void popMouseCursor();
00176 
00178         void enterTextMode(Gump *);
00179 
00181         void leaveTextMode(Gump *);
00182 
00183 protected:
00184         virtual void DeclareArgs();
00185 
00186 private:
00187         uint32 save_count;
00188 
00190         void writeSaveInfo(ODataSource* ods);
00191 
00193         void save(ODataSource* ods);
00194 
00196         bool load(IDataSource* ids, uint32 version);
00197         
00199         void SDLInit();
00200 
00202         void resetEngine();
00203 
00205         void setupCoreGumps();
00206 
00208         void fullReset();
00209 
00210         // full system
00211         Game* game;
00212         Pentagram::istring change_gamename;
00213 
00214         Kernel* kernel;
00215         ObjectManager* objectmanager;
00216         HIDManager* hidmanager;
00217         UCMachine* ucmachine;
00218         RenderSurface *screen;
00219         bool fullscreen;
00220         PaletteManager *palettemanager;
00221         GameData *gamedata;
00222         World *world;
00223         FontManager* fontmanager;
00224         
00225         Gump                    *desktopGump;
00226         ConsoleGump             *consoleGump;
00227         GameMapGump             *gameMapGump;
00228         ScalerGump              *scalerGump;
00229         InverterGump    *inverterGump;
00230 
00231         AvatarMoverProcess* avatarMoverProcess;
00232         
00233         // called depending upon command line arguments
00234         void GraphicSysInit(); // starts/restarts the graphics subsystem
00235         bool LoadConsoleFont(std::string confontini); // loads the console font
00236         
00237         void handleDelayedEvents();
00238         
00239         // Various dependancy flags
00240         bool runSDLInit;
00241         
00242         // Timing stuff
00243         sint32 lerpFactor;              
00244         bool inBetweenFrame;    
00245         
00246         bool frameSkip;                 
00247         bool frameLimit;                
00248         bool interpolate;               
00249         sint32 animationRate;   
00250         
00251         // Sort of Camera Related Stuff, move somewhere else
00252         
00253         bool avatarInStasis;    
00254 
00255         bool paintEditorItems;  
00256         
00257         bool painting;                  
00258 
00259         bool showTouching;                      
00260 
00261         int mouseX, mouseY;
00262 
00263         Texture *defMouse;              
00264 
00266         int getMouseFrame();
00267         std::stack<MouseCursor> cursors;
00268         uint32 flashingcursor; // time (SDL_GetTicks) mouse started flashing, or 0
00269 
00270         // Hack alert
00271         HWMouseCursor                   *hwcursors;     // Shape frames converted into system specific format.
00272 
00273 #if defined(WIN32) && defined(I_AM_COLOURLESS_EXPERIMENTING_WITH_HW_CURSORS)
00274         void                                    CreateHWCursors();
00275         static LRESULT CALLBACK myWindowProc( HWND, UINT, WPARAM, LPARAM );
00276 
00277 #endif
00278 
00279         static void     conAutoPaint(void);
00280 
00281         // mouse input state
00282         MButton mouseButton[MOUSE_LAST];
00283 
00284         uint16 mouseOverGump;
00285 
00286         enum DraggingState {
00287                 DRAG_NOT = 0,
00288                 DRAG_OK = 1,
00289                 DRAG_INVALID = 2,
00290                 DRAG_TEMPFAIL = 3
00291         } dragging;
00292         ObjId dragging_objid;
00293         uint16 dragging_item_startgump;
00294         uint16 dragging_item_lastgump;
00295 
00296         int dragging_offsetX, dragging_offsetY;
00297         unsigned int inversion;
00298 public:
00299         void setDraggingOffset(int x, int y)
00300                 { dragging_offsetX = x; dragging_offsetY = y; }
00301         void getDraggingOffset(int& x, int& y)
00302                 { x = dragging_offsetX; y = dragging_offsetY; }
00303 
00304         unsigned int getInversion() const { return inversion; }
00305         void setInversion(unsigned int i) { inversion = i & 0xFFFF; }
00306         bool isInverted() { return ( inversion >= 0x4000 && inversion < 0xC000 ); }
00307 
00308 private:
00309         void startDragging(int mx, int my);
00310         void moveDragging(int mx, int my);
00311         void stopDragging(int mx, int my);
00312 
00313         sint32 timeOffset;
00314         bool has_cheated;
00315 
00316 public:
00317         bool hasCheated() const { return has_cheated; }
00318         void makeCheater() { has_cheated = true; }
00319 
00320 private:
00321 
00322         std::list<ObjId>        textmodes;              
00323 
00324         // Load and save games from arbitrary filenames from the console
00325         static void                     ConCmd_saveGame(const Console::ArgvType &argv);                 
00326         static void                     ConCmd_loadGame(const Console::ArgvType &argv);                 
00327         static void                     ConCmd_newGame(const Console::ArgvType &argv);                  
00328 
00329         static void                     ConCmd_quit(const Console::ArgvType &argv);                             
00330 
00331         static void                     ConCmd_changeGame(const Console::ArgvType &argv);               
00332         static void                     ConCmd_listGames(const Console::ArgvType &argv);                        
00333 
00334         static void                     ConCmd_setVideoMode(const Console::ArgvType &argv);             
00335         static void                     ConCmd_toggleFullscreen(const Console::ArgvType &argv); 
00336 
00337         // This should be a console variable once they are implemented
00338         bool                            drawRenderStats;
00339         static void                     ConCmd_drawRenderStats(const Console::ArgvType &argv);  
00340 
00341         static void                     ConCmd_engineStats(const Console::ArgvType &argv);      
00342 
00343         static void                     ConCmd_toggleAvatarInStasis(const Console::ArgvType &argv);     
00344         static void                     ConCmd_togglePaintEditorItems(const Console::ArgvType &argv);   
00345         static void                     ConCmd_toggleShowTouchingItems(const Console::ArgvType &argv);  
00346 
00347         static void                     ConCmd_closeItemGumps(const Console::ArgvType &argv);   
00348 
00349         bool                            ttfoverrides;
00350 
00351         // Audio Mixer
00352         Pentagram::AudioMixer *audiomixer;
00353 };
00354 
00355 #endif

Generated on Fri Jul 27 22:27:17 2007 for pentagram by  doxygen 1.4.7