Browse Source

engine: input: fix incorrect client notifying about mouse button states

pull/2/head
Alibek Omarov 3 years ago
parent
commit
abbd0f92a4
  1. 46
      engine/client/input.c
  2. 2
      engine/client/input.h
  3. 12
      engine/platform/sdl/events.c

46
engine/client/input.c

@ -30,8 +30,7 @@ qboolean in_mouseinitialized; @@ -30,8 +30,7 @@ qboolean in_mouseinitialized;
qboolean in_mouse_suspended;
POINT in_lastvalidpos;
qboolean in_mouse_savedpos;
static uint in_mouse_oldbuttonstate;
static int in_mouse_buttons = 5; // SDL maximum
static int in_mstate = 0;
static struct inputstate_s
{
float lastpitch, lastyaw;
@ -337,50 +336,33 @@ void IN_MouseMove( void ) @@ -337,50 +336,33 @@ void IN_MouseMove( void )
IN_MouseEvent
===========
*/
void IN_MouseEvent( uint mstate )
void IN_MouseEvent( int key, int down )
{
int i;
if( !in_mouseinitialized )
return;
if( down )
SetBits( in_mstate, BIT( key ));
else ClearBits( in_mstate, BIT( key ));
if( cls.key_dest == key_game )
{
// perform button actions
for( i = 0; i < in_mouse_buttons; i++ )
{
if( FBitSet( mstate, BIT( i )) && !FBitSet( in_mouse_oldbuttonstate, BIT( i )))
{
VGui_KeyEvent( K_MOUSE1 + i, true );
}
if( !FBitSet( mstate, BIT( i )) && FBitSet( in_mouse_oldbuttonstate, BIT( i )))
{
VGui_KeyEvent( K_MOUSE1 + i, false );
}
}
VGui_KeyEvent( K_MOUSE1 + key, down );
// don't do Key_Event here
// client may override IN_MouseEvent
// but by default it calls back to Key_Event anyway
if( in_mouseactive )
clgame.dllFuncs.IN_MouseEvent( mstate );
in_mouse_oldbuttonstate = mstate;
return;
clgame.dllFuncs.IN_MouseEvent( in_mstate );
}
// perform button actions
for( i = 0; i < in_mouse_buttons; i++ )
else
{
if( FBitSet( mstate, BIT( i )) && !FBitSet( in_mouse_oldbuttonstate, BIT( i )))
{
Key_Event( K_MOUSE1 + i, true );
}
if( !FBitSet( mstate, BIT( i )) && FBitSet( in_mouse_oldbuttonstate, BIT( i )))
{
Key_Event( K_MOUSE1 + i, false );
}
// perform button actions
Key_Event( K_MOUSE1 + key, down );
}
in_mouse_oldbuttonstate = mstate;
}
/*

2
engine/client/input.h

@ -33,7 +33,7 @@ extern qboolean in_mouseinitialized; @@ -33,7 +33,7 @@ extern qboolean in_mouseinitialized;
void IN_Init( void );
void Host_InputFrame( void );
void IN_Shutdown( void );
void IN_MouseEvent( uint mstate );
void IN_MouseEvent( int key, int down );
void IN_ActivateMouse( void );
void IN_DeactivateMouse( void );
void IN_MouseSavePos( void );

12
engine/platform/sdl/events.c

@ -281,19 +281,19 @@ static void SDLash_MouseEvent( SDL_MouseButtonEvent button ) @@ -281,19 +281,19 @@ static void SDLash_MouseEvent( SDL_MouseButtonEvent button )
switch( button.button )
{
case SDL_BUTTON_LEFT:
if( down ) SetBits( mstate, BIT( 0 ));
IN_MouseEvent( 0, down );
break;
case SDL_BUTTON_MIDDLE:
if( down ) SetBits( mstate, BIT( 1 ));
IN_MouseEvent( 1, down );
break;
case SDL_BUTTON_RIGHT:
if( down ) SetBits( mstate, BIT( 2 ));
IN_MouseEvent( 2, down );
break;
case SDL_BUTTON_X1:
if( down ) SetBits( mstate, BIT( 3 ));
IN_MouseEvent( 3, down );
break;
case SDL_BUTTON_X2:
if( down ) SetBits( mstate, BIT( 4 ));
IN_MouseEvent( 4, down );
break;
#if ! SDL_VERSION_ATLEAST( 2, 0, 0 )
case SDL_BUTTON_WHEELUP:
@ -306,8 +306,6 @@ static void SDLash_MouseEvent( SDL_MouseButtonEvent button ) @@ -306,8 +306,6 @@ static void SDLash_MouseEvent( SDL_MouseButtonEvent button )
default:
Con_Printf( "Unknown mouse button ID: %d\n", button.button );
}
IN_MouseEvent( mstate );
}
/*

Loading…
Cancel
Save