using System; using System.Drawing; using Gwen.Control; using Gwen.Input; namespace Gwen.ControlInternal { /// /// Base for controls that can be dragged by mouse. /// public class Dragger : Base { protected bool m_Held; protected Point m_HoldPos; protected Base m_Target; internal Base Target { get { return m_Target; } set { m_Target = value; } } /// /// Indicates if the control is being dragged. /// public bool IsHeld { get { return m_Held; } } /// /// Event invoked when the control position has been changed. /// public event GwenEventHandler Dragged; /// /// Initializes a new instance of the class. /// /// Parent control. public Dragger(Base parent) : base(parent) { MouseInputEnabled = true; m_Held = false; } /// /// 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) { if (null == m_Target) return; if (down) { m_Held = true; m_HoldPos = m_Target.CanvasPosToLocal(new Point(x, y)); InputHandler.MouseFocus = this; } else { m_Held = false; InputHandler.MouseFocus = null; } } /// /// Handler invoked on mouse moved event. /// /// X coordinate. /// Y coordinate. /// X change. /// Y change. protected override void OnMouseMoved(int x, int y, int dx, int dy) { if (null == m_Target) return; if (!m_Held) return; Point p = new Point(x - m_HoldPos.X, y - m_HoldPos.Y); // Translate to parent if (m_Target.Parent != null) p = m_Target.Parent.CanvasPosToLocal(p); //m_Target->SetPosition( p.x, p.y ); m_Target.MoveTo(p.X, p.Y); if (Dragged != null) Dragged.Invoke(this); } /// /// Renders the control using specified skin. /// /// Skin to use. protected override void Render(Skin.Base skin) { } } }