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

window.h

00001 /***************************************************************************
00002                           window.h  -  description
00003                              -------------------
00004     begin                : Thu Aug 28 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 WINDOW_H
00019 #define WINDOW_H
00020 
00021 #include "../constants.h"
00022 #include "../sdlhandler.h"
00023 #include "widget.h"
00024 #include "button.h"
00025 #include "label.h"
00026 #include "checkbox.h"
00027 #include "textfield.h"
00028 #include "guitheme.h"
00029 
00034 class SDLHandler;
00035 class Widget;
00036 class Button;
00037 class Label;
00038 class Checkbox;
00039 class TextField;
00040 
00041 class Window : public Widget {
00042  private:
00043   // the image is 510x270
00044   static const int TILE_W=510 / 2;
00045   static const int TILE_H=270 / 2; 
00046 
00047   static const int MAX_WINDOW = 1000;
00048   static const int MAX_WIDGET = 1000;
00049 
00050   char title[255];
00051   GLuint texture, texture2;
00052   SDLHandler *sdlHandler;
00053   Widget *widget[MAX_WIDGET];
00054   int tileWidth, tileHeight;
00055   int widgetCount;
00056   bool dragging;
00057   int dragX, dragY;
00058   int openHeight, currentY;
00059   GLint lastTick;
00060   int z;  
00061   bool modal;
00062   int type;
00063   bool locked;
00064   GuiTheme *theme;
00065   bool opening;
00066 
00067   static Window *window[];
00068   static int windowCount;  
00069 
00070   static Window *message_dialog;
00071   static Label *message_label;
00072   static Window *currentWin;
00073 
00074   Widget *lastWidget;
00075   int animation;
00076 
00077  public: 
00078 
00079   enum {
00080     DEFAULT_ANIMATION=0,
00081     SLIDE_UP
00082   };
00083    
00084    static const char ROLL_OVER_SOUND[80];
00085    static const char ACTION_SOUND[80];
00086    static const char DROP_SUCCESS[80];
00087    static const char DROP_FAILED[80];
00088    
00089    static bool windowWasClosed;
00090    
00091    Button *closeButton;
00092    
00093    enum {
00094      BASIC_WINDOW=0,
00095      SIMPLE_WINDOW
00096    };
00097 
00098   static const int TOP_HEIGHT = 20;
00099   static const int BOTTOM_HEIGHT = 5;
00100   static const int SCREEN_GUTTER = 5;
00101 
00102   Window(SDLHandler *sdlHandler, int x, int y, int w, int h, char *title=NULL, 
00103          GLuint texture=0, bool hasCloseButton=true, int type=BASIC_WINDOW, 
00104          GLuint texture2=0);
00105 
00106   Window( SDLHandler *sdlHandler, int x, int y, int w, int h, char *title=NULL, 
00107                   bool hasCloseButton=true, int type=BASIC_WINDOW, const char *themeName=NULL );
00108 
00109   ~Window();
00110 
00111   inline void setAnimation( int a ) { animation = a; }
00112   inline int getAnimation() { return animation; }
00113 
00114   inline GuiTheme *getTheme() { return theme; }
00115 
00116   inline void setTitle(char *s) { strncpy(title, ( s ? s : "" ), 255); title[254] = '\0'; }
00117 
00118   inline bool isOpening() { 
00119     return ( opening ); 
00120   }
00121 
00122   inline void setBackgroundTileWidth(int n) { tileWidth = n; }
00123   inline void setBackgroundTileHeight(int n) { tileHeight = n; }
00124   
00125   inline void setZ(int z) { this->z = z; }
00126   inline int getZ() { return z; }
00127 
00128   inline void setModal(bool b) { modal = b; }
00129   inline bool isModal() { return modal; }
00130 
00131   void setVisible(bool b, bool animate=true);
00132   inline SDLHandler *getSDLHandler() { return sdlHandler; }
00133   void toTop();
00134   void toBottom();
00135 
00136   inline void setLocked(bool locked) { this->locked = locked; if(locked) toBottom(); }
00137   inline bool isLocked() { return locked; }
00138 
00139   // crop view to window area. Don't forget to call glDisable( GL_SCISSOR_TEST ) after!
00140   void scissorToWindow( bool insideOnly=true );
00141   
00142   // widget managment functions
00143   Button    * createButton(int x1, int y1, int x2, int y2, char *label, bool toggle=false);    
00144   Label     * createLabel(int x1, int x2, char * label, int color=Constants::DEFAULT_COLOR); 
00145   Checkbox  * createCheckbox(int x1, int y1, int x2, int y2, char *label);  
00146   TextField * createTextField(int x, int y, int numChars);
00147   void addWidget(Widget *widget);
00148   void removeWidget(Widget *widget);
00149   Widget *handleWindowEvent(SDL_Event *event, int x, int y);
00150   void setFocus(Widget *w);
00151   void nextFocus();
00152   void prevFocus();
00153 
00154   // from Widget
00155   void drawWidget(Widget *parent);
00156   bool handleEvent(Widget *parent, SDL_Event *event, int x, int y);
00157   bool isInside(int x, int y);
00158   
00159   
00160   // window management
00161   static void drawVisibleWindows();
00162   static void addWindow(Window *win);
00163   static void removeWindow(Window *win);
00164   static Widget *delegateEvent(SDL_Event *event, int x, int y);
00165   static void toTop(Window *win);
00166   static void toBottom(Window *win);
00167   static void nextWindowToTop();
00168   static void prevWindowToTop();
00169 
00170   // static message dialog
00171   static Button *message_button; // so you can check for it in other classes
00172   static void showMessageDialog(SDLHandler *sdlHandler, 
00173   int x, int y, int w, int h, 
00174   char *title, GLuint texture,
00175   char *message, 
00176   char *buttonLabel = Constants::messages[Constants::OK_LABEL][0]);
00177 
00178   void move(int x, int y);
00179 
00180   void setLastWidget(Widget *w);
00181  protected:
00182   void commonInit(SDLHandler *sdlHandler, int x, int y, int w, int h, char *title, bool hasCloseButton, int type);
00183 };
00184 
00185 #endif
00186 

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