Esempio n. 1
0
        protected void OnMouseMove(MouseMoveEvent e)
        {
            GraphElement ce = e.target as GraphElement;

            if (ce != null && !ce.IsMovable())
            {
                return;
            }

            if (m_Active)
            {
                Vector2 diff = e.localMousePosition - m_Start;
                Rect    rect = CalculatePosition(target.layout.x + diff.x, target.layout.y + diff.y, target.layout.width, target.layout.height);

                if (target.style.positionType == PositionType.Manual)
                {
                    target.layout = rect;
                }
                else if (target.style.positionType == PositionType.Absolute)
                {
                    target.style.positionLeft = rect.x;
                    target.style.positionTop  = rect.y;
                }

                e.StopPropagation();
            }
        }
Esempio n. 2
0
        protected void OnMouseUp(MouseUpEvent e)
        {
            GraphElement ce = e.target as GraphElement;

            if (ce != null && !ce.IsMovable())
            {
                return;
            }

            if (m_Active)
            {
                if (CanStopManipulation(e))
                {
                    var graphElement = target as GraphElement;
                    if (graphElement != null)
                    {
                        graphElement.UpdatePresenterPosition();
                    }

                    m_Active = false;
                    target.ReleaseMouseCapture();
                    e.StopPropagation();
                }
            }
        }
Esempio n. 3
0
 protected new void OnMouseDown(MouseDownEvent e)
 {
     if (this.m_Active)
     {
         e.StopImmediatePropagation();
     }
     else if (base.CanStartManipulation(e))
     {
         this.m_GraphView = (base.target as GraphView);
         if (this.m_GraphView != null)
         {
             this.selectedElement = null;
             this.clickedElement  = (e.target as GraphElement);
             if (this.clickedElement == null)
             {
                 VisualElement visualElement = e.target as VisualElement;
                 this.clickedElement = visualElement.GetFirstAncestorOfType <GraphElement>();
                 if (this.clickedElement == null)
                 {
                     return;
                 }
             }
             if (this.clickedElement.IsMovable() && this.m_GraphView.selection.Contains(this.clickedElement) && this.clickedElement.HitTest(this.clickedElement.WorldToLocal(e.mousePosition)))
             {
                 this.selectedElement = this.clickedElement;
                 this.m_OriginalPos   = new Dictionary <GraphElement, Rect>();
                 foreach (ISelectable current in this.m_GraphView.selection)
                 {
                     GraphElement graphElement = current as GraphElement;
                     if (graphElement != null && graphElement.IsMovable())
                     {
                         this.m_OriginalPos[graphElement] = graphElement.GetPosition();
                     }
                 }
                 this.m_originalMouse = e.mousePosition;
                 this.m_ItemPanDiff   = Vector3.zero;
                 if (this.m_PanSchedule == null)
                 {
                     this.m_PanSchedule = this.m_GraphView.schedule.Execute(new Action <TimerState>(this.Pan)).Every(10L).StartingIn(10L);
                     this.m_PanSchedule.Pause();
                 }
                 this.m_Active = true;
                 base.target.TakeMouseCapture();
                 e.StopPropagation();
             }
         }
     }
 }
Esempio n. 4
0
        protected void OnMouseMove(MouseMoveEvent e)
        {
            GraphElement graphElement = e.target as GraphElement;

            if (graphElement == null || graphElement.IsMovable())
            {
                if (this.m_Active)
                {
                    if (base.target.style.positionType == PositionType.Manual)
                    {
                        Vector2 vector = e.localMousePosition - this.m_Start;
                        base.target.layout = this.CalculatePosition(base.target.layout.x + vector.x, base.target.layout.y + vector.y, base.target.layout.width, base.target.layout.height);
                    }
                    e.StopPropagation();
                }
            }
        }
Esempio n. 5
0
 protected void OnMouseDown(MouseDownEvent e)
 {
     if (this.m_Active)
     {
         e.StopImmediatePropagation();
     }
     else
     {
         GraphElement graphElement = e.target as GraphElement;
         if (graphElement == null || graphElement.IsMovable())
         {
             if (base.CanStartManipulation(e))
             {
                 this.m_Start  = e.localMousePosition;
                 this.m_Active = true;
                 base.target.TakeMouseCapture();
                 e.StopPropagation();
             }
         }
     }
 }
Esempio n. 6
0
        protected void OnMouseUp(MouseUpEvent e)
        {
            GraphElement graphElement = e.target as GraphElement;

            if (graphElement == null || graphElement.IsMovable())
            {
                if (this.m_Active)
                {
                    if (base.CanStopManipulation(e))
                    {
                        GraphElement graphElement2 = base.target as GraphElement;
                        if (graphElement2 != null)
                        {
                            graphElement2.UpdatePresenterPosition();
                        }
                        this.m_Active = false;
                        base.target.ReleaseMouseCapture();
                        e.StopPropagation();
                    }
                }
            }
        }
Esempio n. 7
0
        protected void OnMouseDown(MouseDownEvent e)
        {
            if (m_Active)
            {
                e.StopImmediatePropagation();
                return;
            }

            GraphElement ce = e.target as GraphElement;

            if (ce != null && !ce.IsMovable())
            {
                return;
            }

            if (CanStartManipulation(e))
            {
                m_Start = e.localMousePosition;

                m_Active = true;
                target.TakeMouseCapture();
                e.StopPropagation();
            }
        }
        protected new void OnMouseDown(MouseDownEvent e)
        {
            if (m_Active)
            {
                e.StopImmediatePropagation();
                return;
            }

            if (CanStartManipulation(e))
            {
                m_GraphView = target as GraphView;

                if (m_GraphView == null)
                {
                    return;
                }

                selectedElement = null;

                // avoid starting a manipulation on a non movable object
                clickedElement = e.target as GraphElement;
                if (clickedElement == null)
                {
                    var ve = e.target as VisualElement;
                    clickedElement = ve.GetFirstAncestorOfType <GraphElement>();
                    if (clickedElement == null)
                    {
                        return;
                    }
                }

                // Only start manipulating if the clicked element is movable, selected and that the mouse is in its clickable region (it must be deselected otherwise).
                if (!clickedElement.IsMovable() || !clickedElement.HitTest(clickedElement.WorldToLocal(e.mousePosition)))
                {
                    return;
                }

                // If we hit this, this likely because the element has just been unselected
                // It is important for this manipulator to receive the event so the previous one did not stop it
                // but we shouldn't let it propagate to other manipulators to avoid a re-selection
                if (!m_GraphView.selection.Contains(clickedElement))
                {
                    e.StopImmediatePropagation();
                    return;
                }

                selectedElement = clickedElement;

                m_OriginalPos = new Dictionary <GraphElement, OriginalPos>();

                foreach (ISelectable s in m_GraphView.selection)
                {
                    GraphElement ce = s as GraphElement;
                    if (ce == null || !ce.IsMovable())
                    {
                        continue;
                    }

                    StackNode stackNode = null;
                    if (ce.parent is StackNode)
                    {
                        stackNode = ce.parent as StackNode;

                        if (stackNode.IsSelected(m_GraphView))
                        {
                            continue;
                        }
                    }

                    Rect geometry = ce.GetPosition();
                    Rect geometryInContentViewSpace = ce.shadow.parent.ChangeCoordinatesTo(m_GraphView.contentViewContainer, geometry);
                    m_OriginalPos[ce] = new OriginalPos
                    {
                        pos        = geometryInContentViewSpace,
                        scope      = ce.GetContainingScope(),
                        stack      = stackNode,
                        stackIndex = stackNode != null?stackNode.IndexOf(ce) : -1
                    };
                }

                m_originalMouse = e.mousePosition;
                m_ItemPanDiff   = Vector3.zero;

                if (m_PanSchedule == null)
                {
                    m_PanSchedule = m_GraphView.schedule.Execute(Pan).Every(k_PanInterval).StartingIn(k_PanInterval);
                    m_PanSchedule.Pause();
                }

                m_Active = true;
                target.CaptureMouse(); // We want to receive events even when mouse is not over ourself.
                e.StopImmediatePropagation();
            }
        }
Esempio n. 9
0
        protected new void OnMouseDown(MouseDownEvent e)
        {
            if (m_Active)
            {
                e.StopImmediatePropagation();
                return;
            }

            if (CanStartManipulation(e))
            {
                m_GraphView = target as GraphView;

                if (m_GraphView == null)
                {
                    return;
                }

                selectedElement = null;

                // avoid starting a manipulation on a non movable object
                clickedElement = e.target as GraphElement;
                if (clickedElement == null)
                {
                    var ve = e.target as VisualElement;
                    clickedElement = ve.GetFirstAncestorOfType <GraphElement>();
                    if (clickedElement == null)
                    {
                        return;
                    }
                }

                // Only start manipulating if the clicked element is movable, selected and that the mouse is in its clickable region (it must be deselected otherwise).
                if (!clickedElement.IsMovable() || !m_GraphView.selection.Contains(clickedElement) || !clickedElement.HitTest(clickedElement.WorldToLocal(e.mousePosition)))
                {
                    return;
                }

                selectedElement = clickedElement;

                m_OriginalPos = new Dictionary <GraphElement, Rect>();

                foreach (ISelectable s in m_GraphView.selection)
                {
                    GraphElement ce = s as GraphElement;
                    if (ce == null || !ce.IsMovable())
                    {
                        continue;
                    }

                    if (ce.parent is StackNode)
                    {
                        StackNode stackNode = ce.parent as StackNode;

                        if (stackNode.IsSelected(m_GraphView))
                        {
                            continue;
                        }
                    }

                    Rect geometry = ce.GetPosition();
                    Rect geometryInContentViewSpace = ce.shadow.parent.ChangeCoordinatesTo(m_GraphView.contentViewContainer, geometry);
                    m_OriginalPos[ce] = geometryInContentViewSpace;
                }

                m_originalMouse = e.mousePosition;
                m_ItemPanDiff   = Vector3.zero;

                if (m_PanSchedule == null)
                {
                    m_PanSchedule = m_GraphView.schedule.Execute(Pan).Every(k_PanInterval).StartingIn(k_PanInterval);
                    m_PanSchedule.Pause();
                }

                m_Active = true;
                target.TakeMouseCapture(); // We want to receive events even when mouse is not over ourself.
                e.StopImmediatePropagation();
            }
        }