summaryrefslogtreecommitdiff
path: root/game/client/tf2/vgui_rotation_slider.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/client/tf2/vgui_rotation_slider.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/client/tf2/vgui_rotation_slider.cpp')
-rw-r--r--game/client/tf2/vgui_rotation_slider.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/game/client/tf2/vgui_rotation_slider.cpp b/game/client/tf2/vgui_rotation_slider.cpp
new file mode 100644
index 0000000..e1ee1e6
--- /dev/null
+++ b/game/client/tf2/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 != vgui::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 != vgui::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;
+ }
+}