Browse Source

Mouse capture release works a bit better.

pull/4/head
Steven Kirk 12 years ago
parent
commit
6116890e54
  1. 30
      Perspex.Windows/Input/MouseDevice.cs
  2. 13
      Perspex.Windows/Window.cs

30
Perspex.Windows/Input/MouseDevice.cs

@ -9,18 +9,48 @@ namespace Perspex.Windows.Input
using System;
using System.Reactive.Disposables;
using Perspex.Input;
using Perspex.Input.Raw;
using Splat;
public class MouseDevice : IMouseDevice
{
private static MouseDevice instance = new MouseDevice();
public static MouseDevice Instance
{
get { return instance; }
}
public Interactive Captured
{
get;
private set;
}
public Window CurrentWindow
{
get;
set;
}
public Point Position
{
get;
set;
}
public void Capture(Interactive visual)
{
this.Captured = visual;
RawMouseEventArgs e = new RawMouseEventArgs(
this,
this.CurrentWindow,
RawMouseEventType.Move,
this.Position);
IInputManager inputManager = Locator.Current.GetService<IInputManager>();
inputManager.Process(e);
}
}
}

13
Perspex.Windows/Window.cs

@ -25,8 +25,6 @@ namespace Perspex.Windows
public static readonly PerspexProperty<double> FontSizeProperty =
TextBlock.FontSizeProperty.AddOwner<Window>();
private static readonly IInputDevice MouseDevice = new MouseDevice();
private UnmanagedMethods.WndProc wndProcDelegate;
private string className;
@ -149,7 +147,9 @@ namespace Perspex.Windows
[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Using Win32 naming for consistency.")]
private IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
{
RawInputEventArgs e = null;
RawMouseEventArgs e = null;
MouseDevice.Instance.CurrentWindow = this;
switch ((UnmanagedMethods.WindowsMessage)msg)
{
@ -167,7 +167,7 @@ namespace Perspex.Windows
case UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN:
e = new RawMouseEventArgs(
MouseDevice,
MouseDevice.Instance,
this,
RawMouseEventType.LeftButtonDown,
new Point((uint)lParam & 0xffff, (uint)lParam >> 16));
@ -175,7 +175,7 @@ namespace Perspex.Windows
case UnmanagedMethods.WindowsMessage.WM_LBUTTONUP:
e = new RawMouseEventArgs(
MouseDevice,
MouseDevice.Instance,
this,
RawMouseEventType.LeftButtonUp,
new Point((uint)lParam & 0xffff, (uint)lParam >> 16));
@ -183,7 +183,7 @@ namespace Perspex.Windows
case UnmanagedMethods.WindowsMessage.WM_MOUSEMOVE:
e = new RawMouseEventArgs(
MouseDevice,
MouseDevice.Instance,
this,
RawMouseEventType.Move,
new Point((uint)lParam & 0xffff, (uint)lParam >> 16));
@ -197,6 +197,7 @@ namespace Perspex.Windows
if (e != null)
{
MouseDevice.Instance.Position = e.Position;
this.inputManager.Process(e);
}

Loading…
Cancel
Save