Esempio n. 1
0
        public virtual Rect CalculateRectToFitAll(VisualElement container)
        {
            var rectToFit         = container.layout;
            var reachedFirstChild = false;

            graphElements.ForEach(ge =>
            {
                if (ge is Edge || ge is Port)
                {
                    return;
                }

                if (!reachedFirstChild)
                {
                    rectToFit         = ge.ChangeCoordinatesTo(contentViewContainer, ge.rect);
                    reachedFirstChild = true;
                }
                else
                {
                    rectToFit = RectUtils.Encompass(rectToFit, ge.ChangeCoordinatesTo(contentViewContainer, ge.rect));
                }
            });

            return(rectToFit);
        }
        protected internal override Vector2 DoMeasure(float width, MeasureMode widthMode, float height, MeasureMode heightMode)
        {
            GraphView     graphView = GetFirstAncestorOfType <GraphView>();
            VisualElement viewport  = graphView.contentViewContainer;

            contentRectInViewportSpace = Rect.zero;

            // Compute the bounding box of the content of the scope in viewport space (because nodes are not parented by the scope that contains them)
            foreach (GraphElement subElement in containedElements)
            {
                if (subElement.panel != panel)
                {
                    continue;
                }

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

                if (Scope.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 (!Scope.IsValidRect(contentRectInViewportSpace))
                    {
                        contentRectInViewportSpace = boundingRect;
                    }
                    else
                    {
                        contentRectInViewportSpace = RectUtils.Encompass(contentRectInViewportSpace, boundingRect);
                    }
                }
            }

            return(new Vector2(contentRectInViewportSpace.width, contentRectInViewportSpace.height));
        }
Esempio n. 3
0
        void CalculateRects(VisualElement container)
        {
            m_ContentRect      = graphView.CalculateRectToFitAll(container);
            m_ContentRectLocal = m_ContentRect;

            // Retrieve viewport rectangle as if zoom and pan were inactive
            Matrix4x4 containerInvTransform   = container.worldTransform.inverse;
            Vector4   containerInvTranslation = containerInvTransform.GetColumn(3);
            var       containerInvScale       = new Vector2(containerInvTransform.m00, containerInvTransform.m11);

            m_ViewportRect = parent.rect;

            // Bring back viewport coordinates to (0,0), scale 1:1
            m_ViewportRect.x      += containerInvTranslation.x;
            m_ViewportRect.y      += containerInvTranslation.y;
            m_ViewportRect.x      += (parent.worldBound.x * containerInvScale.x);
            m_ViewportRect.y      += (parent.worldBound.y * containerInvScale.y);
            m_ViewportRect.width  *= containerInvScale.x;
            m_ViewportRect.height *= containerInvScale.y;

            // Update label with new value
            var containerZoomFactor = container.worldTransform.m00;

            m_Label.text = "MiniMap  " + string.Format("{0:F2}", containerZoomFactor) + "x";

            // Adjust rects for MiniMap

            // Encompass viewport rectangle (as if zoom and pan were inactive)
            var totalRect     = RectUtils.Encompass(m_ContentRect, m_ViewportRect);
            var minimapFactor = layout.width / totalRect.width;

            // Transform each rect to MiniMap coordinates
            ChangeToMiniMapCoords(ref totalRect, minimapFactor, Vector3.zero);

            var minimapTranslation = new Vector3(-totalRect.x, titleBarOffset - totalRect.y);

            ChangeToMiniMapCoords(ref m_ViewportRect, minimapFactor, minimapTranslation);
            ChangeToMiniMapCoords(ref m_ContentRect, minimapFactor, minimapTranslation);

            // Diminish and center everything to fit vertically
            if (totalRect.height > (layout.height - titleBarOffset))
            {
                float totalRectFactor  = (layout.height - titleBarOffset) / totalRect.height;
                float totalRectOffsetX = (layout.width - (totalRect.width * totalRectFactor)) / 2.0f;
                float totalRectOffsetY = titleBarOffset - ((totalRect.y + minimapTranslation.y) * totalRectFactor);

                m_ContentRect.width  *= totalRectFactor;
                m_ContentRect.height *= totalRectFactor;
                m_ContentRect.y      *= totalRectFactor;
                m_ContentRect.x      += totalRectOffsetX;
                m_ContentRect.y      += totalRectOffsetY;

                m_ViewportRect.width  *= totalRectFactor;
                m_ViewportRect.height *= totalRectFactor;
                m_ViewportRect.y      *= totalRectFactor;
                m_ViewportRect.x      += totalRectOffsetX;
                m_ViewportRect.y      += totalRectOffsetY;
            }
        }
Esempio n. 4
0
        EventPropagation Frame(FrameType frameType)
        {
            var rectToFit        = contentViewContainer.layout;
            var frameTranslation = Vector3.zero;
            var frameScaling     = Vector3.one;

            if (frameType == FrameType.Selection &&
                (selection.Count == 0 || !selection.Any(e => e.IsSelectable() && !(e is Edge))))
            {
                frameType = FrameType.All;
            }

            if (frameType == FrameType.Selection)
            {
                var graphElement = selection[0] as GraphElement;
                if (graphElement != null)
                {
                    rectToFit = graphElement.ChangeCoordinatesTo(contentViewContainer, graphElement.rect);
                }

                rectToFit = selection.OfType <GraphElement>()
                            .Aggregate(rectToFit, (current, e) => RectUtils.Encompass(current, e.ChangeCoordinatesTo(contentViewContainer, e.rect)));
                CalculateFrameTransform(rectToFit, layout, k_FrameBorder, out frameTranslation, out frameScaling);
            }
            else if (frameType == FrameType.All)
            {
                rectToFit = CalculateRectToFitAll(contentViewContainer);
                CalculateFrameTransform(rectToFit, layout, k_FrameBorder, out frameTranslation, out frameScaling);
            } // else keep going if (frameType == FrameType.Origin)

            if (m_FrameAnimate)
            {
                // TODO Animate framing
                // RMAnimation animation = new RMAnimation();
                // parent.Animate(parent)
                //       .Lerp(new string[] {"m_Scale", "m_Translation"},
                //             new object[] {parent.scale, parent.translation},
                //             new object[] {frameScaling, frameTranslation}, 0.08f);
            }
            else
            {
                Matrix4x4.TRS(frameTranslation, Quaternion.identity, frameScaling);

                UpdateViewTransform(frameTranslation, frameScaling);
            }

            contentViewContainer.Dirty(ChangeType.Repaint);

            UpdatePersistedViewTransform();

            return(EventPropagation.Stop);
        }
Esempio n. 5
0
        private void CalculateRects(VisualElement container)
        {
            this.m_ContentRect      = this.graphView.CalculateRectToFitAll(container);
            this.m_ContentRectLocal = this.m_ContentRect;
            Matrix4x4 inverse = container.worldTransform.inverse;
            Vector4   column  = inverse.GetColumn(3);
            Vector2   vector  = new Vector2(inverse.m00, inverse.m11);

            this.m_ViewportRect        = base.parent.rect;
            this.m_ViewportRect.x      = this.m_ViewportRect.x + column.x;
            this.m_ViewportRect.y      = this.m_ViewportRect.y + column.y;
            this.m_ViewportRect.x      = this.m_ViewportRect.x + base.parent.worldBound.x * vector.x;
            this.m_ViewportRect.y      = this.m_ViewportRect.y + base.parent.worldBound.y * vector.y;
            this.m_ViewportRect.width  = this.m_ViewportRect.width * vector.x;
            this.m_ViewportRect.height = this.m_ViewportRect.height * vector.y;
            float m = container.worldTransform.m00;

            this.m_Label.text = "MiniMap  " + string.Format("{0:F2}", m) + "x";
            Rect  rect   = RectUtils.Encompass(this.m_ContentRect, this.m_ViewportRect);
            float factor = base.layout.width / rect.width;

            MiniMap.ChangeToMiniMapCoords(ref rect, factor, Vector3.zero);
            Vector3 translation = new Vector3(-rect.x, (float)this.titleBarOffset - rect.y);

            MiniMap.ChangeToMiniMapCoords(ref this.m_ViewportRect, factor, translation);
            MiniMap.ChangeToMiniMapCoords(ref this.m_ContentRect, factor, translation);
            if (rect.height > base.layout.height - (float)this.titleBarOffset)
            {
                float num  = (base.layout.height - (float)this.titleBarOffset) / rect.height;
                float num2 = (base.layout.width - rect.width * num) / 2f;
                float num3 = (float)this.titleBarOffset - (rect.y + translation.y) * num;
                this.m_ContentRect.width   = this.m_ContentRect.width * num;
                this.m_ContentRect.height  = this.m_ContentRect.height * num;
                this.m_ContentRect.y       = this.m_ContentRect.y * num;
                this.m_ContentRect.x       = this.m_ContentRect.x + num2;
                this.m_ContentRect.y       = this.m_ContentRect.y + num3;
                this.m_ViewportRect.width  = this.m_ViewportRect.width * num;
                this.m_ViewportRect.height = this.m_ViewportRect.height * num;
                this.m_ViewportRect.y      = this.m_ViewportRect.y * num;
                this.m_ViewportRect.x      = this.m_ViewportRect.x + num2;
                this.m_ViewportRect.y      = this.m_ViewportRect.y + num3;
            }
        }
Esempio n. 6
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;
        }
Esempio n. 7
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;
         }
     }
 }