Team Fortress 2 Source Code as on 22/4/2020
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.

162 lines
6.9 KiB

  1. //========= Copyright 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 "appframework/IAppSystem.h"
  13. #include "inputsystem/InputEnums.h"
  14. #include "inputsystem/ButtonCode.h"
  15. #include "inputsystem/AnalogCode.h"
  16. #include "steam/isteamcontroller.h"
  17. //-----------------------------------------------------------------------------
  18. // Main interface for input. This is a low-level interface
  19. //-----------------------------------------------------------------------------
  20. #define INPUTSYSTEM_INTERFACE_VERSION "InputSystemVersion001"
  21. abstract_class IInputSystem : public IAppSystem
  22. {
  23. public:
  24. // Attach, detach input system from a particular window
  25. // This window should be the root window for the application
  26. // Only 1 window should be attached at any given time.
  27. virtual void AttachToWindow( void* hWnd ) = 0;
  28. virtual void DetachFromWindow( ) = 0;
  29. // Enables/disables input. PollInputState will not update current
  30. // button/analog states when it is called if the system is disabled.
  31. virtual void EnableInput( bool bEnable ) = 0;
  32. // Enables/disables the windows message pump. PollInputState will not
  33. // Peek/Dispatch messages if this is disabled
  34. virtual void EnableMessagePump( bool bEnable ) = 0;
  35. // Polls the current input state
  36. virtual void PollInputState() = 0;
  37. // Gets the time of the last polling in ms
  38. virtual int GetPollTick() const = 0;
  39. // Is a button down? "Buttons" are binary-state input devices (mouse buttons, keyboard keys)
  40. virtual bool IsButtonDown( ButtonCode_t code ) const = 0;
  41. // Returns the tick at which the button was pressed and released
  42. virtual int GetButtonPressedTick( ButtonCode_t code ) const = 0;
  43. virtual int GetButtonReleasedTick( ButtonCode_t code ) const = 0;
  44. // Gets the value of an analog input device this frame
  45. // Includes joysticks, mousewheel, mouse
  46. virtual int GetAnalogValue( AnalogCode_t code ) const = 0;
  47. // Gets the change in a particular analog input device this frame
  48. // Includes joysticks, mousewheel, mouse
  49. virtual int GetAnalogDelta( AnalogCode_t code ) const = 0;
  50. // Returns the input events since the last poll
  51. virtual int GetEventCount() const = 0;
  52. virtual const InputEvent_t* GetEventData( ) const = 0;
  53. // Posts a user-defined event into the event queue; this is expected
  54. // to be called in overridden wndprocs connected to the root panel.
  55. virtual void PostUserEvent( const InputEvent_t &event ) = 0;
  56. // Returns the number of joysticks
  57. virtual int GetJoystickCount() const = 0;
  58. // Enable/disable joystick, it has perf costs
  59. virtual void EnableJoystickInput( int nJoystick, bool bEnable ) = 0;
  60. // Enable/disable diagonal joystick POV (simultaneous POV buttons down)
  61. virtual void EnableJoystickDiagonalPOV( int nJoystick, bool bEnable ) = 0;
  62. // Sample the joystick and append events to the input queue
  63. virtual void SampleDevices( void ) = 0;
  64. // FIXME: Currently force-feedback is only supported on the Xbox 360
  65. virtual void SetRumble( float fLeftMotor, float fRightMotor, int userId = INVALID_USER_ID ) = 0;
  66. virtual void StopRumble( void ) = 0;
  67. // Resets the input state
  68. virtual void ResetInputState() = 0;
  69. // Sets a player as the primary user - all other controllers will be ignored.
  70. virtual void SetPrimaryUserId( int userId ) = 0;
  71. // Convert back + forth between ButtonCode/AnalogCode + strings
  72. virtual const char *ButtonCodeToString( ButtonCode_t code ) const = 0;
  73. virtual const char *AnalogCodeToString( AnalogCode_t code ) const = 0;
  74. virtual ButtonCode_t StringToButtonCode( const char *pString ) const = 0;
  75. virtual AnalogCode_t StringToAnalogCode( const char *pString ) const = 0;
  76. // Sleeps until input happens. Pass a negative number to sleep infinitely
  77. virtual void SleepUntilInput( int nMaxSleepTimeMS = -1 ) = 0;
  78. // Convert back + forth between virtual codes + button codes
  79. // FIXME: This is a temporary piece of code
  80. virtual ButtonCode_t VirtualKeyToButtonCode( int nVirtualKey ) const = 0;
  81. virtual int ButtonCodeToVirtualKey( ButtonCode_t code ) const = 0;
  82. virtual ButtonCode_t ScanCodeToButtonCode( int lParam ) const = 0;
  83. // How many times have we called PollInputState?
  84. virtual int GetPollCount() const = 0;
  85. // Sets the cursor position
  86. virtual void SetCursorPosition( int x, int y ) = 0;
  87. // NVNT get address to haptics interface
  88. virtual void *GetHapticsInterfaceAddress() const = 0;
  89. virtual void SetNovintPure( bool bPure ) = 0;
  90. // read and clear accumulated raw input values
  91. virtual bool GetRawMouseAccumulators( int& accumX, int& accumY ) = 0;
  92. // tell the input system that we're not a game, we're console text mode.
  93. // this is used for dedicated servers to not initialize joystick system.
  94. // this needs to be called before CInputSystem::Init (e.g. in PreInit of
  95. // some system) if you want ot prevent the joystick system from ever
  96. // being initialized.
  97. virtual void SetConsoleTextMode( bool bConsoleTextMode ) = 0;
  98. virtual ISteamController* SteamControllerInterface() = 0;
  99. virtual uint32 GetNumSteamControllersConnected() = 0;
  100. virtual bool IsSteamControllerActive() = 0;
  101. virtual bool IsSteamControllerConnected() = 0;
  102. virtual int GetSteamControllerIndexForSlot( int nSlot ) = 0;
  103. virtual bool GetRadialMenuStickValues( int nSlot, float &fX, float &fY ) = 0;
  104. virtual void ActivateSteamControllerActionSetForSlot( uint64 nSlot, GameActionSet_t eActionSet ) = 0;
  105. virtual ControllerActionSetHandle_t GetActionSetHandle( GameActionSet_t eActionSet ) = 0;
  106. virtual ControllerActionSetHandle_t GetActionSetHandle( const char* szActionSet ) = 0;
  107. // Gets the action origin (i.e. which physical input) maps to the given action for the given action set
  108. virtual EControllerActionOrigin GetSteamControllerActionOrigin( const char* action, GameActionSet_t action_set ) = 0;
  109. virtual EControllerActionOrigin GetSteamControllerActionOrigin( const char* action, ControllerActionSetHandle_t action_set_handle ) = 0;
  110. // Maps a Steam Controller action origin to a string (consisting of a single character) in our SC icon font
  111. virtual const wchar_t* GetSteamControllerFontCharacterForActionOrigin( EControllerActionOrigin origin ) = 0;
  112. // Maps a Steam Controller action origin to a short text string (e.g. "X", "LB", "LDOWN") describing the control.
  113. // Prefer to actually use the icon font wherever possible.
  114. virtual const wchar_t* GetSteamControllerDescriptionForActionOrigin( EControllerActionOrigin origin ) = 0;
  115. // This is called with "true" by dedicated server initialization (before calling Init) in order to
  116. // force us to skip initialization of Steam (which messes up dedicated servers).
  117. virtual void SetSkipControllerInitialization( bool bSkip ) = 0;
  118. // Helper - activate same action set for all controller slots.
  119. void ActivateSteamControllerActionSet( GameActionSet_t eActionSet ) {
  120. ActivateSteamControllerActionSetForSlot( 0xffffffffffffffff, eActionSet );
  121. }
  122. };
  123. #endif // IINPUTSYSTEM_H