Example #1
0
        private static VisualElement PerformPick(VisualElement root, Vector2 point, List <VisualElement> picked = null)
        {
            // Skip picking for elements with display: none
            if (root.resolvedStyle.display == DisplayStyle.None)
            {
                return(null);
            }

            if (root.pickingMode == PickingMode.Ignore && root.hierarchy.childCount == 0)
            {
                return(null);
            }

            Vector2 localPoint = root.WorldToLocal(point);

            if (!root.boundingBox.Contains(localPoint))
            {
                return(null);
            }

            bool containsPoint = root.ContainsPoint(localPoint);

            // we only skip children in the case we visually clip them
            if (!containsPoint && root.ShouldClip())
            {
                return(null);
            }

            VisualElement returnedChild = null;

            // Depth first in reverse order, do children
            for (int i = root.hierarchy.childCount - 1; i >= 0; i--)
            {
                var child  = root.hierarchy[i];
                var result = PerformPick(child, point, picked);
                if (returnedChild == null && result != null && result.visible)
                {
                    returnedChild = result;
                }
            }

            if (picked != null && root.enabledInHierarchy && root.visible && root.pickingMode == PickingMode.Position && containsPoint)
            {
                picked.Add(root);
            }

            if (returnedChild != null)
            {
                return(returnedChild);
            }

            switch (root.pickingMode)
            {
            case PickingMode.Position:
            {
                if (containsPoint && root.enabledInHierarchy && root.visible)
                {
                    return(root);
                }
            }
            break;

            case PickingMode.Ignore:
                break;
            }
            return(null);
        }
Example #2
0
        private static VisualElement PerformPick(VisualElement root, Vector2 point, List <VisualElement> picked = null)
        {
            // Skip picking for elements with display: none
            if (root.resolvedStyle.display == DisplayStyle.None)
            {
                return(null);
            }

            if (root.pickingMode == PickingMode.Ignore && root.hierarchy.childCount == 0)
            {
                return(null);
            }

            if (!root.worldBoundingBox.Contains(point))
            {
                return(null);
            }

            // Problem here: everytime we pick, we need to do that expensive transformation.
            // The default Contains() compares with rect, while we could cache the rect in world space (transform 2 points, 4 if there is rotation) and be done
            // here we have to transform 1 point at every call.
            // Now since this is a virtual, we can't just start to call it with global pos... we could break client code.
            // EdgeControl and port connectors in GraphView overload this.
            Vector2 localPoint = root.WorldToLocal(point);

            bool containsPoint = root.ContainsPoint(localPoint);

            // we only skip children in the case we visually clip them
            if (!containsPoint && root.ShouldClip())
            {
                return(null);
            }

            VisualElement returnedChild = null;
            // Depth first in reverse order, do children
            var cCount = root.hierarchy.childCount;

            for (int i = cCount - 1; i >= 0; i--)
            {
                var child  = root.hierarchy[i];
                var result = PerformPick(child, point, picked);
                if (returnedChild == null && result != null && result.visible)
                {
                    returnedChild = result;
                }
            }

            if (picked != null && root.enabledInHierarchy && root.visible && root.pickingMode == PickingMode.Position && containsPoint)
            {
                picked.Add(root);
            }

            if (returnedChild != null)
            {
                return(returnedChild);
            }

            switch (root.pickingMode)
            {
            case PickingMode.Position:
            {
                if (containsPoint && root.enabledInHierarchy && root.visible)
                {
                    return(root);
                }
            }
            break;

            case PickingMode.Ignore:
                break;
            }
            return(null);
        }
Example #3
0
        private static VisualElement PerformPick(VisualElement root, Vector2 point, List <VisualElement> picked = null)
        {
            bool          flag = root.resolvedStyle.display == DisplayStyle.None;
            VisualElement result;

            if (flag)
            {
                result = null;
            }
            else
            {
                bool flag2 = root.pickingMode == PickingMode.Ignore && root.hierarchy.childCount == 0;
                if (flag2)
                {
                    result = null;
                }
                else
                {
                    bool flag3 = !root.worldBoundingBox.Contains(point);
                    if (flag3)
                    {
                        result = null;
                    }
                    else
                    {
                        Vector2 localPoint = root.WorldToLocal(point);
                        bool    flag4      = root.ContainsPoint(localPoint);
                        bool    flag5      = !flag4 && root.ShouldClip();
                        if (flag5)
                        {
                            result = null;
                        }
                        else
                        {
                            VisualElement visualElement = null;
                            int           childCount    = root.hierarchy.childCount;
                            for (int i = childCount - 1; i >= 0; i--)
                            {
                                VisualElement root2          = root.hierarchy[i];
                                VisualElement visualElement2 = Panel.PerformPick(root2, point, picked);
                                bool          flag6          = visualElement == null && visualElement2 != null && visualElement2.visible;
                                if (flag6)
                                {
                                    bool flag7 = picked == null;
                                    if (flag7)
                                    {
                                        result = visualElement2;
                                        return(result);
                                    }
                                    visualElement = visualElement2;
                                }
                            }
                            bool flag8 = (root.enabledInHierarchy && root.visible && root.pickingMode == PickingMode.Position) & flag4;
                            if (flag8)
                            {
                                if (picked != null)
                                {
                                    picked.Add(root);
                                }
                                bool flag9 = visualElement == null;
                                if (flag9)
                                {
                                    visualElement = root;
                                }
                            }
                            result = visualElement;
                        }
                    }
                }
            }
            return(result);
        }