Counter Strike : Global Offensive Source Code
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.

130 lines
4.3 KiB

  1. //======= Copyright � 1996-2008, Valve Corporation, All rights reserved. ======
  2. //
  3. // Purpose: A 2D Slider
  4. //
  5. //=============================================================================
  6. #ifndef C2DSLIDER_H
  7. #define C2DSLIDER_H
  8. #include <vgui_controls/Panel.h>
  9. class vgui::TextImage;
  10. //-----------------------------------------------------------------------------
  11. // Purpose: A 2D Slider
  12. //-----------------------------------------------------------------------------
  13. class C2DSlider : public vgui::Panel
  14. {
  15. DECLARE_CLASS_SIMPLE( C2DSlider, vgui::Panel );
  16. public:
  17. C2DSlider( Panel *pParent, const char *pName );
  18. virtual ~C2DSlider();
  19. // interface
  20. virtual void SetValueX( float fValueX, bool bTriggerChangeMessage = true );
  21. virtual float GetValueX() const;
  22. virtual void SetValueY( float fValueY, bool bTriggerChangeMessage = true );
  23. virtual float GetValueY() const;
  24. virtual void SetValue( float fValueX, float fValueY, bool bTriggerChangeMessage = true );
  25. virtual void GetValue( float &fValueX, float &fValueY ) const;
  26. virtual void SetRange( float fMinX, float fMaxX, float fMinY, float fMaxY, bool bTriggerChangeMessage = true );
  27. virtual void GetRange( float &fMinX, float &fMaxX, float &fMinY, float &fMaxY ) const;
  28. virtual void SetLabelText( const char *pText );
  29. virtual void SetLabelText( const wchar_t *pText );
  30. virtual void GetLabelText( wchar_t *pBuffer, int nBufferLen ) const;
  31. virtual void GetLabelUnlocalizedText( char *pBuffer, int nBufferLen ) const;
  32. virtual void SetDrawLabel( bool bState );
  33. virtual bool IsDrawingLabel() const;
  34. virtual void GetNobPos( int &nX, int &nY );
  35. virtual void OnCursorMoved( int x, int y );
  36. virtual void OnMousePressed( vgui::MouseCode mouseCode );
  37. virtual void OnMouseDoublePressed( vgui::MouseCode mouseCode );
  38. virtual void OnMouseReleased( vgui::MouseCode mouseCode );
  39. virtual void SetNobWidth( int nWidth );
  40. virtual int GetNobWidth() const;
  41. virtual void SetNobTall( int nTall );
  42. virtual int GetNobTall() const;
  43. virtual void SetNobSize( int nWidth, int nTall );
  44. virtual void GetNobSize( int &nWidth, int &nTall ) const;
  45. // If you click on the slider outside of the nob, the nob jumps
  46. // to the click position, and if this setting is enabled, the nob
  47. // is then draggable from the new position until the mouse is released
  48. virtual void SetDragOnRepositionNob( bool bState );
  49. virtual bool IsDragOnRepositionNob() const;
  50. // Get if the slider nob is being dragged by user, usually the application
  51. // should refuse from forcefully setting slider value if it is being dragged
  52. // by user since the next frame the nob will pop back to mouse position
  53. virtual bool IsDragged() const;
  54. protected:
  55. virtual void OnSizeChanged( int nWide, int nTall );
  56. virtual void Paint();
  57. virtual void PaintBackground();
  58. virtual void PerformLayout();
  59. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  60. virtual void ApplySettings( KeyValues *pInResourceData );
  61. virtual void GetSettings( KeyValues *pOutResourceData );
  62. virtual const char *GetDescription();
  63. virtual void OnKeyCodeTyped( vgui::KeyCode nKeyCode );
  64. virtual void DrawNob();
  65. virtual void GetTrackRect( int &x, int &y, int &w, int &t );
  66. virtual void MoveNobRelative( int nX, int nY );
  67. virtual void RecomputeNobPosFromValue();
  68. virtual void RecomputeValueFromNobPos( bool bTriggerChangeMessage = true );
  69. virtual void SendSliderMovedMessage();
  70. virtual void SendSliderDragStartMessage();
  71. virtual void SendSliderDragEndMessage();
  72. enum Axis_t
  73. {
  74. kXAxis = 0,
  75. kYAxis = 1,
  76. kAxisCount = 2
  77. };
  78. int m_nNobPos[ kAxisCount ]; // Position of the center of the nob in client space pixels
  79. int m_nNobDragStartPos[ kAxisCount ];
  80. int m_nDragStartPos[ kAxisCount ];
  81. float m_fRange[ kAxisCount ][ 2 ];
  82. float m_fValue[ kAxisCount ]; // the position of the Slider, in coordinates as specified by SetRange
  83. vgui::IBorder *m_pNobBorder;
  84. vgui::IBorder *m_pInsetBorder;
  85. int m_nNobHalfSize[ kAxisCount ]; // The number of pixels on each side of the nob center, can be 0 for a 1x1 pixel nob. nob size = m_nNobHalfSize * 2 + 1
  86. static Color s_TextColor;
  87. static Color s_NobColor;
  88. static Color s_TickColor;
  89. static Color s_TickFillXColor;
  90. static Color s_TickFillYColor;
  91. static Color s_TickFillColor;
  92. static Color s_TrackColor;
  93. bool m_bDrawLabel : 1;
  94. bool m_bIsDragOnRepositionNob : 1;
  95. bool m_bDragging : 1;
  96. vgui::TextImage *m_pLabel;
  97. };
  98. #endif // C2DSLIDER_H