home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / XenonSource.exe / gamesystem / includes / gs_joystick.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-12  |  2.2 KB  |  98 lines

  1. //-------------------------------------------------------------
  2. //
  3. // Module:    gsCJoystick
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    12/03/00
  8. //
  9. // Base:    gsCInput
  10. //
  11. // Derived:    None
  12. //
  13. //-------------------------------------------------------------
  14.  
  15. #ifndef _INCLUDE_GS_JOYSTICK_H
  16. #define _INCLUDE_GS_JOYSTICK_H
  17.  
  18. #include "gs_input.h"
  19. #include "gs_point.h"
  20.  
  21. //-------------------------------------------------------------
  22.  
  23. const int gsJOYSTICK_MAX_STICKS = 2;
  24. const int gsJOYSTICK_MAX_BUTTONS = 8;
  25.  
  26. const int gsJOYSTICK_RANGE = 1000;
  27. const int gsJOYSTICK_THRESHOLD = 500;
  28.  
  29. //-------------------------------------------------------------
  30.  
  31. typedef enum {
  32.     gsJOY_NONE = 256,
  33.     gsJOY_LEFT,
  34.     gsJOY_RIGHT,
  35.     gsJOY_UP,
  36.     gsJOY_DOWN,
  37.     gsJOY_BUTTON0,
  38.     gsJOY_BUTTON1,
  39.     gsJOY_BUTTON2,
  40.     gsJOY_BUTTON3,
  41.     gsJOY_BUTTON4,
  42.     gsJOY_BUTTON5,
  43.     gsJOY_BUTTON6,
  44.     gsJOY_BUTTON7,
  45.  
  46.     gsJOY_LAST
  47. } gsJoystickCode;
  48.  
  49. const int gsJOYSTICK_CODES = gsJOY_LAST - gsJOY_NONE;
  50.  
  51. //-------------------------------------------------------------
  52.  
  53. class gsCJoystick : public gsCInput
  54. {
  55.     private:
  56.         static int m_num_joysticks;
  57.  
  58.         static DIDEVICEINSTANCE m_device_desc[gsJOYSTICK_MAX_STICKS];
  59.  
  60.         static gsLPDIRECTINPUTDEVICE m_joystick_device[gsJOYSTICK_MAX_STICKS];
  61.         
  62.         static gsCPoint m_previous_position[gsJOYSTICK_MAX_STICKS];
  63.         static gsCPoint m_position[gsJOYSTICK_MAX_STICKS];
  64.         static bool m_previous_buttons[gsJOYSTICK_MAX_STICKS][gsJOYSTICK_CODES];
  65.         static bool m_buttons[gsJOYSTICK_MAX_STICKS][gsJOYSTICK_CODES];
  66.  
  67.         static BOOL CALLBACK enumDevicesCallback(LPDIDEVICEINSTANCE lpddi,LPVOID pvRef);
  68.  
  69.         static gsJoystickCode m_code;
  70.  
  71.         static const char *joystickcode_description[gsJOYSTICK_CODES];
  72.  
  73.     public:
  74.         gsCJoystick();
  75.         virtual ~gsCJoystick();
  76.  
  77.         bool create();
  78.         bool destroy();
  79.  
  80.         bool acquire();
  81.         bool update();
  82.         bool isActive();
  83.  
  84.         int getNumSticks();
  85.         bool testButton(gsJoystickCode button,int stick = 0);
  86.         bool testButtonPressed(gsJoystickCode button,int stick = 0);
  87.  
  88.         gsCPoint getPosition(int stick = 0);
  89.  
  90.         gsJoystickCode getEmulatedKey();
  91.  
  92.         const char * joystickCodeToDescription(gsJoystickCode code);
  93. };
  94.  
  95. //-------------------------------------------------------------
  96.  
  97. #endif
  98.