This commit is contained in:
nephacks
2025-06-04 03:22:50 +02:00
parent f234f23848
commit f12416cffd
14243 changed files with 6446499 additions and 26 deletions

View File

@@ -0,0 +1,44 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#ifndef ANALOGCODE_H
#define ANALOGCODE_H
#ifdef _WIN32
#pragma once
#endif
#include "inputsystem/InputEnums.h"
//-----------------------------------------------------------------------------
// Macro to get at joystick codes
//-----------------------------------------------------------------------------
#define JOYSTICK_AXIS_INTERNAL( _joystick, _axis ) ( JOYSTICK_FIRST_AXIS + ((_joystick) * MAX_JOYSTICK_AXES) + (_axis) )
#define JOYSTICK_AXIS( _joystick, _axis ) ( (AnalogCode_t)JOYSTICK_AXIS_INTERNAL( _joystick, _axis ) )
//-----------------------------------------------------------------------------
// Enumeration for analog input devices. Includes joysticks, mousewheel, mouse
//-----------------------------------------------------------------------------
enum AnalogCode_t
{
ANALOG_CODE_INVALID = -1,
MOUSE_X = 0,
MOUSE_Y,
MOUSE_XY, // Invoked when either x or y changes
MOUSE_WHEEL,
JOYSTICK_FIRST_AXIS,
JOYSTICK_LAST_AXIS = JOYSTICK_AXIS_INTERNAL( MAX_JOYSTICKS-1, MAX_JOYSTICK_AXES-1 ),
ANALOG_CODE_LAST,
};
#endif // ANALOGCODE_H

View File

@@ -0,0 +1,462 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#ifndef BUTTONCODE_H
#define BUTTONCODE_H
#ifdef _WIN32
#pragma once
#endif
#include "inputsystem/InputEnums.h"
//-----------------------------------------------------------------------------
// Button enum. "Buttons" are binary-state input devices (mouse buttons, keyboard keys)
//-----------------------------------------------------------------------------
enum
{
JOYSTICK_MAX_BUTTON_COUNT = 32,
JOYSTICK_POV_BUTTON_COUNT = 4,
JOYSTICK_AXIS_BUTTON_COUNT = MAX_JOYSTICK_AXES * 2,
};
#define JOYSTICK_BUTTON_INTERNAL( _joystick, _button ) ( JOYSTICK_FIRST_BUTTON + ((_joystick) * JOYSTICK_MAX_BUTTON_COUNT) + (_button) )
#define JOYSTICK_POV_BUTTON_INTERNAL( _joystick, _button ) ( JOYSTICK_FIRST_POV_BUTTON + ((_joystick) * JOYSTICK_POV_BUTTON_COUNT) + (_button) )
#define JOYSTICK_AXIS_BUTTON_INTERNAL( _joystick, _button ) ( JOYSTICK_FIRST_AXIS_BUTTON + ((_joystick) * JOYSTICK_AXIS_BUTTON_COUNT) + (_button) )
#define JOYSTICK_BUTTON( _joystick, _button ) ( (ButtonCode_t)JOYSTICK_BUTTON_INTERNAL( _joystick, _button ) )
#define JOYSTICK_POV_BUTTON( _joystick, _button ) ( (ButtonCode_t)JOYSTICK_POV_BUTTON_INTERNAL( _joystick, _button ) )
#define JOYSTICK_AXIS_BUTTON( _joystick, _button ) ( (ButtonCode_t)JOYSTICK_AXIS_BUTTON_INTERNAL( _joystick, _button ) )
//-----------------------------------------------------------------------------
// Button enum. "Buttons" are binary-state input devices (mouse buttons, keyboard keys)
//-----------------------------------------------------------------------------
enum
{
STEAMCONTROLLER_MAX_BUTTON_COUNT = SK_MAX_KEYS - 1,
STEAMCONTROLLER_AXIS_BUTTON_COUNT = MAX_STEAMPADAXIS * 2,
};
#define STEAMCONTROLLER_BUTTON_INTERNAL( _joystick, _button ) ( STEAMCONTROLLER_FIRST_BUTTON + ((_joystick) * STEAMCONTROLLER_MAX_BUTTON_COUNT) + (_button) )
#define STEAMCONTROLLER_AXIS_BUTTON_INTERNAL( _joystick, _button ) ( STEAMCONTROLLER_FIRST_AXIS_BUTTON + ((_joystick) * STEAMCONTROLLER_AXIS_BUTTON_COUNT) + (_button) )
#define STEAMCONTROLLER_BUTTON( _joystick, _button ) ( (ButtonCode_t)STEAMCONTROLLER_BUTTON_INTERNAL( _joystick, _button ) )
#define STEAMCONTROLLER_AXIS_BUTTON( _joystick, _button ) ( (ButtonCode_t)STEAMCONTROLLER_AXIS_BUTTON_INTERNAL( _joystick, _button ) )
enum ButtonCode_t
{
BUTTON_CODE_INVALID = -1,
BUTTON_CODE_NONE = 0,
KEY_FIRST = 0,
KEY_NONE = KEY_FIRST,
KEY_0,
KEY_1,
KEY_2,
KEY_3,
KEY_4,
KEY_5,
KEY_6,
KEY_7,
KEY_8,
KEY_9,
KEY_A,
KEY_B,
KEY_C,
KEY_D,
KEY_E,
KEY_F,
KEY_G,
KEY_H,
KEY_I,
KEY_J,
KEY_K,
KEY_L,
KEY_M,
KEY_N,
KEY_O,
KEY_P,
KEY_Q,
KEY_R,
KEY_S,
KEY_T,
KEY_U,
KEY_V,
KEY_W,
KEY_X,
KEY_Y,
KEY_Z,
KEY_PAD_0,
KEY_PAD_1,
KEY_PAD_2,
KEY_PAD_3,
KEY_PAD_4,
KEY_PAD_5,
KEY_PAD_6,
KEY_PAD_7,
KEY_PAD_8,
KEY_PAD_9,
KEY_PAD_DIVIDE,
KEY_PAD_MULTIPLY,
KEY_PAD_MINUS,
KEY_PAD_PLUS,
KEY_PAD_ENTER,
KEY_PAD_DECIMAL,
KEY_LBRACKET,
KEY_RBRACKET,
KEY_SEMICOLON,
KEY_APOSTROPHE,
KEY_BACKQUOTE,
KEY_COMMA,
KEY_PERIOD,
KEY_SLASH,
KEY_BACKSLASH,
KEY_MINUS,
KEY_EQUAL,
KEY_ENTER,
KEY_SPACE,
KEY_BACKSPACE,
KEY_TAB,
KEY_CAPSLOCK,
KEY_NUMLOCK,
KEY_ESCAPE,
KEY_SCROLLLOCK,
KEY_INSERT,
KEY_DELETE,
KEY_HOME,
KEY_END,
KEY_PAGEUP,
KEY_PAGEDOWN,
KEY_BREAK,
KEY_LSHIFT,
KEY_RSHIFT,
KEY_LALT,
KEY_RALT,
KEY_LCONTROL,
KEY_RCONTROL,
KEY_LWIN,
KEY_RWIN,
KEY_APP,
KEY_UP,
KEY_LEFT,
KEY_DOWN,
KEY_RIGHT,
KEY_F1,
KEY_F2,
KEY_F3,
KEY_F4,
KEY_F5,
KEY_F6,
KEY_F7,
KEY_F8,
KEY_F9,
KEY_F10,
KEY_F11,
KEY_F12,
KEY_CAPSLOCKTOGGLE,
KEY_NUMLOCKTOGGLE,
KEY_SCROLLLOCKTOGGLE,
KEY_LAST = KEY_SCROLLLOCKTOGGLE,
KEY_COUNT = KEY_LAST - KEY_FIRST + 1,
// Mouse
MOUSE_FIRST = KEY_LAST + 1,
MOUSE_LEFT = MOUSE_FIRST,
MOUSE_RIGHT,
MOUSE_MIDDLE,
MOUSE_4,
MOUSE_5,
MOUSE_WHEEL_UP, // A fake button which is 'pressed' and 'released' when the wheel is moved up
MOUSE_WHEEL_DOWN, // A fake button which is 'pressed' and 'released' when the wheel is moved down
MOUSE_LAST = MOUSE_WHEEL_DOWN,
MOUSE_COUNT = MOUSE_LAST - MOUSE_FIRST + 1,
// Joystick
JOYSTICK_FIRST = MOUSE_LAST + 1,
JOYSTICK_FIRST_BUTTON = JOYSTICK_FIRST,
JOYSTICK_LAST_BUTTON = JOYSTICK_BUTTON_INTERNAL( MAX_JOYSTICKS-1, JOYSTICK_MAX_BUTTON_COUNT-1 ),
JOYSTICK_FIRST_POV_BUTTON,
JOYSTICK_LAST_POV_BUTTON = JOYSTICK_POV_BUTTON_INTERNAL( MAX_JOYSTICKS-1, JOYSTICK_POV_BUTTON_COUNT-1 ),
JOYSTICK_FIRST_AXIS_BUTTON,
JOYSTICK_LAST_AXIS_BUTTON = JOYSTICK_AXIS_BUTTON_INTERNAL( MAX_JOYSTICKS-1, JOYSTICK_AXIS_BUTTON_COUNT-1 ),
JOYSTICK_LAST = JOYSTICK_LAST_AXIS_BUTTON,
STEAMCONTROLLER_FIRST = JOYSTICK_LAST + 1,
STEAMCONTROLLER_FIRST_BUTTON = STEAMCONTROLLER_FIRST,
STEAMCONTROLLER_LAST_BUTTON = STEAMCONTROLLER_BUTTON_INTERNAL( MAX_STEAM_CONTROLLERS-1, STEAMCONTROLLER_MAX_BUTTON_COUNT-1 ),
STEAMCONTROLLER_FIRST_AXIS_BUTTON,
STEAMCONTROLLER_LAST_AXIS_BUTTON = STEAMCONTROLLER_AXIS_BUTTON_INTERNAL( MAX_STEAM_CONTROLLERS-1, STEAMCONTROLLER_AXIS_BUTTON_COUNT-1 ),
STEAMCONTROLLER_LAST = STEAMCONTROLLER_LAST_AXIS_BUTTON,
BUTTON_CODE_LAST,
BUTTON_CODE_COUNT = BUTTON_CODE_LAST - KEY_FIRST + 1,
// Helpers for XBox 360
KEY_XBUTTON_UP = JOYSTICK_FIRST_POV_BUTTON, // POV buttons
KEY_XBUTTON_RIGHT,
KEY_XBUTTON_DOWN,
KEY_XBUTTON_LEFT,
KEY_XBUTTON_A = JOYSTICK_FIRST_BUTTON, // Buttons
KEY_XBUTTON_B,
KEY_XBUTTON_X,
KEY_XBUTTON_Y,
KEY_XBUTTON_LEFT_SHOULDER,
KEY_XBUTTON_RIGHT_SHOULDER,
KEY_XBUTTON_BACK,
KEY_XBUTTON_START,
KEY_XBUTTON_STICK1,
KEY_XBUTTON_STICK2,
KEY_XBUTTON_INACTIVE_START,
KEY_XBUTTON_FIREMODE_SELECTOR_1,
KEY_XBUTTON_FIREMODE_SELECTOR_2,
KEY_XBUTTON_FIREMODE_SELECTOR_3,
KEY_XBUTTON_RELOAD,
KEY_XBUTTON_TRIGGER,
KEY_XBUTTON_PUMP_ACTION,
KEY_XBUTTON_ROLL_RIGHT,
KEY_XBUTTON_ROLL_LEFT,
KEY_XSTICK1_RIGHT = JOYSTICK_FIRST_AXIS_BUTTON, // XAXIS POSITIVE
KEY_XSTICK1_LEFT, // XAXIS NEGATIVE
KEY_XSTICK1_DOWN, // YAXIS POSITIVE
KEY_XSTICK1_UP, // YAXIS NEGATIVE
KEY_XBUTTON_LTRIGGER, // ZAXIS POSITIVE
KEY_XBUTTON_RTRIGGER, // ZAXIS NEGATIVE
KEY_XSTICK2_RIGHT, // UAXIS POSITIVE
KEY_XSTICK2_LEFT, // UAXIS NEGATIVE
KEY_XSTICK2_DOWN, // VAXIS POSITIVE
KEY_XSTICK2_UP, // VAXIS NEGATIVE
// Helpers for Steam Controller
STEAMCONTROLLER_A = STEAMCONTROLLER_FIRST_BUTTON,
STEAMCONTROLLER_B,
STEAMCONTROLLER_X,
STEAMCONTROLLER_Y,
STEAMCONTROLLER_DPAD_UP,
STEAMCONTROLLER_DPAD_RIGHT,
STEAMCONTROLLER_DPAD_DOWN,
STEAMCONTROLLER_DPAD_LEFT,
STEAMCONTROLLER_LEFT_BUMPER,
STEAMCONTROLLER_RIGHT_BUMPER,
STEAMCONTROLLER_LEFT_TRIGGER,
STEAMCONTROLLER_RIGHT_TRIGGER,
STEAMCONTROLLER_LEFT_GRIP,
STEAMCONTROLLER_RIGHT_GRIP,
STEAMCONTROLLER_LEFT_PAD_FINGERDOWN,
STEAMCONTROLLER_RIGHT_PAD_FINGERDOWN,
STEAMCONTROLLER_LEFT_PAD_CLICK,
STEAMCONTROLLER_RIGHT_PAD_CLICK,
STEAMCONTROLLER_LEFT_PAD_UP,
STEAMCONTROLLER_LEFT_PAD_RIGHT,
STEAMCONTROLLER_LEFT_PAD_DOWN,
STEAMCONTROLLER_LEFT_PAD_LEFT,
STEAMCONTROLLER_RIGHT_PAD_UP,
STEAMCONTROLLER_RIGHT_PAD_RIGHT,
STEAMCONTROLLER_RIGHT_PAD_DOWN,
STEAMCONTROLLER_RIGHT_PAD_LEFT,
STEAMCONTROLLER_SELECT,
STEAMCONTROLLER_START,
STEAMCONTROLLER_STEAM,
STEAMCONTROLLER_INACTIVE_START,
};
inline bool IsAlpha( ButtonCode_t code )
{
return ( code >= KEY_A ) && ( code <= KEY_Z );
}
inline bool IsAlphaNumeric( ButtonCode_t code )
{
return ( code >= KEY_0 ) && ( code <= KEY_Z );
}
inline bool IsSpace( ButtonCode_t code )
{
return ( code == KEY_ENTER ) || ( code == KEY_TAB ) || ( code == KEY_SPACE );
}
inline bool IsKeypad( ButtonCode_t code )
{
return ( code >= MOUSE_FIRST ) && ( code <= KEY_PAD_DECIMAL );
}
inline bool IsPunctuation( ButtonCode_t code )
{
return ( code >= KEY_0 ) && ( code <= KEY_SPACE ) && !IsAlphaNumeric( code ) && !IsSpace( code ) && !IsKeypad( code );
}
inline bool IsKeyCode( ButtonCode_t code )
{
return ( code >= KEY_FIRST ) && ( code <= KEY_LAST );
}
inline bool IsMouseCode( ButtonCode_t code )
{
return ( code >= MOUSE_FIRST ) && ( code <= MOUSE_LAST );
}
inline bool IsJoystickCode( ButtonCode_t code )
{
return ( ( code >= JOYSTICK_FIRST ) && ( code <= JOYSTICK_LAST ) ) ||
( ( code >= STEAMCONTROLLER_FIRST ) && ( code <= STEAMCONTROLLER_LAST ) );
}
inline bool IsJoystickButtonCode( ButtonCode_t code )
{
return ( code >= JOYSTICK_FIRST_BUTTON ) && ( code <= JOYSTICK_LAST_BUTTON );
}
inline bool IsJoystickPOVCode( ButtonCode_t code )
{
return ( code >= JOYSTICK_FIRST_POV_BUTTON ) && ( code <= JOYSTICK_LAST_POV_BUTTON );
}
inline bool IsJoystickAxisCode( ButtonCode_t code )
{
return ( code >= JOYSTICK_FIRST_AXIS_BUTTON ) && ( code <= JOYSTICK_LAST_AXIS_BUTTON );
}
inline bool IsSteamControllerCode( ButtonCode_t code )
{
return ( ( code >= STEAMCONTROLLER_FIRST ) && ( code <= STEAMCONTROLLER_LAST ) );
}
inline bool IsSteamControllerButtonCode( ButtonCode_t code )
{
return ( code >= STEAMCONTROLLER_FIRST_BUTTON ) && ( code <= STEAMCONTROLLER_LAST_BUTTON );
}
inline bool IsSteamControllerAxisCode( ButtonCode_t code )
{
return ( code >= STEAMCONTROLLER_FIRST_AXIS_BUTTON ) && ( code <= STEAMCONTROLLER_LAST_AXIS_BUTTON );
}
inline ButtonCode_t GetBaseButtonCode( ButtonCode_t code )
{
if ( IsJoystickButtonCode( code ) )
{
int offset = ( code - JOYSTICK_FIRST_BUTTON ) % JOYSTICK_MAX_BUTTON_COUNT;
return (ButtonCode_t)( JOYSTICK_FIRST_BUTTON + offset );
}
if ( IsJoystickPOVCode( code ) )
{
int offset = ( code - JOYSTICK_FIRST_POV_BUTTON ) % JOYSTICK_POV_BUTTON_COUNT;
return (ButtonCode_t)( JOYSTICK_FIRST_POV_BUTTON + offset );
}
if ( IsJoystickAxisCode( code ) )
{
int offset = ( code - JOYSTICK_FIRST_AXIS_BUTTON ) % JOYSTICK_AXIS_BUTTON_COUNT;
return (ButtonCode_t)( JOYSTICK_FIRST_AXIS_BUTTON + offset );
}
if ( IsSteamControllerButtonCode( code ) )
{
int offset = ( code - STEAMCONTROLLER_FIRST_BUTTON ) % STEAMCONTROLLER_MAX_BUTTON_COUNT;
return (ButtonCode_t)( STEAMCONTROLLER_FIRST_BUTTON + offset );
}
if ( IsSteamControllerAxisCode( code ) )
{
int offset = ( code - STEAMCONTROLLER_FIRST_AXIS_BUTTON ) % STEAMCONTROLLER_AXIS_BUTTON_COUNT;
return (ButtonCode_t)( STEAMCONTROLLER_FIRST_AXIS_BUTTON + offset );
}
return code;
}
inline int GetJoystickForCode( ButtonCode_t code )
{
if ( !IsJoystickCode( code ) )
return 0;
if ( IsJoystickButtonCode( code ) )
{
int offset = ( code - JOYSTICK_FIRST_BUTTON ) / JOYSTICK_MAX_BUTTON_COUNT;
return offset;
}
if ( IsJoystickPOVCode( code ) )
{
int offset = ( code - JOYSTICK_FIRST_POV_BUTTON ) / JOYSTICK_POV_BUTTON_COUNT;
return offset;
}
if ( IsJoystickAxisCode( code ) )
{
int offset = ( code - JOYSTICK_FIRST_AXIS_BUTTON ) / JOYSTICK_AXIS_BUTTON_COUNT;
return offset;
}
if ( IsSteamControllerButtonCode( code ) )
{
int offset = ( code - STEAMCONTROLLER_FIRST_BUTTON ) / STEAMCONTROLLER_MAX_BUTTON_COUNT;
return offset;
}
if ( IsSteamControllerAxisCode( code ) )
{
int offset = ( code - STEAMCONTROLLER_FIRST_AXIS_BUTTON ) / STEAMCONTROLLER_AXIS_BUTTON_COUNT;
return offset;
}
return 0;
}
inline ButtonCode_t ButtonCodeToJoystickButtonCode( ButtonCode_t code, int nDesiredJoystick )
{
if ( !IsJoystickCode( code ) || nDesiredJoystick == 0 )
return code;
nDesiredJoystick = clamp( nDesiredJoystick, 0, MAX_JOYSTICKS - 1 );
code = GetBaseButtonCode( code );
// Now upsample it
if ( IsJoystickButtonCode( code ) )
{
int nOffset = code - JOYSTICK_FIRST_BUTTON;
return JOYSTICK_BUTTON( nDesiredJoystick, nOffset );
}
if ( IsJoystickPOVCode( code ) )
{
int nOffset = code - JOYSTICK_FIRST_POV_BUTTON;
return JOYSTICK_POV_BUTTON( nDesiredJoystick, nOffset );
}
if ( IsJoystickAxisCode( code ) )
{
int nOffset = code - JOYSTICK_FIRST_AXIS_BUTTON;
return JOYSTICK_AXIS_BUTTON( nDesiredJoystick, nOffset );
}
if ( IsSteamControllerButtonCode( code ) )
{
int nOffset = code - STEAMCONTROLLER_FIRST_BUTTON;
return STEAMCONTROLLER_BUTTON( nDesiredJoystick, nOffset );
}
if ( IsJoystickAxisCode( code ) )
{
int nOffset = code - STEAMCONTROLLER_FIRST_AXIS_BUTTON;
return STEAMCONTROLLER_AXIS_BUTTON( nDesiredJoystick, nOffset );
}
return code;
}
#endif // BUTTONCODE_H

View File

@@ -0,0 +1,182 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef INPUTENUMS_H
#define INPUTENUMS_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/basetypes.h"
// Standard maximum +/- value of a joystick axis
#define MAX_BUTTONSAMPLE 32768
#if !defined( _X360 )
#define INVALID_USER_ID -1
#else
#define INVALID_USER_ID XBX_INVALID_USER_ID
#endif
//-----------------------------------------------------------------------------
// Forward declarations:
//-----------------------------------------------------------------------------
enum
{
#ifdef _PS3
MAX_JOYSTICKS = 7,
#else
MAX_JOYSTICKS = 4,
#endif
MOUSE_BUTTON_COUNT = 5,
MAX_NOVINT_DEVICES = 2,
};
enum JoystickAxis_t
{
JOY_AXIS_X = 0,
JOY_AXIS_Y,
JOY_AXIS_Z,
JOY_AXIS_R,
JOY_AXIS_U,
JOY_AXIS_V,
MAX_JOYSTICK_AXES,
};
enum JoystickDeadzoneMode_t
{
JOYSTICK_DEADZONE_CROSS = 0,
JOYSTICK_DEADZONE_SQUARE = 1,
};
//-----------------------------------------------------------------------------
// Extra mouse codes
//-----------------------------------------------------------------------------
enum
{
MS_WM_XBUTTONDOWN = 0x020B,
MS_WM_XBUTTONUP = 0x020C,
MS_WM_XBUTTONDBLCLK = 0x020D,
MS_MK_BUTTON4 = 0x0020,
MS_MK_BUTTON5 = 0x0040,
};
//-----------------------------------------------------------------------------
// Events
//-----------------------------------------------------------------------------
enum InputEventType_t
{
IE_ButtonPressed = 0, // m_nData contains a ButtonCode_t
IE_ButtonReleased, // m_nData contains a ButtonCode_t
IE_ButtonDoubleClicked, // m_nData contains a ButtonCode_t
IE_AnalogValueChanged, // m_nData contains an AnalogCode_t, m_nData2 contains the value
IE_FirstSystemEvent = 100,
IE_Quit = IE_FirstSystemEvent,
IE_ControllerInserted, // m_nData contains the controller ID
IE_ControllerUnplugged, // m_nData contains the controller ID
IE_Close,
IE_WindowSizeChanged, // m_nData contains width, m_nData2 contains height, m_nData3 = 0 if not minimized, 1 if minimized
IE_PS_CameraUnplugged, // m_nData contains code for type of disconnect.
IE_PS_Move_OutOfView, // m_nData contains bool (0, 1) for whether the move is now out of view (1) or in view (0)
IE_FirstUIEvent = 200,
IE_LocateMouseClick = IE_FirstUIEvent,
IE_SetCursor,
IE_KeyTyped,
IE_KeyCodeTyped,
IE_InputLanguageChanged,
IE_IMESetWindow,
IE_IMEStartComposition,
IE_IMEComposition,
IE_IMEEndComposition,
IE_IMEShowCandidates,
IE_IMEChangeCandidates,
IE_IMECloseCandidates,
IE_IMERecomputeModes,
IE_OverlayEvent,
IE_FirstVguiEvent = 1000, // Assign ranges for other systems that post user events here
IE_FirstAppEvent = 2000,
};
struct InputEvent_t
{
int m_nType; // Type of the event (see InputEventType_t)
int m_nTick; // Tick on which the event occurred
int m_nData; // Generic 32-bit data, what it contains depends on the event
int m_nData2; // Generic 32-bit data, what it contains depends on the event
int m_nData3; // Generic 32-bit data, what it contains depends on the event
};
//-----------------------------------------------------------------------------
// Steam Controller Enums
//-----------------------------------------------------------------------------
#ifndef MAX_STEAM_CONTROLLERS
#define MAX_STEAM_CONTROLLERS 16
#endif
typedef enum
{
SK_NULL,
SK_BUTTON_A,
SK_BUTTON_B,
SK_BUTTON_X,
SK_BUTTON_Y,
SK_BUTTON_UP,
SK_BUTTON_RIGHT,
SK_BUTTON_DOWN,
SK_BUTTON_LEFT,
SK_BUTTON_LEFT_BUMPER,
SK_BUTTON_RIGHT_BUMPER,
SK_BUTTON_LEFT_TRIGGER,
SK_BUTTON_RIGHT_TRIGGER,
SK_BUTTON_LEFT_GRIP,
SK_BUTTON_RIGHT_GRIP,
SK_BUTTON_LPAD_TOUCH,
SK_BUTTON_RPAD_TOUCH,
SK_BUTTON_LPAD_CLICK,
SK_BUTTON_RPAD_CLICK,
SK_BUTTON_LPAD_UP,
SK_BUTTON_LPAD_RIGHT,
SK_BUTTON_LPAD_DOWN,
SK_BUTTON_LPAD_LEFT,
SK_BUTTON_RPAD_UP,
SK_BUTTON_RPAD_RIGHT,
SK_BUTTON_RPAD_DOWN,
SK_BUTTON_RPAD_LEFT,
SK_BUTTON_SELECT,
SK_BUTTON_START,
SK_BUTTON_STEAM,
SK_BUTTON_INACTIVE_START,
SK_MAX_KEYS
} sKey_t;
enum ESteamPadAxis
{
LEFTPAD_AXIS_X,
LEFTPAD_AXIS_Y,
RIGHTPAD_AXIS_X,
RIGHTPAD_AXIS_Y,
LEFT_TRIGGER_AXIS,
RIGHT_TRIGGER_AXIS,
GYRO_AXIS_PITCH,
GYRO_AXIS_ROLL,
GYRO_AXIS_YAW,
MAX_STEAMPADAXIS = GYRO_AXIS_YAW
};
enum
{
LASTINPUT_KBMOUSE = 0,
LASTINPUT_CONTROLLER = 1,
LASTINPUT_STEAMCONTROLLER = 2
};
#endif // INPUTENUMS_H

View File

@@ -0,0 +1,76 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: This is input priority system, allowing various clients to
// cause input messages / cursor control to be routed to them as opposed to
// other clients.
//
//===========================================================================//
#ifndef IINPUTCLIENTSTACK_H
#define IINPUTCLIENTSTACK_H
#ifdef _WIN32
#pragma once
#endif
#include "appframework/iappsystem.h"
#include "inputsystem/iinputsystem.h"
///-----------------------------------------------------------------------------
/// A handle to an input context. These are arranged in a priority-based
/// stack; the top context on the stack which is also enabled wins.
///-----------------------------------------------------------------------------
DECLARE_POINTER_HANDLE( InputContextHandle_t );
#define INPUT_CONTEXT_HANDLE_INVALID ( (InputContextHandle_t)0 )
///-----------------------------------------------------------------------------
/// Purpose: This is input priority system, allowing various clients to
/// cause input messages / cursor control to be routed to them as opposed to
/// other clients.
///
/// NOTE: For Source1, it would be a huge change to move all input (like
/// the code in engine/keys.cpp for example) to go through this interface.
/// Therefore, I'm going to stick with only dealing with cursor control,
/// which is necessary for Jen's new gameUI system to interoperate with VGui.
///-----------------------------------------------------------------------------
abstract_class IInputStackSystem : public IAppSystem
{
public:
/// Allocates an input context, pushing it on top of the input stack,
/// thereby giving it top priority
virtual InputContextHandle_t PushInputContext() = 0;
/// Pops the top input context off the input stack, and destroys it.
virtual void PopInputContext( ) = 0;
/// Enables/disables an input context, allowing something lower on the
/// stack to have control of input. Disabling an input context which
/// owns mouse capture
virtual void EnableInputContext( InputContextHandle_t hContext, bool bEnable ) = 0;
/// Allows a context to make the cursor visible;
/// the topmost enabled context wins
virtual void SetCursorVisible( InputContextHandle_t hContext, bool bVisible ) = 0;
/// Allows a context to set the cursor icon;
/// the topmost enabled context wins
virtual void SetCursorIcon( InputContextHandle_t hContext, InputCursorHandle_t hCursor ) = 0;
/// Allows a context to enable mouse capture. Disabling an input context
/// deactivates mouse capture. Capture will occur if it happens on the
/// topmost enabled context
virtual void SetMouseCapture( InputContextHandle_t hContext, bool bEnable ) = 0;
/// Allows a context to set the mouse position. It only has any effect if the
/// specified context is the topmost enabled context
virtual void SetCursorPosition( InputContextHandle_t hContext, int x, int y ) = 0;
/// Returns true if the specified context is the topmost enabled context
virtual bool IsTopmostEnabledContext( InputContextHandle_t hContext ) const = 0;
};
DECLARE_TIER2_INTERFACE( IInputStackSystem, g_pInputStackSystem );
#endif // IINPUTCLIENTSTACK_H

View File

@@ -0,0 +1,269 @@
//===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef IINPUTSYSTEM_H
#define IINPUTSYSTEM_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/platform.h"
#include "tier0/platwindow.h"
#include "appframework/iappsystem.h"
#include "inputsystem/InputEnums.h"
#include "inputsystem/ButtonCode.h"
#include "inputsystem/AnalogCode.h"
#include <mathlib/vector.h>
#include "input_device.h"
///-----------------------------------------------------------------------------
/// A handle to a cursor icon
///-----------------------------------------------------------------------------
DECLARE_POINTER_HANDLE( InputCursorHandle_t );
#define INPUT_CURSOR_HANDLE_INVALID ( (InputCursorHandle_t)0 )
///-----------------------------------------------------------------------------
/// An enumeration describing well-known cursor icons
///-----------------------------------------------------------------------------
enum InputStandardCursor_t
{
INPUT_CURSOR_NONE = 0,
INPUT_CURSOR_ARROW,
INPUT_CURSOR_IBEAM,
INPUT_CURSOR_HOURGLASS,
INPUT_CURSOR_CROSSHAIR,
INPUT_CURSOR_WAITARROW,
INPUT_CURSOR_UP,
INPUT_CURSOR_SIZE_NW_SE,
INPUT_CURSOR_SIZE_NE_SW,
INPUT_CURSOR_SIZE_W_E,
INPUT_CURSOR_SIZE_N_S,
INPUT_CURSOR_SIZE_ALL,
INPUT_CURSOR_NO,
INPUT_CURSOR_HAND,
INPUT_CURSOR_COUNT
};
#ifdef _PS3
#include "cell/pad.h"
typedef bool (*BCellPadDataHook_t)( CellPadData &data );
typedef bool (*BCellPadNoDataHook_t)();
#endif
///-----------------------------------------------------------------------------
/// Main interface for input. This is a low-level interface, creating an
/// OS-independent queue of low-level input events which were sampled since
/// the last call to PollInputState. It also contains facilities for cursor
/// control and creation.
///-----------------------------------------------------------------------------
abstract_class IInputSystem : public IAppSystem
{
public:
/// Attach, detach input system from a particular window
/// This window should be the root window for the application
/// Only 1 window should be attached at any given time.
virtual void AttachToWindow( void* hWnd ) = 0;
virtual void DetachFromWindow( ) = 0;
/// Enables/disables input. PollInputState will not update current
/// button/analog states when it is called if the system is disabled.
virtual void EnableInput( bool bEnable ) = 0;
/// Enables/disables the windows message pump. PollInputState will not
/// Peek/Dispatch messages if this is disabled
virtual void EnableMessagePump( bool bEnable ) = 0;
/// Polls the current input state
virtual void PollInputState( bool bIsInGame = false ) = 0;
/// Gets the time of the last polling in ms
virtual int GetPollTick() const = 0;
/// Is a button down? "Buttons" are binary-state input devices (mouse buttons, keyboard keys)
virtual bool IsButtonDown( ButtonCode_t code ) const = 0;
/// Returns the tick at which the button was pressed and released
virtual int GetButtonPressedTick( ButtonCode_t code ) const = 0;
virtual int GetButtonReleasedTick( ButtonCode_t code ) const = 0;
/// Gets the value of an analog input device this frame
/// Includes joysticks, mousewheel, mouse
virtual int GetAnalogValue( AnalogCode_t code ) const = 0;
/// Gets the change in a particular analog input device this frame
/// Includes joysticks, mousewheel, mouse
virtual int GetAnalogDelta( AnalogCode_t code ) const = 0;
/// Returns the input events since the last poll
virtual int GetEventCount() const = 0;
virtual const InputEvent_t* GetEventData( ) const = 0;
// Motion Controller status
virtual bool MotionControllerActive() const = 0;
virtual Quaternion GetMotionControllerOrientation() const = 0; // Pointer direction
virtual float GetMotionControllerPosX() const = 0;
virtual float GetMotionControllerPosY() const = 0;
virtual int GetMotionControllerDeviceStatus() const = 0;
virtual uint64 GetMotionControllerDeviceStatusFlags() const = 0;
virtual void SetMotionControllerDeviceStatus( int nStatus ) = 0;
virtual void SetMotionControllerCalibrationInvalid( void ) = 0;
virtual void StepMotionControllerCalibration( void ) = 0;
virtual void ResetMotionControllerScreenCalibration( void ) = 0;
/// Posts a user-defined event into the event queue; this is expected
/// to be called in overridden wndprocs connected to the root panel.
virtual void PostUserEvent( const InputEvent_t &event ) = 0;
/// Returns the number of joysticks
virtual int GetJoystickCount() const = 0;
/// Enable/disable joystick, it has perf costs
virtual void EnableJoystickInput( int nJoystick, bool bEnable ) = 0;
/// Enable/disable diagonal joystick POV (simultaneous POV buttons down)
virtual void EnableJoystickDiagonalPOV( int nJoystick, bool bEnable ) = 0;
/// Sample the joystick and append events to the input queue
virtual void SampleDevices( void ) = 0;
// FIXME: Currently force-feedback is only supported on the Xbox 360
virtual void SetRumble( float fLeftMotor, float fRightMotor, int userId = INVALID_USER_ID ) = 0;
virtual void StopRumble( int userId = INVALID_USER_ID ) = 0;
/// Resets the input state
virtual void ResetInputState() = 0;
/// Convert back + forth between ButtonCode/AnalogCode + strings
virtual const char *ButtonCodeToString( ButtonCode_t code ) const = 0;
virtual const char *AnalogCodeToString( AnalogCode_t code ) const = 0;
virtual ButtonCode_t StringToButtonCode( const char *pString ) const = 0;
virtual AnalogCode_t StringToAnalogCode( const char *pString ) const = 0;
/// Sleeps until input happens. Pass a negative number to sleep infinitely
virtual void SleepUntilInput( int nMaxSleepTimeMS = -1 ) = 0;
/// Convert back + forth between virtual codes + button codes
// FIXME: This is a temporary piece of code
virtual ButtonCode_t VirtualKeyToButtonCode( int nVirtualKey ) const = 0;
virtual int ButtonCodeToVirtualKey( ButtonCode_t code ) const = 0;
virtual ButtonCode_t ScanCodeToButtonCode( int lParam ) const = 0;
/// How many times have we called PollInputState?
virtual int GetPollCount() const = 0;
/// Sets the cursor position
virtual void SetCursorPosition( int x, int y ) = 0;
/// Tells the input system to generate UI-related events, defined
/// in inputsystem/inputenums.h (see IE_FirstUIEvent)
/// We could have multiple clients that care about UI-related events
/// so we refcount the clients with an Add/Remove strategy. If there
/// are no interested clients, the UI events are not generated
virtual void AddUIEventListener() = 0;
virtual void RemoveUIEventListener() = 0;
/// Returns the currently attached window
virtual PlatWindow_t GetAttachedWindow() const = 0;
/// Creates a cursor using one of the well-known cursor icons
virtual InputCursorHandle_t GetStandardCursor( InputStandardCursor_t id ) = 0;
/// Loads a cursor defined in a file
virtual InputCursorHandle_t LoadCursorFromFile( const char *pFileName, const char *pPathID = NULL ) = 0;
/// Sets the cursor icon
virtual void SetCursorIcon( InputCursorHandle_t hCursor ) = 0;
/// Gets the cursor position
virtual void GetCursorPosition( int *pX, int *pY ) = 0;
/// Mouse capture
virtual void EnableMouseCapture( PlatWindow_t hWnd ) = 0;
virtual void DisableMouseCapture() = 0;
// Mouse visibility, tell inputsystem when we hide stuff rather than querying the OS which is expensive on OSX
virtual void SetMouseCursorVisible( bool bVisible ) = 0;
#ifdef _PS3
virtual void SetPS3CellPadDataHook( BCellPadDataHook_t hookFunc ) = 0;
virtual void SetPS3CellPadNoDataHook( BCellPadNoDataHook_t hookFunc ) = 0;
virtual void SetPS3StartButtonIdentificationMode() = 0;
virtual bool GetPS3CursorPos( int &x, int &y ) = 0;
virtual void PS3SetupHardwareCursor( void* image ) = 0;
virtual void DisableHardwareCursor( void ) = 0;
virtual void EnableHardwareCursor( void ) = 0;
#endif
#if defined( USE_SDL ) || defined( LINUX )
virtual void DisableHardwareCursor( void ) = 0;
virtual void EnableHardwareCursor( void ) = 0;
#endif
/// 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
/// icon because it was outside of the client rect during the reload.
virtual void ResetCursorIcon() = 0;
// read and clear accumulated raw input values
virtual void GetRawMouseAccumulators( int& accumX, int& accumY ) = 0;
// ========================================================================
// Platform Input Device Interface
//
// This section provides a way to determine what Input/controller setup(s) are available on a
// given platform (PC, MAC, PS3, XBox) and what input device is currently selected/in use on
// the local client
//
// Modules outside of the inputsystem need this information for tasks such as statistics,
// achievements, and player rankings which take into account what input controller setup the
// player is using on a per-platform basis.
//
// The platform can be specified because a dedicate server may be running on a different
// platform than the clients connected to it.
//
// The master list of input devices and platforms used here is located in src\common\input_device.h
//
// The methods here allow the user to write platform agnostic code to iterate through and
// and process the list of input devices specific to the current (or specified) platform
// without seeing devices not applicable to that platform.
//
// Terminology:
// Connected Device = Input setup is connected and available for use, can be more than one
// Current Device = Input setup being actively used
//
// ================================================================
// Input Device Functions specific to the local client and hardware
// ================================================================
// Manage the list of input devices that are connected
virtual InputDevice_t GetConnectedInputDevices( void ) = 0; // returns the bitfield of all connected devices
virtual bool IsInputDeviceConnected( InputDevice_t device ) = 0;
virtual void SetInputDeviceConnected( InputDevice_t device, bool connected = true ) = 0;
virtual InputDevice_t IsOnlySingleDeviceConnected( void ) = 0;
// Access the currently selected Input device
virtual InputDevice_t GetCurrentInputDevice( void ) = 0; // returns the enum referring to the one currently selected device
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.
virtual void SetCurrentInputDevice( InputDevice_t device ) = 0;
virtual void ResetCurrentInputDevice( void ) = 0; // sets the input device to the platform default
virtual void SampleInputToFindCurrentDevice( bool ) = 0; // looks for the next 'significant' button press to determine and set the current input device
virtual bool IsSamplingForCurrentDevice( void ) = 0;
virtual bool IsSteamControllerActive() const = 0;
virtual void SetSteamControllerMode( const char *pMode, const void *obj=NULL ) = 0;
};
DECLARE_TIER2_INTERFACE( IInputSystem, g_pInputSystem );
#endif // IINPUTSYSTEM_H