Exemplo n.º 1
0
        void OnMouseDown(MouseDownEvent evt)
        {
            if (s_CurrentlyActiveBuilderDragger != null && s_CurrentlyActiveBuilderDragger != this)
            {
                return;
            }

            var target = evt.currentTarget as VisualElement;

            if (m_WeStartedTheDrag && target.HasMouseCapture())
            {
                evt.StopImmediatePropagation();
                evt.PreventDefault();
                return;
            }

            if (!CanStartManipulation(evt))
            {
                return;
            }

            var stopEvent = StopEventOnMouseDown(evt);

            if (stopEvent)
            {
                evt.StopImmediatePropagation();
            }

            if (target.HasMouseCapture())
            {
                if (!stopEvent)
                {
                    evt.StopImmediatePropagation();
                }

                return;
            }

            s_CurrentlyActiveBuilderDragger = this;
            m_Start            = evt.mousePosition;
            m_WeStartedTheDrag = true;
            target.CaptureMouse();
        }
Exemplo n.º 2
0
        void OnMouseUp(MouseUpEvent evt)
        {
            if (evt.button != (int)MouseButton.LeftMouse)
            {
                evt.StopPropagation();
                evt.PreventDefault();

                return;
            }

            var target = evt.currentTarget as VisualElement;

            if (!CanStopManipulation(evt))
            {
                return;
            }

            target.ReleaseMouse();
            s_CurrentlyActiveBuilderDragger = null;
            m_WeStartedTheDrag = false;

            if (!m_Active)
            {
                SelectItemOnSingleClick(evt);
                return;
            }

            if (m_Active)
            {
                var currentMouse = evt.mousePosition;
                if (m_LastHoverElement != null)
                {
                    var localCanvasMouse = viewport != null?m_Canvas.WorldToLocal(currentMouse) : Vector2.zero;

                    var localHierarchyMouse = builderHierarchyRoot != null?builderHierarchyRoot.WorldToLocal(currentMouse) : Vector2.zero;

                    if (viewport != null && m_Canvas.ContainsPoint(localCanvasMouse))
                    {
                        PerformAction(m_LastHoverElement, DestinationPane.Viewport, localCanvasMouse, m_LastHoverElementChildIndex);
                    }
                    else if (builderHierarchyRoot != null && builderHierarchyRoot.ContainsPoint(localHierarchyMouse))
                    {
                        VisualElement newParent;
                        int           index;
                        GetPickedElementFromHoverElement(out newParent, out index);

                        PerformAction(newParent, DestinationPane.Hierarchy, localHierarchyMouse, index);
                    }
                }

                m_Active = false;
            }
            else
            {
                FailAction(target);
            }

            evt.StopPropagation();

            EndDragInner();
        }