예제 #1
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();
         }
     }
 }
예제 #2
0
 private void Pan(TimerState ts)
 {
     this.m_GraphView.viewTransform.position -= this.m_PanDiff;
     this.m_ItemPanDiff += this.m_PanDiff;
     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));
     }
 }
예제 #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();
             }
         }
     }
 }
예제 #4
0
 private void MoveElements(float deltaX, float deltaY)
 {
     if (this.m_ContainedElements != null)
     {
         this.m_IsMovingElements = true;
         for (int i = 0; i < this.m_ContainedElements.Count; i++)
         {
             GraphElement graphElement = this.m_ContainedElements[i];
             if (!this.m_IsUpdatingGeometryFromContent)
             {
                 Rect position = graphElement.GetPosition();
                 graphElement.SetPosition(new Rect(position.x + deltaX, position.y + deltaY, position.width, position.height));
             }
         }
         this.m_IsMovingElements = false;
     }
 }
예제 #5
0
        private void Pan(TimerState ts)
        {
            m_GraphView.viewTransform.position -= m_PanDiff;
            m_ItemPanDiff += m_PanDiff;

            foreach (KeyValuePair <GraphElement, Rect> v in m_OriginalPos)
            {
                GraphElement ce = v.Key;

                Matrix4x4 g     = ce.worldTransform;
                var       scale = new Vector3(g.m00, g.m11, g.m22);

                Rect ceLayout = ce.GetPosition();

                ce.SetPosition(
                    new Rect(v.Value.x - (m_MouseDiff.x - m_ItemPanDiff.x) * panSpeed.x / scale.x,
                             v.Value.y - (m_MouseDiff.y - m_ItemPanDiff.y) * panSpeed.y / scale.y,
                             ceLayout.width, ceLayout.height));
            }
        }
예제 #6
0
        void MoveElements(float deltaX, float deltaY)
        {
            if (m_ContainedElements != null)
            {
                m_IsMovingElements = true;

                for (int i = 0; i < m_ContainedElements.Count; ++i)
                {
                    GraphElement subElement = m_ContainedElements[i];

                    if (m_IsUpdatingGeometryFromContent == false)
                    {
                        Rect currentPosition = subElement.GetPosition();

                        subElement.SetPosition(new Rect(currentPosition.x + deltaX, currentPosition.y + deltaY, currentPosition.width, currentPosition.height));
                    }
                }

                m_IsMovingElements = false;
            }
        }
예제 #7
0
        public void UpdateGeometryFromContent()
        {
            if (panel == null || !m_Initialized || m_IsUpdatingGeometryFromContent || m_IsMovingElements)
            {
                return;
            }

            GraphView graphView = GetFirstAncestorOfType <GraphView>();

            if (graphView == null)
            {
                return;
            }

            m_IsUpdatingGeometryFromContent = true;

            VisualElement viewport = graphView.contentViewContainer;
            Rect          contentRectInViewportSpace = Rect.zero;

            // Compute the bounding box of the content of the group in viewport space (because nodes are not parented by the group that contains them)
            if (m_ContainedElements != null)
            {
                for (int i = 0; i < m_ContainedElements.Count; ++i)
                {
                    GraphElement subElement = m_ContainedElements[i];

                    if (subElement.panel != panel)
                    {
                        continue;
                    }

                    Rect boundingRect = new Rect(0, 0, subElement.GetPosition().width, subElement.GetPosition().height);

                    if (IsValidRect(boundingRect))
                    {
                        boundingRect = subElement.ChangeCoordinatesTo(viewport, boundingRect);

                        // Use the first element with a valid geometry as reference to compute the bounding box of contained elements
                        if (!IsValidRect(contentRectInViewportSpace))
                        {
                            contentRectInViewportSpace = boundingRect;
                        }
                        else
                        {
                            contentRectInViewportSpace = RectUtils.Encompass(contentRectInViewportSpace, boundingRect);
                        }
                    }
                }
            }

            if ((m_ContainedElements == null) || (m_ContainedElements.Count == 0))
            {
                float contentX = m_ContentItem.style.borderLeftWidth.value + m_ContentItem.style.paddingLeft.value;
                float contentY = m_HeaderItem.layout.height + m_ContentItem.style.borderTopWidth.value + m_ContentItem.style.paddingTop.value;

                contentRectInViewportSpace = this.ChangeCoordinatesTo(viewport, new Rect(contentX, contentY, 0, 0));
            }

            float titleItemImplicitWidth = k_TitleItemMinWidth;

            if (m_HeaderItem != null)
            {
                Vector2 implicitSize = m_TitleItem.DoMeasure(100, MeasureMode.Undefined, 100, MeasureMode.Undefined);

                if (IsValidSize(implicitSize))
                {
                    titleItemImplicitWidth = implicitSize.x + m_TitleItem.style.marginLeft.value + m_TitleItem.style.paddingLeft.value
                                             + m_TitleItem.style.paddingRight.value + m_TitleItem.style.marginRight.value;
                }
            }

            float headerItemImplicitWidth = titleItemImplicitWidth + m_HeaderItem.style.paddingLeft.value + m_HeaderItem.style.paddingRight.value;

            Vector2 contentRectSize = contentRectInViewportSpace.size;

            contentRectSize.x += m_ContentItem.style.borderLeftWidth.value + m_ContentItem.style.paddingLeft.value + m_ContentItem.style.paddingRight.value + m_ContentItem.style.borderRightWidth.value;
            contentRectSize.y += m_ContentItem.style.borderTopWidth.value + m_ContentItem.style.paddingTop.value + m_ContentItem.style.paddingBottom.value + m_ContentItem.style.borderBottomWidth.value;

            Rect groupGeometry = new Rect();

            groupGeometry.position = viewport.ChangeCoordinatesTo(parent, contentRectInViewportSpace.position);
            groupGeometry.width    = Math.Max(contentRectSize.x, headerItemImplicitWidth) + style.borderLeftWidth.value + style.borderRightWidth.value; // Ensure that the title is always visible
            groupGeometry.height   = contentRectSize.y + m_HeaderItem.layout.height + style.borderTopWidth.value + style.borderBottomWidth.value;

            groupGeometry.x -= m_ContentItem.style.paddingLeft.value + style.borderLeftWidth.value;
            groupGeometry.y -= m_ContentItem.style.paddingTop.value + m_HeaderItem.layout.height + style.borderTopWidth.value;

            SetPosition(groupGeometry);

            Vector2 newPosInCanvasSpace = this.ChangeCoordinatesTo(viewport, new Vector2(0, 0));

            mPreviousPosInCanvasSpace       = newPosInCanvasSpace;
            m_ContainedElementsRect         = viewport.ChangeCoordinatesTo(this, contentRectInViewportSpace);
            m_IsUpdatingGeometryFromContent = false;
        }
        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();
            }
        }
예제 #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();
            }
        }
예제 #10
0
 public void UpdateGeometryFromContent()
 {
     if (base.panel != null && this.m_Initialized && !this.m_IsUpdatingGeometryFromContent && !this.m_IsMovingElements)
     {
         GraphView firstAncestorOfType = base.GetFirstAncestorOfType <GraphView>();
         if (firstAncestorOfType != null)
         {
             this.m_IsUpdatingGeometryFromContent = true;
             VisualElement contentViewContainer = firstAncestorOfType.contentViewContainer;
             Rect          rect = Rect.zero;
             if (this.m_ContainedElements != null)
             {
                 for (int i = 0; i < this.m_ContainedElements.Count; i++)
                 {
                     GraphElement graphElement = this.m_ContainedElements[i];
                     if (graphElement.panel == base.panel)
                     {
                         Rect rect2 = new Rect(0f, 0f, graphElement.GetPosition().width, graphElement.GetPosition().height);
                         if (GroupNode.IsValidRect(rect2))
                         {
                             rect2 = graphElement.ChangeCoordinatesTo(contentViewContainer, rect2);
                             if (!GroupNode.IsValidRect(rect))
                             {
                                 rect = rect2;
                             }
                             else
                             {
                                 rect = RectUtils.Encompass(rect, rect2);
                             }
                         }
                     }
                 }
             }
             if (this.m_ContainedElements == null || this.m_ContainedElements.Count == 0)
             {
                 float x = this.m_ContentItem.style.borderLeftWidth.value + this.m_ContentItem.style.paddingLeft.value;
                 float y = this.m_HeaderItem.layout.height + this.m_ContentItem.style.borderTopWidth.value + this.m_ContentItem.style.paddingTop.value;
                 rect = this.ChangeCoordinatesTo(contentViewContainer, new Rect(x, y, 0f, 0f));
             }
             float num = 10f;
             if (this.m_HeaderItem != null)
             {
                 Vector2 size = this.m_TitleItem.DoMeasure(100f, VisualElement.MeasureMode.Undefined, 100f, VisualElement.MeasureMode.Undefined);
                 if (GroupNode.IsValidSize(size))
                 {
                     num = size.x + this.m_TitleItem.style.marginLeft.value + this.m_TitleItem.style.paddingLeft.value + this.m_TitleItem.style.paddingRight.value + this.m_TitleItem.style.marginRight.value;
                 }
             }
             float   val   = num + this.m_HeaderItem.style.paddingLeft.value + this.m_HeaderItem.style.paddingRight.value;
             Vector2 size2 = rect.size;
             size2.x += this.m_ContentItem.style.borderLeftWidth.value + this.m_ContentItem.style.paddingLeft.value + this.m_ContentItem.style.paddingRight.value + this.m_ContentItem.style.borderRightWidth.value;
             size2.y += this.m_ContentItem.style.borderTopWidth.value + this.m_ContentItem.style.paddingTop.value + this.m_ContentItem.style.paddingBottom.value + this.m_ContentItem.style.borderBottomWidth.value;
             Rect position = default(Rect);
             position.position = contentViewContainer.ChangeCoordinatesTo(base.parent, rect.position);
             position.width    = Math.Max(size2.x, val) + base.style.borderLeftWidth.value + base.style.borderRightWidth.value;
             position.height   = size2.y + this.m_HeaderItem.layout.height + base.style.borderTopWidth.value + base.style.borderBottomWidth.value;
             position.x       -= this.m_ContentItem.style.paddingLeft.value + base.style.borderLeftWidth.value;
             position.y       -= this.m_ContentItem.style.paddingTop.value + this.m_HeaderItem.layout.height + base.style.borderTopWidth.value;
             this.SetPosition(position);
             Vector2 vector = this.ChangeCoordinatesTo(contentViewContainer, new Vector2(0f, 0f));
             this.mPreviousPosInCanvasSpace       = vector;
             this.m_ContainedElementsRect         = contentViewContainer.ChangeCoordinatesTo(this, rect);
             this.m_IsUpdatingGeometryFromContent = false;
         }
     }
 }
예제 #11
0
        protected new void OnMouseMove(MouseMoveEvent e)
        {
            if (!target.HasMouseCapture())
            {
                // We lost the capture. Since we still receive mouse events,
                // the MouseDown target must have taken it in its ExecuteDefaultAction().
                // Stop processing the event sequence, then.
                // FIXME: replace this by a handler on the upcoming LostCaptureEvent.

                m_PrevDropTarget = null;
                m_Active         = false;
            }

            if (!m_Active)
            {
                return;
            }

            if (m_GraphView == null)
            {
                return;
            }

            var     ve         = (VisualElement)e.target;
            Vector2 gvMousePos = ve.ChangeCoordinatesTo(m_GraphView.contentContainer, e.localMousePosition);

            m_PanDiff = GetEffectivePanSpeed(gvMousePos);


            if (m_PanDiff != Vector3.zero)
            {
                m_PanSchedule.Resume();
            }
            else
            {
                m_PanSchedule.Pause();
            }

            // We need to monitor the mouse diff "by hand" because we stop positionning the graph elements once the
            // mouse has gone out.
            m_MouseDiff = m_originalMouse - e.mousePosition;

            foreach (KeyValuePair <GraphElement, Rect> v in m_OriginalPos)
            {
                GraphElement ce = v.Key;

                Matrix4x4 g     = ce.worldTransform;
                var       scale = new Vector3(g.m00, g.m11, g.m22);

                Rect ceLayout = ce.GetPosition();

                ce.SetPosition(
                    new Rect(v.Value.x - (m_MouseDiff.x - m_ItemPanDiff.x) * panSpeed.x / scale.x,
                             v.Value.y - (m_MouseDiff.y - m_ItemPanDiff.y) * panSpeed.y / scale.y,
                             ceLayout.width, ceLayout.height));
            }
            List <ISelectable> selection = m_GraphView.selection;

            // TODO: Replace with a temp drawing or something...maybe manipulator could fake position
            // all this to let operation know which element sits under cursor...or is there another way to draw stuff that is being dragged?

            IDropTarget dropTarget = GetDropTargetAt(e.localMousePosition);

            if (m_PrevDropTarget != dropTarget && m_PrevDropTarget != null)
            {
                using (IMGUIEvent eexit = IMGUIEvent.GetPooled(e.imguiEvent))
                {
                    eexit.imguiEvent.type = EventType.DragExited;
                    SendDragAndDropEvent(eexit, selection, m_PrevDropTarget);
                }
            }

            using (IMGUIEvent eupdated = IMGUIEvent.GetPooled(e.imguiEvent))
            {
                eupdated.imguiEvent.type = EventType.DragUpdated;
                SendDragAndDropEvent(eupdated, selection, dropTarget);
            }

            m_PrevDropTarget = dropTarget;

            selectedElement = null;
            e.StopPropagation();
        }