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);
        }
示例#2
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);
            }
        }
示例#3
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 (m_ContainedElements == null)
            {
                m_ContainedElements = new List <GraphElement>();
            }
            else if (m_ContainedElements.Contains(element))
            {
                throw new ArgumentException("The element is already contained in this group node.");
            }

            // Removes the element from its current group
            GroupNode currentGroup = element.GetContainingGroupNode();

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

            m_ContainedElements.Add(element);

            // To update the group geometry whenever the added element's geometry changes
            element.RegisterCallback <PostLayoutEvent>(OnSubElementPostLayout);
            element.RegisterCallback <DetachFromPanelEvent>(OnSubElementDetachedFromPanel);

            UpdateGeometryFromContent();

            GraphView gv = GetFirstAncestorOfType <GraphView>();

            if (gv != null && gv.elementAddedToGroupNode != null)
            {
                gv.elementAddedToGroupNode(this, element);
            }
        }
示例#4
0
        public EventPropagation DragUpdated(IMGUIEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget)
        {
            GroupNode group   = parent.GetFirstAncestorOfType <GroupNode>();
            bool      canDrop = false;

            foreach (ISelectable selectedElement in selection)
            {
                if (selectedElement == group)
                {
                    continue;
                }

                var   selectedGraphElement = selectedElement as GraphElement;
                Event e = evt.imguiEvent;

                if (e.shift)
                {
                    if (group.ContainsElement(selectedGraphElement))
                    {
                        group.RemoveElement(selectedGraphElement);
                    }
                }
                else
                {
                    if (!group.ContainsElement(selectedGraphElement) && selectedGraphElement.GetContainingGroupNode() == null)
                    {
                        canDrop = true;
                    }
                }
            }

            if (canDrop)
            {
                AddToClassList("dragEntered");
            }
            else
            {
                RemoveFromClassList("dragEntered");
            }

            return(EventPropagation.Stop);
        }