From d1918c7a774a043a7133d829ab65be5800e263d2 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 5 Feb 2016 20:12:40 +0100 Subject: [PATCH] MouseDevice,Position should be in screen coords. --- src/Perspex.Input/IMouseDevice.cs | 6 ++++ src/Perspex.Input/MouseDevice.cs | 46 +++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/Perspex.Input/IMouseDevice.cs b/src/Perspex.Input/IMouseDevice.cs index 9b5a7281b3..9d40e12896 100644 --- a/src/Perspex.Input/IMouseDevice.cs +++ b/src/Perspex.Input/IMouseDevice.cs @@ -3,8 +3,14 @@ namespace Perspex.Input { + /// + /// Represents a mouse device. + /// public interface IMouseDevice : IPointerDevice { + /// + /// Gets the mouse position, in screen coordinates. + /// Point Position { get; } } } diff --git a/src/Perspex.Input/MouseDevice.cs b/src/Perspex.Input/MouseDevice.cs index 84c723db36..df30b06644 100644 --- a/src/Perspex.Input/MouseDevice.cs +++ b/src/Perspex.Input/MouseDevice.cs @@ -12,16 +12,19 @@ using Perspex.VisualTree; namespace Perspex.Input { + /// + /// Represents a mouse device. + /// public class MouseDevice : IMouseDevice { private int _clickCount; - private Rect _lastClickRect; - private uint _lastClickTime; - private readonly List _pointerOvers = new List(); + /// + /// Intializes a new instance of . + /// public MouseDevice() { InputManager.RawEventReceived @@ -30,46 +33,79 @@ namespace Perspex.Input .Subscribe(ProcessRawEvent); } + /// + /// Gets the current mouse device instance. + /// public static IMouseDevice Instance => PerspexLocator.Current.GetService(); + /// + /// Gets the control that is currently capturing by the mouse, if any. + /// + /// + /// When an element captures the mouse, it recieves mouse input whether the cursor is + /// within the control's bounds or not. To set the mouse capture, call the + /// method. + /// public IInputElement Captured { get; protected set; } + /// + /// Gets the application's input manager. + /// public IInputManager InputManager => PerspexLocator.Current.GetService(); + /// + /// Gets the mouse position, in screen coordinates. + /// public Point Position { get; protected set; } + /// + /// Captures mouse input to the specified control. + /// + /// The control. + /// + /// When an element captures the mouse, it recieves mouse input whether the cursor is + /// within the control's bounds or not. The current mouse capture control is exposed + /// by the property. + /// public virtual void Capture(IInputElement control) { Captured = control; } + /// + /// Gets the mouse position relative to a control. + /// + /// The control. + /// The mouse position in the control's coordinates. public Point GetPosition(IVisual relativeTo) { Point p = Position; IVisual v = relativeTo; + IVisual root = null; while (v != null) { p -= v.Bounds.Position; + root = v; v = v.VisualParent; } - return p; + return root.PointToClient(p); } private void ProcessRawEvent(RawMouseEventArgs e) { var mouse = (IMouseDevice)e.Device; - Position = e.Position; + Position = e.Root.PointToScreen(e.Position); switch (e.Type) {