mirror of
https://github.com/nillerusr/source-engine.git
synced 2025-01-03 14:06:44 +00:00
add vgui touch panel, touch logic
This commit is contained in:
parent
81b976c384
commit
63e458ef84
@ -1837,6 +1837,8 @@ void CSDLMgr::PumpWindowsMessageLoop()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(nillerusr): SDL posts SDL_QUIT when map loaded on android, idk why.
|
||||||
|
#ifndef ANDROID
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
{
|
{
|
||||||
CCocoaEvent theEvent;
|
CCocoaEvent theEvent;
|
||||||
@ -1844,7 +1846,7 @@ void CSDLMgr::PumpWindowsMessageLoop()
|
|||||||
PostEvent( theEvent );
|
PostEvent( theEvent );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -364,7 +364,11 @@ void CGame::DispatchInputEvent( const InputEvent_t &event )
|
|||||||
case IE_ButtonReleased:
|
case IE_ButtonReleased:
|
||||||
Key_Event( event );
|
Key_Event( event );
|
||||||
break;
|
break;
|
||||||
|
case IE_FingerDown:
|
||||||
|
case IE_FingerUp:
|
||||||
|
case IE_FingerMotion:
|
||||||
|
if( g_ClientDLL )
|
||||||
|
g_ClientDLL->IN_TouchEvent( event.m_nType, event.m_nData, event.m_nData2, event.m_nData3 );
|
||||||
default:
|
default:
|
||||||
// Let vgui have the first whack at events
|
// Let vgui have the first whack at events
|
||||||
if ( g_pMatSystemSurface && g_pMatSystemSurface->HandleInputEvent( event ) )
|
if ( g_pMatSystemSurface && g_pMatSystemSurface->HandleInputEvent( event ) )
|
||||||
|
@ -126,6 +126,7 @@
|
|||||||
#include "client_virtualreality.h"
|
#include "client_virtualreality.h"
|
||||||
#include "mumble.h"
|
#include "mumble.h"
|
||||||
#include "vgui_controls/BuildGroup.h"
|
#include "vgui_controls/BuildGroup.h"
|
||||||
|
#include "touch.h"
|
||||||
|
|
||||||
// NVNT includes
|
// NVNT includes
|
||||||
#include "hud_macros.h"
|
#include "hud_macros.h"
|
||||||
@ -729,11 +730,12 @@ public:
|
|||||||
|
|
||||||
// Returns true if the disconnect command has been handled by the client
|
// Returns true if the disconnect command has been handled by the client
|
||||||
virtual bool DisconnectAttempt( void );
|
virtual bool DisconnectAttempt( void );
|
||||||
public:
|
|
||||||
void PrecacheMaterial( const char *pMaterialName );
|
void PrecacheMaterial( const char *pMaterialName );
|
||||||
|
|
||||||
virtual bool IsConnectedUserInfoChangeAllowed( IConVar *pCvar );
|
virtual bool IsConnectedUserInfoChangeAllowed( IConVar *pCvar );
|
||||||
|
|
||||||
|
virtual void IN_TouchEvent( int type, int fingerId, int x, int y );
|
||||||
private:
|
private:
|
||||||
void UncacheAllMaterials( );
|
void UncacheAllMaterials( );
|
||||||
void ResetStringTablePointers();
|
void ResetStringTablePointers();
|
||||||
@ -1039,6 +1041,8 @@ int CHLClient::Init( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physi
|
|||||||
|
|
||||||
gHUD.Init();
|
gHUD.Init();
|
||||||
|
|
||||||
|
gTouch.Init();
|
||||||
|
|
||||||
g_pClientMode->Init();
|
g_pClientMode->Init();
|
||||||
|
|
||||||
if ( !IGameSystem::InitAllSystems() )
|
if ( !IGameSystem::InitAllSystems() )
|
||||||
@ -1419,8 +1423,23 @@ int CHLClient::IN_KeyEvent( int eventcode, ButtonCode_t keynum, const char *pszC
|
|||||||
return input->KeyEvent( eventcode, keynum, pszCurrentBinding );
|
return input->KeyEvent( eventcode, keynum, pszCurrentBinding );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHLClient::ExtraMouseSample( float frametime, bool active )
|
void CHLClient::IN_TouchEvent( int type, int fingerId, int x, int y )
|
||||||
{
|
{
|
||||||
|
if( enginevgui->IsGameUIVisible() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
touch_event_t ev;
|
||||||
|
|
||||||
|
ev.type = type;
|
||||||
|
ev.fingerid = fingerId;
|
||||||
|
ev.x = x;
|
||||||
|
ev.y = y;
|
||||||
|
|
||||||
|
gTouch.ProcessEvent( &ev );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CHLClient::ExtraMouseSample( float frametime, bool active )
|
||||||
|
{
|
||||||
Assert( C_BaseEntity::IsAbsRecomputationsEnabled() );
|
Assert( C_BaseEntity::IsAbsRecomputationsEnabled() );
|
||||||
Assert( C_BaseEntity::IsAbsQueriesValid() );
|
Assert( C_BaseEntity::IsAbsQueriesValid() );
|
||||||
|
|
||||||
|
@ -19,12 +19,16 @@
|
|||||||
#include "bitbuf.h"
|
#include "bitbuf.h"
|
||||||
#include "checksum_md5.h"
|
#include "checksum_md5.h"
|
||||||
#include "hltvcamera.h"
|
#include "hltvcamera.h"
|
||||||
|
#include "touch.h"
|
||||||
|
#include "ienginevgui.h"
|
||||||
|
|
||||||
#if defined( REPLAY_ENABLED )
|
#if defined( REPLAY_ENABLED )
|
||||||
#include "replay/replaycamera.h"
|
#include "replay/replaycamera.h"
|
||||||
#endif
|
#endif
|
||||||
#include <ctype.h> // isalnum()
|
#include <ctype.h> // isalnum()
|
||||||
#include <voice_status.h>
|
#include <voice_status.h>
|
||||||
#include "cam_thirdperson.h"
|
#include "cam_thirdperson.h"
|
||||||
|
#include "inputsystem/iinputsystem.h"
|
||||||
|
|
||||||
#ifdef SIXENSE
|
#ifdef SIXENSE
|
||||||
#include "sixense/in_sixense.h"
|
#include "sixense/in_sixense.h"
|
||||||
@ -952,6 +956,7 @@ void CInput::ControllerMove( float frametime, CUserCmd *cmd )
|
|||||||
|
|
||||||
SteamControllerMove( frametime, cmd );
|
SteamControllerMove( frametime, cmd );
|
||||||
JoyStickMove( frametime, cmd );
|
JoyStickMove( frametime, cmd );
|
||||||
|
gTouch.Move( frametime, cmd );
|
||||||
|
|
||||||
// NVNT if we have a haptic device..
|
// NVNT if we have a haptic device..
|
||||||
if(haptics && haptics->HasDevice())
|
if(haptics && haptics->HasDevice())
|
||||||
@ -1105,7 +1110,6 @@ void CInput::ExtraMouseSample( float frametime, bool active )
|
|||||||
prediction->SetLocalViewAngles( cmd->viewangles );
|
prediction->SetLocalViewAngles( cmd->viewangles );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInput::CreateMove ( int sequence_number, float input_sample_frametime, bool active )
|
void CInput::CreateMove ( int sequence_number, float input_sample_frametime, bool active )
|
||||||
@ -1196,11 +1200,11 @@ void CInput::CreateMove ( int sequence_number, float input_sample_frametime, boo
|
|||||||
cmd->buttons = GetButtonBits( 1 );
|
cmd->buttons = GetButtonBits( 1 );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Using joystick?
|
// Using joystick or touch?
|
||||||
#ifdef SIXENSE
|
#ifdef SIXENSE
|
||||||
if ( in_joystick.GetInt() || g_pSixenseInput->IsEnabled() )
|
if ( in_joystick.GetInt() || g_pSixenseInput->IsEnabled() || touch_enable.GetInt() )
|
||||||
#else
|
#else
|
||||||
if ( in_joystick.GetInt() )
|
if ( in_joystick.GetInt() || touch_enable.GetInt() )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if ( cmd->forwardmove > 0 )
|
if ( cmd->forwardmove > 0 )
|
||||||
|
337
game/client/touch.cpp
Normal file
337
game/client/touch.cpp
Normal file
@ -0,0 +1,337 @@
|
|||||||
|
#include "convar.h"
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "vgui/IInputInternal.h"
|
||||||
|
#include "VGuiMatSurface/IMatSystemSurface.h"
|
||||||
|
#include "vgui/ISurface.h"
|
||||||
|
#include "touch.h"
|
||||||
|
#include "cdll_int.h"
|
||||||
|
#include "ienginevgui.h"
|
||||||
|
#include "in_buttons.h"
|
||||||
|
|
||||||
|
extern ConVar cl_sidespeed;
|
||||||
|
extern ConVar cl_forwardspeed;
|
||||||
|
extern ConVar cl_upspeed;
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
#define TOUCH_DEFAULT "1"
|
||||||
|
#else
|
||||||
|
#define TOUCH_DEFAULT "0"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ConVar touch_enable( "touch_enable", TOUCH_DEFAULT, FCVAR_ARCHIVE );
|
||||||
|
|
||||||
|
#define boundmax( num, high ) ( (num) < (high) ? (num) : (high) )
|
||||||
|
#define boundmin( num, low ) ( (num) >= (low) ? (num) : (low) )
|
||||||
|
#define bound( low, num, high ) ( boundmin( boundmax(num, high), low ))
|
||||||
|
#define S
|
||||||
|
|
||||||
|
extern IVEngineClient *engine;
|
||||||
|
extern vgui::IInputInternal *g_pInputInternal;
|
||||||
|
|
||||||
|
static int g_LastDefaultButton = 0;
|
||||||
|
int screen_h, screen_w;
|
||||||
|
|
||||||
|
static CTouchButton g_Buttons[512];
|
||||||
|
static int g_LastButton = 0;
|
||||||
|
|
||||||
|
CTouchControls gTouch;
|
||||||
|
static VTouchPanel g_TouchPanel;
|
||||||
|
VTouchPanel *touch_panel = &g_TouchPanel;
|
||||||
|
|
||||||
|
CTouchPanel::CTouchPanel( vgui::VPANEL parent ) : BaseClass( NULL, "TouchPanel" )
|
||||||
|
{
|
||||||
|
SetParent( parent );
|
||||||
|
|
||||||
|
int w, h;
|
||||||
|
engine->GetScreenSize(w, h);
|
||||||
|
SetBounds( 0, 0, w, h );
|
||||||
|
|
||||||
|
SetFgColor( Color( 0, 0, 0, 255 ) );
|
||||||
|
SetPaintBackgroundEnabled( false );
|
||||||
|
|
||||||
|
SetKeyBoardInputEnabled( false );
|
||||||
|
SetMouseInputEnabled( false );
|
||||||
|
|
||||||
|
SetVisible( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
CTouchPanel::~CTouchPanel( void )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CTouchPanel::ShouldDraw( void )
|
||||||
|
{
|
||||||
|
return touch_enable.GetBool() && !enginevgui->IsGameUIVisible();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTouchPanel::Paint()
|
||||||
|
{
|
||||||
|
gTouch.Frame();
|
||||||
|
}
|
||||||
|
|
||||||
|
CTouchControls::CTouchControls()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CTouchControls::~CTouchControls()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTouchControls::Init()
|
||||||
|
{
|
||||||
|
engine->GetScreenSize( screen_w, screen_h );
|
||||||
|
initialized = true;
|
||||||
|
btns.EnsureCapacity( 64 );
|
||||||
|
look_finger = move_finger = resize_finger = -1;
|
||||||
|
forward = side = 0;
|
||||||
|
scolor = rgba_t( -1, -1, -1, -1 );
|
||||||
|
state = state_none;
|
||||||
|
swidth = 1;
|
||||||
|
move = edit = selection = NULL;
|
||||||
|
showbuttons = true;
|
||||||
|
clientonly = false;
|
||||||
|
precision = false;
|
||||||
|
mouse_events = 0;
|
||||||
|
move_start_x = move_start_y = 0.0f;
|
||||||
|
|
||||||
|
showtexture = hidetexture = resettexture = closetexture = joytexture = 0;
|
||||||
|
configchanged = false;
|
||||||
|
|
||||||
|
rgba_t color(255, 255, 255, 255);
|
||||||
|
|
||||||
|
IN_TouchAddButton( "use", "vgui/touch/use", "+use", touch_command, 0.880000, 0.213333, 1.000000, 0.426667, color );
|
||||||
|
IN_TouchAddButton( "jump", "vgui/touch/jump", "+jump", touch_command, 0.880000, 0.462222, 1.000000, 0.675556, color );
|
||||||
|
IN_TouchAddButton( "attack", "vgui/touch/shoot", "+attack", touch_command, 0.760000, 0.583333, 0.880000, 0.796667, color );
|
||||||
|
IN_TouchAddButton( "attack2", "vgui/touch/shoot_alt", "+attack2", touch_command, 0.760000, 0.320000, 0.880000, 0.533333, color );
|
||||||
|
IN_TouchAddButton( "duck", "vgui/touch/crouch", "+duck", touch_command, 0.880000, 0.746667, 1.000000, 0.960000, color );
|
||||||
|
IN_TouchAddButton( "tduck", "vgui/touch/tduck", ";+duck", touch_command, 0.560000, 0.817778, 0.620000, 0.924444, color );
|
||||||
|
IN_TouchAddButton( "look", "", "", touch_look, 0.5, 0, 1, 1, color );
|
||||||
|
IN_TouchAddButton( "move", "", "", touch_move, 0, 0, 0.5, 1, color );
|
||||||
|
IN_TouchAddButton( "zoom", "vgui/touch/zoom", "+zoom", touch_command, 0.680000, 0.00000, 0.760000, 0.142222, color );
|
||||||
|
IN_TouchAddButton( "speed", "vgui/touch/speed", "+speed", touch_command, 0.180000, 0.568889, 0.280000, 0.746667, color );
|
||||||
|
IN_TouchAddButton( "loadquick", "vgui/touch/load", "load quick", touch_command, 0.760000, 0.000000, 0.840000, 0.142222, color );
|
||||||
|
IN_TouchAddButton( "savequick", "vgui/touch/save", "save quick", touch_command, 0.840000, 0.000000, 0.920000, 0.142222, color );
|
||||||
|
IN_TouchAddButton( "reload", "vgui/touch/reload", "+reload", touch_command, 0.000000, 0.320000, 0.120000, 0.533333, color );
|
||||||
|
IN_TouchAddButton( "flashlight", "vgui/touch/flash_light_filled", "impulse 100", touch_command, 0.920000, 0.000000, 1.000000, 0.142222, color );
|
||||||
|
IN_TouchAddButton( "invnext", "vgui/touch/next_weap", "invnext", touch_command, 0.000000, 0.533333, 0.120000, 0.746667, color );
|
||||||
|
IN_TouchAddButton( "invprev", "vgui/touch/prev_weap", "invprev", touch_command, 0.000000, 0.071111, 0.120000, 0.284444, color );
|
||||||
|
|
||||||
|
IN_TouchAddButton( "menu", "vgui/touch/menu", "gameui_activate", touch_command, 0.000000, 0.00000, 0.080000, 0.142222, color );
|
||||||
|
}
|
||||||
|
|
||||||
|
#define GRID_COUNT 50
|
||||||
|
#define GRID_COUNT_X (GRID_COUNT)
|
||||||
|
#define GRID_COUNT_Y (GRID_COUNT * screen_h / screen_w)
|
||||||
|
#define GRID_X (1.0/GRID_COUNT_X)
|
||||||
|
#define GRID_Y (screen_w/screen_h/GRID_COUNT_X)
|
||||||
|
#define GRID_ROUND_X(x) ((float)round( x * GRID_COUNT_X ) / GRID_COUNT_X)
|
||||||
|
#define GRID_ROUND_Y(x) ((float)round( x * GRID_COUNT_Y ) / GRID_COUNT_Y)
|
||||||
|
|
||||||
|
static void IN_TouchCheckCoords( float *x1, float *y1, float *x2, float *y2 )
|
||||||
|
{
|
||||||
|
/// TODO: grid check here
|
||||||
|
if( *x2 - *x1 < GRID_X * 2 )
|
||||||
|
*x2 = *x1 + GRID_X * 2;
|
||||||
|
if( *y2 - *y1 < GRID_Y * 2)
|
||||||
|
*y2 = *y1 + GRID_Y * 2;
|
||||||
|
if( *x1 < 0 )
|
||||||
|
*x2 -= *x1, *x1 = 0;
|
||||||
|
if( *y1 < 0 )
|
||||||
|
*y2 -= *y1, *y1 = 0;
|
||||||
|
if( *y2 > 1 )
|
||||||
|
*y1 -= *y2 - 1, *y2 = 1;
|
||||||
|
if( *x2 > 1 )
|
||||||
|
*x1 -= *x2 - 1, *x2 = 1;
|
||||||
|
|
||||||
|
*x1 = GRID_ROUND_X( *x1 );
|
||||||
|
*x2 = GRID_ROUND_X( *x2 );
|
||||||
|
*y1 = GRID_ROUND_Y( *y1 );
|
||||||
|
*y2 = GRID_ROUND_Y( *y2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTouchControls::VidInit( ) { }
|
||||||
|
|
||||||
|
void CTouchControls::Shutdown( ) { }
|
||||||
|
|
||||||
|
void CTouchControls::Move( float frametime, CUserCmd *cmd )
|
||||||
|
{
|
||||||
|
cmd->sidemove -= cl_sidespeed.GetFloat() * side;
|
||||||
|
cmd->forwardmove += cl_forwardspeed.GetFloat() * forward;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTouchControls::IN_Look()
|
||||||
|
{
|
||||||
|
if( !pitch && !yaw )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QAngle ang;
|
||||||
|
engine->GetViewAngles( ang );
|
||||||
|
ang.x += pitch;
|
||||||
|
ang.y += yaw;
|
||||||
|
engine->SetViewAngles( ang );
|
||||||
|
pitch = yaw = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTouchControls::Frame()
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
return;
|
||||||
|
|
||||||
|
IN_Look();
|
||||||
|
Paint();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTouchControls::Paint( )
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( !enginevgui->IsGameUIVisible() )
|
||||||
|
{
|
||||||
|
for (int i = 0; i < g_LastButton; i++)
|
||||||
|
{
|
||||||
|
if( g_Buttons[i].type == touch_move || g_Buttons[i].type == touch_look )
|
||||||
|
continue;
|
||||||
|
g_pMatSystemSurface->DrawSetColor(255, 255, 255, 155);
|
||||||
|
g_pMatSystemSurface->DrawSetTexture( g_Buttons[i].textureID );
|
||||||
|
g_pMatSystemSurface->DrawTexturedRect( g_Buttons[i].x1*screen_w, g_Buttons[i].y1*screen_h, g_Buttons[i].x2*screen_w, g_Buttons[i].y2*screen_h );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTouchControls::IN_TouchAddButton( const char *name, const char *texturefile, const char *command, ETouchButtonType type, float x1, float y1, float x2, float y2, rgba_t color )
|
||||||
|
{
|
||||||
|
if( g_LastButton >= 64 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
Q_strncpy( g_Buttons[g_LastButton].name, name, 32 );
|
||||||
|
Q_strncpy( g_Buttons[g_LastButton].texturefile, texturefile, 256 );
|
||||||
|
Q_strncpy( g_Buttons[g_LastButton].command, command, 256 );
|
||||||
|
|
||||||
|
IN_TouchCheckCoords(&x1, &y1, &x2, &y2);
|
||||||
|
|
||||||
|
g_Buttons[g_LastButton].x1 = x1;
|
||||||
|
g_Buttons[g_LastButton].y1 = y1;
|
||||||
|
g_Buttons[g_LastButton].x2 = x2;
|
||||||
|
g_Buttons[g_LastButton].y2 = y1 + ( x2 - x1 ) * (((float)screen_w)/screen_h);
|
||||||
|
|
||||||
|
IN_TouchCheckCoords(&g_Buttons[g_LastButton].x1, &g_Buttons[g_LastButton].y1, &g_Buttons[g_LastButton].x2, &g_Buttons[g_LastButton].y2);
|
||||||
|
|
||||||
|
g_Buttons[g_LastButton].color = color;
|
||||||
|
g_Buttons[g_LastButton].type = type;
|
||||||
|
g_Buttons[g_LastButton].finger = -1;
|
||||||
|
g_Buttons[g_LastButton].textureID = g_pMatSystemSurface->CreateNewTextureID();
|
||||||
|
g_pMatSystemSurface->DrawSetTextureFile( g_Buttons[g_LastButton].textureID, g_Buttons[g_LastButton].texturefile, true, false);
|
||||||
|
|
||||||
|
g_LastButton++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTouchControls::ProcessEvent(touch_event_t *ev)
|
||||||
|
{
|
||||||
|
if( !touch_enable.GetBool() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( ev->type == IE_FingerMotion )
|
||||||
|
FingerMotion( ev );
|
||||||
|
else
|
||||||
|
FingerPress( ev );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTouchControls::FingerMotion(touch_event_t *ev)
|
||||||
|
{
|
||||||
|
float x = ev->x / (float)screen_w;
|
||||||
|
float y = ev->y / (float)screen_h;
|
||||||
|
|
||||||
|
float f, s;
|
||||||
|
|
||||||
|
for (int i = 0; i < g_LastButton; i++)
|
||||||
|
{
|
||||||
|
if( g_Buttons[i].finger == ev->fingerid )
|
||||||
|
{
|
||||||
|
if( g_Buttons[i].type == touch_move )
|
||||||
|
{
|
||||||
|
f = ( move_start_y - y ) / touch_settings.sidezone;
|
||||||
|
s = ( move_start_x - x ) / touch_settings.sidezone;
|
||||||
|
forward = bound( -1, f, 1 );
|
||||||
|
side = bound( -1, s, 1 );
|
||||||
|
}
|
||||||
|
else if( g_Buttons[i].type == touch_look )
|
||||||
|
{
|
||||||
|
yaw += touch_settings.yaw * ( dx - x ) * touch_settings.sensitivity;
|
||||||
|
pitch -= touch_settings.pitch * ( dy - y ) * touch_settings.sensitivity;
|
||||||
|
dx = x;
|
||||||
|
dy = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTouchControls::FingerPress(touch_event_t *ev)
|
||||||
|
{
|
||||||
|
float x = ev->x / (float)screen_w;
|
||||||
|
float y = ev->y / (float)screen_h;
|
||||||
|
|
||||||
|
if( ev->type == IE_FingerDown )
|
||||||
|
{
|
||||||
|
for (int i = 0; i < g_LastButton; i++)
|
||||||
|
{
|
||||||
|
if( x > g_Buttons[i].x1 && x < g_Buttons[i].x2 && y > g_Buttons[i].y1 && y < g_Buttons[i].y2 )
|
||||||
|
{
|
||||||
|
g_Buttons[i].finger = ev->fingerid;
|
||||||
|
if( g_Buttons[i].type == touch_move )
|
||||||
|
{
|
||||||
|
if( move_finger == -1 )
|
||||||
|
{
|
||||||
|
move_start_x = x;
|
||||||
|
move_start_y = y;
|
||||||
|
move_finger = ev->fingerid;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g_Buttons[i].finger = move_finger;
|
||||||
|
}
|
||||||
|
else if( g_Buttons[i].type == touch_look )
|
||||||
|
{
|
||||||
|
if( look_finger == -1 )
|
||||||
|
{
|
||||||
|
dx = x;
|
||||||
|
dy = y;
|
||||||
|
look_finger = ev->fingerid;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g_Buttons[i].finger = look_finger;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
engine->ClientCmd( g_Buttons[i].command );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( ev->type == IE_FingerUp )
|
||||||
|
{
|
||||||
|
{
|
||||||
|
for (int i = 0; i < g_LastButton; i++)
|
||||||
|
{
|
||||||
|
if( g_Buttons[i].finger == ev->fingerid )
|
||||||
|
{
|
||||||
|
g_Buttons[i].finger = -1;
|
||||||
|
|
||||||
|
if( g_Buttons[i].type == touch_move )
|
||||||
|
{
|
||||||
|
forward = side = 0;
|
||||||
|
move_finger = -1;
|
||||||
|
}
|
||||||
|
else if( g_Buttons[i].type == touch_look )
|
||||||
|
look_finger = -1;
|
||||||
|
else if( g_Buttons[i].command[0] == '+' )
|
||||||
|
{
|
||||||
|
char cmd[256];
|
||||||
|
|
||||||
|
snprintf( cmd, sizeof cmd, "%s", g_Buttons[i].command );
|
||||||
|
cmd[0] = '-';
|
||||||
|
engine->ClientCmd( cmd );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
212
game/client/touch.h
Normal file
212
game/client/touch.h
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
#include "utllinkedlist.h"
|
||||||
|
#include "vgui/VGUI.h"
|
||||||
|
#include <vgui_controls/Panel.h>
|
||||||
|
#include "cbase.h"
|
||||||
|
#include "kbutton.h"
|
||||||
|
#include "usercmd.h"
|
||||||
|
|
||||||
|
extern ConVar touch_enable;
|
||||||
|
|
||||||
|
#define STEAMCONTROLLER_A -3
|
||||||
|
|
||||||
|
#define MOUSE_EVENT_PRESS 0x02
|
||||||
|
#define MOUSE_EVENT_RELEASE 0x04
|
||||||
|
|
||||||
|
enum ActivationType_t
|
||||||
|
{
|
||||||
|
ACTIVATE_ONPRESSEDANDRELEASED, // normal button behaviour
|
||||||
|
ACTIVATE_ONPRESSED, // menu buttons, toggle buttons
|
||||||
|
ACTIVATE_ONRELEASED, // menu items
|
||||||
|
};
|
||||||
|
|
||||||
|
#define CMD_SIZE 64
|
||||||
|
|
||||||
|
enum ETouchButtonType
|
||||||
|
{
|
||||||
|
touch_command = 0, // Tap button
|
||||||
|
touch_move, // Like a joystick stick.
|
||||||
|
touch_joy, // Like a joystick stick, centered.
|
||||||
|
touch_dpad, // Only two directions.
|
||||||
|
touch_look, // Like a touchpad.
|
||||||
|
touch_key
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ETouchState
|
||||||
|
{
|
||||||
|
state_none = 0,
|
||||||
|
state_edit,
|
||||||
|
state_edit_move
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ETouchRound
|
||||||
|
{
|
||||||
|
round_none = 0,
|
||||||
|
round_grid,
|
||||||
|
round_aspect
|
||||||
|
};
|
||||||
|
|
||||||
|
struct rgba_t
|
||||||
|
{
|
||||||
|
rgba_t( unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255 ) : r( r ), g( g ), b( b ), a( a ) { }
|
||||||
|
rgba_t() : r( 0 ), g( 0 ), b( 0 ), a( 0 ) { }
|
||||||
|
rgba_t( unsigned char *x ) : r( x[0] ), g( x[1] ), b( x[2] ), a( x[3] ) { }
|
||||||
|
|
||||||
|
operator unsigned char*() { return &r; }
|
||||||
|
|
||||||
|
unsigned char r, g, b, a;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct event_clientcmd_t
|
||||||
|
{
|
||||||
|
char buf[CMD_SIZE];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct event_s
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int fingerid;
|
||||||
|
} typedef touch_event_t;
|
||||||
|
|
||||||
|
|
||||||
|
class CTouchButton
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Touch button type: tap, stick or slider
|
||||||
|
ETouchButtonType type;
|
||||||
|
|
||||||
|
// Field of button in pixels
|
||||||
|
float x1, y1, x2, y2;
|
||||||
|
|
||||||
|
// Button texture
|
||||||
|
int texture;
|
||||||
|
|
||||||
|
rgba_t color;
|
||||||
|
char texturefile[256];
|
||||||
|
char command[256];
|
||||||
|
char name[32];
|
||||||
|
int finger;
|
||||||
|
int flags;
|
||||||
|
float fade;
|
||||||
|
float fadespeed;
|
||||||
|
float fadeend;
|
||||||
|
float aspect;
|
||||||
|
int textureID;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct touch_settings_s
|
||||||
|
{
|
||||||
|
float pitch = 90;
|
||||||
|
float yaw = 120;
|
||||||
|
float sensitivity = 2;
|
||||||
|
float forwardzone = 0.8;
|
||||||
|
float sidezone = 0.12;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CTouchPanel : public vgui::Panel
|
||||||
|
{
|
||||||
|
DECLARE_CLASS_SIMPLE( CTouchPanel, vgui::Panel );
|
||||||
|
|
||||||
|
public:
|
||||||
|
CTouchPanel( vgui::VPANEL parent );
|
||||||
|
virtual ~CTouchPanel( void );
|
||||||
|
|
||||||
|
virtual void Paint();
|
||||||
|
virtual bool ShouldDraw( void );
|
||||||
|
};
|
||||||
|
|
||||||
|
abstract_class ITouchPanel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void Create( vgui::VPANEL parent ) = 0;
|
||||||
|
virtual void Destroy( void ) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class VTouchPanel : public ITouchPanel
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
CTouchPanel *touchPanel;
|
||||||
|
public:
|
||||||
|
VTouchPanel( void )
|
||||||
|
{
|
||||||
|
touchPanel = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Create( vgui::VPANEL parent )
|
||||||
|
{
|
||||||
|
touchPanel = new CTouchPanel( parent );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Destroy( void )
|
||||||
|
{
|
||||||
|
if ( touchPanel )
|
||||||
|
{
|
||||||
|
touchPanel->SetParent( (vgui::Panel *)NULL );
|
||||||
|
touchPanel->MarkForDeletion();
|
||||||
|
touchPanel = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class CTouchControls
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CTouchControls();
|
||||||
|
~CTouchControls();
|
||||||
|
|
||||||
|
void VidInit( );
|
||||||
|
void Shutdown( );
|
||||||
|
|
||||||
|
void Init( );
|
||||||
|
void Paint( );
|
||||||
|
void Frame( );
|
||||||
|
|
||||||
|
void IN_TouchAddButton( const char *name, const char *texturefile, const char *command, ETouchButtonType type, float x1, float y1, float x2, float y2, rgba_t color );
|
||||||
|
void Move( float frametime, CUserCmd *cmd );
|
||||||
|
void IN_Look( );
|
||||||
|
|
||||||
|
void ProcessEvent( touch_event_t *ev );
|
||||||
|
void FingerPress( touch_event_t *ev );
|
||||||
|
void FingerMotion( touch_event_t *ev );
|
||||||
|
|
||||||
|
CTouchPanel *touchPanel;
|
||||||
|
private:
|
||||||
|
bool initialized;
|
||||||
|
ETouchState state;
|
||||||
|
CUtlLinkedList<CTouchButton> btns;
|
||||||
|
|
||||||
|
int look_finger;
|
||||||
|
int move_finger;
|
||||||
|
float forward, side, movecount;
|
||||||
|
float yaw, pitch;
|
||||||
|
CTouchButton *move;
|
||||||
|
|
||||||
|
float move_start_x, move_start_y;
|
||||||
|
float dx, dy;
|
||||||
|
|
||||||
|
// editing
|
||||||
|
CTouchButton *edit;
|
||||||
|
CTouchButton *selection;
|
||||||
|
int resize_finger;
|
||||||
|
bool showbuttons;
|
||||||
|
bool clientonly;
|
||||||
|
rgba_t scolor;
|
||||||
|
int swidth;
|
||||||
|
bool precision;
|
||||||
|
// textures
|
||||||
|
int showtexture;
|
||||||
|
int hidetexture;
|
||||||
|
int resettexture;
|
||||||
|
int closetexture;
|
||||||
|
int joytexture; // touch indicator
|
||||||
|
bool configchanged;
|
||||||
|
vgui::HFont textfont;
|
||||||
|
int mouse_events;
|
||||||
|
|
||||||
|
struct touch_settings_s touch_settings;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern CTouchControls gTouch;
|
||||||
|
extern VTouchPanel *touch_panel;
|
@ -22,6 +22,7 @@
|
|||||||
#include <vgui_controls/Panel.h>
|
#include <vgui_controls/Panel.h>
|
||||||
#include <KeyValues.h>
|
#include <KeyValues.h>
|
||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
|
#include "touch.h"
|
||||||
#include "matsys_controls/matsyscontrols.h"
|
#include "matsys_controls/matsyscontrols.h"
|
||||||
|
|
||||||
#ifdef SIXENSE
|
#ifdef SIXENSE
|
||||||
@ -129,6 +130,7 @@ static void VGui_VideoMode_AdjustForModeChange( void )
|
|||||||
fps->Destroy();
|
fps->Destroy();
|
||||||
messagechars->Destroy();
|
messagechars->Destroy();
|
||||||
loadingdisc->Destroy();
|
loadingdisc->Destroy();
|
||||||
|
touch_panel->Destroy();
|
||||||
|
|
||||||
// Recreate our panels.
|
// Recreate our panels.
|
||||||
VPANEL gameToolParent = enginevgui->GetPanel( PANEL_CLIENTDLL_TOOLS );
|
VPANEL gameToolParent = enginevgui->GetPanel( PANEL_CLIENTDLL_TOOLS );
|
||||||
@ -142,6 +144,7 @@ static void VGui_VideoMode_AdjustForModeChange( void )
|
|||||||
|
|
||||||
// Debugging or related tool
|
// Debugging or related tool
|
||||||
fps->Create( toolParent );
|
fps->Create( toolParent );
|
||||||
|
touch_panel->Create( toolParent );
|
||||||
#if defined( TRACK_BLOCKING_IO )
|
#if defined( TRACK_BLOCKING_IO )
|
||||||
iopanel->Create( gameDLLPanel );
|
iopanel->Create( gameDLLPanel );
|
||||||
#endif
|
#endif
|
||||||
@ -207,6 +210,8 @@ void VGui_CreateGlobalPanels( void )
|
|||||||
|
|
||||||
// Debugging or related tool
|
// Debugging or related tool
|
||||||
fps->Create( toolParent );
|
fps->Create( toolParent );
|
||||||
|
touch_panel->Create( toolParent );
|
||||||
|
|
||||||
#if defined( TRACK_BLOCKING_IO )
|
#if defined( TRACK_BLOCKING_IO )
|
||||||
iopanel->Create( gameDLLPanel );
|
iopanel->Create( gameDLLPanel );
|
||||||
#endif
|
#endif
|
||||||
@ -236,6 +241,7 @@ void VGui_Shutdown()
|
|||||||
iopanel->Destroy();
|
iopanel->Destroy();
|
||||||
#endif
|
#endif
|
||||||
fps->Destroy();
|
fps->Destroy();
|
||||||
|
touch_panel->Destroy();
|
||||||
|
|
||||||
messagechars->Destroy();
|
messagechars->Destroy();
|
||||||
loadingdisc->Destroy();
|
loadingdisc->Destroy();
|
||||||
|
@ -521,7 +521,8 @@ def build(bld):
|
|||||||
'hl2/hud_zoom.cpp',
|
'hl2/hud_zoom.cpp',
|
||||||
'hl2/shieldproxy.cpp',
|
'hl2/shieldproxy.cpp',
|
||||||
'hl2/vgui_rootpanel_hl2.cpp',
|
'hl2/vgui_rootpanel_hl2.cpp',
|
||||||
'episodic/c_vort_charge_token.cpp'
|
'episodic/c_vort_charge_token.cpp',
|
||||||
|
'touch.cpp'
|
||||||
]
|
]
|
||||||
|
|
||||||
includes = [
|
includes = [
|
||||||
|
@ -18,6 +18,7 @@ def build(bld):
|
|||||||
source = [
|
source = [
|
||||||
'inputsystem.cpp',
|
'inputsystem.cpp',
|
||||||
'joystick_sdl.cpp',
|
'joystick_sdl.cpp',
|
||||||
|
'touch_sdl.cpp',
|
||||||
#'novint.cpp', # [$WIN32]
|
#'novint.cpp', # [$WIN32]
|
||||||
'key_translation.cpp',
|
'key_translation.cpp',
|
||||||
'steamcontroller.cpp'
|
'steamcontroller.cpp'
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
#include <SDL_hints.h>
|
||||||
|
|
||||||
#include "tier0/threadtools.h"
|
#include "tier0/threadtools.h"
|
||||||
|
|
||||||
@ -92,9 +92,9 @@ t_eglGetProcAddress eglGetProcAddress;
|
|||||||
void *GetProcAddress( const char *procname )
|
void *GetProcAddress( const char *procname )
|
||||||
{
|
{
|
||||||
void *result = dlsym(lgles, procname);
|
void *result = dlsym(lgles, procname);
|
||||||
if(result)
|
if( result )
|
||||||
return result;
|
return result;
|
||||||
else
|
else if( eglGetProcAddress )
|
||||||
return eglGetProcAddress(procname);
|
return eglGetProcAddress(procname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ DLLEXPORT int LauncherMainAndroid( int argc, char **argv )
|
|||||||
gl4es_set_getprocaddress = (t_set_getprocaddress)dlsym(lgl4es, "set_getprocaddress");
|
gl4es_set_getprocaddress = (t_set_getprocaddress)dlsym(lgl4es, "set_getprocaddress");
|
||||||
eglGetProcAddress = (t_eglGetProcAddress)dlsym(lEGL, "eglGetProcAddress");
|
eglGetProcAddress = (t_eglGetProcAddress)dlsym(lEGL, "eglGetProcAddress");
|
||||||
|
|
||||||
if( gl4es_set_getprocaddress && eglGetProcAddress )
|
if( gl4es_set_getprocaddress )
|
||||||
{
|
{
|
||||||
gl4es_set_getprocaddress( &GetProcAddress );
|
gl4es_set_getprocaddress( &GetProcAddress );
|
||||||
}
|
}
|
||||||
@ -137,6 +137,7 @@ DLLEXPORT int LauncherMainAndroid( int argc, char **argv )
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
|
||||||
DeclareCurrentThreadIsMainThread(); // Init thread propertly on Android
|
DeclareCurrentThreadIsMainThread(); // Init thread propertly on Android
|
||||||
|
|
||||||
return LauncherMain(iLastArgs, LauncherArgv);
|
return LauncherMain(iLastArgs, LauncherArgv);
|
||||||
|
@ -789,6 +789,8 @@ public:
|
|||||||
virtual bool DisconnectAttempt( void ) = 0;
|
virtual bool DisconnectAttempt( void ) = 0;
|
||||||
|
|
||||||
virtual bool IsConnectedUserInfoChangeAllowed( IConVar *pCvar ) = 0;
|
virtual bool IsConnectedUserInfoChangeAllowed( IConVar *pCvar ) = 0;
|
||||||
|
|
||||||
|
virtual void IN_TouchEvent( int type, int fingerId, int x, int y ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CLIENT_DLL_INTERFACE_VERSION "VClient017"
|
#define CLIENT_DLL_INTERFACE_VERSION "VClient017"
|
||||||
|
Loading…
Reference in New Issue
Block a user