10 changed files with 250 additions and 58 deletions
@ -0,0 +1,14 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="MouseDevice.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Windows.Input |
|||
{ |
|||
using Perspex.Input; |
|||
|
|||
public class MouseDevice : IInputDevice |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="IInputDevice.cs" company="Steven Kirk">
|
|||
// Copyright 2013 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Input |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
public interface IInputDevice |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="IInputManager.cs" company="Steven Kirk">
|
|||
// Copyright 2013 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Input |
|||
{ |
|||
using Perspex.Input.Raw; |
|||
|
|||
public interface IInputManager |
|||
{ |
|||
void Process(RawInputEventArgs e); |
|||
} |
|||
} |
|||
@ -0,0 +1,95 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="InputManager.cs" company="Steven Kirk">
|
|||
// Copyright 2013 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Input |
|||
{ |
|||
using Perspex.Controls; |
|||
using Perspex.Input.Raw; |
|||
|
|||
public class InputManager : IInputManager |
|||
{ |
|||
public void Process(RawInputEventArgs e) |
|||
{ |
|||
RawMouseEventArgs mouse = e as RawMouseEventArgs; |
|||
|
|||
if (mouse != null) |
|||
{ |
|||
this.ProcessMouse(mouse); |
|||
} |
|||
} |
|||
|
|||
private void ProcessMouse(RawMouseEventArgs e) |
|||
{ |
|||
switch (e.Type) |
|||
{ |
|||
case RawMouseEventType.Move: |
|||
this.MouseMove((IVisual)e.Root, e.Position); |
|||
break; |
|||
case RawMouseEventType.LeftButtonDown: |
|||
this.MouseDown((IVisual)e.Root, e.Position); |
|||
break; |
|||
case RawMouseEventType.LeftButtonUp: |
|||
this.MouseUp((IVisual)e.Root, e.Position); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
private void MouseMove(IVisual visual, Point p) |
|||
{ |
|||
Control control = visual as Control; |
|||
|
|||
if (control != null) |
|||
{ |
|||
control.IsPointerOver = visual.Bounds.Contains(p); |
|||
} |
|||
|
|||
foreach (IVisual child in visual.VisualChildren) |
|||
{ |
|||
this.MouseMove(child, p - visual.Bounds.Position); |
|||
} |
|||
} |
|||
|
|||
private void MouseDown(IVisual visual, Point p) |
|||
{ |
|||
IVisual hit = visual.GetVisualAt(p); |
|||
|
|||
if (hit != null) |
|||
{ |
|||
Interactive source = (hit as Interactive) ?? hit.GetVisualAncestor<Interactive>(); |
|||
|
|||
if (source != null) |
|||
{ |
|||
source.RaiseEvent(new PointerEventArgs |
|||
{ |
|||
RoutedEvent = Control.PointerPressedEvent, |
|||
OriginalSource = source, |
|||
Source = source, |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private void MouseUp(IVisual visual, Point p) |
|||
{ |
|||
IVisual hit = visual.GetVisualAt(p); |
|||
|
|||
if (hit != null) |
|||
{ |
|||
Interactive source = (hit as Interactive) ?? hit.GetVisualAncestor<Interactive>(); |
|||
|
|||
if (source != null) |
|||
{ |
|||
source.RaiseEvent(new PointerEventArgs |
|||
{ |
|||
RoutedEvent = Control.PointerReleasedEvent, |
|||
OriginalSource = source, |
|||
Source = source, |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="RawInputEventArgs.cs" company="Steven Kirk">
|
|||
// Copyright 2013 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Input.Raw |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Perspex.Layout; |
|||
|
|||
public class RawInputEventArgs : EventArgs |
|||
{ |
|||
public RawInputEventArgs(IInputDevice device) |
|||
{ |
|||
Contract.Requires<ArgumentNullException>(device != null); |
|||
|
|||
this.Device = device; |
|||
} |
|||
|
|||
public IInputDevice Device { get; private set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="RawMouseEventArgs.cs" company="Steven Kirk">
|
|||
// Copyright 2013 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Input.Raw |
|||
{ |
|||
using System; |
|||
using Perspex.Layout; |
|||
|
|||
public enum RawMouseEventType |
|||
{ |
|||
Move, |
|||
LeftButtonDown, |
|||
LeftButtonUp, |
|||
} |
|||
|
|||
public class RawMouseEventArgs : RawInputEventArgs |
|||
{ |
|||
public RawMouseEventArgs( |
|||
IInputDevice device, |
|||
ILayoutRoot root, |
|||
RawMouseEventType type, |
|||
Point position) |
|||
: base(device) |
|||
{ |
|||
Contract.Requires<ArgumentNullException>(device != null); |
|||
Contract.Requires<ArgumentNullException>(root != null); |
|||
|
|||
this.Root = root; |
|||
this.Position = position; |
|||
this.Type = type; |
|||
} |
|||
|
|||
public ILayoutRoot Root { get; private set; } |
|||
|
|||
public Point Position { get; private set; } |
|||
|
|||
public RawMouseEventType Type { get; private set; } |
|||
} |
|||
} |
|||
Loading…
Reference in new issue