bool TryToPickInCanvas(Vector2 mousePosition) { var localMouse = m_Canvas.WorldToLocal(mousePosition); if (!m_Canvas.ContainsPoint(localMouse)) { m_ParentTracker.Deactivate(); return(false); } var pickedElement = Panel.PickAllWithoutValidatingLayout(m_Canvas, mousePosition); // Don't allow selection of elements inside template instances. pickedElement = pickedElement.GetClosestElementPartOfCurrentDocument(); // Get Closest valid element. pickedElement = pickedElement.GetClosestElementThatIsValid(IsPickedElementValid); if (pickedElement == null) { m_ParentTracker.Deactivate(); return(false); } m_LastHoverElement = pickedElement; m_ParentTracker.Activate(pickedElement); return(true); }
bool TryToPickInCanvas(Vector2 mousePosition) { if (viewport == null) { return(false); } var localMouse = m_Canvas.WorldToLocal(mousePosition); if (!m_Canvas.ContainsPoint(localMouse)) { m_ParentTracker?.Deactivate(); m_PlacementIndicator?.Deactivate(); return(false); } var pickedElement = Panel.PickAllWithoutValidatingLayout(m_Canvas, mousePosition); // Don't allow selection of elements inside template instances or outside current active document. pickedElement = pickedElement.GetClosestElementPartOfCurrentDocument(); if (pickedElement != null && !pickedElement.IsPartOfActiveVisualTreeAsset(m_PaneWindow.document)) { pickedElement = null; } // Get Closest valid element. pickedElement = pickedElement.GetClosestElementThatIsValid(IsPickedElementValid); if (pickedElement == null) { m_ParentTracker?.Deactivate(); m_PlacementIndicator?.Deactivate(); m_LastHoverElement = null; return(false); } // The placement indicator might decide to change the parent. if (SupportsPlacementIndicator() && m_PlacementIndicator != null) { m_PlacementIndicator.Activate(pickedElement, mousePosition); pickedElement = m_PlacementIndicator.parentElement; } m_ParentTracker.Activate(pickedElement); m_LastHoverElement = pickedElement; if (SupportsPlacementIndicator() && m_PlacementIndicator != null) { m_LastHoverElementChildIndex = m_PlacementIndicator.indexWithinParent; } return(true); }
int InsertionIndex(Vector2 pos) { int index = -1; VisualElement owner = contentContainer != null ? contentContainer : this; Vector2 localPos = this.ChangeCoordinatesTo(owner, pos); if (owner.ContainsPoint(localPos)) { index = 0; foreach (VisualElement child in Children()) { Rect rect = child.layout; if (localPos.y > (rect.y + rect.height / 2)) { ++index; } else { break; } } } return(index); }
int InsertionIndex(Vector2 pos) { VisualElement owner = contentContainer != null ? contentContainer : this; Vector2 localPos = this.ChangeCoordinatesTo(owner, pos); if (owner.ContainsPoint(localPos)) { int defaultCatIndex = IndexOf(m_DefaultCategory); for (int i = defaultCatIndex + 1; i < childCount; ++i) { VFXBlackboardCategory cat = ElementAt(i) as VFXBlackboardCategory; if (cat == null) { return i; } Rect rect = cat.layout; if (localPos.y <= (rect.y + rect.height / 2)) { return i; } } return childCount; } return -1; }
protected override void ExecuteDefaultActionAtTarget(EventBase evt) { base.ExecuteDefaultActionAtTarget(evt); if (evt == null) { return; } var showEnumMenu = false; KeyDownEvent kde = (evt as KeyDownEvent); if (kde != null) { if ((kde.keyCode == KeyCode.Space) || (kde.keyCode == KeyCode.KeypadEnter) || (kde.keyCode == KeyCode.Return)) { showEnumMenu = true; } } else if ((evt as MouseDownEvent)?.button == (int)MouseButton.LeftMouse) { var mde = (MouseDownEvent)evt; if (visualInput.ContainsPoint(visualInput.WorldToLocal(mde.mousePosition))) { showEnumMenu = true; } } if (showEnumMenu) { ShowMenu(); evt.StopPropagation(); } }
internal static int GetInsertionIndex(VisualElement owner, Vector2 position, IEnumerable <VisualElement> children) { var index = -1; if (owner.ContainsPoint(position)) { index = 0; foreach (VisualElement child in children) { Rect rect = child.layout; if (position.y > (rect.y + rect.height / 2)) { ++index; } else { break; } } } return(index); }
public override bool HitTest(Vector2 localPoint) { Vector2 mappedPoint = this.ChangeCoordinatesTo(m_HeaderItem, localPoint); return(m_HeaderItem.ContainsPoint(mappedPoint)); }
/// <summary> /// Override HitTest to only trigger when they click the title /// </summary> public override bool HitTest(Vector2 localPoint) { Vector2 mappedPoint = this.ChangeCoordinatesTo(titleContainer, localPoint); return(titleContainer.ContainsPoint(mappedPoint)); }
static bool CanPickInExplorerRoot(Vector2 mousePosition, VisualElement explorerRoot) { return(explorerRoot != null && explorerRoot.ContainsPoint(explorerRoot.WorldToLocal(mousePosition))); }