using System; using Gwen.ControlInternal; namespace Gwen.Control { /// /// Base class for scrollbars. /// public class ScrollBar : Base { protected readonly ScrollBarButton[] m_ScrollButton; protected readonly ScrollBarBar m_Bar; protected bool m_Depressed; protected float m_ScrollAmount; protected float m_ContentSize; protected float m_ViewableContentSize; protected float m_NudgeAmount; /// /// Invoked when the bar is moved. /// public event GwenEventHandler BarMoved; /// /// Bar size (in pixels). /// public virtual int BarSize { get; set; } /// /// Bar position (in pixels). /// public virtual int BarPos { get { return 0; } } /// /// Button size (in pixels). /// public virtual int ButtonSize { get { return 0; } } public virtual float NudgeAmount { get { return m_NudgeAmount / m_ContentSize; } set { m_NudgeAmount = value; } } public float ScrollAmount { get { return m_ScrollAmount; } } public float ContentSize { get { return m_ContentSize; } set { if (m_ContentSize != value) Invalidate(); m_ContentSize = value; } } public float ViewableContentSize { get { return m_ViewableContentSize; } set { if (m_ViewableContentSize != value) Invalidate(); m_ViewableContentSize = value; } } /// /// Indicates whether the bar is horizontal. /// public virtual bool IsHorizontal { get { return false; } } /// /// Initializes a new instance of the class. /// /// Parent control. protected ScrollBar(Base parent) : base(parent) { m_ScrollButton = new ScrollBarButton[2]; m_ScrollButton[0] = new ScrollBarButton(this); m_ScrollButton[1] = new ScrollBarButton(this); m_Bar = new ScrollBarBar(this); SetBounds(0, 0, 15, 15); m_Depressed = false; m_ScrollAmount = 0; m_ContentSize = 0; m_ViewableContentSize = 0; NudgeAmount = 20; } /// /// Sets the scroll amount (0-1). /// /// Scroll amount. /// Determines whether the control should be updated. /// True if control state changed. public virtual bool SetScrollAmount(float value, bool forceUpdate = false) { if (m_ScrollAmount == value && !forceUpdate) return false; m_ScrollAmount = value; Invalidate(); OnBarMoved(this); return true; } /// /// Handler invoked on mouse click (left) event. /// /// X coordinate. /// Y coordinate. /// If set to true mouse button is down. protected override void OnMouseClickedLeft(int x, int y, bool down) { } /// /// Renders the control using specified skin. /// /// Skin to use. protected override void Render(Skin.Base skin) { skin.DrawScrollBar(this, IsHorizontal, m_Depressed); } /// /// Handler for the BarMoved event. /// /// The control. protected virtual void OnBarMoved(Base control) { if (BarMoved != null) BarMoved.Invoke(this); } protected virtual float CalculateScrolledAmount() { return 0; } protected virtual int CalculateBarSize() { return 0; } public virtual void ScrollToLeft() { } public virtual void ScrollToRight() { } public virtual void ScrollToTop() { } public virtual void ScrollToBottom() { } } }