diff --git a/Perspex.Windows/Input/MouseDevice.cs b/Perspex.Windows/Input/MouseDevice.cs index 08d0253570..4569887011 100644 --- a/Perspex.Windows/Input/MouseDevice.cs +++ b/Perspex.Windows/Input/MouseDevice.cs @@ -6,9 +6,22 @@ namespace Perspex.Windows.Input { + using System; + using System.Reactive.Disposables; using Perspex.Input; - public class MouseDevice : IInputDevice + public class MouseDevice : IMouseDevice { + public IVisual Captured + { + get; + private set; + } + + public IDisposable Capture(IVisual visual) + { + this.Captured = visual; + return Disposable.Create(() => this.Captured = null); + } } } diff --git a/Perspex/Controls/Control.cs b/Perspex/Controls/Control.cs index b599168387..69f97047bd 100644 --- a/Perspex/Controls/Control.cs +++ b/Perspex/Controls/Control.cs @@ -220,7 +220,7 @@ namespace Perspex.Controls public bool IsPointerOver { get { return this.GetValue(IsPointerOverProperty); } - set { this.SetValue(IsPointerOverProperty, value); } + internal set { this.SetValue(IsPointerOverProperty, value); } } public HorizontalAlignment HorizontalAlignment diff --git a/Perspex/Input/IInputDevice.cs b/Perspex/Input/IInputDevice.cs index f69f13e837..e2ba98a205 100644 --- a/Perspex/Input/IInputDevice.cs +++ b/Perspex/Input/IInputDevice.cs @@ -1,17 +1,11 @@ // ----------------------------------------------------------------------- // -// Copyright 2013 MIT Licence. See licence.md for more information. +// Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Input { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - public interface IInputDevice { } diff --git a/Perspex/Input/IMouseDevice.cs b/Perspex/Input/IMouseDevice.cs new file mode 100644 index 0000000000..6a51c65eb0 --- /dev/null +++ b/Perspex/Input/IMouseDevice.cs @@ -0,0 +1,14 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Input +{ + using System; + + public interface IMouseDevice : IPointerDevice + { + } +} diff --git a/Perspex/Input/IPointerDevice.cs b/Perspex/Input/IPointerDevice.cs new file mode 100644 index 0000000000..0603453f49 --- /dev/null +++ b/Perspex/Input/IPointerDevice.cs @@ -0,0 +1,17 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Input +{ + using System; + + public interface IPointerDevice : IInputDevice + { + IVisual Captured { get; } + + IDisposable Capture(IVisual visual); + } +} diff --git a/Perspex/Input/InputManager.cs b/Perspex/Input/InputManager.cs index d2341bd3f2..0aa310fc41 100644 --- a/Perspex/Input/InputManager.cs +++ b/Perspex/Input/InputManager.cs @@ -29,10 +29,10 @@ namespace Perspex.Input this.MouseMove((IVisual)e.Root, e.Position); break; case RawMouseEventType.LeftButtonDown: - this.MouseDown((IVisual)e.Root, e.Position); + this.MouseDown((IMouseDevice)e.Device, (IVisual)e.Root, e.Position); break; case RawMouseEventType.LeftButtonUp: - this.MouseUp((IVisual)e.Root, e.Position); + this.MouseUp((IMouseDevice)e.Device, (IVisual)e.Root, e.Position); break; } } @@ -52,7 +52,7 @@ namespace Perspex.Input } } - private void MouseDown(IVisual visual, Point p) + private void MouseDown(IMouseDevice device, IVisual visual, Point p) { IVisual hit = visual.GetVisualAt(p); @@ -64,6 +64,7 @@ namespace Perspex.Input { source.RaiseEvent(new PointerEventArgs { + Device = device, RoutedEvent = Control.PointerPressedEvent, OriginalSource = source, Source = source, @@ -72,7 +73,7 @@ namespace Perspex.Input } } - private void MouseUp(IVisual visual, Point p) + private void MouseUp(IMouseDevice device, IVisual visual, Point p) { IVisual hit = visual.GetVisualAt(p); @@ -84,6 +85,7 @@ namespace Perspex.Input { source.RaiseEvent(new PointerEventArgs { + Device = device, RoutedEvent = Control.PointerReleasedEvent, OriginalSource = source, Source = source, diff --git a/Perspex/Input/PointerEventArgs.cs b/Perspex/Input/PointerEventArgs.cs index e32ca18a28..056328f5a1 100644 --- a/Perspex/Input/PointerEventArgs.cs +++ b/Perspex/Input/PointerEventArgs.cs @@ -10,5 +10,6 @@ namespace Perspex.Input public class PointerEventArgs : RoutedEventArgs { + public IPointerDevice Device { get; set; } } } diff --git a/Perspex/Perspex.csproj b/Perspex/Perspex.csproj index a85e1de6c6..a020101356 100644 --- a/Perspex/Perspex.csproj +++ b/Perspex/Perspex.csproj @@ -73,6 +73,8 @@ + +