Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields

sdlhandler.h

00001 /***************************************************************************
00002                           sdlhandler.h  -  description
00003                              -------------------
00004     begin                : Sat May 3 2003
00005     copyright            : (C) 2003 by Gabor Torok
00006     email                : cctorok@yahoo.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef SDLHANDLER_H
00019 #define SDLHANDLER_H
00020 
00021 #include <iostream>
00022 #include <stdlib.h>
00023 #include <stdarg.h>
00024 #include "constants.h"
00025 #include "sdleventhandler.h"
00026 #include "sdlscreenview.h"
00027 #include "shapepalette.h"
00028 #include "text.h"
00029 #include "gui/window.h"
00030 #include "userconfiguration.h"
00031 #include "freetype/FreeType.h"
00032 #include "sound.h"
00033 
00034 class TexturedText;
00035 
00043 #define MAX_TICK_COUNT 20
00044 
00045 /* screen width, height, and bit depth */
00046 #define SCREEN_WIDTH  640
00047 #define SCREEN_HEIGHT 480
00048 #define SCREEN_BPP     16
00049 
00050 /* Define our booleans */
00051 #define TRUE  1
00052 #define FALSE 0
00053 
00054 class ShapePalette;                          
00055 class SDLEventHandler;
00056 class UserConfiguration;
00057 class Sound;
00058 
00059 class SDLHandler {
00060 private:
00061   /* These are to calculate our fps */
00062   Sound *sound;
00063   GLint T0, Frames;
00064   double fps;
00065   SDL_Surface *screen;
00066   SDLEventHandler *eventHandler;
00067   SDLScreenView *screenView;
00068   /* Flags to pass to SDL_SetVideoMode */
00069   int videoFlags;
00070   ShapePalette *shapePal;
00071   bool invertMouse;
00072   int cursorMode;
00073 
00074   // rotation for test draw view
00075   GLfloat rtri, rquad;
00076   int lastWidth, lastHeight;
00077 
00078   TexturedText *text;
00079 
00080   SDLEventHandler *eventHandlers[10];
00081   SDLScreenView *screenViews[10];
00082   int handlerCount;
00083 
00084   // the last event fired by a widget
00085   Widget *storedWidget;
00086   SDL_Event *storedEvent; 
00087   
00088   // truetype font  
00089   freetype_font_data font, monoFont, largeFont;
00090   bool font_initialized;
00091   int fontType;
00092 
00093   char *debugStr;
00094 
00095   bool attackCursor;
00096 
00097   // only do stencil buffer ops if this is true
00098   static bool stencilBufferUsed;
00099 
00100 public: 
00101 
00102   static bool showDebugInfo;
00103 
00104   enum {
00105     SCOURGE_DEFAULT_FONT=0,
00106     SCOURGE_MONO_FONT,
00107     SCOURGE_LARGE_FONT
00108   };
00109 
00110   bool dontUpdateScreen;
00111 
00112   enum {
00113     CURSOR_NORMAL=0,
00114     CURSOR_CROSSHAIR,
00115     CURSOR_ATTACK,
00116     CURSOR_TALK
00117   };  
00118 
00119   SDLHandler(ShapePalette *shapePal);
00120   ~SDLHandler();
00121 
00122   void drawTooltip( float xpos2, float ypos2, float zpos2, 
00123                     float zrot, float yrot, 
00124                     char *message );
00125 
00126   inline void setDebugStr(char *s) { debugStr = s; }
00127   
00128   Uint16 mouseX, mouseY, lastMouseX, lastMouseY;
00129   Uint16 mouseFocusX, mouseFocusY;
00130   Uint8 mouseButton, mouseEvent;
00131   bool mouseDragging;
00132   bool mouseIsMovingOverMap;
00133   Uint32 lastMouseMoveTime;
00134   Uint32 lastLeftClick;
00135   bool isDoubleClick;
00136 
00137   void setOrthoView();
00138 
00139   inline Sound *getSound() { return sound; }
00140 
00141   void setCursorMode(int n) { cursorMode = n; }
00142   int getCursorMode() { return cursorMode; }
00143   void applyMouseOffset(int x, int y, int *newX, int *newY);
00144 
00150   void pushHandlers(SDLEventHandler *eventHandler, SDLScreenView *screenView);
00151 
00155   void setHandlers(SDLEventHandler *eventHandler, SDLScreenView *screenView);
00156 
00160   inline SDLEventHandler *getEventHandler() { return eventHandler; }
00161    
00162   void setVideoMode(UserConfiguration *uc);
00163   char ** getVideoModes(int &nbModes);
00164   void mainLoop();
00165   void drawScreen();
00166   void fireEvent(Widget *widget, SDL_Event *event);
00167   bool firedEventWaiting();
00168 
00169   inline void setFontType( int fontType ) { this->fontType = fontType; }
00170   inline int getFontType() { return fontType; }
00171   void texPrint(GLfloat x, GLfloat y, const char *fmt, ...);
00172   int textWidth( const char *fmt, ... );
00173   const freetype_font_data *getCurrentFont();
00174   void initFonts();
00175 
00176   GLvoid glPrint( const char *fmt, ... );
00177 
00178   static bool intersects(SDL_Rect *r1, SDL_Rect *r2);
00179   static bool sectionIntersects(int a1, int a2, int b1, int b2);
00180 
00181   inline double getFps() { return fps; }
00182 
00183   inline SDL_Surface *getScreen() { return screen; }  
00184 
00185   void testDrawView();
00186 
00187   inline ShapePalette *getShapePalette() { return shapePal; }
00188  
00189   void quit( int returnCode );
00190 
00191   inline double getFPS() { return fps; }
00192 
00193 protected:
00194     bool popHandlers();
00195     int resizeWindow( int width, int height );
00196     int initGL( GLvoid );  
00197     GLvoid buildFont( GLvoid );
00198 };
00199 
00200 #endif

Generated on Thu Jun 16 21:50:43 2005 for scourge by  doxygen 1.4.0