diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/client/tf/vgui/vgui_rotation_slider.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'game/client/tf/vgui/vgui_rotation_slider.cpp')
| -rw-r--r-- | game/client/tf/vgui/vgui_rotation_slider.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/game/client/tf/vgui/vgui_rotation_slider.cpp b/game/client/tf/vgui/vgui_rotation_slider.cpp new file mode 100644 index 0000000..8fc8928 --- /dev/null +++ b/game/client/tf/vgui/vgui_rotation_slider.cpp @@ -0,0 +1,74 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "cbase.h" +#include <vgui/MouseCode.h> +#include "vgui_rotation_slider.h" + + +CRotationSlider::CRotationSlider( vgui::Panel *pParent, const char *pName ) : + BaseClass( pParent, pName ) +{ + AddActionSignalTarget( this ); + SetRange( -180, 180 ); + SetTickCaptions("-180", "180"); + SetValue( 0 ); + m_flYaw = 0; +} + +void CRotationSlider::SetControlledObject( C_BaseObject *pObject ) +{ + m_hObject.Set( pObject ); +} + +//----------------------------------------------------------------------------- +// When the slider is activated, deactivated, or moves +//----------------------------------------------------------------------------- +void CRotationSlider::OnMousePressed( vgui::MouseCode code ) +{ + BaseClass::OnMousePressed( code ); + + if (code != MOUSE_LEFT) + return; + + C_BaseObject *pObj = m_hObject.Get(); + if (pObj) + { + m_flInitialYaw = pObj->GetAbsAngles().y; + pObj->PreviewYaw( m_flInitialYaw ); + pObj->ActivateYawPreview( true ); + } +} + +void CRotationSlider::OnSliderMoved( int position ) +{ + C_BaseObject *pObj = m_hObject.Get(); + if (pObj && pObj->IsPreviewingYaw()) + { + m_flYaw = anglemod(position); + pObj->PreviewYaw( m_flInitialYaw - m_flYaw ); + } +} + +void CRotationSlider::OnMouseReleased( vgui::MouseCode code ) +{ + BaseClass::OnMouseReleased( code ); + + if (code != MOUSE_LEFT) + return; + + C_BaseObject *pObj = m_hObject.Get(); + if (pObj) + { + char szbuf[48]; + Q_snprintf( szbuf, sizeof( szbuf ), "yaw %0.2f\n", m_flInitialYaw - m_flYaw ); + pObj->SendClientCommand( szbuf ); + pObj->ActivateYawPreview( false ); + SetValue(0); + m_flYaw = 0; + } +} |