Slider.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. GWEN
  3. Copyright (c) 2010 Facepunch Studios
  4. See license in Gwen.h
  5. */
  6. #pragma once
  7. #ifndef GWEN_CONTROLS_SLIDER_H
  8. #define GWEN_CONTROLS_SLIDER_H
  9. #include "Gwen/Controls/Base.h"
  10. #include "Gwen/Controls/Button.h"
  11. #include "Gwen/Controls/Dragger.h"
  12. #include "Gwen/Gwen.h"
  13. #include "Gwen/Skin.h"
  14. namespace Gwen
  15. {
  16. namespace ControlsInternal
  17. {
  18. class GWEN_EXPORT SliderBar : public ControlsInternal::Dragger
  19. {
  20. GWEN_CONTROL( SliderBar, ControlsInternal::Dragger );
  21. virtual void Render( Skin::Base* skin );
  22. };
  23. }
  24. namespace Controls
  25. {
  26. class GWEN_EXPORT Slider : public Base
  27. {
  28. GWEN_CONTROL( Slider, Base );
  29. virtual void Render( Skin::Base* skin ) = 0;
  30. virtual void Layout( Skin::Base* skin );
  31. virtual void SetClampToNotches( bool bClamp ) { m_bClampToNotches = bClamp; }
  32. virtual void SetNotchCount( int num ) { m_iNumNotches = num; }
  33. virtual int GetNotchCount() { return m_iNumNotches; }
  34. virtual void SetRange( float fMin, float fMax );
  35. virtual float GetRangeMin() const
  36. {
  37. return m_fMin;
  38. }
  39. virtual float GetRangeMax() const
  40. {
  41. return m_fMax;
  42. }
  43. virtual float GetValue();
  44. virtual void SetValue( float val, bool forceUpdate = true );
  45. virtual float CalculateValue();
  46. virtual void OnMoved( Controls::Base * control );
  47. virtual void OnMouseClickLeft( int /*x*/, int /*y*/, bool /*bDown*/ ){};
  48. virtual bool OnKeyRight( bool bDown ) { if ( bDown ) SetValue( GetValue() + 1, true ); return true; }
  49. virtual bool OnKeyLeft( bool bDown ) { if ( bDown ) SetValue( GetValue() - 1, true ); return true; }
  50. virtual bool OnKeyUp( bool bDown ) { if ( bDown ) SetValue( GetValue() + 1, true ); return true; }
  51. virtual bool OnKeyDown( bool bDown ) { if ( bDown ) SetValue( GetValue() - 1, true ); return true; }
  52. virtual void RenderFocus( Gwen::Skin::Base* skin);
  53. Gwen::Event::Caller onValueChanged;
  54. protected:
  55. virtual void SetValueInternal( float fVal );
  56. virtual void UpdateBarFromValue() = 0;
  57. ControlsInternal::SliderBar * m_SliderBar;
  58. bool m_bClampToNotches;
  59. int m_iNumNotches;
  60. float m_fValue;
  61. float m_fMin;
  62. float m_fMax;
  63. };
  64. }
  65. }
  66. #endif