home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / Input.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-16  |  2.3 KB  |  123 lines

  1. #ifndef __Input_h__
  2. #define __Input_h__
  3.  
  4. #include "SDL.h"
  5. #include "InputInfo.h"
  6.  
  7. typedef enum actions_e{
  8.     NO_ACTION,
  9.  
  10.     MOVE_FORWARD,
  11.     MOVE_BACKWARD,
  12.     MOVE_LEFT,
  13.     MOVE_RIGHT,
  14.     MOVE_UP,
  15.     MOVE_DOWN,
  16.  
  17.     TURN_LEFT,
  18.     TURN_RIGHT,
  19.     TURN_UP,
  20.     TURN_DOWN,
  21.  
  22.     FIRE_WEAPON_1,
  23.     FIRE_WEAPON_2,
  24.     FIRE_WEAPON_3,
  25.     FIRE_WEAPON_4,
  26.  
  27.     CAMERA_ZOOM_IN,
  28.     CAMERA_ZOOM_OUT,
  29.     CAMERA_ROTATE_LEFT,
  30.     CAMERA_ROTATE_RIGHT,
  31.     CAMERA_ROTATE_UP,
  32.     CAMERA_ROTATE_DOWN,
  33.     CAMERA_RESET,
  34.  
  35.     TOGGLE_CONSOLE,
  36.  
  37.     NUM_ACTIONS
  38. }action_t;
  39.  
  40. typedef struct inputArrayElement_s{
  41.     bool pressed;
  42. }inputArrayElement_t;
  43.  
  44. typedef inputArrayElement_t inputArray_t[NUM_ACTIONS];
  45.  
  46.  
  47. typedef struct keyMapElement_s{
  48.     bool pressed;
  49.     action_t action;
  50.     char* consoleString;
  51. }keyMapElement_t;
  52.  
  53. typedef keyMapElement_t keyMap_t[SDLK_LAST];
  54.  
  55.  
  56. enum mouseButtons_e{
  57.     MOUSE_BUTTON1=1,    // left
  58.     MOUSE_BUTTON2,        // middle
  59.     MOUSE_BUTTON3,        // right
  60.     MOUSE_BUTTON4,        // mwheelup
  61.     MOUSE_BUTTON5,        // mwheeldown
  62.  
  63.     NUM_MOUSE_BUTTONS
  64. };
  65.  
  66. typedef struct mouseButton_s{
  67.     bool pressed;
  68.     action_t action;
  69.     char* consoleString;
  70.     int x,y;
  71. }mouseButton_t;
  72.  
  73. typedef struct mouse_{
  74.     int x,y;
  75.     mouseButton_t buttons[NUM_MOUSE_BUTTONS];
  76.     float sensitivity;
  77. }mouse_t;
  78.  
  79.  
  80. class Input{
  81. public:
  82.     static InputInfo info;
  83.  
  84.     static bool init();
  85.     static bool shutdown();
  86.     static bool wasInit();
  87.  
  88.     static bool registerCVarsAndCCmds();
  89.     static bool unregisterCVarsAndCCmds();
  90.  
  91. protected:
  92.     static bool initialized;
  93.  
  94.  
  95. public:
  96.     static mouse_t mouse;
  97.     static keyMap_t keyMap;
  98.     static inputArray_t inputArray;
  99.  
  100.     static void handleKeyboardEvent(SDL_KeyboardEvent* event);
  101.     static void handleMouseMotionEvent(SDL_MouseMotionEvent* event);
  102.     static void handleMouseButtonEvent(SDL_MouseButtonEvent* event);
  103.  
  104.     static void showMouseCursor();
  105.     static void hideMouseCursor();
  106.     static void grabInput();
  107.     static void freeInput();
  108.  
  109.     static void processInputArray();
  110.  
  111.     static const char* keyNames[SDLK_LAST];
  112.     static const char* actionNames[NUM_ACTIONS];
  113.     static void initKeyNames();
  114.     static void initActionNames();
  115.     static int getMouseButtonForString(char* str);
  116.     static int getKeyForString(char* str);
  117.     static int getActionForString(char* str);
  118.     static const char* getKeyName(int keysym);
  119.     static const char* getActionName(int action);
  120. };
  121.  
  122. #endif    /* __Input_h__ */
  123.