mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-17 18:40:02 +00:00
engine: client: rework mouse input, use IN_MouseEvent for clientdll, don't emit mouse events when mouse is visible or touch emulate is used
This commit is contained in:
parent
01b2266b7e
commit
284eeea3c3
@ -18,7 +18,7 @@ GNU General Public License for more details.
|
|||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "vgui_draw.h"
|
#include "vgui_draw.h"
|
||||||
|
|
||||||
#ifdef XASH_SDL
|
#if XASH_SDL
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -30,6 +30,8 @@ qboolean in_mouseinitialized;
|
|||||||
qboolean in_mouse_suspended;
|
qboolean in_mouse_suspended;
|
||||||
POINT in_lastvalidpos;
|
POINT in_lastvalidpos;
|
||||||
qboolean in_mouse_savedpos;
|
qboolean in_mouse_savedpos;
|
||||||
|
static uint in_mouse_oldbuttonstate;
|
||||||
|
static int in_mouse_buttons = 5; // SDL maximum
|
||||||
static struct inputstate_s
|
static struct inputstate_s
|
||||||
{
|
{
|
||||||
float lastpitch, lastyaw;
|
float lastpitch, lastyaw;
|
||||||
@ -131,7 +133,7 @@ static void IN_ActivateCursor( void )
|
|||||||
{
|
{
|
||||||
if( cls.key_dest == key_menu )
|
if( cls.key_dest == key_menu )
|
||||||
{
|
{
|
||||||
#ifdef XASH_SDL
|
#if XASH_SDL
|
||||||
SDL_SetCursor( in_mousecursor );
|
SDL_SetCursor( in_mousecursor );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -196,24 +198,24 @@ void IN_ToggleClientMouse( int newstate, int oldstate )
|
|||||||
else if( newstate == key_game )
|
else if( newstate == key_game )
|
||||||
{
|
{
|
||||||
// reset mouse pos, so cancel effect in game
|
// reset mouse pos, so cancel effect in game
|
||||||
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
|
#if XASH_SDL >= 2
|
||||||
if( CVAR_TO_BOOL( touch_enable ) )
|
if( CVAR_TO_BOOL( touch_enable ) )
|
||||||
{
|
{
|
||||||
SDL_SetRelativeMouseMode( SDL_FALSE );
|
SDL_SetRelativeMouseMode( SDL_FALSE );
|
||||||
SDL_SetWindowGrab( host.hWnd, SDL_FALSE );
|
SDL_SetWindowGrab( host.hWnd, SDL_FALSE );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif // XASH_SDL >= 2
|
||||||
{
|
{
|
||||||
Platform_SetMousePos( host.window_center_x, host.window_center_y );
|
Platform_SetMousePos( host.window_center_x, host.window_center_y );
|
||||||
#if XASH_SDL
|
#if XASH_SDL
|
||||||
SDL_SetWindowGrab( host.hWnd, SDL_TRUE );
|
SDL_SetWindowGrab( host.hWnd, SDL_TRUE );
|
||||||
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
|
#if XASH_SDL >= 2
|
||||||
if ( clgame.dllFuncs.pfnLookEvent || ( clgame.client_dll_uses_sdl && CVAR_TO_BOOL( m_rawinput ) ) )
|
if ( clgame.dllFuncs.pfnLookEvent || ( clgame.client_dll_uses_sdl && CVAR_TO_BOOL( m_rawinput ) ) )
|
||||||
{
|
{
|
||||||
SDL_SetRelativeMouseMode( SDL_TRUE );
|
SDL_SetRelativeMouseMode( SDL_TRUE );
|
||||||
}
|
}
|
||||||
#endif
|
#endif // XASH_SDL >= 2
|
||||||
#endif // XASH_SDL
|
#endif // XASH_SDL
|
||||||
}
|
}
|
||||||
if( cls.initialized )
|
if( cls.initialized )
|
||||||
@ -222,14 +224,14 @@ void IN_ToggleClientMouse( int newstate, int oldstate )
|
|||||||
|
|
||||||
if( ( newstate == key_menu || newstate == key_console || newstate == key_message ) && ( !CL_IsBackgroundMap() || CL_IsBackgroundDemo( )))
|
if( ( newstate == key_menu || newstate == key_console || newstate == key_message ) && ( !CL_IsBackgroundMap() || CL_IsBackgroundDemo( )))
|
||||||
{
|
{
|
||||||
#ifdef XASH_SDL
|
#if XASH_SDL
|
||||||
SDL_SetWindowGrab(host.hWnd, SDL_FALSE);
|
SDL_SetWindowGrab(host.hWnd, SDL_FALSE);
|
||||||
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
|
#if XASH_SDL >= 2
|
||||||
if ( clgame.dllFuncs.pfnLookEvent || ( clgame.client_dll_uses_sdl && CVAR_TO_BOOL( m_rawinput ) ) )
|
if ( clgame.dllFuncs.pfnLookEvent || ( clgame.client_dll_uses_sdl && CVAR_TO_BOOL( m_rawinput ) ) )
|
||||||
{
|
{
|
||||||
SDL_SetRelativeMouseMode( SDL_FALSE );
|
SDL_SetRelativeMouseMode( SDL_FALSE );
|
||||||
}
|
}
|
||||||
#endif
|
#endif // XASH_SDL >= 2
|
||||||
#endif // XASH_SDL
|
#endif // XASH_SDL
|
||||||
#if XASH_ANDROID
|
#if XASH_ANDROID
|
||||||
Android_ShowMouse( true );
|
Android_ShowMouse( true );
|
||||||
@ -258,8 +260,7 @@ Called when the window gains focus or changes in some way
|
|||||||
*/
|
*/
|
||||||
void IN_ActivateMouse( qboolean force )
|
void IN_ActivateMouse( qboolean force )
|
||||||
{
|
{
|
||||||
int width, height;
|
static qboolean oldstate;
|
||||||
static int oldstate;
|
|
||||||
|
|
||||||
if( !in_mouseinitialized )
|
if( !in_mouseinitialized )
|
||||||
return;
|
return;
|
||||||
@ -277,7 +278,7 @@ void IN_ActivateMouse( qboolean force )
|
|||||||
{
|
{
|
||||||
if( in_mouse_suspended )
|
if( in_mouse_suspended )
|
||||||
{
|
{
|
||||||
#ifdef XASH_SDL
|
#if XASH_SDL
|
||||||
/// TODO: Platform_ShowCursor
|
/// TODO: Platform_ShowCursor
|
||||||
if( !touch_emulate )
|
if( !touch_emulate )
|
||||||
SDL_ShowCursor( SDL_FALSE );
|
SDL_ShowCursor( SDL_FALSE );
|
||||||
@ -303,10 +304,11 @@ void IN_ActivateMouse( qboolean force )
|
|||||||
|
|
||||||
if( cls.key_dest == key_game )
|
if( cls.key_dest == key_game )
|
||||||
{
|
{
|
||||||
clgame.dllFuncs.IN_ActivateMouse();
|
#if XASH_SDL
|
||||||
#ifdef XASH_SDL
|
SDL_SetRelativeMouseMode( SDL_TRUE );
|
||||||
SDL_GetRelativeMouseState( 0, 0 ); // Reset mouse position
|
SDL_GetRelativeMouseState( 0, 0 );
|
||||||
#endif
|
#endif
|
||||||
|
clgame.dllFuncs.IN_ActivateMouse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,15 +324,17 @@ void IN_DeactivateMouse( void )
|
|||||||
if( !in_mouseinitialized || !in_mouseactive )
|
if( !in_mouseinitialized || !in_mouseactive )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#if XASH_SDL
|
||||||
|
SDL_SetRelativeMouseMode( SDL_FALSE );
|
||||||
|
SDL_SetWindowGrab( host.hWnd, SDL_FALSE );
|
||||||
|
#endif // XASH_SDL
|
||||||
|
|
||||||
if( cls.key_dest == key_game )
|
if( cls.key_dest == key_game )
|
||||||
{
|
{
|
||||||
clgame.dllFuncs.IN_DeactivateMouse();
|
clgame.dllFuncs.IN_DeactivateMouse();
|
||||||
}
|
}
|
||||||
|
|
||||||
in_mouseactive = false;
|
in_mouseactive = false;
|
||||||
#ifdef XASH_SDL
|
|
||||||
SDL_SetWindowGrab( host.hWnd, SDL_FALSE );
|
|
||||||
#endif // XASH_SDL
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -342,9 +346,14 @@ void IN_MouseMove( void )
|
|||||||
{
|
{
|
||||||
POINT current_pos;
|
POINT current_pos;
|
||||||
|
|
||||||
if( !in_mouseinitialized || !in_mouseactive || !UI_IsVisible( ))
|
if( !in_mouseinitialized || !in_mouseactive )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#if XASH_SDL >= 2
|
||||||
|
if( cls.key_dest == key_game && !host.mouse_visible && touch_emulate->value == 0.0f )
|
||||||
|
SDL_SetRelativeMouseMode( SDL_TRUE );
|
||||||
|
#endif // XASH_SDL >= 2
|
||||||
|
|
||||||
// find mouse movement
|
// find mouse movement
|
||||||
Platform_GetMousePos( ¤t_pos.x, ¤t_pos.y );
|
Platform_GetMousePos( ¤t_pos.x, ¤t_pos.y );
|
||||||
|
|
||||||
@ -352,7 +361,7 @@ void IN_MouseMove( void )
|
|||||||
|
|
||||||
// HACKHACK: show cursor in UI, as mainui doesn't call
|
// HACKHACK: show cursor in UI, as mainui doesn't call
|
||||||
// platform-dependent SetCursor anymore
|
// platform-dependent SetCursor anymore
|
||||||
#ifdef XASH_SDL
|
#if XASH_SDL
|
||||||
if( UI_IsVisible() )
|
if( UI_IsVisible() )
|
||||||
SDL_ShowCursor( SDL_TRUE );
|
SDL_ShowCursor( SDL_TRUE );
|
||||||
#endif
|
#endif
|
||||||
@ -368,74 +377,49 @@ void IN_MouseMove( void )
|
|||||||
IN_MouseEvent
|
IN_MouseEvent
|
||||||
===========
|
===========
|
||||||
*/
|
*/
|
||||||
void IN_MouseEvent( void )
|
void IN_MouseEvent( uint mstate )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// touch emu: handle motion
|
|
||||||
if( CVAR_TO_BOOL( touch_emulate ))
|
|
||||||
{
|
|
||||||
if( Key_IsDown( K_SHIFT ) )
|
|
||||||
Touch_KeyEvent( K_MOUSE2, 2 );
|
|
||||||
else
|
|
||||||
Touch_KeyEvent( K_MOUSE1, 2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !in_mouseinitialized || !in_mouseactive )
|
if( !in_mouseinitialized || !in_mouseactive )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
if( m_ignore->value )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if( cls.key_dest == key_game )
|
if( cls.key_dest == key_game )
|
||||||
{
|
{
|
||||||
#if defined( XASH_SDL )
|
// perform button actions
|
||||||
static qboolean ignore; // igonre mouse warp event
|
for( i = 0; i < in_mouse_buttons; i++ )
|
||||||
int x, y;
|
|
||||||
Platform_GetMousePos(&x, &y);
|
|
||||||
if( host.mouse_visible )
|
|
||||||
SDL_ShowCursor( SDL_TRUE );
|
|
||||||
else if( !CVAR_TO_BOOL( touch_emulate ) )
|
|
||||||
SDL_ShowCursor( SDL_FALSE );
|
|
||||||
|
|
||||||
if( x < host.window_center_x / 2 ||
|
|
||||||
y < host.window_center_y / 2 ||
|
|
||||||
x > host.window_center_x + host.window_center_x / 2 ||
|
|
||||||
y > host.window_center_y + host.window_center_y / 2 )
|
|
||||||
{
|
{
|
||||||
Platform_SetMousePos( host.window_center_x, host.window_center_y );
|
if( FBitSet( mstate, BIT( i )) && !FBitSet( in_mouse_oldbuttonstate, BIT( i )))
|
||||||
ignore = 1; // next mouse event will be mouse warp
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !ignore )
|
|
||||||
{
|
|
||||||
if( !m_enginemouse->value )
|
|
||||||
{
|
{
|
||||||
// a1ba: mouse keys are now separated
|
VGui_KeyEvent( K_MOUSE1 + i, true );
|
||||||
// so pass 0 here
|
}
|
||||||
clgame.dllFuncs.IN_MouseEvent( 0 );
|
|
||||||
|
if( !FBitSet( mstate, BIT( i )) && FBitSet( in_mouse_oldbuttonstate, BIT( i )))
|
||||||
|
{
|
||||||
|
VGui_KeyEvent( K_MOUSE1 + i, false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
clgame.dllFuncs.IN_MouseEvent( mstate );
|
||||||
SDL_GetRelativeMouseState( 0, 0 ); // reset relative state
|
|
||||||
ignore = 0;
|
in_mouse_oldbuttonstate = mstate;
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
// perform button actions
|
||||||
|
for( i = 0; i < in_mouse_buttons; i++ )
|
||||||
{
|
{
|
||||||
#if XASH_SDL && !XASH_WIN32
|
if( FBitSet( mstate, BIT( i )) && !FBitSet( in_mouse_oldbuttonstate, BIT( i )))
|
||||||
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
|
{
|
||||||
SDL_SetRelativeMouseMode( SDL_FALSE );
|
Key_Event( K_MOUSE1 + i, true );
|
||||||
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
|
}
|
||||||
SDL_ShowCursor( SDL_TRUE );
|
|
||||||
#endif // XASH_SDL && !XASH_WIN32
|
if( !FBitSet( mstate, BIT( i )) && FBitSet( in_mouse_oldbuttonstate, BIT( i )))
|
||||||
IN_MouseMove();
|
{
|
||||||
|
Key_Event( K_MOUSE1 + i, false );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
in_mouse_oldbuttonstate = mstate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -626,7 +610,9 @@ void IN_EngineAppendMove( float frametime, void *cmd1, qboolean active )
|
|||||||
{
|
{
|
||||||
float sensitivity = 1;//( (float)cl.local.scr_fov / (float)90.0f );
|
float sensitivity = 1;//( (float)cl.local.scr_fov / (float)90.0f );
|
||||||
|
|
||||||
IN_CollectInput( &forward, &side, &pitch, &yaw, in_mouseinitialized && !CVAR_TO_BOOL( m_ignore ), m_enginemouse->value );
|
IN_CollectInput( &forward, &side, &pitch, &yaw,
|
||||||
|
!host.mouse_visible && in_mouseinitialized && !CVAR_TO_BOOL( m_ignore ),
|
||||||
|
m_enginemouse->value );
|
||||||
|
|
||||||
IN_JoyAppendMove( cmd, forward, side );
|
IN_JoyAppendMove( cmd, forward, side );
|
||||||
|
|
||||||
@ -635,7 +621,7 @@ void IN_EngineAppendMove( float frametime, void *cmd1, qboolean active )
|
|||||||
cmd->viewangles[YAW] += yaw * sensitivity;
|
cmd->viewangles[YAW] += yaw * sensitivity;
|
||||||
cmd->viewangles[PITCH] += pitch * sensitivity;
|
cmd->viewangles[PITCH] += pitch * sensitivity;
|
||||||
cmd->viewangles[PITCH] = bound( -90, cmd->viewangles[PITCH], 90 );
|
cmd->viewangles[PITCH] = bound( -90, cmd->viewangles[PITCH], 90 );
|
||||||
VectorCopy(cmd->viewangles, cl.viewangles);
|
VectorCopy( cmd->viewangles, cl.viewangles );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ extern qboolean in_mouseinitialized;
|
|||||||
void IN_Init( void );
|
void IN_Init( void );
|
||||||
void Host_InputFrame( void );
|
void Host_InputFrame( void );
|
||||||
void IN_Shutdown( void );
|
void IN_Shutdown( void );
|
||||||
void IN_MouseEvent( void );
|
void IN_MouseEvent( uint mstate );
|
||||||
void IN_ActivateMouse( qboolean force );
|
void IN_ActivateMouse( qboolean force );
|
||||||
void IN_DeactivateMouse( void );
|
void IN_DeactivateMouse( void );
|
||||||
void IN_MouseSavePos( void );
|
void IN_MouseSavePos( void );
|
||||||
|
@ -271,30 +271,27 @@ SDLash_MouseEvent
|
|||||||
static void SDLash_MouseEvent( SDL_MouseButtonEvent button )
|
static void SDLash_MouseEvent( SDL_MouseButtonEvent button )
|
||||||
{
|
{
|
||||||
int down = button.state != SDL_RELEASED;
|
int down = button.state != SDL_RELEASED;
|
||||||
qboolean istouch;
|
uint mstate = 0;
|
||||||
|
|
||||||
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
|
if( button.which == SDL_TOUCH_MOUSEID )
|
||||||
istouch = button.which == SDL_TOUCH_MOUSEID;
|
return;
|
||||||
#else // SDL_VERSION_ATLEAST( 2, 0, 0 )
|
|
||||||
istouch = false;
|
|
||||||
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
|
|
||||||
|
|
||||||
switch( button.button )
|
switch( button.button )
|
||||||
{
|
{
|
||||||
case SDL_BUTTON_LEFT:
|
case SDL_BUTTON_LEFT:
|
||||||
SDLash_MouseKey( K_MOUSE1, down, istouch );
|
if( down ) SetBits( mstate, BIT( 0 ));
|
||||||
break;
|
|
||||||
case SDL_BUTTON_RIGHT:
|
|
||||||
SDLash_MouseKey( K_MOUSE2, down, istouch );
|
|
||||||
break;
|
break;
|
||||||
case SDL_BUTTON_MIDDLE:
|
case SDL_BUTTON_MIDDLE:
|
||||||
SDLash_MouseKey( K_MOUSE3, down, istouch );
|
if( down ) SetBits( mstate, BIT( 1 ));
|
||||||
|
break;
|
||||||
|
case SDL_BUTTON_RIGHT:
|
||||||
|
if( down ) SetBits( mstate, BIT( 2 ));
|
||||||
break;
|
break;
|
||||||
case SDL_BUTTON_X1:
|
case SDL_BUTTON_X1:
|
||||||
SDLash_MouseKey( K_MOUSE4, down, istouch );
|
if( down ) SetBits( mstate, BIT( 3 ));
|
||||||
break;
|
break;
|
||||||
case SDL_BUTTON_X2:
|
case SDL_BUTTON_X2:
|
||||||
SDLash_MouseKey( K_MOUSE5, down, istouch );
|
if( down ) SetBits( mstate, BIT( 4 ));
|
||||||
break;
|
break;
|
||||||
#if ! SDL_VERSION_ATLEAST( 2, 0, 0 )
|
#if ! SDL_VERSION_ATLEAST( 2, 0, 0 )
|
||||||
case SDL_BUTTON_WHEELUP:
|
case SDL_BUTTON_WHEELUP:
|
||||||
@ -307,6 +304,8 @@ static void SDLash_MouseEvent( SDL_MouseButtonEvent button )
|
|||||||
default:
|
default:
|
||||||
Con_Printf( "Unknown mouse button ID: %d\n", button.button );
|
Con_Printf( "Unknown mouse button ID: %d\n", button.button );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IN_MouseEvent( mstate );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -426,13 +425,7 @@ static void SDLash_EventFilter( SDL_Event *event )
|
|||||||
{
|
{
|
||||||
/* Mouse events */
|
/* Mouse events */
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
if( !host.mouse_visible
|
/* ignored */
|
||||||
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
|
|
||||||
&& event->motion.which != SDL_TOUCH_MOUSEID )
|
|
||||||
#else
|
|
||||||
)
|
|
||||||
#endif
|
|
||||||
IN_MouseEvent();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user