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.

123 lines
4.0 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef PANORAMA_SLIDER_H
  6. #define PANORAMA_SLIDER_H
  7. #ifdef _WIN32
  8. #pragma once
  9. #endif
  10. #include "panorama/controls/panel2d.h"
  11. namespace panorama
  12. {
  13. DECLARE_PANEL_EVENT1( SliderValueChanged, float );
  14. DECLARE_PANEL_EVENT1( SlottedSliderValueChanged, int );
  15. DECLARE_PANEL_EVENT1( SliderFocusChanged, bool );
  16. //-----------------------------------------------------------------------------
  17. // Purpose: Slider control which includes track, progress & thumb
  18. //-----------------------------------------------------------------------------
  19. class CSlider: public CPanel2D
  20. {
  21. DECLARE_PANEL2D( CSlider, CPanel2D );
  22. public:
  23. CSlider( CPanel2D *pParent, const char *pchID );
  24. virtual ~CSlider();
  25. enum ESliderDirection
  26. {
  27. k_EDirectionVertical,
  28. k_EDirectionHorizontal
  29. };
  30. void SetMin( float flMin ) { m_flMin = flMin; InvalidateSizeAndPosition(); }
  31. void SetMax( float flMax ) { m_flMax = flMax; InvalidateSizeAndPosition(); }
  32. void SetIncrement( float flValue ) { m_flIncrement = flValue; }
  33. virtual void SetValue( float flValue );
  34. float GetValue() { return m_flCur; }
  35. float GetDefaultValue() { return m_flDefault; }
  36. void SetDefaultValue ( float flValue ) { m_flDefault = flValue; }
  37. void SetShowDefaultValue( bool bShow ) { m_bShowDefault = bShow; }
  38. void SetDirection( ESliderDirection eValue );
  39. virtual bool BSetProperty( CPanoramaSymbol symName, const char *pchValue );
  40. virtual bool OnMouseButtonDown( const MouseData_t &code ) OVERRIDE;
  41. virtual bool OnMouseButtonUp( const MouseData_t &code ) OVERRIDE;
  42. virtual void OnMouseMove( float flMouseX, float flMouseY ) OVERRIDE;
  43. virtual bool OnMoveUp( int nRepeats ) OVERRIDE;
  44. virtual bool OnMoveRight( int nRepeats ) OVERRIDE;
  45. virtual bool OnMoveDown( int nRepeats ) OVERRIDE;
  46. virtual bool OnMoveLeft( int nRepeats ) OVERRIDE;
  47. virtual bool OnActivate(panorama::EPanelEventSource_t eSource);
  48. virtual bool OnCancel(panorama::EPanelEventSource_t eSource);
  49. virtual void OnStyleFlagsChanged();
  50. virtual void OnResetToDefaultValue();
  51. void SetRequiresSelection( bool bRequireSelection ) { m_bRequiresSelection = bRequireSelection; }
  52. protected:
  53. bool EventPanelActivated( const CPanelPtr< IUIPanel > &pPanel, EPanelEventSource_t eSource );
  54. virtual void OnLayoutTraverse( float flFinalWidth, float flFinalHeight );
  55. void SetValueFromMouse( float x, float y );
  56. float GetMin() { return m_flMin; }
  57. float GetMax() { return m_flMax; }
  58. ESliderDirection GetDirection() { return m_eDirection; }
  59. CPanel2D *m_pThumb;
  60. CPanel2D *m_pTrack;
  61. CPanel2D *m_pProgress;
  62. CPanel2D *m_pDefaultTick;
  63. bool EventActivated( const panorama::CPanelPtr< panorama::IUIPanel > &pPanel, panorama::EPanelEventSource_t eSource );
  64. bool EventCancelled( const panorama::CPanelPtr< panorama::IUIPanel > &pPanel, panorama::EPanelEventSource_t eSource );
  65. bool EventStyleFlagsChanged( const panorama::CPanelPtr< panorama::IUIPanel > &pPanel );
  66. bool EventResetToDefault( const panorama::CPanelPtr< panorama::IUIPanel > &pPanel );
  67. private:
  68. bool AllowInteraction( void );
  69. bool ShouldShowDefault( void ) { return m_bShowDefault; }
  70. float m_flMin;
  71. float m_flMax;
  72. float m_flDefault;
  73. float m_flCur;
  74. float m_flLast;
  75. float m_flIncrement;
  76. bool m_bRequiresSelection;
  77. bool m_bDraggingThumb;
  78. bool m_bShowDefault;
  79. ESliderDirection m_eDirection;
  80. float m_flLastMouseX;
  81. float m_flLastMouseY;
  82. };
  83. class CSlottedSlider : public CSlider
  84. {
  85. DECLARE_PANEL2D( CSlottedSlider, CSlider );
  86. public:
  87. CSlottedSlider( CPanel2D *pParent, const char *pchID );
  88. virtual ~CSlottedSlider();
  89. virtual bool BSetProperty( CPanoramaSymbol symName, const char *pchValue );
  90. virtual void SetValue( float flValue );
  91. void SetValue( int nValue );
  92. virtual void OnLayoutTraverse( float flFinalWidth, float flFinalHeight );
  93. int GetCurrentNotch() { return m_nCurNotch; }
  94. private:
  95. int m_nNumNotches;
  96. int m_nCurNotch;
  97. CUtlVector< CPanel2D* > m_pNotches;
  98. };
  99. } // namespace panorama
  100. #endif // PANORAMA_SLIDER_H