Browse Source

inputsystem: touch event handling

pull/26/head
nillerusr 3 years ago
parent
commit
81b976c384
  1. 16
      inputsystem/inputsystem.cpp
  2. 18
      inputsystem/inputsystem.h
  3. 98
      inputsystem/touch_sdl.cpp
  4. 3
      public/inputsystem/InputEnums.h
  5. 22
      vguimatsurface/Input.cpp

16
inputsystem/inputsystem.cpp

@ -31,7 +31,6 @@ EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CInputSystem, IInputSystem, @@ -31,7 +31,6 @@ EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CInputSystem, IInputSystem,
INPUTSYSTEM_INTERFACE_VERSION, g_InputSystem );
#if defined( WIN32 ) && !defined( _X360 )
typedef BOOL (WINAPI *RegisterRawInputDevices_t)
(
@ -70,6 +69,7 @@ CInputSystem::CInputSystem() @@ -70,6 +69,7 @@ CInputSystem::CInputSystem()
m_JoysticksEnabled.ClearAllFlags();
m_nJoystickCount = 0;
m_bJoystickInitialized = false;
m_bTouchInitialized = false;
m_nPollCount = 0;
m_PrimaryUserId = INVALID_USER_ID;
m_uiMouseWheel = 0;
@ -166,6 +166,10 @@ InitReturnVal_t CInputSystem::Init() @@ -166,6 +166,10 @@ InitReturnVal_t CInputSystem::Init()
ButtonCode_UpdateScanCodeLayout();
joy_xcontroller_found.SetValue( 0 );
if( !m_bConsoleTextMode )
InitializeTouch();
if ( IsPC() && !m_bConsoleTextMode )
{
InitializeJoysticks();
@ -1526,6 +1530,16 @@ bool CInputSystem::GetRawMouseAccumulators( int& accumX, int& accumY ) @@ -1526,6 +1530,16 @@ bool CInputSystem::GetRawMouseAccumulators( int& accumX, int& accumY )
#endif
}
bool CInputSystem::GetTouchAccumulators( InputEventType_t &event, int &fingerId, int& accumX, int& accumY )
{
event = m_touchAccumEvent;
fingerId = m_touchAccumFingerId;
accumX = m_touchAccumX;
accumY = m_touchAccumY;
return m_bJoystickInitialized;
}
void CInputSystem::SetConsoleTextMode( bool bConsoleTextMode )
{
/* If someone calls this after init, shut it down. */

18
inputsystem/inputsystem.h

@ -101,6 +101,8 @@ public: @@ -101,6 +101,8 @@ public:
virtual void *GetHapticsInterfaceAddress() const { return NULL;}
#endif
bool GetRawMouseAccumulators( int& accumX, int& accumY );
bool GetTouchAccumulators( InputEventType_t &event, int &fingerId, int& accumX, int& accumY );
virtual void SetConsoleTextMode( bool bConsoleTextMode );
// Windows proc
@ -241,6 +243,13 @@ public: @@ -241,6 +243,13 @@ public:
// Record button state and post the event
void JoystickButtonEvent( ButtonCode_t button, int sample );
// Init touch
void InitializeTouch( void );
// Shut down touch
void ShutdownTouch( void );
#if defined( WIN32 ) && !defined ( _X360 )
// NVNT attaches window to novint devices
void AttachWindowToNovintDevices( void * hWnd );
@ -324,6 +333,11 @@ public: @@ -324,6 +333,11 @@ public:
void JoystickButtonRelease( int joystickId, int button ); // same as above.
void JoystickAxisMotion( int joystickId, int axis, int value );
void FingerDown( int fingerId, int x, int y );
void FingerUp( int fingerId, int x, int y );
void FingerMotion( int fingerId, int x, int y );
// Steam Controller
void ReadSteamController( int iIndex );
void PostKeyEvent( int iIndex, sKey_t sKey, int nSample );
@ -390,6 +404,7 @@ public: @@ -390,6 +404,7 @@ public:
CUtlFlags<unsigned short> m_JoysticksEnabled;
int m_nJoystickCount;
bool m_bJoystickInitialized;
bool m_bTouchInitialized;
bool m_bXController;
JoystickInfo_t m_pJoystickInfo[ MAX_JOYSTICKS ];
@ -444,6 +459,9 @@ public: @@ -444,6 +459,9 @@ public:
bool m_bRawInputSupported;
int m_mouseRawAccumX, m_mouseRawAccumY;
InputEventType_t m_touchAccumEvent;
int m_touchAccumFingerId, m_touchAccumX, m_touchAccumY;
// For the 'SleepUntilInput' feature
HANDLE m_hEvent;

98
inputsystem/touch_sdl.cpp

@ -0,0 +1,98 @@ @@ -0,0 +1,98 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Linux/Android touch implementation for inputsystem
//
//===========================================================================//
/* For force feedback testing. */
#include "inputsystem.h"
#include "tier1/convar.h"
#include "tier0/icommandline.h"
#include "SDL.h"
#include "SDL_touch.h"
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Handle the events coming from the Touch SDL subsystem.
//-----------------------------------------------------------------------------
int TouchSDLWatcher( void *userInfo, SDL_Event *event )
{
CInputSystem *pInputSystem = (CInputSystem *)userInfo;
SDL_Window *window = SDL_GetWindowFromID(event->tfinger.windowID);
if( !window )
return 0;
int width, height;
width = height = 0;
SDL_GetWindowSize(window, &width, &height);
switch ( event->type ) {
case SDL_FINGERDOWN:
pInputSystem->FingerDown( event->tfinger.fingerId, event->tfinger.x*width, event->tfinger.y*height );
break;
case SDL_FINGERUP:
pInputSystem->FingerUp( event->tfinger.fingerId, event->tfinger.x*width, event->tfinger.y*height );
break;
case SDL_FINGERMOTION:
pInputSystem->FingerMotion( event->tfinger.fingerId, event->tfinger.x*width, event->tfinger.y*height );
break;
}
return 1;
}
//-----------------------------------------------------------------------------
// Initialize all joysticks
//-----------------------------------------------------------------------------
void CInputSystem::InitializeTouch( void )
{
if ( m_bTouchInitialized )
ShutdownTouch();
// abort startup if user requests no touch
if ( CommandLine()->FindParm("-notouch") ) return;
m_bJoystickInitialized = true;
SDL_AddEventWatch(TouchSDLWatcher, this);
}
void CInputSystem::ShutdownTouch()
{
if ( !m_bTouchInitialized )
return;
SDL_DelEventWatch( TouchSDLWatcher, this );
m_bTouchInitialized = false;
}
void CInputSystem::FingerDown(int fingerId, int x, int y)
{
m_touchAccumEvent = IE_FingerDown;
m_touchAccumFingerId = fingerId;
m_touchAccumX = x;
m_touchAccumY = y;
PostEvent(IE_FingerDown, m_nLastSampleTick, fingerId, x, y);
}
void CInputSystem::FingerUp(int fingerId, int x, int y)
{
m_touchAccumEvent = IE_FingerUp;
m_touchAccumFingerId = fingerId;
m_touchAccumX = x;
m_touchAccumY = y;
PostEvent(IE_FingerUp, m_nLastSampleTick, fingerId, x, y);
}
void CInputSystem::FingerMotion(int fingerId, int x, int y)
{
m_touchAccumEvent = IE_FingerMotion;
m_touchAccumFingerId = fingerId;
m_touchAccumX = x;
m_touchAccumY = y;
PostEvent(IE_FingerMotion, m_nLastSampleTick, fingerId, x, y);
}

3
public/inputsystem/InputEnums.h

@ -76,6 +76,9 @@ enum InputEventType_t @@ -76,6 +76,9 @@ enum InputEventType_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_FingerDown,
IE_FingerUp,
IE_FingerMotion,
IE_FirstSystemEvent = 100,
IE_Quit = IE_FirstSystemEvent,

22
vguimatsurface/Input.cpp

@ -423,7 +423,27 @@ bool InputHandleInputEvent( const InputEvent_t &event ) @@ -423,7 +423,27 @@ bool InputHandleInputEvent( const InputEvent_t &event )
}
}
break;
case IE_FingerDown:
{
//g_pIInput->InternalCursorMoved( event.m_nData2, event.m_nData3 );
g_pIInput->UpdateCursorPosInternal( event.m_nData2, event.m_nData3 );
g_pIInput->SetMouseCodeState( MOUSE_LEFT, vgui::BUTTON_PRESSED );
g_pIInput->InternalMousePressed( MOUSE_LEFT );
}
return true;
case IE_FingerUp:
{
g_pIInput->UpdateCursorPosInternal( event.m_nData2, event.m_nData3 );
g_pIInput->SetMouseCodeState( MOUSE_LEFT, vgui::BUTTON_RELEASED );
g_pIInput->InternalMouseReleased( MOUSE_LEFT );
}
return true;
case IE_FingerMotion:
{
//g_pIInput->UpdateCursorPosInternal( event.m_nData2, event.m_nData3 );
g_pIInput->InternalCursorMoved( event.m_nData2, event.m_nData3 );
}
return true;
case IE_ButtonDoubleClicked:
{
// NOTE: data2 is the virtual key code (data1 contains the scan-code one)

Loading…
Cancel
Save