Browse Source

Adapt input code to newer engine

pull/2/head
Alibek Omarov 7 years ago
parent
commit
92c321848d
  1. 67
      engine/client/in_joy.c
  2. 116
      engine/client/in_touch.c
  3. 1
      engine/common/input.h
  4. 15
      engine/common/keys.c

67
engine/client/in_joy.c

@ -19,7 +19,6 @@ GNU General Public License for more details.
#include "common.h" #include "common.h"
#include "input.h" #include "input.h"
#include "keydefs.h" #include "keydefs.h"
#include "joyinput.h"
#include "client.h" #include "client.h"
#include "gl_local.h" #include "gl_local.h"
@ -149,11 +148,11 @@ void Joy_ProcessTrigger( const engineAxis_t engineAxis, short value )
{ {
case JOY_AXIS_RT: case JOY_AXIS_RT:
trigButton = K_JOY2; trigButton = K_JOY2;
trigThreshold = joy_rt_threshold->integer; trigThreshold = joy_rt_threshold->value;
break; break;
case JOY_AXIS_LT: case JOY_AXIS_LT:
trigButton = K_JOY1; trigButton = K_JOY1;
trigThreshold = joy_lt_threshold->integer; trigThreshold = joy_lt_threshold->value;
break; break;
default: default:
MsgDev( D_ERROR, "Joy_ProcessTrigger: invalid axis = %i", engineAxis ); MsgDev( D_ERROR, "Joy_ProcessTrigger: invalid axis = %i", engineAxis );
@ -183,12 +182,12 @@ int Joy_GetHatValueForAxis( const engineAxis_t engineAxis )
switch( engineAxis ) switch( engineAxis )
{ {
case JOY_AXIS_SIDE: case JOY_AXIS_SIDE:
threshold = joy_side_key_threshold->integer; threshold = joy_side_key_threshold->value;
negative = JOY_HAT_LEFT; negative = JOY_HAT_LEFT;
positive = JOY_HAT_RIGHT; positive = JOY_HAT_RIGHT;
break; break;
case JOY_AXIS_FWD: case JOY_AXIS_FWD:
threshold = joy_side_key_threshold->integer; threshold = joy_side_key_threshold->value;
negative = JOY_HAT_UP; negative = JOY_HAT_UP;
positive = JOY_HAT_DOWN; positive = JOY_HAT_DOWN;
break; break;
@ -222,10 +221,10 @@ void Joy_ProcessStick( const engineAxis_t engineAxis, short value )
switch( engineAxis ) switch( engineAxis )
{ {
case JOY_AXIS_FWD: deadzone = joy_forward_deadzone->integer; break; case JOY_AXIS_FWD: deadzone = joy_forward_deadzone->value; break;
case JOY_AXIS_SIDE: deadzone = joy_side_deadzone->integer; break; case JOY_AXIS_SIDE: deadzone = joy_side_deadzone->value; break;
case JOY_AXIS_PITCH: deadzone = joy_pitch_deadzone->integer; break; case JOY_AXIS_PITCH: deadzone = joy_pitch_deadzone->value; break;
case JOY_AXIS_YAW: deadzone = joy_yaw_deadzone->integer; break; case JOY_AXIS_YAW: deadzone = joy_yaw_deadzone->value; break;
default: default:
MsgDev( D_ERROR, "Joy_ProcessStick: invalid axis = %i", engineAxis ); MsgDev( D_ERROR, "Joy_ProcessStick: invalid axis = %i", engineAxis );
break; break;
@ -332,8 +331,8 @@ Called when joystick is removed. For future expansion
*/ */
void Joy_RemoveEvent( int id ) void Joy_RemoveEvent( int id )
{ {
if( !forcedisable && initialized && joy_found->integer ) if( !forcedisable && initialized && joy_found->value )
Cvar_SetFloat("joy_found", joy_found->value - 1.0f); Cvar_SetValue("joy_found", joy_found->value - 1.0f);
} }
/* /*
@ -350,7 +349,7 @@ void Joy_AddEvent( int id )
initialized = true; initialized = true;
Cvar_SetFloat("joy_found", joy_found->value + 1.0f); Cvar_SetValue("joy_found", joy_found->value + 1.0f);
} }
/* /*
@ -362,10 +361,10 @@ Append movement from axis. Called everyframe
*/ */
void Joy_FinalizeMove( float *fw, float *side, float *dpitch, float *dyaw ) void Joy_FinalizeMove( float *fw, float *side, float *dpitch, float *dyaw )
{ {
if( !initialized || !joy_enable->integer ) if( !initialized || !joy_enable->value )
return; return;
if( joy_axis_binding->modified ) if( FBitSet( joy_axis_binding->flags, FCVAR_CHANGED ) )
{ {
char bind[7] = { 0 }; // fill it with zeros char bind[7] = { 0 }; // fill it with zeros
size_t i; size_t i;
@ -384,7 +383,7 @@ void Joy_FinalizeMove( float *fw, float *side, float *dpitch, float *dyaw )
default : joyaxesmap[i] = JOY_AXIS_NULL; break; default : joyaxesmap[i] = JOY_AXIS_NULL; break;
} }
} }
joy_axis_binding->modified = false; ClearBits( joy_axis_binding->flags, FCVAR_CHANGED );
} }
*fw -= joy_forward->value * (float)joyaxis[JOY_AXIS_FWD ].val/(float)SHRT_MAX; // must be form -1.0 to 1.0 *fw -= joy_forward->value * (float)joyaxis[JOY_AXIS_FWD ].val/(float)SHRT_MAX; // must be form -1.0 to 1.0
@ -408,32 +407,32 @@ Main init procedure
*/ */
void Joy_Init( void ) void Joy_Init( void )
{ {
joy_pitch = Cvar_Get( "joy_pitch", "100.0", CVAR_ARCHIVE, "joystick pitch sensitivity" ); joy_pitch = Cvar_Get( "joy_pitch", "100.0", FCVAR_ARCHIVE, "joystick pitch sensitivity" );
joy_yaw = Cvar_Get( "joy_yaw", "100.0", CVAR_ARCHIVE, "joystick yaw sensitivity" ); joy_yaw = Cvar_Get( "joy_yaw", "100.0", FCVAR_ARCHIVE, "joystick yaw sensitivity" );
joy_side = Cvar_Get( "joy_side", "1.0", CVAR_ARCHIVE, "joystick side sensitivity. Values from -1.0 to 1.0" ); joy_side = Cvar_Get( "joy_side", "1.0", FCVAR_ARCHIVE, "joystick side sensitivity. Values from -1.0 to 1.0" );
joy_forward = Cvar_Get( "joy_forward", "1.0", CVAR_ARCHIVE, "joystick forward sensitivity. Values from -1.0 to 1.0" ); joy_forward = Cvar_Get( "joy_forward", "1.0", FCVAR_ARCHIVE, "joystick forward sensitivity. Values from -1.0 to 1.0" );
joy_lt_threshold = Cvar_Get( "joy_lt_threshold", "-16384", CVAR_ARCHIVE, "left trigger threshold. Value from -32768 to 32767"); joy_lt_threshold = Cvar_Get( "joy_lt_threshold", "-16384", FCVAR_ARCHIVE, "left trigger threshold. Value from -32768 to 32767");
joy_rt_threshold = Cvar_Get( "joy_rt_threshold", "-16384", CVAR_ARCHIVE, "right trigger threshold. Value from -32768 to 32767" ); joy_rt_threshold = Cvar_Get( "joy_rt_threshold", "-16384", FCVAR_ARCHIVE, "right trigger threshold. Value from -32768 to 32767" );
// emit a key event at 75% axis move // emit a key event at 75% axis move
joy_side_key_threshold = Cvar_Get( "joy_side_key_threshold", "24576", CVAR_ARCHIVE, "side axis key event emit threshold. Value from 0 to 32767" ); joy_side_key_threshold = Cvar_Get( "joy_side_key_threshold", "24576", FCVAR_ARCHIVE, "side axis key event emit threshold. Value from 0 to 32767" );
joy_forward_key_threshold = Cvar_Get( "joy_forward_key_threshold", "24576", CVAR_ARCHIVE, "forward axis key event emit threshold. Value from 0 to 32767"); joy_forward_key_threshold = Cvar_Get( "joy_forward_key_threshold", "24576", FCVAR_ARCHIVE, "forward axis key event emit threshold. Value from 0 to 32767");
// by default, we rely on deadzone detection come from system, but some glitchy devices report false deadzones // by default, we rely on deadzone detection come from system, but some glitchy devices report false deadzones
joy_side_deadzone = Cvar_Get( "joy_side_deadzone", "0", CVAR_ARCHIVE, "side axis deadzone. Value from 0 to 32767" ); joy_side_deadzone = Cvar_Get( "joy_side_deadzone", "0", FCVAR_ARCHIVE, "side axis deadzone. Value from 0 to 32767" );
joy_forward_deadzone = Cvar_Get( "joy_forward_deadzone", "0", CVAR_ARCHIVE, "forward axis deadzone. Value from 0 to 32767"); joy_forward_deadzone = Cvar_Get( "joy_forward_deadzone", "0", FCVAR_ARCHIVE, "forward axis deadzone. Value from 0 to 32767");
joy_pitch_deadzone = Cvar_Get( "joy_pitch_deadzone", "0", CVAR_ARCHIVE, "pitch axis deadzone. Value from 0 to 32767"); joy_pitch_deadzone = Cvar_Get( "joy_pitch_deadzone", "0", FCVAR_ARCHIVE, "pitch axis deadzone. Value from 0 to 32767");
joy_yaw_deadzone = Cvar_Get( "joy_yaw_deadzone", "0", CVAR_ARCHIVE, "yaw axis deadzone. Value from 0 to 32767" ); joy_yaw_deadzone = Cvar_Get( "joy_yaw_deadzone", "0", FCVAR_ARCHIVE, "yaw axis deadzone. Value from 0 to 32767" );
joy_axis_binding = Cvar_Get( "joy_axis_binding", "sfpyrl", CVAR_ARCHIVE, "axis hardware id to engine inner axis binding, " joy_axis_binding = Cvar_Get( "joy_axis_binding", "sfpyrl", FCVAR_ARCHIVE, "axis hardware id to engine inner axis binding, "
"s - side, f - forward, y - yaw, p - pitch, r - left trigger, l - right trigger" ); "s - side, f - forward, y - yaw, p - pitch, r - left trigger, l - right trigger" );
joy_found = Cvar_Get( "joy_found", "0", CVAR_READ_ONLY, "total num of connected joysticks" ); joy_found = Cvar_Get( "joy_found", "0", FCVAR_READ_ONLY, "total num of connected joysticks" );
// we doesn't loaded config.cfg yet, so this cvar is not archive. // we doesn't loaded config.cfg yet, so this cvar is not archive.
// change by +set joy_index in cmdline // change by +set joy_index in cmdline
joy_index = Cvar_Get( "joy_index", "0", CVAR_READ_ONLY, "current active joystick" ); joy_index = Cvar_Get( "joy_index", "0", FCVAR_READ_ONLY, "current active joystick" );
joy_enable = Cvar_Get( "joy_enable", "1", CVAR_ARCHIVE, "enable joystick" ); joy_enable = Cvar_Get( "joy_enable", "1", FCVAR_ARCHIVE, "enable joystick" );
if( Sys_CheckParm("-nojoy" ) ) if( Sys_CheckParm("-nojoy" ) )
{ {
@ -443,14 +442,14 @@ void Joy_Init( void )
#if defined(XASH_SDL) #if defined(XASH_SDL)
// SDL can tell us about connected joysticks // SDL can tell us about connected joysticks
Cvar_SetFloat( "joy_found", SDLash_JoyInit( joy_index->integer ) ); Cvar_SetValue( "joy_found", SDLash_JoyInit( joy_index->value ) );
#elif defined(ANDROID) #elif defined(ANDROID)
// Initalized after first Joy_AddEvent // Initalized after first Joy_AddEvent
#else #else
#warning "Any platform must implement platform-dependent JoyInit, start event system. Otherwise no joystick support" #warning "Any platform must implement platform-dependent JoyInit, start event system. Otherwise no joystick support"
#endif #endif
if( joy_found->integer > 0 ) if( joy_found->value > 0 )
initialized = true; initialized = true;
else else
initialized = false; initialized = false;
@ -465,7 +464,7 @@ Shutdown joystick code
*/ */
void Joy_Shutdown( void ) void Joy_Shutdown( void )
{ {
Cvar_SetFloat( "joy_found", 0 ); Cvar_SetValue( "joy_found", 0 );
initialized = false; initialized = false;
} }

116
engine/client/in_touch.c

@ -17,13 +17,12 @@ GNU General Public License for more details.
#include "common.h" #include "common.h"
#include "gl_local.h" #include "gl_local.h"
#include "input.h" #include "input.h"
#include "mobility_int.h"
#include "client.h" #include "client.h"
#include "touch.h"
#include "math.h" #include "math.h"
#include "vgui_draw.h" #include "vgui_draw.h"
#ifdef XASH_SDL #ifdef XASH_SDL
#include <SDL_hints.h> #include <SDL.h>
#include <SDL_keyboard.h>
#endif #endif
typedef enum typedef enum
@ -154,10 +153,11 @@ convar_t *touch_joy_texture;
// code looks smaller with it // code looks smaller with it
#define B(x) button->x #define B(x) button->x
#define SCR_W (scr_width->value) #define SCR_W ((float)glState.width)
#define SCR_H (scr_height->value) #define SCR_H ((float)glState.height)
#define TO_SCRN_Y(x) (scr_height->integer * (x)) #define TO_SCRN_Y(x) (glState.height * (x))
#define TO_SCRN_X(x) (scr_width->integer * (x)) #define TO_SCRN_X(x) (glState.width * (x))
int pfnDrawCharacter( int x, int y, int number, int r, int g, int b ); int pfnDrawCharacter( int x, int y, int number, int r, int g, int b );
static void IN_TouchCheckCoords( float *x1, float *y1, float *x2, float *y2 ); static void IN_TouchCheckCoords( float *x1, float *y1, float *x2, float *y2 );
@ -193,12 +193,12 @@ void IN_TouchWriteConfig( void )
FS_Printf( f, "touch_yaw \"%f\"\n", touch_yaw->value ); FS_Printf( f, "touch_yaw \"%f\"\n", touch_yaw->value );
FS_Printf( f, "touch_forwardzone \"%f\"\n", touch_forwardzone->value ); FS_Printf( f, "touch_forwardzone \"%f\"\n", touch_forwardzone->value );
FS_Printf( f, "touch_sidezone \"%f\"\n", touch_sidezone->value ); FS_Printf( f, "touch_sidezone \"%f\"\n", touch_sidezone->value );
FS_Printf( f, "touch_nonlinear_look \"%d\"\n", touch_nonlinear_look->integer ); FS_Printf( f, "touch_nonlinear_look \"%d\"\n", (int)touch_nonlinear_look->value );
FS_Printf( f, "touch_pow_factor \"%f\"\n", touch_pow_factor->value ); FS_Printf( f, "touch_pow_factor \"%f\"\n", touch_pow_factor->value );
FS_Printf( f, "touch_pow_mult \"%f\"\n", touch_pow_mult->value ); FS_Printf( f, "touch_pow_mult \"%f\"\n", touch_pow_mult->value );
FS_Printf( f, "touch_exp_mult \"%f\"\n", touch_exp_mult->value ); FS_Printf( f, "\n// grid settings\n" ); FS_Printf( f, "touch_exp_mult \"%f\"\n", touch_exp_mult->value ); FS_Printf( f, "\n// grid settings\n" );
FS_Printf( f, "touch_grid_count \"%d\"\n", touch_grid_count->integer ); FS_Printf( f, "touch_grid_count \"%d\"\n", (int)touch_grid_count->value );
FS_Printf( f, "touch_grid_enable \"%d\"\n", touch_grid_enable->integer ); FS_Printf( f, "touch_grid_enable \"%d\"\n", (int)touch_grid_enable->value );
FS_Printf( f, "\n// global overstroke (width, r, g, b, a)\n" ); FS_Printf( f, "\n// global overstroke (width, r, g, b, a)\n" );
FS_Printf( f, "touch_set_stroke %d %d %d %d %d\n", touch.swidth, touch.scolor[0], touch.scolor[1], touch.scolor[2], touch.scolor[3] ); FS_Printf( f, "touch_set_stroke %d %d %d %d %d\n", touch.swidth, touch.scolor[0], touch.scolor[1], touch.scolor[2], touch.scolor[3] );
FS_Printf( f, "\n// highlight when pressed\n" ); FS_Printf( f, "\n// highlight when pressed\n" );
@ -212,7 +212,7 @@ void IN_TouchWriteConfig( void )
FS_Printf( f, "\n// how much slowdown when Precise Look button pressed\n" ); FS_Printf( f, "\n// how much slowdown when Precise Look button pressed\n" );
FS_Printf( f, "touch_precise_amount \"%f\"\n", touch_precise_amount->value ); FS_Printf( f, "touch_precise_amount \"%f\"\n", touch_precise_amount->value );
FS_Printf( f, "\n// enable/disable move indicator\n" ); FS_Printf( f, "\n// enable/disable move indicator\n" );
FS_Printf( f, "touch_move_indicator \"%d\"\n", touch_move_indicator->integer ); FS_Printf( f, "touch_move_indicator \"%d\"\n", (int)touch_move_indicator->value );
FS_Printf( f, "\n// reset menu state when execing config\n" ); FS_Printf( f, "\n// reset menu state when execing config\n" );
FS_Printf( f, "touch_setclientonly 0\n" ); FS_Printf( f, "touch_setclientonly 0\n" );
@ -267,7 +267,7 @@ void IN_TouchExportConfig_f( void )
touchbutton2_t *button; touchbutton2_t *button;
if( Q_strstr( name, "touch_presets/" ) ) if( Q_strstr( name, "touch_presets/" ) )
{ {
FS_FileBase( name, profilebase ); COM_FileBase( name, profilebase );
Q_snprintf( profilename, 256, "touch_profiles/%s (copy).cfg", profilebase ); Q_snprintf( profilename, 256, "touch_profiles/%s (copy).cfg", profilebase );
} }
else Q_strncpy( profilename, name, 256 ); else Q_strncpy( profilename, name, 256 );
@ -282,13 +282,13 @@ void IN_TouchExportConfig_f( void )
FS_Printf( f, "touch_yaw \"%f\"\n", touch_yaw->value ); FS_Printf( f, "touch_yaw \"%f\"\n", touch_yaw->value );
FS_Printf( f, "touch_forwardzone \"%f\"\n", touch_forwardzone->value ); FS_Printf( f, "touch_forwardzone \"%f\"\n", touch_forwardzone->value );
FS_Printf( f, "touch_sidezone \"%f\"\n", touch_sidezone->value ); FS_Printf( f, "touch_sidezone \"%f\"\n", touch_sidezone->value );
FS_Printf( f, "touch_nonlinear_look \"%d\"\n", touch_nonlinear_look->integer ); FS_Printf( f, "touch_nonlinear_look \"%d\"\n", (int)touch_nonlinear_look->value );
FS_Printf( f, "touch_pow_factor \"%f\"\n", touch_pow_factor->value ); FS_Printf( f, "touch_pow_factor \"%f\"\n", touch_pow_factor->value );
FS_Printf( f, "touch_pow_mult \"%f\"\n", touch_pow_mult->value ); FS_Printf( f, "touch_pow_mult \"%f\"\n", touch_pow_mult->value );
FS_Printf( f, "touch_exp_mult \"%f\"\n", touch_exp_mult->value ); FS_Printf( f, "touch_exp_mult \"%f\"\n", touch_exp_mult->value );
FS_Printf( f, "\n// grid settings\n" ); FS_Printf( f, "\n// grid settings\n" );
FS_Printf( f, "touch_grid_count \"%d\"\n", touch_grid_count->integer ); FS_Printf( f, "touch_grid_count \"%d\"\n", (int)touch_grid_count->value );
FS_Printf( f, "touch_grid_enable \"%d\"\n", touch_grid_enable->integer ); FS_Printf( f, "touch_grid_enable \"%d\"\n", (int)touch_grid_enable->value );
FS_Printf( f, "\n// global overstroke (width, r, g, b, a)\n" ); FS_Printf( f, "\n// global overstroke (width, r, g, b, a)\n" );
FS_Printf( f, "touch_set_stroke %d %d %d %d %d\n", touch.swidth, touch.scolor[0], touch.scolor[1], touch.scolor[2], touch.scolor[3] ); FS_Printf( f, "touch_set_stroke %d %d %d %d %d\n", touch.swidth, touch.scolor[0], touch.scolor[1], touch.scolor[2], touch.scolor[3] );
FS_Printf( f, "\n// highlight when pressed\n" ); FS_Printf( f, "\n// highlight when pressed\n" );
@ -302,7 +302,7 @@ void IN_TouchExportConfig_f( void )
FS_Printf( f, "\n// how much slowdown when Precise Look button pressed\n" ); FS_Printf( f, "\n// how much slowdown when Precise Look button pressed\n" );
FS_Printf( f, "touch_precise_amount \"%f\"\n", touch_precise_amount->value ); FS_Printf( f, "touch_precise_amount \"%f\"\n", touch_precise_amount->value );
FS_Printf( f, "\n// enable/disable move indicator\n" ); FS_Printf( f, "\n// enable/disable move indicator\n" );
FS_Printf( f, "touch_move_indicator \"%d\"\n", touch_move_indicator->integer ); FS_Printf( f, "touch_move_indicator \"%d\"\n", (int)touch_move_indicator->value );
FS_Printf( f, "\n// reset menu state when execing config\n" ); FS_Printf( f, "\n// reset menu state when execing config\n" );
FS_Printf( f, "touch_setclientonly 0\n" ); FS_Printf( f, "touch_setclientonly 0\n" );
@ -358,10 +358,10 @@ void IN_TouchGenetateCode_f( void )
flags |= TOUCH_FL_HIDE; flags |= TOUCH_FL_HIDE;
aspect = ( B(y2) - B(y1) ) / ( ( B(x2) - B(x1) ) /(SCR_H/SCR_W) ); aspect = ( B(y2) - B(y1) ) / ( ( B(x2) - B(x1) ) /(SCR_H/SCR_W) );
if( Q_memcmp( &c, &B(color), sizeof( rgba_t ) ) ) if( memcmp( &c, &B(color), sizeof( rgba_t ) ) )
{ {
Msg( "MakeRGBA( color, %d, %d, %d, %d );\n", B(color[0]), B(color[1]), B(color[2]), B(color[3]) ); Msg( "MakeRGBA( color, %d, %d, %d, %d );\n", B(color[0]), B(color[1]), B(color[2]), B(color[3]) );
Q_memcpy( &c, &B(color), sizeof( rgba_t ) ); memcpy( &c, &B(color), sizeof( rgba_t ) );
} }
Msg( "TOUCH_ADDDEFAULT( \"%s\", \"%s\", \"%s\", %f, %f, %f, %f, color, %d, %f, %d );\n", Msg( "TOUCH_ADDDEFAULT( \"%s\", \"%s\", \"%s\", %f, %f, %f, %f, color, %d, %f, %d );\n",
B(name), B(texturefile), B(command), B(name), B(texturefile), B(command),
@ -894,7 +894,7 @@ void IN_TouchInit( void )
// touch.cfg // touch.cfg
touch_grid_count = Cvar_Get( "touch_grid_count", "50", 0, "touch grid count" ); touch_grid_count = Cvar_Get( "touch_grid_count", "50", 0, "touch grid count" );
touch_grid_enable = Cvar_Get( "touch_grid_enable", "1", 0, "enable touch grid" ); touch_grid_enable = Cvar_Get( "touch_grid_enable", "1", 0, "enable touch grid" );
touch_config_file = Cvar_Get( "touch_config_file", "touch.cfg", CVAR_ARCHIVE, "current touch profile file" ); touch_config_file = Cvar_Get( "touch_config_file", "touch.cfg", FCVAR_ARCHIVE, "current touch profile file" );
touch_precise_amount = Cvar_Get( "touch_precise_amount", "0.5", 0, "sensitivity multiplier for precise-look" ); touch_precise_amount = Cvar_Get( "touch_precise_amount", "0.5", 0, "sensitivity multiplier for precise-look" );
touch_highlight_r = Cvar_Get( "touch_highlight_r", "1.0", 0, "highlight r color" ); touch_highlight_r = Cvar_Get( "touch_highlight_r", "1.0", 0, "highlight r color" );
touch_highlight_g = Cvar_Get( "touch_highlight_g", "1.0", 0, "highlight g color" ); touch_highlight_g = Cvar_Get( "touch_highlight_g", "1.0", 0, "highlight g color" );
@ -906,28 +906,28 @@ void IN_TouchInit( void )
touch_joy_texture = Cvar_Get( "touch_joy_texture", "touch_default/joy.tga", 0, "texture for move indicator"); touch_joy_texture = Cvar_Get( "touch_joy_texture", "touch_default/joy.tga", 0, "texture for move indicator");
// input devices cvar // input devices cvar
touch_enable = Cvar_Get( "touch_enable", DEFAULT_TOUCH_ENABLE, CVAR_ARCHIVE, "enable touch controls" ); touch_enable = Cvar_Get( "touch_enable", DEFAULT_TOUCH_ENABLE, FCVAR_ARCHIVE, "enable touch controls" );
#if defined(XASH_SDL) && defined(__ANDROID__) #if defined(XASH_SDL) && defined(__ANDROID__)
SDL_SetHint( SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH, "1" ); SDL_SetHint( SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH, "1" );
#endif #endif
touch.initialized = true; touch.initialized = true;
} }
int pfnGetScreenInfo( SCREENINFO *pscrinfo );
// must be called after executing config.cfg // must be called after executing config.cfg
void IN_TouchInitConfig( void ) void IN_TouchInitConfig( void )
{ {
if( !touch.initialized ) if( !touch.initialized )
return; return;
pfnGetScreenInfo( NULL ); //HACK: update hud screen parameters like iHeight CL_GetScreenInfo( NULL ); //HACK: update hud screen parameters like iHeight
if( FS_FileExists( touch_config_file->string, true ) ) if( FS_FileExists( touch_config_file->string, true ) )
Cbuf_AddText( va( "exec \"%s\"\n", touch_config_file->string ) ); Cbuf_AddText( va( "exec \"%s\"\n", touch_config_file->string ) );
else IN_TouchLoadDefaults_f( ); else IN_TouchLoadDefaults_f( );
touch.closetexture = GL_LoadTexture( "touch_default/edit_close.tga", NULL, 0, TF_NOPICMIP, NULL ); touch.closetexture = GL_LoadTexture( "touch_default/edit_close.tga", NULL, 0, TF_NOMIPMAP, NULL );
touch.hidetexture = GL_LoadTexture( "touch_default/edit_hide.tga", NULL, 0, TF_NOPICMIP, NULL ); touch.hidetexture = GL_LoadTexture( "touch_default/edit_hide.tga", NULL, 0, TF_NOMIPMAP, NULL );
touch.showtexture = GL_LoadTexture( "touch_default/edit_show.tga", NULL, 0, TF_NOPICMIP, NULL ); touch.showtexture = GL_LoadTexture( "touch_default/edit_show.tga", NULL, 0, TF_NOMIPMAP, NULL );
touch.resettexture = GL_LoadTexture( "touch_default/edit_reset.tga", NULL, 0, TF_NOPICMIP, NULL ); touch.resettexture = GL_LoadTexture( "touch_default/edit_reset.tga", NULL, 0, TF_NOMIPMAP, NULL );
touch.joytexture = GL_LoadTexture( touch_joy_texture->string, NULL, 0, TF_NOPICMIP, NULL ); touch.joytexture = GL_LoadTexture( touch_joy_texture->string, NULL, 0, TF_NOMIPMAP, NULL );
touch.configchanged = false; touch.configchanged = false;
} }
qboolean IN_TouchIsVisible( touchbutton2_t *button ) qboolean IN_TouchIsVisible( touchbutton2_t *button )
@ -983,8 +983,8 @@ static __inline int round(float f)
} }
#endif #endif
#define GRID_COUNT_X (touch_grid_count->integer) #define GRID_COUNT_X (touch_grid_count->value)
#define GRID_COUNT_Y (touch_grid_count->integer * SCR_H / SCR_W) #define GRID_COUNT_Y (touch_grid_count->value * SCR_H / SCR_W)
#define GRID_X (1.0/GRID_COUNT_X) #define GRID_X (1.0/GRID_COUNT_X)
#define GRID_Y (SCR_W/SCR_H/GRID_COUNT_X) #define GRID_Y (SCR_W/SCR_H/GRID_COUNT_X)
#define GRID_ROUND_X(x) ((float)round( x * GRID_COUNT_X ) / GRID_COUNT_X) #define GRID_ROUND_X(x) ((float)round( x * GRID_COUNT_X ) / GRID_COUNT_X)
@ -1005,7 +1005,7 @@ static void IN_TouchCheckCoords( float *x1, float *y1, float *x2, float *y2 )
*y1 -= *y2 - 1, *y2 = 1; *y1 -= *y2 - 1, *y2 = 1;
if( *x2 > 1 ) if( *x2 > 1 )
*x1 -= *x2 - 1, *x2 = 1; *x1 -= *x2 - 1, *x2 = 1;
if ( touch_grid_enable->integer ) if ( touch_grid_enable->value )
{ {
*x1 = GRID_ROUND_X( *x1 ); *x1 = GRID_ROUND_X( *x1 );
*x2 = GRID_ROUND_X( *x2 ); *x2 = GRID_ROUND_X( *x2 );
@ -1115,7 +1115,7 @@ void Touch_DrawButtons( touchbuttonlist_t *list )
{ {
if( button->texture == -1 ) if( button->texture == -1 )
{ {
button->texture = GL_LoadTexture( button->texturefile, NULL, 0, TF_NOPICMIP, NULL ); button->texture = GL_LoadTexture( button->texturefile, NULL, 0, TF_NOMIPMAP, NULL );
} }
if( B(flags) & TOUCH_FL_DRAW_ADDITIVE ) if( B(flags) & TOUCH_FL_DRAW_ADDITIVE )
@ -1132,22 +1132,22 @@ void Touch_DrawButtons( touchbuttonlist_t *list )
TO_SCRN_Y(B(y1)), TO_SCRN_Y(B(y1)),
touch.swidth, touch.swidth,
TO_SCRN_Y(B(y2)-B(y1)) - touch.swidth, TO_SCRN_Y(B(y2)-B(y1)) - touch.swidth,
0, 0, 1, 1, cls.fillImage ); 0, 0, 1, 1, tr.whiteTexture );
R_DrawStretchPic( TO_SCRN_X(B(x1)) + touch.swidth, R_DrawStretchPic( TO_SCRN_X(B(x1)) + touch.swidth,
TO_SCRN_Y(B(y1)), TO_SCRN_Y(B(y1)),
TO_SCRN_X(B(x2)-B(x1)) - touch.swidth, TO_SCRN_X(B(x2)-B(x1)) - touch.swidth,
touch.swidth, touch.swidth,
0, 0, 1, 1, cls.fillImage ); 0, 0, 1, 1, tr.whiteTexture );
R_DrawStretchPic( TO_SCRN_X(B(x2))-touch.swidth, R_DrawStretchPic( TO_SCRN_X(B(x2))-touch.swidth,
TO_SCRN_Y(B(y1)) + touch.swidth, TO_SCRN_Y(B(y1)) + touch.swidth,
touch.swidth, touch.swidth,
TO_SCRN_Y(B(y2)-B(y1)) - touch.swidth, TO_SCRN_Y(B(y2)-B(y1)) - touch.swidth,
0, 0, 1, 1, cls.fillImage ); 0, 0, 1, 1, tr.whiteTexture );
R_DrawStretchPic( TO_SCRN_X(B(x1)), R_DrawStretchPic( TO_SCRN_X(B(x1)),
TO_SCRN_Y(B(y2))-touch.swidth, TO_SCRN_Y(B(y2))-touch.swidth,
TO_SCRN_X(B(x2)-B(x1)) - touch.swidth, TO_SCRN_X(B(x2)-B(x1)) - touch.swidth,
touch.swidth, touch.swidth,
0, 0, 1, 1, cls.fillImage ); 0, 0, 1, 1, tr.whiteTexture );
pglColor4ub( 255, 255, 255, 255 ); pglColor4ub( 255, 255, 255, 255 );
} }
} }
@ -1155,9 +1155,9 @@ void Touch_DrawButtons( touchbuttonlist_t *list )
{ {
rgba_t color; rgba_t color;
if( !( button->flags & TOUCH_FL_HIDE ) ) if( !( button->flags & TOUCH_FL_HIDE ) )
Touch_DrawTexture( B(x1), B(y1), B(x2), B(y2), cls.fillImage, 255, 255, 0, 32 ); Touch_DrawTexture( B(x1), B(y1), B(x2), B(y2), tr.whiteTexture, 255, 255, 0, 32 );
else else
Touch_DrawTexture( B(x1), B(y1), B(x2), B(y2), cls.fillImage, 128, 128, 128, 128 ); Touch_DrawTexture( B(x1), B(y1), B(x2), B(y2), tr.whiteTexture, 128, 128, 128, 128 );
MakeRGBA( color, 255, 255,127, 255 ); MakeRGBA( color, 255, 255,127, 255 );
Con_DrawString( TO_SCRN_X( B(x1) ), TO_SCRN_Y( B(y1) ), B(name), color ); Con_DrawString( TO_SCRN_X( B(x1) ), TO_SCRN_Y( B(y1) ), B(name), color );
} }
@ -1169,34 +1169,34 @@ void IN_TouchDraw( void )
{ {
touchbutton2_t *button; touchbutton2_t *button;
if( !touch.initialized || (!touch_enable->integer && !touch.clientonly) ) if( !touch.initialized || (!touch_enable->value && !touch.clientonly) )
return; return;
if( cls.key_dest != key_game && touch_in_menu->integer == 0 ) if( cls.key_dest != key_game && touch_in_menu->value == 0.0f )
return; return;
GL_SetRenderMode( kRenderTransTexture ); GL_SetRenderMode( kRenderTransTexture );
if( touch.state >= state_edit && touch_grid_enable->integer ) if( touch.state >= state_edit && touch_grid_enable->value )
{ {
float x; float x;
if( touch_in_menu->integer ) if( touch_in_menu->value )
Touch_DrawTexture( 0, 0, 1, 1, cls.fillImage, 32, 32, 32, 255 ); Touch_DrawTexture( 0, 0, 1, 1, tr.whiteTexture, 32, 32, 32, 255 );
else else
Touch_DrawTexture( 0, 0, 1, 1, cls.fillImage, 0, 0, 0, 112 ); Touch_DrawTexture( 0, 0, 1, 1, tr.whiteTexture, 0, 0, 0, 112 );
pglColor4ub( 0, 224, 224, 112 ); pglColor4ub( 0, 224, 224, 112 );
for ( x = 0; x < 1 ; x += GRID_X ) for ( x = 0; x < 1 ; x += GRID_X )
R_DrawStretchPic( TO_SCRN_X(x), R_DrawStretchPic( TO_SCRN_X(x),
0, 0,
1, 1,
TO_SCRN_Y(1), TO_SCRN_Y(1),
0, 0, 1, 1, cls.fillImage ); 0, 0, 1, 1, tr.whiteTexture );
for ( x = 0; x < 1 ; x += GRID_Y ) for ( x = 0; x < 1 ; x += GRID_Y )
R_DrawStretchPic( 0, R_DrawStretchPic( 0,
TO_SCRN_Y(x), TO_SCRN_Y(x),
TO_SCRN_X(1), TO_SCRN_X(1),
1, 1,
0, 0, 1, 1, cls.fillImage ); 0, 0, 1, 1, tr.whiteTexture );
} }
Touch_DrawButtons( &touch.list_user ); Touch_DrawButtons( &touch.list_user );
@ -1212,13 +1212,13 @@ void IN_TouchDraw( void )
x2 = touch.edit->x2, x2 = touch.edit->x2,
y2 = touch.edit->y2; y2 = touch.edit->y2;
IN_TouchCheckCoords( &x1, &y1, &x2, &y2 ); IN_TouchCheckCoords( &x1, &y1, &x2, &y2 );
Touch_DrawTexture( x1, y1, x2, y2, cls.fillImage, 0, 255, 0, 32 ); Touch_DrawTexture( x1, y1, x2, y2, tr.whiteTexture, 0, 255, 0, 32 );
} }
Touch_DrawTexture( 0, 0, GRID_X, GRID_Y, cls.fillImage, 255, 255, 255, 64 ); Touch_DrawTexture( 0, 0, GRID_X, GRID_Y, tr.whiteTexture, 255, 255, 255, 64 );
if( touch.selection ) if( touch.selection )
{ {
button = touch.selection; button = touch.selection;
Touch_DrawTexture( B(x1), B(y1), B(x2), B(y2), cls.fillImage, 255, 0, 0, 64 ); Touch_DrawTexture( B(x1), B(y1), B(x2), B(y2), tr.whiteTexture, 255, 0, 0, 64 );
if( touch.showbuttons ) if( touch.showbuttons )
{ {
if( button->flags & TOUCH_FL_HIDE ) if( button->flags & TOUCH_FL_HIDE )
@ -1257,10 +1257,10 @@ void IN_TouchDraw( void )
{ {
float width; float width;
float height; float height;
if( touch_joy_texture->modified ) if( FBitSet( touch_joy_texture->flags, FCVAR_CHANGED ) )
{ {
touch_joy_texture->modified = false; ClearBits( touch_joy_texture->flags, FCVAR_CHANGED );
touch.joytexture = GL_LoadTexture( touch_joy_texture->string, NULL, 0, TF_NOPICMIP, NULL ); touch.joytexture = GL_LoadTexture( touch_joy_texture->string, NULL, 0, TF_NOMIPMAP, NULL );
} }
if( touch.move->type == touch_move ) if( touch.move->type == touch_move )
{ {
@ -1354,9 +1354,9 @@ static void Touch_Motion( touchEventType type, int fingerID, float x, float y, f
{ {
// check bounds // check bounds
if( touch_forwardzone->value <= 0 ) if( touch_forwardzone->value <= 0 )
Cvar_SetFloat( "touch_forwardzone", 0.5 ); Cvar_SetValue( "touch_forwardzone", 0.5 );
if( touch_sidezone->value <= 0 ) if( touch_sidezone->value <= 0 )
Cvar_SetFloat( "touch_sidezone", 0.3 ); Cvar_SetValue( "touch_sidezone", 0.3 );
if( !touch.move || touch.move->type == touch_move ) if( !touch.move || touch.move->type == touch_move )
{ {
@ -1387,7 +1387,7 @@ static void Touch_Motion( touchEventType type, int fingerID, float x, float y, f
if( touch.precision ) if( touch.precision )
dx *= touch_precise_amount->value, dy *= touch_precise_amount->value; dx *= touch_precise_amount->value, dy *= touch_precise_amount->value;
if( touch_nonlinear_look->integer ); if( touch_nonlinear_look->value );
{ {
// save angle, modify only velocity // save angle, modify only velocity
float dabs = sqrt( dx*dx+dy*dy ); float dabs = sqrt( dx*dx+dy*dy );
@ -1548,7 +1548,7 @@ static qboolean Touch_ButtonEdit( touchEventType type, int fingerID, float x, fl
if( ( y > GRID_Y * 2 ) && ( y < GRID_Y * 4 ) ) // close button if( ( y > GRID_Y * 2 ) && ( y < GRID_Y * 4 ) ) // close button
{ {
IN_TouchDisableEdit_f(); IN_TouchDisableEdit_f();
if( touch_in_menu->integer ) if( touch_in_menu->value )
{ {
Cvar_Set( "touch_in_menu", "0" ); Cvar_Set( "touch_in_menu", "0" );
} }
@ -1639,7 +1639,7 @@ int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx
{ {
// simulate menu mouse click // simulate menu mouse click
if( cls.key_dest != key_game && !touch_in_menu->integer ) if( cls.key_dest != key_game && !touch_in_menu->value )
{ {
touch.move_finger = touch.resize_finger = touch.look_finger = -1; touch.move_finger = touch.resize_finger = touch.look_finger = -1;
// Hack for keyboard, hope it help // Hack for keyboard, hope it help
@ -1690,7 +1690,7 @@ int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx
return 0; return 0;
} }
if( !touch.initialized || (!touch_enable->integer && !touch.clientonly) ) if( !touch.initialized || (!touch_enable->value && !touch.clientonly) )
{ {
#if 0 #if 0
if( type == event_down ) if( type == event_down )
@ -1722,7 +1722,7 @@ void IN_TouchKeyEvent( int key, int down )
int xi, yi; int xi, yi;
float x, y; float x, y;
if( touch_enable->integer ) if( touch_enable->value )
return; return;
if( !touch.clientonly ) if( !touch.clientonly )

1
engine/common/input.h

@ -29,6 +29,7 @@ INPUT
// //
// input.c // input.c
// //
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 );

15
engine/common/keys.c

@ -17,6 +17,9 @@ GNU General Public License for more details.
#include "input.h" #include "input.h"
#include "client.h" #include "client.h"
#include "vgui_draw.h" #include "vgui_draw.h"
#ifdef XASH_SDL
#include "platform/sdl/events.h"
#endif // XASH_SDL
typedef struct typedef struct
{ {
@ -681,6 +684,18 @@ void Key_Event( int key, qboolean down )
} }
} }
void Key_EnableTextInput( qboolean enable, qboolean force )
{
#if XASH_INPUT == INPUT_SDL
SDLash_EnableTextInput( enable, force );
#elif XASH_INPUT == INPUT_ANDROID
Android_EnableTextInput( enable, force );
#endif
#if 0
Joy_EnableTextInput( enable, force );
#endif
}
/* /*
========= =========
Key_SetKeyDest Key_SetKeyDest

Loading…
Cancel
Save