Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include <vgui/MouseCode.h>
  9. #include "vgui_rotation_slider.h"
  10. CRotationSlider::CRotationSlider( vgui::Panel *pParent, const char *pName ) :
  11. BaseClass( pParent, pName )
  12. {
  13. AddActionSignalTarget( this );
  14. SetRange( -180, 180 );
  15. SetTickCaptions("-180", "180");
  16. SetValue( 0 );
  17. m_flYaw = 0;
  18. }
  19. void CRotationSlider::SetControlledObject( C_BaseObject *pObject )
  20. {
  21. m_hObject.Set( pObject );
  22. }
  23. //-----------------------------------------------------------------------------
  24. // When the slider is activated, deactivated, or moves
  25. //-----------------------------------------------------------------------------
  26. void CRotationSlider::OnMousePressed( vgui::MouseCode code )
  27. {
  28. BaseClass::OnMousePressed( code );
  29. if (code != MOUSE_LEFT)
  30. return;
  31. C_BaseObject *pObj = m_hObject.Get();
  32. if (pObj)
  33. {
  34. m_flInitialYaw = pObj->GetAbsAngles().y;
  35. pObj->PreviewYaw( m_flInitialYaw );
  36. pObj->ActivateYawPreview( true );
  37. }
  38. }
  39. void CRotationSlider::OnSliderMoved( int position )
  40. {
  41. C_BaseObject *pObj = m_hObject.Get();
  42. if (pObj && pObj->IsPreviewingYaw())
  43. {
  44. m_flYaw = anglemod(position);
  45. pObj->PreviewYaw( m_flInitialYaw - m_flYaw );
  46. }
  47. }
  48. void CRotationSlider::OnMouseReleased( vgui::MouseCode code )
  49. {
  50. BaseClass::OnMouseReleased( code );
  51. if (code != MOUSE_LEFT)
  52. return;
  53. C_BaseObject *pObj = m_hObject.Get();
  54. if (pObj)
  55. {
  56. char szbuf[48];
  57. Q_snprintf( szbuf, sizeof( szbuf ), "yaw %0.2f\n", m_flInitialYaw - m_flYaw );
  58. pObj->SendClientCommand( szbuf );
  59. pObj->ActivateYawPreview( false );
  60. SetValue(0);
  61. m_flYaw = 0;
  62. }
  63. }