コード例 #1
0
        public static GroupNode GetContainingGroupNode(this GraphElement element)
        {
            GroupNode result;

            if (element == null)
            {
                result = null;
            }
            else
            {
                GraphView firstAncestorOfType = element.GetFirstAncestorOfType <GraphView>();
                if (firstAncestorOfType == null)
                {
                    result = null;
                }
                else
                {
                    List <GroupNode> list = firstAncestorOfType.Query(null, null).ToList();
                    foreach (GroupNode current in list)
                    {
                        if (current.ContainsElement(element))
                        {
                            result = current;
                            return(result);
                        }
                    }
                    result = null;
                }
            }
            return(result);
        }
コード例 #2
0
 protected void OnMouseDown(MouseDownEvent e)
 {
     if (e.currentTarget is ISelectable)
     {
         if (base.CanStartManipulation(e))
         {
             if ((base.target as ISelectable).HitTest(e.localMousePosition))
             {
                 GraphElement graphElement = e.currentTarget as GraphElement;
                 if (graphElement != null)
                 {
                     VisualElement parent = graphElement.shadow.parent;
                     while (parent != null && !(parent is GraphView))
                     {
                         parent = parent.shadow.parent;
                     }
                     GraphView selectionContainer = parent as GraphView;
                     if (graphElement.IsSelected(selectionContainer) && e.ctrlKey)
                     {
                         graphElement.Unselect(selectionContainer);
                     }
                     else
                     {
                         graphElement.Select(selectionContainer, e.shiftKey || e.ctrlKey);
                     }
                 }
             }
         }
     }
 }
コード例 #3
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();
            }
        }
コード例 #4
0
        public void AddElement(GraphElement element)
        {
            if (element == null)
            {
                throw new ArgumentException("Cannot add null element");
            }
            if (element is GroupNode)
            {
                throw new ArgumentException("Nested group node is not supported yet.");
            }
            if (this.m_ContainedElements == null)
            {
                this.m_ContainedElements = new List <GraphElement>();
            }
            else if (this.m_ContainedElements.Contains(element))
            {
                throw new ArgumentException("The element is already contained in this group node.");
            }
            GroupNode containingGroupNode = element.GetContainingGroupNode();

            if (containingGroupNode != null)
            {
                containingGroupNode.RemoveElement(element);
            }
            this.m_ContainedElements.Add(element);
            element.RegisterCallback <PostLayoutEvent>(new EventCallback <PostLayoutEvent>(this.OnSubElementPostLayout), Capture.NoCapture);
            element.RegisterCallback <DetachFromPanelEvent>(new EventCallback <DetachFromPanelEvent>(this.OnSubElementDetachedFromPanel), Capture.NoCapture);
            this.UpdateGeometryFromContent();
            GraphView firstAncestorOfType = base.GetFirstAncestorOfType <GraphView>();

            if (firstAncestorOfType != null && firstAncestorOfType.elementAddedToGroupNode != null)
            {
                firstAncestorOfType.elementAddedToGroupNode(this, element);
            }
        }
コード例 #5
0
        private void OnMouseMove(MouseMoveEvent e)
        {
            GraphElement graphElement = base.parent as GraphElement;

            if (graphElement != null)
            {
                if (graphElement.IsResizable())
                {
                    if (this.m_Active && base.parent.style.positionType == PositionType.Manual)
                    {
                        Vector2 vector  = this.ChangeCoordinatesTo(base.parent, e.localMousePosition) - this.m_Start;
                        Vector2 vector2 = new Vector2(this.m_StartPos.width + vector.x, this.m_StartPos.height + vector.y);
                        if (vector2.x < this.m_MinimumSize.x)
                        {
                            vector2.x = this.m_MinimumSize.x;
                        }
                        if (vector2.y < this.m_MinimumSize.y)
                        {
                            vector2.y = this.m_MinimumSize.y;
                        }
                        graphElement.SetPosition(new Rect(graphElement.layout.x, graphElement.layout.y, vector2.x, vector2.y));
                        graphElement.UpdatePresenterPosition();
                        GraphView firstAncestorOfType = graphElement.GetFirstAncestorOfType <GraphView>();
                        if (firstAncestorOfType != null && firstAncestorOfType.elementResized != null)
                        {
                            firstAncestorOfType.elementResized(graphElement);
                        }
                        this.m_LabelText.text = string.Format("{0:0}", base.parent.layout.width) + "x" + string.Format("{0:0}", base.parent.layout.height);
                        e.StopPropagation();
                    }
                }
            }
        }
コード例 #6
0
 private void OnMouseDown(MouseDownEvent e)
 {
     if (this.m_Active)
     {
         e.StopImmediatePropagation();
     }
     else if (!MouseCaptureController.IsMouseCaptureTaken())
     {
         GraphElement graphElement = base.parent as GraphElement;
         if (graphElement != null)
         {
             if (graphElement.IsResizable())
             {
                 if (e.button == (int)this.activateButton)
                 {
                     this.m_Start    = this.ChangeCoordinatesTo(base.parent, e.localMousePosition);
                     this.m_StartPos = base.parent.layout;
                     if (base.parent.style.positionType != PositionType.Manual)
                     {
                         Debug.LogWarning("Attempting to resize an object with a non manual position");
                     }
                     this.m_Active = true;
                     this.TakeMouseCapture();
                     e.StopPropagation();
                 }
             }
         }
     }
 }
コード例 #7
0
 private void OnChildAdded(GraphElement element)
 {
     element.AddToClassList("stack-child-element");
     element.ResetPositionProperties();
     element.RegisterCallback <DetachFromPanelEvent>(OnChildDetachedFromPanel);
     UpdatePlaceholderVisibility();
 }
コード例 #8
0
        static bool WasSelectableDescendantHitByMouse(GraphElement currentTarget, MouseDownEvent evt)
        {
            VisualElement targetElement = evt.target as VisualElement;

            if (targetElement == null || currentTarget == targetElement)
            {
                return(false);
            }

            VisualElement descendant = targetElement;

            while (descendant != null && currentTarget != descendant)
            {
                GraphElement selectableDescendant = descendant as GraphElement;

                if (selectableDescendant != null && selectableDescendant.enabledInHierarchy && selectableDescendant.pickingMode != PickingMode.Ignore && selectableDescendant.IsSelectable())
                {
                    Vector2 localMousePosition = currentTarget.ChangeCoordinatesTo(descendant, evt.localMousePosition);

                    if (selectableDescendant.HitTest(localMousePosition))
                    {
                        return(true);
                    }
                }
                descendant = descendant.parent;
            }
            return(false);
        }
コード例 #9
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();
                }
            }
        }
コード例 #10
0
 private bool AcceptsElementInternal(GraphElement element, ref int proposedIndex, int maxIndex)
 {
     return(element != null && !(element is Scope) &&
            !(element is StackNode) && !(element is TokenNode) &&
            (element.GetContainingScope() as Group) == null &&
            AcceptsElement(element, ref proposedIndex, maxIndex));
 }
コード例 #11
0
        // TODO: Do we limit to GraphElements or can we tab through ISelectable's?
        EventPropagation FramePrevNext(List <GraphElement> childrenList)
        {
            GraphElement graphElement = null;

            // Start from current selection, if any
            if (selection.Count != 0)
            {
                graphElement = selection[0] as GraphElement;
            }

            int idx = childrenList.IndexOf(graphElement);

            if (idx < 0)
            {
                return(EventPropagation.Continue);
            }

            if (idx < childrenList.Count - 1)
            {
                graphElement = childrenList[idx + 1];
            }
            else
            {
                graphElement = childrenList[0];
            }

            // New selection...
            ClearSelection();
            AddToSelection(graphElement);

            // ...and frame this new selection
            return(Frame(FrameType.Selection));
        }
コード例 #12
0
        public EventPropagation DragUpdated(IMGUIEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget)
        {
            GroupNode firstAncestorOfType = base.parent.GetFirstAncestorOfType <GroupNode>();
            bool      flag = false;

            foreach (ISelectable current in selection)
            {
                if (current != firstAncestorOfType)
                {
                    GraphElement element    = current as GraphElement;
                    Event        imguiEvent = evt.imguiEvent;
                    if (imguiEvent.shift)
                    {
                        if (firstAncestorOfType.ContainsElement(element))
                        {
                            firstAncestorOfType.RemoveElement(element);
                        }
                    }
                    else if (!firstAncestorOfType.ContainsElement(element) && element.GetContainingGroupNode() == null)
                    {
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                base.AddToClassList("dragEntered");
            }
            else
            {
                base.RemoveFromClassList("dragEntered");
            }
            return(EventPropagation.Stop);
        }
コード例 #13
0
        private void AddElementInternal(GraphElement element)
        {
            if (element == null)
            {
                throw new ArgumentException("Cannot add null element");
            }

            if (containedElements.Contains(element))
            {
                throw new ArgumentException("The specified element is already contained in this scope.");
            }

            string reasonWhyNotAccepted = "Cannot add the specified element to this scope.";

            if (!AcceptsElement(element, ref reasonWhyNotAccepted))
            {
                throw new ArgumentException(reasonWhyNotAccepted);
            }

            // Removes the element from its current scope
            Scope currentScope = element.GetContainingScope();

            if (currentScope != null)
            {
                currentScope.RemoveElement(element);
            }

            m_ContainedElements.Add(element);

            // To update the scope geometry whenever the added element's geometry changes
            element.RegisterCallback <GeometryChangedEvent>(OnSubElementGeometryChanged);
            ScheduleUpdateGeometryFromContent();
        }
コード例 #14
0
        public void RemoveElement(GraphElement element)
        {
            if (element == null)
            {
                throw new ArgumentException("Cannot remove null element from this group");
            }

            if (m_ContainedElements == null)
            {
                return;
            }

            if (!m_ContainedElements.Contains(element))
            {
                throw new ArgumentException("This element is not contained in this group");
            }

            m_ContainedElements.Remove(element);
            element.UnregisterCallback <PostLayoutEvent>(OnSubElementPostLayout);
            element.UnregisterCallback <DetachFromPanelEvent>(OnSubElementDetachedFromPanel);
            UpdateGeometryFromContent();

            GraphView gv = GetFirstAncestorOfType <GraphView>();

            if (gv != null && gv.elementRemovedFromGroupNode != null)
            {
                gv.elementRemovedFromGroupNode(this, element);
            }
        }
コード例 #15
0
        public static GroupNode GetContainingGroupNode(this GraphElement element)
        {
            if (element == null)
            {
                return(null);
            }

            GraphView graphView = element.GetFirstAncestorOfType <GraphView>();

            if (graphView == null)
            {
                return(null);
            }

            List <GroupNode> groups = graphView.Query <GroupNode>().ToList();

            foreach (GroupNode group in groups)
            {
                if (group.ContainsElement(element))
                {
                    return(group);
                }
            }
            return(null);
        }
コード例 #16
0
        public bool DragPerform(DragPerformEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget)
        {
            HandleDragAndDropEvent(evt, selection);

            GraphElement droppedElement = selection.First() as GraphElement;

            // Remove the current preview with no animation
            RemovePreview(false);

            if (m_CurrentInsertIndex != -1)
            {
                // Notify the model that an element should be inserted at the specified index
                if (graphView != null && graphView.elementInsertedToStackNode != null)
                {
                    graphView.elementInsertedToStackNode(this, m_CurrentInsertIndex, droppedElement);
                }
                else
                {
                    InsertElement(m_CurrentInsertIndex, droppedElement);
                }
            }

            dragEntered = false;

            return(true);
        }
コード例 #17
0
        private static VisualElement DefaultDropPreviewTemplate(GraphElement source)
        {
            VisualElement preview = new VisualElement();

            preview.AddToClassList("default");

            return(preview);
        }
コード例 #18
0
 private void OnSubElementDetachedFromPanel(DetachFromPanelEvent evt)
 {
     if (base.panel != null)
     {
         GraphElement element = evt.target as GraphElement;
         this.RemoveElement(element);
     }
 }
コード例 #19
0
        protected override void OnElementAdded(GraphElement element)
        {
            GraphView gv = GetFirstAncestorOfType <GraphView>();

            if (gv != null && gv.elementAddedToGroup != null)
            {
                gv.elementAddedToGroup(this, element);
            }
        }
コード例 #20
0
        private VisualElement CreateDropPreview(GraphElement element)
        {
            VisualElement preview = dropPreviewTemplate(element);

            preview.Add(new Label(element.title));
            preview.AddToClassList(k_PreviewClass);
            preview.style.positionType = PositionType.Relative;
            return(preview);
        }
コード例 #21
0
        public virtual bool AcceptsElement(GraphElement element, ref string reasonWhyNotAccepted)
        {
            if (element.GetType() == typeof(Scope))
            {
                reasonWhyNotAccepted = "Nested scope is not supported yet.";
                return(false);
            }

            return(true);
        }
コード例 #22
0
        private void AddToSelectionNoUndoRecord(GraphElement graphElement)
        {
            graphElement.selected = true;
            selection.Add(graphElement);
            graphElement.OnSelected();

            // To ensure that the selected GraphElement gets unselected if it is removed from the GraphView.
            graphElement.RegisterCallback <DetachFromPanelEvent>(OnSelectedElementDetachedFromPanel);

            contentViewContainer.Dirty(ChangeType.Repaint);
        }
コード例 #23
0
        public void RemoveElement(GraphElement graphElement)
        {
            // TODO : Find a better way to remove a graphElement from its scope when it is removed from the GraphView.
            Scope scope = graphElement.GetContainingScope();

            if (scope != null)
            {
                scope.RemoveElement(graphElement);
            }
            graphElement.RemoveFromHierarchy();
        }
コード例 #24
0
        private void OnChildDetachedFromPanel(DetachFromPanelEvent evt)
        {
            if (panel == null)
            {
                return;
            }

            GraphElement element = evt.target as GraphElement;

            OnChildRemoved(element);
        }
コード例 #25
0
        void OnSubElementDetachedFromPanel(DetachFromPanelEvent evt)
        {
            // Do nothing if the group is not in a panel
            if (panel == null)
            {
                return;
            }

            GraphElement element = evt.target as GraphElement;

            RemoveElement(element);
        }
コード例 #26
0
 protected new void OnMouseMove(MouseMoveEvent e)
 {
     if (!base.target.HasMouseCapture())
     {
         this.m_PrevDropTarget = null;
         this.m_Active         = false;
     }
     if (this.m_Active)
     {
         if (this.m_GraphView != null)
         {
             VisualElement src      = (VisualElement)e.target;
             Vector2       mousePos = src.ChangeCoordinatesTo(this.m_GraphView.contentContainer, e.localMousePosition);
             this.m_PanDiff = this.GetEffectivePanSpeed(mousePos);
             if (this.m_PanDiff != Vector3.zero)
             {
                 this.m_PanSchedule.Resume();
             }
             else
             {
                 this.m_PanSchedule.Pause();
             }
             this.m_MouseDiff = this.m_originalMouse - e.mousePosition;
             foreach (KeyValuePair <GraphElement, Rect> current in this.m_OriginalPos)
             {
                 GraphElement key            = current.Key;
                 Matrix4x4    worldTransform = key.worldTransform;
                 Vector3      vector         = new Vector3(worldTransform.m00, worldTransform.m11, worldTransform.m22);
                 Rect         position       = key.GetPosition();
                 key.SetPosition(new Rect(current.Value.x - (this.m_MouseDiff.x - this.m_ItemPanDiff.x) * base.panSpeed.x / vector.x, current.Value.y - (this.m_MouseDiff.y - this.m_ItemPanDiff.y) * base.panSpeed.y / vector.y, position.width, position.height));
             }
             List <ISelectable> selection    = this.m_GraphView.selection;
             IDropTarget        dropTargetAt = this.GetDropTargetAt(e.localMousePosition);
             if (this.m_PrevDropTarget != dropTargetAt && this.m_PrevDropTarget != null)
             {
                 using (IMGUIEvent pooled = IMGUIEvent.GetPooled(e.imguiEvent))
                 {
                     pooled.imguiEvent.type = EventType.DragExited;
                     this.SendDragAndDropEvent(pooled, selection, this.m_PrevDropTarget);
                 }
             }
             using (IMGUIEvent pooled2 = IMGUIEvent.GetPooled(e.imguiEvent))
             {
                 pooled2.imguiEvent.type = EventType.DragUpdated;
                 this.SendDragAndDropEvent(pooled2, selection, dropTargetAt);
             }
             this.m_PrevDropTarget = dropTargetAt;
             this.selectedElement  = null;
             e.StopPropagation();
         }
     }
 }
コード例 #27
0
        void MoveElement(GraphElement element, Rect originalPos)
        {
            Matrix4x4 g     = element.worldTransform;
            var       scale = new Vector3(g.m00, g.m11, g.m22);

            Rect newPost = new Rect(0, 0, originalPos.width, originalPos.height);

            // Compute the new position of the selected element using the mouse delta position and panning info
            newPost.x = originalPos.x - (m_MouseDiff.x - m_ItemPanDiff.x) * panSpeed.x / scale.x * element.transform.scale.x;
            newPost.y = originalPos.y - (m_MouseDiff.y - m_ItemPanDiff.y) * panSpeed.y / scale.y * element.transform.scale.y;

            element.SetPosition(m_GraphView.contentViewContainer.ChangeCoordinatesTo(element.shadow.parent, newPost));
        }
コード例 #28
0
        public virtual void OnStartDragging(GraphElement ge)
        {
            var node = ge as Node;

            if (node != null)
            {
                ge.RemoveFromHierarchy();

                graphView.AddElement(ge);
                // Reselect it because RemoveFromHierarchy unselected it
                ge.Select(graphView, true);
            }
        }
コード例 #29
0
        private void OnChildRemoved(GraphElement element)
        {
            element.RemoveFromClassList("stack-child-element");
            element.UnregisterCallback <DetachFromPanelEvent>(OnChildDetachedFromPanel);

            // Disable the animation temporarily
            if (m_InstantAdd == false)
            {
                m_InstantAdd = true;
                schedule.Execute(() => m_InstantAdd = false);
            }
            UpdatePlaceholderVisibility();
        }
コード例 #30
0
        public static void Reload(this GraphElement element)
        {
            var evt = new Event()
            {
                type        = EventType.ExecuteCommand,
                commandName = UdonGraphCommands.Reload
            };

            using (var e = ExecuteCommandEvent.GetPooled(evt))
            {
                element.SendEvent(e);
            }
        }