nillerusr
3 years ago
12 changed files with 505 additions and 76 deletions
@ -0,0 +1,113 @@ |
|||||||
|
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||||
|
//
|
||||||
|
// Purpose: Mouse input routines
|
||||||
|
//
|
||||||
|
// $Workfile: $
|
||||||
|
// $Date: $
|
||||||
|
// $NoKeywords: $
|
||||||
|
//===========================================================================//
|
||||||
|
#if defined( WIN32 ) && !defined( _X360 ) |
||||||
|
#define _WIN32_WINNT 0x0502 |
||||||
|
#include <windows.h> |
||||||
|
#endif |
||||||
|
#include "cbase.h" |
||||||
|
#include "hud.h" |
||||||
|
#include "cdll_int.h" |
||||||
|
#include "kbutton.h" |
||||||
|
#include "basehandle.h" |
||||||
|
#include "usercmd.h" |
||||||
|
#include "input.h" |
||||||
|
#include "iviewrender.h" |
||||||
|
#include "iclientmode.h" |
||||||
|
#include "tier0/icommandline.h" |
||||||
|
#include "vgui/ISurface.h" |
||||||
|
#include "vgui_controls/Controls.h" |
||||||
|
#include "vgui/Cursor.h" |
||||||
|
#include "cdll_client_int.h" |
||||||
|
#include "cdll_util.h" |
||||||
|
#include "tier1/convar_serverbounded.h" |
||||||
|
#include "cam_thirdperson.h" |
||||||
|
#include "inputsystem/iinputsystem.h" |
||||||
|
#include "touch.h" |
||||||
|
|
||||||
|
// up / down
|
||||||
|
#define PITCH 0 |
||||||
|
// left / right
|
||||||
|
#define YAW 1 |
||||||
|
|
||||||
|
extern ConVar cl_sidespeed; |
||||||
|
extern ConVar cl_forwardspeed; |
||||||
|
extern ConVar sensitivity; |
||||||
|
extern ConVar lookstrafe; |
||||||
|
extern ConVar thirdperson_platformer; |
||||||
|
extern ConVar touch_pitch; |
||||||
|
extern ConVar touch_yaw; |
||||||
|
extern ConVar default_fov; |
||||||
|
|
||||||
|
#ifdef PORTAL |
||||||
|
extern bool g_bUpsideDown; |
||||||
|
#endif |
||||||
|
|
||||||
|
ConVar touch_enable_accel( "touch_enable_accel", "0", FCVAR_ARCHIVE ); |
||||||
|
ConVar touch_accel( "touch_accel", "1.f", FCVAR_ARCHIVE ); |
||||||
|
ConVar touch_reverse( "touch_reverse", "0", FCVAR_ARCHIVE ); |
||||||
|
ConVar touch_sensitivity( "touch_sensitivity", "3.0", FCVAR_ARCHIVE, "touch look sensitivity" ); |
||||||
|
|
||||||
|
void CInput::TouchScale( float &dx, float &dy ) |
||||||
|
{ |
||||||
|
dx *= touch_yaw.GetFloat(); |
||||||
|
dy *= touch_pitch.GetFloat(); |
||||||
|
|
||||||
|
float sensitivity = touch_sensitivity.GetFloat() * gHUD.GetFOVSensitivityAdjust() * ( touch_reverse.GetBool() ? -1.f : 1.f ); |
||||||
|
|
||||||
|
if( touch_enable_accel.GetBool() ) |
||||||
|
{ |
||||||
|
float raw_touch_movement_distance_squared = dx * dx + dy * dy; |
||||||
|
float fExp = MAX(0.0f, (touch_accel.GetFloat() - 1.0f) / 2.0f); |
||||||
|
float accelerated_sensitivity = powf( raw_touch_movement_distance_squared, fExp ) * sensitivity; |
||||||
|
|
||||||
|
dx *= accelerated_sensitivity; |
||||||
|
dy *= accelerated_sensitivity; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
dx *= sensitivity; |
||||||
|
dy *= sensitivity; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void CInput::ApplyTouch( QAngle &viewangles, CUserCmd *cmd, float dx, float dy ) |
||||||
|
{ |
||||||
|
viewangles[YAW] -= dx; |
||||||
|
viewangles[PITCH] += dy; |
||||||
|
cmd->mousedx = dx; |
||||||
|
cmd->mousedy = dy; |
||||||
|
} |
||||||
|
|
||||||
|
void CInput::TouchMove( CUserCmd *cmd ) |
||||||
|
{ |
||||||
|
QAngle viewangles; |
||||||
|
float dx,dy,side,forward,pitch,yaw; |
||||||
|
|
||||||
|
engine->GetViewAngles( viewangles ); |
||||||
|
|
||||||
|
view->StopPitchDrift(); |
||||||
|
|
||||||
|
gTouch.GetTouchAccumulators( &side, &forward, &yaw, &pitch ); |
||||||
|
|
||||||
|
cmd->sidemove -= cl_sidespeed.GetFloat() * side; |
||||||
|
cmd->forwardmove += cl_forwardspeed.GetFloat() * forward; |
||||||
|
|
||||||
|
gTouch.GetTouchDelta( yaw, pitch, &dx, &dy ); |
||||||
|
|
||||||
|
TouchScale( dx, dy ); |
||||||
|
|
||||||
|
// Let the client mode at the mouse input before it's used
|
||||||
|
g_pClientMode->OverrideMouseInput( &dx, &dy ); |
||||||
|
|
||||||
|
// Add mouse X/Y movement to cmd
|
||||||
|
ApplyTouch( viewangles, cmd, dx, dy ); |
||||||
|
|
||||||
|
// Store out the new viewangles.
|
||||||
|
engine->SetViewAngles( viewangles ); |
||||||
|
} |
@ -0,0 +1,220 @@ |
|||||||
|
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
//
|
||||||
|
// $NoKeywords: $
|
||||||
|
//
|
||||||
|
//=============================================================================//
|
||||||
|
#include "OptionsSubTouch.h" |
||||||
|
//#include "CommandCheckButton.h"
|
||||||
|
#include "KeyToggleCheckButton.h" |
||||||
|
#include "CvarNegateCheckButton.h" |
||||||
|
#include "CvarToggleCheckButton.h" |
||||||
|
#include "cvarslider.h" |
||||||
|
|
||||||
|
#include "EngineInterface.h" |
||||||
|
|
||||||
|
#include <KeyValues.h> |
||||||
|
#include <vgui/IScheme.h> |
||||||
|
#include "tier1/convar.h" |
||||||
|
#include <stdio.h> |
||||||
|
#include <vgui_controls/TextEntry.h> |
||||||
|
// memdbgon must be the last include file in a .cpp file!!!
|
||||||
|
#include <tier0/memdbgon.h> |
||||||
|
|
||||||
|
using namespace vgui; |
||||||
|
|
||||||
|
COptionsSubTouch::COptionsSubTouch(vgui::Panel *parent) : PropertyPage(parent, NULL) |
||||||
|
{ |
||||||
|
m_pTouchEnableCheckBox = new CCvarToggleCheckButton(this, |
||||||
|
"EnableTouch", |
||||||
|
"Enable touch", |
||||||
|
"touch_enable"); |
||||||
|
|
||||||
|
m_pTouchDrawCheckBox = new CCvarToggleCheckButton(this, |
||||||
|
"DrawTouch", |
||||||
|
"Draw touch", |
||||||
|
"touch_draw"); |
||||||
|
|
||||||
|
m_pReverseTouchCheckBox = new CCvarToggleCheckButton( |
||||||
|
this, |
||||||
|
"ReverseTouch", |
||||||
|
"Reverse touch", |
||||||
|
"touch_reverse" ); |
||||||
|
|
||||||
|
m_pTouchFilterCheckBox = new CCvarToggleCheckButton( |
||||||
|
this, |
||||||
|
"TouchFilter", |
||||||
|
"Touch filter", |
||||||
|
"touch_filter" ); |
||||||
|
|
||||||
|
m_pTouchAccelerationCheckBox = new CCvarToggleCheckButton( |
||||||
|
this, |
||||||
|
"TouchAccelerationCheckbox", |
||||||
|
"Touch acceleration", |
||||||
|
"touch_enable_accel" ); |
||||||
|
|
||||||
|
m_pTouchSensitivitySlider = new CCvarSlider( this, "Slider", "Touch sensitivity", |
||||||
|
0.1f, 6.0f, "touch_sensitivity", true ); |
||||||
|
|
||||||
|
m_pTouchSensitivityLabel = new TextEntry(this, "SensitivityLabel"); |
||||||
|
m_pTouchSensitivityLabel->AddActionSignalTarget(this); |
||||||
|
|
||||||
|
m_pTouchAccelExponentSlider = new CCvarSlider( this, "TouchAccelerationSlider", "Touch acceleration", |
||||||
|
1.0f, 1.5f, "touch_accel", true ); |
||||||
|
|
||||||
|
m_pTouchAccelExponentLabel = new TextEntry(this, "TouchAccelerationLabel"); |
||||||
|
m_pTouchAccelExponentLabel->AddActionSignalTarget(this); |
||||||
|
|
||||||
|
m_pTouchYawSensitivitySlider = new CCvarSlider( this, "TouchYawSlider", "#GameUI_JoystickYawSensitivity", |
||||||
|
50.f, 300.f, "touch_yaw", true ); |
||||||
|
m_pTouchYawSensitivityPreLabel = new Label(this, "TouchYawSensitivityPreLabel", "#GameUI_JoystickLookSpeedYaw" ); |
||||||
|
m_pTouchYawSensitivityLabel = new TextEntry(this, "TouchYawSensitivityLabel"); |
||||||
|
m_pTouchYawSensitivityLabel->AddActionSignalTarget(this); |
||||||
|
|
||||||
|
m_pTouchPitchSensitivitySlider = new CCvarSlider( this, "TouchPitchSlider", "#GameUI_JoystickPitchSensitivity", |
||||||
|
50.f, 300.f, "touch_pitch", true ); |
||||||
|
m_pTouchPitchSensitivityPreLabel = new Label(this, "TouchPitchSensitivityPreLabel", "#GameUI_JoystickLookSpeedPitch" ); |
||||||
|
m_pTouchPitchSensitivityLabel = new TextEntry(this, "TouchPitchSensitivityLabel"); |
||||||
|
m_pTouchPitchSensitivityLabel->AddActionSignalTarget(this); |
||||||
|
|
||||||
|
LoadControlSettings("Resource\\OptionsSubTouch.res"); |
||||||
|
|
||||||
|
UpdateLabel(m_pTouchSensitivitySlider, m_pTouchSensitivityLabel); |
||||||
|
UpdateLabel(m_pTouchAccelExponentSlider, m_pTouchAccelExponentLabel); |
||||||
|
UpdateLabel(m_pTouchYawSensitivitySlider, m_pTouchYawSensitivityLabel); |
||||||
|
UpdateLabel(m_pTouchPitchSensitivitySlider, m_pTouchPitchSensitivityLabel); |
||||||
|
} |
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
COptionsSubTouch::~COptionsSubTouch() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void COptionsSubTouch::OnResetData() |
||||||
|
{ |
||||||
|
m_pReverseTouchCheckBox->Reset(); |
||||||
|
m_pTouchFilterCheckBox->Reset(); |
||||||
|
m_pTouchSensitivitySlider->Reset(); |
||||||
|
m_pTouchAccelExponentSlider->Reset(); |
||||||
|
m_pTouchYawSensitivitySlider->Reset(); |
||||||
|
m_pTouchPitchSensitivitySlider->Reset(); |
||||||
|
m_pTouchAccelerationCheckBox->Reset(); |
||||||
|
} |
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void COptionsSubTouch::OnApplyChanges() |
||||||
|
{ |
||||||
|
m_pReverseTouchCheckBox->ApplyChanges(); |
||||||
|
m_pTouchFilterCheckBox->ApplyChanges(); |
||||||
|
m_pTouchSensitivitySlider->ApplyChanges(); |
||||||
|
m_pTouchAccelExponentSlider->ApplyChanges(); |
||||||
|
m_pTouchYawSensitivitySlider->ApplyChanges(); |
||||||
|
m_pTouchPitchSensitivitySlider->ApplyChanges(); |
||||||
|
m_pTouchEnableCheckBox->ApplyChanges(); |
||||||
|
m_pTouchDrawCheckBox->ApplyChanges(); |
||||||
|
m_pTouchAccelerationCheckBox->ApplyChanges(); |
||||||
|
} |
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose: sets background color & border
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void COptionsSubTouch::ApplySchemeSettings(IScheme *pScheme) |
||||||
|
{ |
||||||
|
BaseClass::ApplySchemeSettings(pScheme); |
||||||
|
} |
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void COptionsSubTouch::OnControlModified(Panel *panel) |
||||||
|
{ |
||||||
|
PostActionSignal(new KeyValues("ApplyButtonEnable")); |
||||||
|
|
||||||
|
// the HasBeenModified() check is so that if the value is outside of the range of the
|
||||||
|
// slider, it won't use the slider to determine the display value but leave the
|
||||||
|
// real value that we determined in the constructor
|
||||||
|
if (panel == m_pTouchSensitivitySlider && m_pTouchSensitivitySlider->HasBeenModified()) |
||||||
|
UpdateLabel( m_pTouchSensitivitySlider, m_pTouchSensitivityLabel ); |
||||||
|
else if (panel == m_pTouchAccelExponentSlider && m_pTouchAccelExponentSlider->HasBeenModified()) |
||||||
|
UpdateLabel( m_pTouchAccelExponentSlider, m_pTouchAccelExponentLabel ); |
||||||
|
else if (panel == m_pTouchYawSensitivitySlider && m_pTouchYawSensitivitySlider->HasBeenModified()) |
||||||
|
UpdateLabel( m_pTouchYawSensitivitySlider, m_pTouchYawSensitivityLabel ); |
||||||
|
else if (panel == m_pTouchPitchSensitivitySlider && m_pTouchPitchSensitivitySlider->HasBeenModified()) |
||||||
|
UpdateLabel( m_pTouchPitchSensitivitySlider, m_pTouchPitchSensitivityLabel ); |
||||||
|
else if (panel == m_pTouchAccelerationCheckBox) |
||||||
|
{ |
||||||
|
m_pTouchAccelExponentSlider->SetEnabled(m_pTouchAccelerationCheckBox->IsSelected()); |
||||||
|
m_pTouchAccelExponentLabel->SetEnabled(m_pTouchAccelerationCheckBox->IsSelected()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void COptionsSubTouch::OnTextChanged(Panel *panel) |
||||||
|
{ |
||||||
|
if ( panel == m_pTouchSensitivityLabel ) |
||||||
|
{ |
||||||
|
char buf[64]; |
||||||
|
m_pTouchSensitivityLabel->GetText(buf, 64); |
||||||
|
|
||||||
|
float fValue; |
||||||
|
int numParsed = sscanf(buf, "%f", &fValue); |
||||||
|
if ( ( numParsed == 1 ) && ( fValue >= 0.0f ) ) |
||||||
|
{ |
||||||
|
m_pTouchSensitivitySlider->SetSliderValue(fValue); |
||||||
|
PostActionSignal(new KeyValues("ApplyButtonEnable")); |
||||||
|
} |
||||||
|
} |
||||||
|
else if ( panel == m_pTouchAccelExponentLabel ) |
||||||
|
{ |
||||||
|
char buf[64]; |
||||||
|
m_pTouchAccelExponentLabel->GetText(buf, 64); |
||||||
|
|
||||||
|
float fValue = (float) atof(buf); |
||||||
|
if (fValue >= 1.0) |
||||||
|
{ |
||||||
|
m_pTouchAccelExponentSlider->SetSliderValue(fValue); |
||||||
|
PostActionSignal(new KeyValues("ApplyButtonEnable")); |
||||||
|
} |
||||||
|
} |
||||||
|
else if( panel == m_pTouchPitchSensitivityLabel ) |
||||||
|
{ |
||||||
|
char buf[64]; |
||||||
|
m_pTouchPitchSensitivityLabel->GetText(buf, 64); |
||||||
|
|
||||||
|
float fValue = (float) atof(buf); |
||||||
|
if (fValue >= 1.0) |
||||||
|
{ |
||||||
|
m_pTouchPitchSensitivitySlider->SetSliderValue(fValue); |
||||||
|
PostActionSignal(new KeyValues("ApplyButtonEnable")); |
||||||
|
} |
||||||
|
} |
||||||
|
else if( panel == m_pTouchYawSensitivityLabel ) |
||||||
|
{ |
||||||
|
char buf[64]; |
||||||
|
m_pTouchYawSensitivityLabel->GetText(buf, 64); |
||||||
|
|
||||||
|
float fValue = (float) atof(buf); |
||||||
|
if (fValue >= 1.0) |
||||||
|
{ |
||||||
|
m_pTouchYawSensitivitySlider->SetSliderValue(fValue); |
||||||
|
PostActionSignal(new KeyValues("ApplyButtonEnable")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void COptionsSubTouch::UpdateLabel(CCvarSlider *slider, vgui::TextEntry *label) |
||||||
|
{ |
||||||
|
char buf[64]; |
||||||
|
Q_snprintf(buf, sizeof( buf ), " %.2f", slider->GetSliderValue()); |
||||||
|
label->SetText(buf); |
||||||
|
} |
@ -0,0 +1,81 @@ |
|||||||
|
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
//
|
||||||
|
// $NoKeywords: $
|
||||||
|
//=============================================================================//
|
||||||
|
|
||||||
|
#ifndef OPTIONS_SUB_TOUCH_H |
||||||
|
#define OPTIONS_SUB_TOUCH_H |
||||||
|
#ifdef _WIN32 |
||||||
|
#pragma once |
||||||
|
#endif |
||||||
|
|
||||||
|
#include <vgui_controls/PropertyPage.h> |
||||||
|
|
||||||
|
class CCvarNegateCheckButton; |
||||||
|
class CKeyToggleCheckButton; |
||||||
|
class CCvarToggleCheckButton; |
||||||
|
class CCvarSlider; |
||||||
|
|
||||||
|
namespace vgui |
||||||
|
{ |
||||||
|
class Label; |
||||||
|
class Panel; |
||||||
|
} |
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose: Touch Details, Part of OptionsDialog
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
class COptionsSubTouch : public vgui::PropertyPage |
||||||
|
{ |
||||||
|
DECLARE_CLASS_SIMPLE( COptionsSubTouch, vgui::PropertyPage ); |
||||||
|
|
||||||
|
public: |
||||||
|
COptionsSubTouch(vgui::Panel *parent); |
||||||
|
~COptionsSubTouch(); |
||||||
|
|
||||||
|
virtual void OnResetData(); |
||||||
|
virtual void OnApplyChanges(); |
||||||
|
|
||||||
|
protected: |
||||||
|
virtual void ApplySchemeSettings(vgui::IScheme *pScheme); |
||||||
|
|
||||||
|
MESSAGE_FUNC_PTR( OnControlModified, "ControlModified", panel ); |
||||||
|
MESSAGE_FUNC_PTR( OnTextChanged, "TextChanged", panel ); |
||||||
|
MESSAGE_FUNC_PTR( OnCheckButtonChecked, "CheckButtonChecked", panel ) |
||||||
|
{ |
||||||
|
OnControlModified( panel ); |
||||||
|
} |
||||||
|
|
||||||
|
void UpdateLabel(CCvarSlider *slider, vgui::TextEntry *label); |
||||||
|
private: |
||||||
|
CCvarToggleCheckButton *m_pReverseTouchCheckBox; |
||||||
|
CCvarToggleCheckButton *m_pTouchFilterCheckBox; |
||||||
|
CCvarToggleCheckButton *m_pTouchRawCheckBox; |
||||||
|
CCvarToggleCheckButton *m_pTouchAccelerationCheckBox; |
||||||
|
|
||||||
|
CCvarToggleCheckButton *m_pTouchCheckBox; |
||||||
|
CCvarToggleCheckButton *m_pTouchSouthpawCheckBox; |
||||||
|
CCvarToggleCheckButton *m_pQuickInfoCheckBox; |
||||||
|
CCvarToggleCheckButton *m_pTouchEnableCheckBox; |
||||||
|
CCvarToggleCheckButton *m_pTouchDrawCheckBox; |
||||||
|
|
||||||
|
CCvarSlider *m_pTouchSensitivitySlider; |
||||||
|
vgui::TextEntry *m_pTouchSensitivityLabel; |
||||||
|
|
||||||
|
CCvarSlider *m_pTouchAccelExponentSlider; |
||||||
|
vgui::TextEntry *m_pTouchAccelExponentLabel; |
||||||
|
|
||||||
|
CCvarSlider *m_pTouchYawSensitivitySlider; |
||||||
|
vgui::Label *m_pTouchYawSensitivityPreLabel; |
||||||
|
CCvarSlider *m_pTouchPitchSensitivitySlider; |
||||||
|
vgui::Label *m_pTouchPitchSensitivityPreLabel; |
||||||
|
vgui::TextEntry *m_pTouchYawSensitivityLabel; |
||||||
|
vgui::TextEntry *m_pTouchPitchSensitivityLabel; |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // OPTIONS_SUB_TOUCH_H
|
Loading…
Reference in new issue