Skip to content
Permalink
Browse files

[UI/INPUT] Expose mouseOverElement

  • Loading branch information
CharlesWoodhill authored and xen2 committed Sep 5, 2019
1 parent 9b4e65f commit 21399ae559fe078a9e8ff38a8bc04cf71e43506b
Showing with 8 additions and 7 deletions.
  1. +8 −7 sources/engine/Xenko.UI/Rendering/UI/UIRenderFeature.Picking.cs
@@ -19,6 +19,8 @@ public partial class UIRenderFeature

private readonly List<PointerEvent> compactedPointerEvents = new List<PointerEvent>();

public UIElement UIElementUnderMouseCursor { get; private set; }

partial void PickingUpdate(RenderUIElement renderUIElement, Viewport viewport, ref Matrix worldViewProj, GameTime drawTime)
{
if (renderUIElement.Page?.RootElement == null)
@@ -238,7 +240,6 @@ private void UpdateMouseOver(ref Viewport viewport, ref Matrix worldViewProj, Re
var mousePosition = input.MousePosition;
var rootElement = state.Page.RootElement;
var lastMouseOverElement = state.LastMouseOverElement;
var mouseOverElement = lastMouseOverElement;

// determine currently overred element.
if (mousePosition != state.LastMousePosition)
@@ -247,11 +248,11 @@ private void UpdateMouseOver(ref Viewport viewport, ref Matrix worldViewProj, Re
if (!GetTouchPosition(state.Resolution, ref viewport, ref worldViewProj, mousePosition, out uiRay))
return;

mouseOverElement = GetElementAtScreenPosition(rootElement, ref uiRay, ref worldViewProj, ref intersectionPoint);
UIElementUnderMouseCursor = GetElementAtScreenPosition(rootElement, ref uiRay, ref worldViewProj, ref intersectionPoint);
}

// find the common parent between current and last overred elements
var commonElement = FindCommonParent(mouseOverElement, lastMouseOverElement);
var commonElement = FindCommonParent(UIElementUnderMouseCursor, lastMouseOverElement);

// disable mouse over state to previously overred hierarchy
var parent = lastMouseOverElement;
@@ -262,13 +263,13 @@ private void UpdateMouseOver(ref Viewport viewport, ref Matrix worldViewProj, Re
}

// enable mouse over state to currently overred hierarchy
if (mouseOverElement != null)
if (UIElementUnderMouseCursor != null)
{
// the element itself
mouseOverElement.MouseOverState = MouseOverState.MouseOverElement;
UIElementUnderMouseCursor.MouseOverState = MouseOverState.MouseOverElement;

// its hierarchy
parent = mouseOverElement.VisualParent;
parent = UIElementUnderMouseCursor.VisualParent;
while (parent != null)
{
if (parent.IsHierarchyEnabled)
@@ -279,7 +280,7 @@ private void UpdateMouseOver(ref Viewport viewport, ref Matrix worldViewProj, Re
}

// update cached values
state.LastMouseOverElement = mouseOverElement;
state.LastMouseOverElement = UIElementUnderMouseCursor;
state.LastMousePosition = mousePosition;
}

0 comments on commit 21399ae

Please sign in to comment.
You can’t perform that action at this time.