示例#1
0
        /// Get a bounding rectangle around all the widgets that have been added to this frame
        public Rect CalculateWidgetBounds()
        {
            if (mAutoLayoutNeedsUpdate)
            {
                AutoLayoutUpdate();
            }

            Rect?bounds = null;

            foreach (KeyValuePair <IWidget, IGuiPosition> widget in mWidgets)
            {
                if (widget.Key != null)
                {
                    Vector2 position     = widget.Value.GetPosition(widget.Key);
                    Vector2 size         = widget.Key.ExternalSize;
                    Rect    widgetBounds = new Rect(position.x, position.y, size.x, size.y);
                    if (bounds == null)
                    {
                        bounds = widgetBounds;
                    }
                    else
                    {
                        bounds = RectUtility.BoundingRect(widgetBounds, (Rect)bounds);
                    }
                }
            }

            if (bounds == null)
            {
                bounds = new Rect();
            }

            return((Rect)bounds);
        }
示例#2
0
        public Vector2 SizeThumb(IGuiElement thumb)
        {
            if (thumb != mThumb)
            {
                throw new Exception("ProceduralSize is applying the SizeThumb function to the wrong widget (" + thumb.Name + ")");
            }

            float minHeight = 0.0f;

            if (thumb.Style != null)
            {
                // Keep the thumb graphic from overlapping itself
                minHeight = thumb.Style.NinePartScale.GetSizeDifference().y;
            }

            Vector2 result       = InternalSize;
            float   maxHeight    = result.y;
            Rect    widgetBounds = Frame.CalculateWidgetBounds();

            widgetBounds = RectUtility.BoundingRect(Vector2.zero, widgetBounds);
            float percentInView = Frame.InternalSize.y / widgetBounds.yMax;

            // If the entire frame fits, make sure we are viewing the top of the frame
            if (percentInView >= 1.0f)
            {
                Frame.ResetScroll();
            }
            // Refresh the frame to make sure the scrollbar's percent is again accurate,
            // but only if the bounds changed (as an optimization)
            if (mOldWidgetBounds != null && (Rect)mOldWidgetBounds != widgetBounds)
            {
                Refresh();
            }
            // Remember this run's bounds for next time
            mOldWidgetBounds = widgetBounds;
            result.y         = Mathf.Lerp(minHeight, maxHeight, percentInView);

            return(result);
        }
示例#3
0
        public void BoundingRectVerifivation()
        {
            Rect testRect1 = new Rect(0.0f, 0.0f, 30.0f, 30.0f);
            Rect testRect2 = new Rect(10.0f, 10.0f, 10.0f, 10.0f);

            Rect    testRect3 = new Rect(10.0f, 10.0f, 100.0f, 100.0f);
            Vector2 testPnt1  = new Vector2(0.0f, 0.0f);
            Vector2 testPnt2  = new Vector2(-100.0f, 100.0f);

            Rect bounds1 = RectUtility.BoundingRect(testRect1, testRect2);

            Assert.AreEqual(0.0f, bounds1.xMin);
            Assert.AreEqual(0.0f, bounds1.yMin);
            Assert.AreEqual(30.0f, bounds1.xMax);
            Assert.AreEqual(30.0f, bounds1.yMax);

            Rect bounds2 = RectUtility.BoundingRect(bounds1, testRect3);

            Assert.AreEqual(0.0f, bounds2.x);
            Assert.AreEqual(0.0f, bounds2.y);
            Assert.AreEqual(110.0f, bounds2.width);
            Assert.AreEqual(110.0f, bounds2.height);

            Rect bounds3 = RectUtility.BoundingRect(testPnt1, testRect2);

            Assert.AreEqual(0.0f, bounds3.x);
            Assert.AreEqual(0.0f, bounds3.y);
            Assert.AreEqual(20.0f, bounds3.width);
            Assert.AreEqual(20.0f, bounds3.height);

            Rect bounds4 = RectUtility.BoundingRect(testPnt2, testRect1);

            Assert.AreEqual(-100.0f, bounds4.x);
            Assert.AreEqual(0.0f, bounds4.y);
            Assert.AreEqual(130.0f, bounds4.width);
            Assert.AreEqual(100.0f, bounds4.height);
        }