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

io.h

Go to the documentation of this file.
00001 
00006 #ifndef SYS_IO_H
00007 #define SYS_IO_H
00008 
00009 
00010 #include <string>
00011 
00012 
00013 #include "menus.h"
00014 #include "config.h"
00015 
00016 
00017 #ifdef GLUT
00018 #define EVENT_FOR_MOUSE_MOVES
00019 #else
00020 #define POLL_FOR_MOUSE_MOVES
00021 #endif
00022 
00023 
00025 typedef enum
00026 {
00027   IO_None = 0,
00028   IO_Initialize,
00029   IO_Resize,
00030   IO_Render,
00031   IO_Exit,
00032   IO_KeyPress,
00033   IO_KeyRelease,
00034   IO_MouseMove,
00035   IO_MenuEvent
00036 } IO_EventId;
00037 
00038 /* control key state masks */
00039 #define IO_CONTROL 0x01
00040 #define IO_ALT     0x02
00041 #define IO_SHIFT   0x04
00042 #define IO_CAPS    0x08
00043 
00044 /* @brief Enumeration of keys and any other input device that acts like a key
00045    (mouse buttons, etc) */
00046 typedef enum
00047 {
00048   IO_Invalid = 0x00,
00049 
00050   IO_Escape,
00051 
00052   IO_F1,
00053   IO_F2,
00054   IO_F3,
00055   IO_F4,
00056   IO_F5,
00057   IO_F6,
00058   IO_F7,
00059   IO_F8,
00060   IO_F9,
00061   IO_F10,
00062   IO_F11,
00063   IO_F12,
00064 
00065   IO_PrintScreen,
00066   /*IO_ScrollLock,*/
00067   IO_Pause,
00068 
00069   IO_Tilde,
00070   IO_1,
00071   IO_2,
00072   IO_3,
00073   IO_4,
00074   IO_5,
00075   IO_6,
00076   IO_7,
00077   IO_8,
00078   IO_9,
00079   IO_0,
00080   IO_Dash,
00081   IO_Equals,
00082   IO_BackSpace,
00083 
00084   IO_Tab,
00085   IO_Q,
00086   IO_W,
00087   IO_E,
00088   IO_R,
00089   IO_T,
00090   IO_Y,
00091   IO_U,
00092   IO_I,
00093   IO_O,
00094   IO_P,
00095   IO_LBracket,
00096   IO_RBracket,
00097   IO_BackSlash,
00098 
00099   /*IO_CapsLock,*/
00100   IO_A,
00101   IO_S,
00102   IO_D,
00103   IO_F,
00104   IO_G,
00105   IO_H,
00106   IO_J,
00107   IO_K,
00108   IO_L,
00109   IO_Semicolon,
00110   IO_Apostrophe,
00111   IO_Enter,
00112 
00113   IO_Z,
00114   IO_X,
00115   IO_C,
00116   IO_V,
00117   IO_B,
00118   IO_N,
00119   IO_M,
00120   IO_Comma,
00121   IO_Period,
00122   IO_Slash,
00123   IO_Space,
00124 
00125   IO_Insert,
00126   IO_Home,
00127   IO_PageUp,
00128   IO_Delete,
00129   IO_End,
00130   IO_PageDown,
00131 
00132   IO_Up,
00133   IO_Down,
00134   IO_Left,
00135   IO_Right,
00136 
00137   /*IO_KP_NumLock,*/
00138   IO_KP_Slash,
00139   IO_KP_Star,
00140   IO_KP_Dash,
00141   IO_KP_Plus,
00142   IO_KP_Enter,
00143 
00144   IO_KP_Home,
00145   IO_KP_Up,
00146   IO_KP_PageUp,
00147   IO_KP_Left,
00148   IO_KP_Right,
00149   IO_KP_End,
00150   IO_KP_Down,
00151   IO_KP_PageDown,
00152   IO_KP_Insert,
00153   IO_KP_Delete,
00154 
00155   IO_KP_0,
00156   IO_KP_1,
00157   IO_KP_2,
00158   IO_KP_3,
00159   IO_KP_4,
00160   IO_KP_5,
00161   IO_KP_6,
00162   IO_KP_7,
00163   IO_KP_8,
00164   IO_KP_9,
00165   IO_KP_Period,
00166 
00167   IO_Mouse0,
00168   IO_Mouse1,
00169   IO_Mouse2,
00170   IO_Mouse3,
00171   IO_Mouse4,
00172 
00173   IO_MWheelUp,
00174   IO_MWheelDown,
00175 
00176   //Joystick Buttons
00177   IO_Joystick1,
00178   IO_Joystick2,
00179   IO_Joystick3,
00180   IO_Joystick4,
00181   IO_Joystick5,
00182   IO_Joystick6,
00183   IO_Joystick7,
00184   IO_Joystick8,
00185   IO_Joystick9,
00186 
00187   //Joystick Axes
00188   IO_JoystickAxis1,
00189   IO_JoystickAxis2,
00190   IO_JoystickAxis3,
00191   IO_JoystickAxis4,
00192   IO_JoystickAxis5,
00193   IO_JoystickAxis6,
00194 
00195   IO_JoystickSlider,
00196 
00197   /* just so we know how many keys there are */
00198   IO_NumKeys
00199 
00200 } IO_KeyId;
00201 
00203 class IO_Key
00204 {
00205 public:
00206   /* default contructor (invalid key) */
00207   IO_Key (void) { state = 0; id = IO_Invalid; }
00208 
00209   /* construction from a name */
00210   IO_Key (const std::string &name);
00211 
00212   /* construction from a state and ID */
00213   IO_Key (uint st, IO_KeyId i) { state = st; id = i; }
00214 
00215   /* gets the key name */
00216   std::string Name (void) const;
00217 
00218   /* gets the key ID */
00219   IO_KeyId Id (void) const { return id; }
00220 
00221   /* gets the state of the control keys */
00222   uint State (void) const { return state; }
00223 
00224   /* gets the ascii value */
00225   char Ascii (void) const;
00226 
00227 private:
00228   /* state of the control keys */
00229   uint state;
00230 
00231   IO_KeyId id;
00232 };
00233 
00235 class IO_Event
00236 {
00237 public:
00238   /* constructors */
00239   IO_Event (IO_EventId i) : id (i) { }
00240   IO_Event (IO_EventId i, const IO_Key &k) : id (i), key (k) { }
00241   IO_Event (IO_EventId i, const MenuEvent &m) : id (i), me (m) { }
00242 
00243   /* data accesors */
00244   IO_EventId Id (void) const { return id; }
00245   const IO_Key &Key (void) const { return key; }
00246   const MenuEvent &Menu (void) const { return me; }
00247 
00248 private:
00249   IO_EventId id;
00250 
00251   /* for key presses and releases.  */
00252   IO_Key key;
00253 
00254   /* menu event */
00255   MenuEvent me;
00256 };
00257 
00258 class IO_Window;
00260 typedef void (*IO_EventHandler)(IO_Window *win, const IO_Event &e);
00261 
00268 typedef enum
00269 {
00270   IO_Absolute,
00271   IO_Relative
00272 } IO_MouseMode;
00273 
00275 struct IO_Position
00276 {
00277   double x, y;
00278 };
00279 
00282 void IO_initialize_window_system(int argc, char **argv, char **environ);
00283 
00284 
00285 struct IO_WindowData;
00287 class IO_Window
00288 {
00289 public:
00290 
00292   IO_Window (void)
00293   {
00294     rc = NULL;
00295   }
00296 
00298   IO_Window (const std::string &title, IO_EventHandler handler,
00299              const ConStruct &cfg, bool menu)
00300   {
00301     try
00302       {
00303         Create (title, handler, cfg, menu);
00304       }
00305     catch (Error &e)
00306       {
00307         Destroy ();
00308         throw e;
00309       }
00310 
00311     rc = new int;
00312     *rc = 1;
00313   }
00314 private:
00315   /* does the actual work for the constructor */
00316   void Create (const std::string &title, IO_EventHandler handler,
00317                const ConStruct &cfg, bool menu);
00318 public:
00319 
00321   IO_Window (IO_Window &w)
00322   {
00323     rc = w.rc;
00324     (*rc)++;
00325     data = w.data;
00326   }
00327 
00329   IO_Window& operator = (IO_Window &w)
00330   {
00331     if (rc != NULL)
00332       {  
00333         (*rc)--;
00334         if (*rc == 0)
00335           {
00336             delete rc;
00337             Destroy ();
00338           }
00339       }
00340 
00341     rc = w.rc;
00342     (*rc)++;
00343     data = w.data;
00344 
00345     return (*this);
00346   }
00347 
00349   uint Width (void) const;
00350 
00352   uint Height (void) const;
00353 
00357   void Poll (void);
00358 
00360   void Select (void) const;
00361 
00366   bool KeyState (IO_KeyId id) const;
00367 
00368   //the following two functions added by Bender for joystick support
00370   bool JoystickState(IO_KeyId id) const;
00371 
00373   double JoystickAxisState(IO_KeyId id) const;
00374   
00377   void MouseMode (IO_MouseMode mm);
00378 
00380   IO_MouseMode MouseMode (void) const;
00381 
00382   /* Set the mouse sensitivity.  Only affects relative mouse mode.  */
00383   //void Sensitivity (double s);
00384 
00385   /* Get the mouse sensitivity.  */
00386   //double Sensitivity (void) const;
00387 
00396   IO_Position MousePos (void) const;
00397 
00406   void Update (void);
00407 
00409   ConStruct Config (void) const;
00410 
00411   /* destructor */
00412   ~IO_Window (void)
00413   {
00414     if (rc != NULL)
00415       {  
00416         (*rc)--;
00417         if (*rc == 0)
00418           {
00419             delete rc;
00420             Destroy ();
00421           }
00422       }
00423   }
00424 private:
00425   /* does the actual work for the destructor */
00426   void Destroy (void);
00427 
00428   /* data... */
00429 private:
00430 
00431   /* reference count */
00432   int *rc;
00433 
00434   /* Since this is an abstract interface, we only store a pointer to
00435      some system specific window data.  The implementation can define
00436      what this data actually is.  */
00437   IO_WindowData *data;
00438 
00439   //added by Bender, remaps the keys based mapping.cfg
00440   int mapping[7];
00441 };
00442 
00444 void DisplayError (std::string error);
00445 
00446 #endif

Generated on Fri Jan 12 14:15:02 2007 for Construct by  doxygen 1.4.3-20050530