Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

269 lines
11 KiB

  1. //===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef IINPUTSYSTEM_H
  7. #define IINPUTSYSTEM_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier0/platform.h"
  12. #include "tier0/platwindow.h"
  13. #include "appframework/iappsystem.h"
  14. #include "inputsystem/InputEnums.h"
  15. #include "inputsystem/ButtonCode.h"
  16. #include "inputsystem/AnalogCode.h"
  17. #include <mathlib/vector.h>
  18. #include "input_device.h"
  19. ///-----------------------------------------------------------------------------
  20. /// A handle to a cursor icon
  21. ///-----------------------------------------------------------------------------
  22. DECLARE_POINTER_HANDLE( InputCursorHandle_t );
  23. #define INPUT_CURSOR_HANDLE_INVALID ( (InputCursorHandle_t)0 )
  24. ///-----------------------------------------------------------------------------
  25. /// An enumeration describing well-known cursor icons
  26. ///-----------------------------------------------------------------------------
  27. enum InputStandardCursor_t
  28. {
  29. INPUT_CURSOR_NONE = 0,
  30. INPUT_CURSOR_ARROW,
  31. INPUT_CURSOR_IBEAM,
  32. INPUT_CURSOR_HOURGLASS,
  33. INPUT_CURSOR_CROSSHAIR,
  34. INPUT_CURSOR_WAITARROW,
  35. INPUT_CURSOR_UP,
  36. INPUT_CURSOR_SIZE_NW_SE,
  37. INPUT_CURSOR_SIZE_NE_SW,
  38. INPUT_CURSOR_SIZE_W_E,
  39. INPUT_CURSOR_SIZE_N_S,
  40. INPUT_CURSOR_SIZE_ALL,
  41. INPUT_CURSOR_NO,
  42. INPUT_CURSOR_HAND,
  43. INPUT_CURSOR_COUNT
  44. };
  45. #ifdef _PS3
  46. #include "cell/pad.h"
  47. typedef bool (*BCellPadDataHook_t)( CellPadData &data );
  48. typedef bool (*BCellPadNoDataHook_t)();
  49. #endif
  50. ///-----------------------------------------------------------------------------
  51. /// Main interface for input. This is a low-level interface, creating an
  52. /// OS-independent queue of low-level input events which were sampled since
  53. /// the last call to PollInputState. It also contains facilities for cursor
  54. /// control and creation.
  55. ///-----------------------------------------------------------------------------
  56. abstract_class IInputSystem : public IAppSystem
  57. {
  58. public:
  59. /// Attach, detach input system from a particular window
  60. /// This window should be the root window for the application
  61. /// Only 1 window should be attached at any given time.
  62. virtual void AttachToWindow( void* hWnd ) = 0;
  63. virtual void DetachFromWindow( ) = 0;
  64. /// Enables/disables input. PollInputState will not update current
  65. /// button/analog states when it is called if the system is disabled.
  66. virtual void EnableInput( bool bEnable ) = 0;
  67. /// Enables/disables the windows message pump. PollInputState will not
  68. /// Peek/Dispatch messages if this is disabled
  69. virtual void EnableMessagePump( bool bEnable ) = 0;
  70. /// Polls the current input state
  71. virtual void PollInputState( bool bIsInGame = false ) = 0;
  72. /// Gets the time of the last polling in ms
  73. virtual int GetPollTick() const = 0;
  74. /// Is a button down? "Buttons" are binary-state input devices (mouse buttons, keyboard keys)
  75. virtual bool IsButtonDown( ButtonCode_t code ) const = 0;
  76. /// Returns the tick at which the button was pressed and released
  77. virtual int GetButtonPressedTick( ButtonCode_t code ) const = 0;
  78. virtual int GetButtonReleasedTick( ButtonCode_t code ) const = 0;
  79. /// Gets the value of an analog input device this frame
  80. /// Includes joysticks, mousewheel, mouse
  81. virtual int GetAnalogValue( AnalogCode_t code ) const = 0;
  82. /// Gets the change in a particular analog input device this frame
  83. /// Includes joysticks, mousewheel, mouse
  84. virtual int GetAnalogDelta( AnalogCode_t code ) const = 0;
  85. /// Returns the input events since the last poll
  86. virtual int GetEventCount() const = 0;
  87. virtual const InputEvent_t* GetEventData( ) const = 0;
  88. // Motion Controller status
  89. virtual bool MotionControllerActive() const = 0;
  90. virtual Quaternion GetMotionControllerOrientation() const = 0; // Pointer direction
  91. virtual float GetMotionControllerPosX() const = 0;
  92. virtual float GetMotionControllerPosY() const = 0;
  93. virtual int GetMotionControllerDeviceStatus() const = 0;
  94. virtual uint64 GetMotionControllerDeviceStatusFlags() const = 0;
  95. virtual void SetMotionControllerDeviceStatus( int nStatus ) = 0;
  96. virtual void SetMotionControllerCalibrationInvalid( void ) = 0;
  97. virtual void StepMotionControllerCalibration( void ) = 0;
  98. virtual void ResetMotionControllerScreenCalibration( void ) = 0;
  99. /// Posts a user-defined event into the event queue; this is expected
  100. /// to be called in overridden wndprocs connected to the root panel.
  101. virtual void PostUserEvent( const InputEvent_t &event ) = 0;
  102. /// Returns the number of joysticks
  103. virtual int GetJoystickCount() const = 0;
  104. /// Enable/disable joystick, it has perf costs
  105. virtual void EnableJoystickInput( int nJoystick, bool bEnable ) = 0;
  106. /// Enable/disable diagonal joystick POV (simultaneous POV buttons down)
  107. virtual void EnableJoystickDiagonalPOV( int nJoystick, bool bEnable ) = 0;
  108. /// Sample the joystick and append events to the input queue
  109. virtual void SampleDevices( void ) = 0;
  110. // FIXME: Currently force-feedback is only supported on the Xbox 360
  111. virtual void SetRumble( float fLeftMotor, float fRightMotor, int userId = INVALID_USER_ID ) = 0;
  112. virtual void StopRumble( int userId = INVALID_USER_ID ) = 0;
  113. /// Resets the input state
  114. virtual void ResetInputState() = 0;
  115. /// Convert back + forth between ButtonCode/AnalogCode + strings
  116. virtual const char *ButtonCodeToString( ButtonCode_t code ) const = 0;
  117. virtual const char *AnalogCodeToString( AnalogCode_t code ) const = 0;
  118. virtual ButtonCode_t StringToButtonCode( const char *pString ) const = 0;
  119. virtual AnalogCode_t StringToAnalogCode( const char *pString ) const = 0;
  120. /// Sleeps until input happens. Pass a negative number to sleep infinitely
  121. virtual void SleepUntilInput( int nMaxSleepTimeMS = -1 ) = 0;
  122. /// Convert back + forth between virtual codes + button codes
  123. // FIXME: This is a temporary piece of code
  124. virtual ButtonCode_t VirtualKeyToButtonCode( int nVirtualKey ) const = 0;
  125. virtual int ButtonCodeToVirtualKey( ButtonCode_t code ) const = 0;
  126. virtual ButtonCode_t ScanCodeToButtonCode( int lParam ) const = 0;
  127. /// How many times have we called PollInputState?
  128. virtual int GetPollCount() const = 0;
  129. /// Sets the cursor position
  130. virtual void SetCursorPosition( int x, int y ) = 0;
  131. /// Tells the input system to generate UI-related events, defined
  132. /// in inputsystem/inputenums.h (see IE_FirstUIEvent)
  133. /// We could have multiple clients that care about UI-related events
  134. /// so we refcount the clients with an Add/Remove strategy. If there
  135. /// are no interested clients, the UI events are not generated
  136. virtual void AddUIEventListener() = 0;
  137. virtual void RemoveUIEventListener() = 0;
  138. /// Returns the currently attached window
  139. virtual PlatWindow_t GetAttachedWindow() const = 0;
  140. /// Creates a cursor using one of the well-known cursor icons
  141. virtual InputCursorHandle_t GetStandardCursor( InputStandardCursor_t id ) = 0;
  142. /// Loads a cursor defined in a file
  143. virtual InputCursorHandle_t LoadCursorFromFile( const char *pFileName, const char *pPathID = NULL ) = 0;
  144. /// Sets the cursor icon
  145. virtual void SetCursorIcon( InputCursorHandle_t hCursor ) = 0;
  146. /// Gets the cursor position
  147. virtual void GetCursorPosition( int *pX, int *pY ) = 0;
  148. /// Mouse capture
  149. virtual void EnableMouseCapture( PlatWindow_t hWnd ) = 0;
  150. virtual void DisableMouseCapture() = 0;
  151. // Mouse visibility, tell inputsystem when we hide stuff rather than querying the OS which is expensive on OSX
  152. virtual void SetMouseCursorVisible( bool bVisible ) = 0;
  153. #ifdef _PS3
  154. virtual void SetPS3CellPadDataHook( BCellPadDataHook_t hookFunc ) = 0;
  155. virtual void SetPS3CellPadNoDataHook( BCellPadNoDataHook_t hookFunc ) = 0;
  156. virtual void SetPS3StartButtonIdentificationMode() = 0;
  157. virtual bool GetPS3CursorPos( int &x, int &y ) = 0;
  158. virtual void PS3SetupHardwareCursor( void* image ) = 0;
  159. virtual void DisableHardwareCursor( void ) = 0;
  160. virtual void EnableHardwareCursor( void ) = 0;
  161. #endif
  162. #if defined( USE_SDL ) || defined( LINUX )
  163. virtual void DisableHardwareCursor( void ) = 0;
  164. virtual void EnableHardwareCursor( void ) = 0;
  165. #endif
  166. /// Reset the current cursor icon. Used to reset the icon in the case of alt+tabs where the cursor has been forced to a different
  167. /// icon because it was outside of the client rect during the reload.
  168. virtual void ResetCursorIcon() = 0;
  169. // read and clear accumulated raw input values
  170. virtual void GetRawMouseAccumulators( int& accumX, int& accumY ) = 0;
  171. // ========================================================================
  172. // Platform Input Device Interface
  173. //
  174. // This section provides a way to determine what Input/controller setup(s) are available on a
  175. // given platform (PC, MAC, PS3, XBox) and what input device is currently selected/in use on
  176. // the local client
  177. //
  178. // Modules outside of the inputsystem need this information for tasks such as statistics,
  179. // achievements, and player rankings which take into account what input controller setup the
  180. // player is using on a per-platform basis.
  181. //
  182. // The platform can be specified because a dedicate server may be running on a different
  183. // platform than the clients connected to it.
  184. //
  185. // The master list of input devices and platforms used here is located in src\common\input_device.h
  186. //
  187. // The methods here allow the user to write platform agnostic code to iterate through and
  188. // and process the list of input devices specific to the current (or specified) platform
  189. // without seeing devices not applicable to that platform.
  190. //
  191. // Terminology:
  192. // Connected Device = Input setup is connected and available for use, can be more than one
  193. // Current Device = Input setup being actively used
  194. //
  195. // ================================================================
  196. // Input Device Functions specific to the local client and hardware
  197. // ================================================================
  198. // Manage the list of input devices that are connected
  199. virtual InputDevice_t GetConnectedInputDevices( void ) = 0; // returns the bitfield of all connected devices
  200. virtual bool IsInputDeviceConnected( InputDevice_t device ) = 0;
  201. virtual void SetInputDeviceConnected( InputDevice_t device, bool connected = true ) = 0;
  202. virtual InputDevice_t IsOnlySingleDeviceConnected( void ) = 0;
  203. // Access the currently selected Input device
  204. virtual InputDevice_t GetCurrentInputDevice( void ) = 0; // returns the enum referring to the one currently selected device
  205. virtual bool IsDeviceReadingInput( InputDevice_t device ) const = 0; // returns whether the passed in device is the current device. Returns true if no current device is defined.
  206. virtual void SetCurrentInputDevice( InputDevice_t device ) = 0;
  207. virtual void ResetCurrentInputDevice( void ) = 0; // sets the input device to the platform default
  208. virtual void SampleInputToFindCurrentDevice( bool ) = 0; // looks for the next 'significant' button press to determine and set the current input device
  209. virtual bool IsSamplingForCurrentDevice( void ) = 0;
  210. virtual bool IsSteamControllerActive() const = 0;
  211. virtual void SetSteamControllerMode( const char *pMode, const void *obj=NULL ) = 0;
  212. };
  213. DECLARE_TIER2_INTERFACE( IInputSystem, g_pInputSystem );
  214. #endif // IINPUTSYSTEM_H