directinput.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/directinput.h $*
  25. * *
  26. * $Author:: Patrick $*
  27. * *
  28. * $Modtime:: 1/15/02 5:31p $*
  29. * *
  30. * $Revision:: 11 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef DIRECTINPUT_H
  36. #define DIRECTINPUT_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #include "vector3.h"
  41. #include "vector2.h"
  42. typedef enum {
  43. DIK_SHIFT = 0xF0,
  44. DIK_CONTROL,
  45. DIK_ALT,
  46. DIK_WIN,
  47. } DupeKeys;
  48. /*
  49. **
  50. */
  51. class DirectInput {
  52. public:
  53. typedef enum {
  54. NUM_KEYBOARD_BUTTONS = 256,
  55. NUM_MOUSE_BUTTONS = 3,
  56. NUM_JOYSTICK_BUTTONS = 2
  57. } ButtonCounts;
  58. typedef enum {
  59. MOUSE_X_AXIS,
  60. MOUSE_Y_AXIS,
  61. MOUSE_Z_AXIS,
  62. NUM_MOUSE_AXIS,
  63. } MouseAxis;
  64. typedef enum {
  65. JOYSTICK_X_AXIS,
  66. JOYSTICK_Y_AXIS,
  67. } JoystickAxis;
  68. typedef enum {
  69. DI_BUTTON_HELD = 1,
  70. DI_BUTTON_HIT = 2,
  71. DI_BUTTON_RELEASED = 4
  72. } ButtonStateBitMask;
  73. /*
  74. ** Buttons include all keyboard keys, plus the buttons
  75. ** on the mouse and joysticks
  76. */
  77. enum {
  78. BUTTON_KEYBOARD_FIRST = 0,
  79. BUTTON_MOUSE_FIRST = 256,
  80. BUTTON_MOUSE_LEFT = BUTTON_MOUSE_FIRST,
  81. BUTTON_MOUSE_RIGHT,
  82. BUTTON_MOUSE_CENTER,
  83. BUTTON_JOYSTICK_FIRST,
  84. BUTTON_JOYSTICK_A = BUTTON_JOYSTICK_FIRST,
  85. BUTTON_JOYSTICK_B,
  86. BUTTON_MAX
  87. //NUM_BUTTONS,
  88. };
  89. /*
  90. **
  91. */
  92. static void Init( void );
  93. static void Shutdown( void );
  94. static void Read( void );
  95. static void Flush( void );
  96. static void Acquire(void);
  97. static void Unacquire(void);
  98. /*
  99. **
  100. */
  101. static int Get_Keyboard_Button( int button ) { return DIKeyboardButtons[ button & 0xFF ]; }
  102. static int Get_Mouse_Button( int button ) { return DIMouseButtons[ button & 0xFF ]; }
  103. static int Get_Joystick_Button( int button ) { return DIJoystickButtons[ button & 0xFF ]; }
  104. static long Get_Mouse_Axis( MouseAxis axis ) { return DIMouseAxis[axis]; }
  105. /*
  106. **
  107. */
  108. static void Eat_Mouse_Held_States (void);
  109. // Still non-buffered
  110. static long Get_Joystick_Axis_State( JoystickAxis axis );
  111. //
  112. // Cursor support
  113. //
  114. static void Reset_Cursor_Pos (const Vector2 &pos) { CursorPos.X = pos.X; CursorPos.Y = pos.Y; }
  115. static void Get_Cursor_Pos (Vector3 *pos) { *pos = CursorPos; }
  116. //
  117. // Button support
  118. //
  119. static char Get_Button_Value (int button_id);
  120. //
  121. // Return the DIK ID of the last keyboard key pressed
  122. //
  123. static int Get_Last_Key_Pressed (void) { return LastKeyPressed; }
  124. private:
  125. //
  126. // Internal methods
  127. //
  128. static void Update_Double_Clicks (void);
  129. //
  130. // Private member data
  131. //
  132. static char DIKeyboardButtons[NUM_KEYBOARD_BUTTONS];
  133. static char DIMouseButtons[NUM_MOUSE_BUTTONS];
  134. static long DIMouseAxis[NUM_MOUSE_AXIS];
  135. static char DIJoystickButtons[NUM_MOUSE_BUTTONS];
  136. static float ButtonLastHitTime[NUM_KEYBOARD_BUTTONS];
  137. static Vector3 CursorPos;
  138. static bool EatMouseHeld;
  139. static void * DirectInputLibrary;
  140. static int LastKeyPressed;
  141. static bool Captured;
  142. static void ReadKeyboard( void );
  143. static void ReadMouse( void );
  144. static void ReadJoystick( void );
  145. };
  146. ///////////////////////////////////////////////////////////
  147. // Get_Button_Value
  148. ///////////////////////////////////////////////////////////
  149. WWINLINE char
  150. DirectInput::Get_Button_Value (int button_id)
  151. {
  152. char retval = 0;
  153. if (button_id < BUTTON_MOUSE_FIRST) {
  154. retval = DIKeyboardButtons[button_id];
  155. } else if (button_id < BUTTON_JOYSTICK_FIRST) {
  156. retval = DIMouseButtons[button_id - BUTTON_MOUSE_FIRST];
  157. } else if (button_id < BUTTON_MAX) {
  158. retval = DIJoystickButtons[button_id - BUTTON_JOYSTICK_FIRST];
  159. }
  160. return retval;
  161. }
  162. #endif