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