예제 #1
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();
            m_WeStartedTheDrag = false;

            if (s_CurrentlyActiveBuilderDragger == this)
            {
                s_CurrentlyActiveBuilderDragger = null;
            }

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

            var currentMouse = evt.mousePosition;

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

                var localHierarchyMouse  = builderHierarchyRoot?.WorldToLocal(currentMouse) ?? Vector2.zero;
                var localStylesheetMouse = builderStylesheetRoot?.WorldToLocal(currentMouse) ?? Vector2.zero;

                if (builderHierarchyRoot != null && builderHierarchyRoot.ContainsPoint(localHierarchyMouse))
                {
                    VisualElement newParent;
                    int           index;
                    GetPickedElementFromHoverElement(out newParent, out index);

                    PerformAction(newParent, DestinationPane.Hierarchy, localHierarchyMouse, index);
                }
                else if (builderStylesheetRoot != null && builderStylesheetRoot.ContainsPoint(localStylesheetMouse))
                {
                    VisualElement newParent;
                    int           index;
                    GetPickedElementFromHoverElement(out newParent, out index);

                    PerformAction(newParent, DestinationPane.Stylesheet, localStylesheetMouse, index);
                }
                else if (viewport != null && m_Canvas.ContainsPoint(localCanvasMouse))
                {
                    PerformAction(m_LastHoverElement, DestinationPane.Viewport, localCanvasMouse, m_LastHoverElementChildIndex);
                }
            }

            m_Active = false;

            evt.StopPropagation();

            EndDragInner();
        }
예제 #2
0
        protected new void OnMouseUp(MouseUpEvent evt)
        {
            if (m_GraphView == null)
            {
                if (m_Active)
                {
                    target.ReleaseMouseCapture();
                    selectedElement  = null;
                    m_Active         = false;
                    m_PrevDropTarget = null;
                }

                return;
            }

            List <ISelectable> selection = m_GraphView.selection;

            if (CanStopManipulation(evt))
            {
                if (m_Active)
                {
                    if (selectedElement == null)
                    {
                        m_MovedElements.Clear();
                        foreach (GraphElement ce in m_OriginalPos.Keys)
                        {
                            ce.UpdatePresenterPosition();

                            m_MovedElements.Add(ce);
                        }

                        var graphView = target as GraphView;
                        if (graphView != null && graphView.graphViewChanged != null)
                        {
                            graphView.graphViewChanged(m_GraphViewChange);
                        }
                    }

                    m_PanSchedule.Pause();

                    if (m_ItemPanDiff != Vector3.zero)
                    {
                        Vector3 p = m_GraphView.contentViewContainer.transform.position;
                        Vector3 s = m_GraphView.contentViewContainer.transform.scale;
                        m_GraphView.UpdateViewTransform(p, s);
                    }

                    if (selection.Count > 0 && m_PrevDropTarget != null)
                    {
                        using (DragPerformEvent drop = DragPerformEvent.GetPooled(evt))
                        {
                            SendDragAndDropEvent(drop, selection, m_PrevDropTarget);
                        }
                    }

                    target.ReleaseMouseCapture();
                    evt.StopPropagation();
                }
                selectedElement  = null;
                m_Active         = false;
                m_PrevDropTarget = null;
            }
        }
예제 #3
0
 void OnMouseUp(MouseUpEvent evt)
 {
     evt.StopPropagation();
 }
 void OnMouseUp(MouseUpEvent e)
 {
     Release();
     e.StopPropagation();
 }
예제 #5
0
 protected virtual void OnMouseUp(MouseUpEvent evt)
 {
     evt.StopPropagation();
     target.Blur();
     ExecuteIfEnabled();
 }
예제 #6
0
        protected new void OnMouseUp(MouseUpEvent evt)
        {
            if (m_GraphView == null)
            {
                if (m_Active)
                {
                    target.ReleaseMouse();
                    selectedElement  = null;
                    m_Active         = false;
                    m_Dragging       = false;
                    m_PrevDropTarget = null;
                }

                return;
            }

            List <ISelectable> selection = m_GraphView.selection;

            if (CanStopManipulation(evt))
            {
                if (m_Active)
                {
                    if (m_Dragging || selectedElement == null)
                    {
                        m_MovedElements.Clear();

                        foreach (IGrouping <StackNode, GraphElement> grouping in m_OriginalPos.GroupBy(v => v.Value.stack, v => v.Key))
                        {
                            if (grouping.Key != null && m_GraphView.elementsRemovedFromStackNode != null)
                            {
                                m_GraphView.elementsRemovedFromStackNode(grouping.Key, grouping);
                            }

                            foreach (GraphElement ge in grouping)
                            {
                                ge.UpdatePresenterPosition();
                            }

                            m_MovedElements.AddRange(grouping);
                        }

                        var graphView = target as GraphView;
                        if (graphView != null && graphView.graphViewChanged != null)
                        {
                            KeyValuePair <GraphElement, OriginalPos> firstPos = m_OriginalPos.First();
                            m_GraphViewChange.moveDelta = firstPos.Key.GetPosition().position - firstPos.Value.pos.position;
                            graphView.graphViewChanged(m_GraphViewChange);
                        }
                    }

                    m_PanSchedule.Pause();

                    if (m_ItemPanDiff != Vector3.zero)
                    {
                        Vector3 p = m_GraphView.contentViewContainer.transform.position;
                        Vector3 s = m_GraphView.contentViewContainer.transform.scale;
                        m_GraphView.UpdateViewTransform(p, s);
                    }

                    if (selection.Count > 0 && m_PrevDropTarget != null)
                    {
                        if (m_PrevDropTarget.CanAcceptDrop(selection))
                        {
                            using (DragPerformEvent drop = DragPerformEvent.GetPooled(evt)) {
                                SendDragAndDropEvent(drop, selection, m_PrevDropTarget, m_GraphView);
                            }
                        }
                        else
                        {
                            using (DragExitedEvent dexit = DragExitedEvent.GetPooled(evt)) {
                                SendDragAndDropEvent(dexit, selection, m_PrevDropTarget, m_GraphView);
                            }
                        }
                    }
                    if (selection.Any())
                    {
                        m_Snapper.EndSnap();
                    }

                    target.ReleaseMouse();
                    evt.StopPropagation();
                }
                selectedElement  = null;
                m_Active         = false;
                m_Dragging       = false;
                m_PrevDropTarget = null;
            }
        }
        private void OnMouseUp(MouseUpEvent e)
        {
            if (!m_Active || !CanStopManipulation(e))
            {
                return;
            }

            m_GraphView.Remove(m_FreehandElement);

            m_FreehandElement.points.Add(e.localMousePosition);

            List <ISelectable> selection = m_GraphView.selection;

            // a copy is necessary because Add To selection might cause a SendElementToFront which will change the order.
            List <ISelectable> newSelection = new List <ISelectable>();

            m_GraphView.graphElements.ForEach(element =>
            {
                if (element.IsSelectable())
                {
                    for (int i = 1; i < m_FreehandElement.points.Count; i++)
                    {
                        // Apply offset
                        Vector2 start = m_GraphView.ChangeCoordinatesTo(element, m_FreehandElement.points[i - 1]);
                        Vector2 end   = m_GraphView.ChangeCoordinatesTo(element, m_FreehandElement.points[i]);
                        float minx    = Mathf.Min(start.x, end.x);
                        float maxx    = Mathf.Max(start.x, end.x);
                        float miny    = Mathf.Min(start.y, end.y);
                        float maxy    = Mathf.Max(start.y, end.y);

                        var rect = new Rect(minx, miny, maxx - minx + 1, maxy - miny + 1);
                        if (element.Overlaps(rect))
                        {
                            newSelection.Add(element);
                            break;
                        }
                    }
                }
            });

            foreach (ISelectable selectable in newSelection)
            {
                if (selectable is Placemat && e.altKey)
                {
                    continue;
                }

                if (!selection.Contains(selectable))
                {
                    m_GraphView.AddToSelection(selectable);
                }
            }

            if (e.altKey)
            {
                // Delete instead
                m_GraphView.DeleteSelection();
            }

            m_Active = false;
            target.ReleaseMouse();
            e.StopPropagation();
        }
        private void OnMouseUp(MouseUpEvent e)
        {
            if (!m_Active)
            {
                return;
            }

            var graphView = target as GraphView;

            if (graphView == null)
            {
                return;
            }

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

            graphView.Remove(m_Rectangle);

            m_Rectangle.end = e.localMousePosition;

            var selectionRect = new Rect()
            {
                min = new Vector2(Math.Min(m_Rectangle.start.x, m_Rectangle.end.x), Math.Min(m_Rectangle.start.y, m_Rectangle.end.y)),
                max = new Vector2(Math.Max(m_Rectangle.start.x, m_Rectangle.end.x), Math.Max(m_Rectangle.start.y, m_Rectangle.end.y))
            };

            selectionRect = ComputeAxisAlignedBound(selectionRect, graphView.viewTransform.matrix.inverse);

            List <ISelectable> selection = graphView.selection;

            // a copy is necessary because Add To selection might cause a SendElementToFront which will change the order.
            List <ISelectable> newSelection = new List <ISelectable>();

            graphView.graphElements.ForEach(child =>
            {
                var localSelRect = graphView.contentViewContainer.ChangeCoordinatesTo(child, selectionRect);
                if (child.IsSelectable() && child.Overlaps(localSelRect))
                {
                    newSelection.Add(child);
                }
            });

            foreach (var selectable in newSelection)
            {
                if (selection.Contains(selectable))
                {
                    if (e.actionKey) // invert selection on shift only
                    {
                        graphView.RemoveFromSelection(selectable);
                    }
                }
                else
                {
                    graphView.AddToSelection(selectable);
                }
            }

            m_Active = false;
            target.ReleaseMouse();
            e.StopPropagation();
        }
예제 #9
0
        /// <summary>
        /// Callback for the MouseUp event.
        /// </summary>
        /// <param name="evt">The event.</param>
        protected void OnMouseUp(MouseUpEvent evt)
        {
            if (m_GraphView == null)
            {
                if (m_Active)
                {
                    target.ReleaseMouse();
                    m_SelectedElement   = null;
                    m_Active            = false;
                    m_Dragging          = false;
                    m_CurrentDropTarget = null;
                }

                return;
            }

            var selectedModels = m_GraphView.GetSelection();

            if (CanStopManipulation(evt))
            {
                if (m_Active)
                {
                    if (m_Dragging || m_SelectedElement == null)
                    {
                        if (target is GraphView graphView)
                        {
                            graphView.StopSelectionDragger();
                            graphView.PositionDependenciesManager.StopNotifyMove();
                        }

                        // if we stop dragging on something else than a DropTarget, just move elements
                        if (m_GraphView != null && (m_CurrentDropTarget == null || !m_CurrentDropTarget.CanAcceptDrop(selectedModels)))
                        {
                            var movedElements = new HashSet <GraphElement>(m_OriginalPos.Keys);
                            movedElements.AddRangeInternal(m_EdgesToUpdate);

                            KeyValuePair <GraphElement, OriginalPos> firstPos = m_OriginalPos.First();
                            var delta  = firstPos.Key.GetPosition().position - firstPos.Value.pos.position;
                            var models = movedElements
                                         // PF remove this Where clause. It comes from VseGraphView.OnGraphViewChanged.
                                         .Where(e => !(e.Model is INodeModel) || e.IsMovable())
                                         .Select(e => e.Model)
                                         .OfType <IMovable>();
                            m_GraphView.CommandDispatcher.Dispatch(
                                new MoveElementsCommand(delta, models.ToList()));
                        }
                    }

                    foreach (var edge in m_EdgesToUpdate)
                    {
                        edge.EdgeControl.ControlPointOffset = Vector2.zero;
                    }
                    m_EdgesToUpdate.Clear();

                    m_PanSchedule.Pause();

                    if (m_ItemPanDiff != Vector3.zero)
                    {
                        Vector3 p = m_GraphView.ContentViewContainer.transform.position;
                        Vector3 s = m_GraphView.ContentViewContainer.transform.scale;
                        m_GraphView.CommandDispatcher.Dispatch(new ReframeGraphViewCommand(p, s));
                    }

                    if (selectedModels.Count > 0 && m_CurrentDropTarget != null)
                    {
                        if (m_CurrentDropTarget.CanAcceptDrop(selectedModels))
                        {
                            using (DragPerformEvent ePerform = DragPerformEvent.GetPooled(evt))
                            {
                                ePerform.target = m_CurrentDropTarget;
                                m_GraphView.SendEvent(ePerform);
                            }
                        }
                        else
                        {
                            using (DragExitedEvent eExit = DragExitedEvent.GetPooled(evt))
                            {
                                eExit.target = m_CurrentDropTarget;
                                m_GraphView.SendEvent(eExit);
                            }
                        }
                    }

                    if (selectedModels.Any())
                    {
                        m_Snapper.EndSnap();
                    }

                    target.ReleaseMouse();
                    evt.StopPropagation();
                }
                m_SelectedElement   = null;
                m_Active            = false;
                m_CurrentDropTarget = null;
                m_Dragging          = false;
                m_CurrentDropTarget = null;
            }
        }