Browse Source

Added IsHitTestVisible property.

pull/39/head
Steven Kirk 12 years ago
parent
commit
557fb4d215
  1. 2
      Perspex.Input/IInputElement.cs
  2. 2
      Perspex.Input/IInputManager.cs
  3. 14
      Perspex.Input/InputElement.cs
  4. 38
      Perspex.Input/InputExtensions.cs
  5. 6
      Perspex.Input/InputManager.cs
  6. 1
      Perspex.Input/Perspex.Input.csproj

2
Perspex.Input/IInputElement.cs

@ -33,6 +33,8 @@ namespace Perspex.Input
bool IsFocused { get; }
bool IsHitTestVisible { get; }
bool IsPointerOver { get; }
void Focus();

2
Perspex.Input/IInputManager.cs

@ -18,6 +18,6 @@ namespace Perspex.Input
void Process(RawInputEventArgs e);
void SetPointerOver(IPointerDevice device, IVisual visual, Point p);
void SetPointerOver(IPointerDevice device, IInputElement element, Point p);
}
}

14
Perspex.Input/InputElement.cs

@ -25,6 +25,9 @@ namespace Perspex.Input
public static readonly PerspexProperty<bool> IsFocusedProperty =
PerspexProperty.Register<InputElement, bool>("IsFocused", false);
public static readonly PerspexProperty<bool> IsHitTestVisibleProperty =
PerspexProperty.Register<InputElement, bool>("IsHitTestVisible", true);
public static readonly PerspexProperty<bool> IsPointerOverProperty =
PerspexProperty.Register<InputElement, bool>("IsPointerOver");
@ -152,6 +155,12 @@ namespace Perspex.Input
private set { this.SetValue(IsFocusedProperty, value); }
}
public bool IsHitTestVisible
{
get { return this.GetValue(IsHitTestVisibleProperty); }
set { this.SetValue(IsHitTestVisibleProperty, value); }
}
public bool IsPointerOver
{
get { return this.GetValue(IsPointerOverProperty); }
@ -171,10 +180,7 @@ namespace Perspex.Input
public IInputElement InputHitTest(Point p)
{
return this.GetVisualsAt(p)
.OfType<IInputElement>()
.Where(x => x.IsEnabledCore)
.FirstOrDefault();
return this.GetInputElementsAt(p).FirstOrDefault();
}
public void Focus()

38
Perspex.Input/InputExtensions.cs

@ -0,0 +1,38 @@
// -----------------------------------------------------------------------
// <copyright file="InputExtensions.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Input
{
using System;
using System.Collections.Generic;
using System.Linq;
public static class InputExtensions
{
public static IEnumerable<IInputElement> GetInputElementsAt(this IInputElement element, Point p)
{
Contract.Requires<NullReferenceException>(element != null);
if (element.Bounds.Contains(p) && element.IsHitTestVisible && element.IsEnabledCore)
{
p -= element.Bounds.Position;
if (element.VisualChildren.Any())
{
foreach (var child in element.VisualChildren.OfType<IInputElement>())
{
foreach (var result in child.GetInputElementsAt(p))
{
yield return result;
}
}
}
yield return element;
}
}
}
}

6
Perspex.Input/InputManager.cs

@ -46,11 +46,9 @@ namespace Perspex.Input
this.rawEventReceived.OnNext(e);
}
public void SetPointerOver(IPointerDevice device, IVisual visual, Point p)
public void SetPointerOver(IPointerDevice device, IInputElement element, Point p)
{
IEnumerable<IInputElement> hits = visual.GetVisualsAt(p)
.OfType<IInputElement>()
.Where(x => x.IsEnabledCore);
IEnumerable<IInputElement> hits = element.GetInputElementsAt(p);
foreach (var control in this.pointerOvers.Except(hits).ToList())
{

1
Perspex.Input/Perspex.Input.csproj

@ -68,6 +68,7 @@
<Compile Include="IKeyboardDevice.cs" />
<Compile Include="IMouseDevice.cs" />
<Compile Include="InputElement.cs" />
<Compile Include="InputExtensions.cs" />
<Compile Include="InputManager.cs" />
<Compile Include="IPointerDevice.cs" />
<Compile Include="Key.cs" />

Loading…
Cancel
Save