예제 #1
0
        /// <summary>
        /// Removes any white space.  The canvas may be panned and zoomed in to do this.
        /// </summary>
        /// <param name="aCamera">The camera whose view will be adjusted.</param>
        protected virtual void FillViewWhiteSpace(PCamera aCamera)
        {
            RectangleFx rootBounds = aCamera.Root.FullBounds;
            RectangleFx viewBounds = aCamera.ViewBounds;

            if (!rootBounds.Contains(aCamera.ViewBounds))
            {
                aCamera.AnimateViewToPanToBounds(rootBounds, 0);
                aCamera.AnimateViewToPanToBounds(focusNode.GlobalFullBounds, 0);

                // center content.
                float dx = 0;
                float dy = 0;
                viewBounds = aCamera.ViewBounds;

                if (viewBounds.Width > rootBounds.Width)                     // then center along x axis.
                {
                    float rootBoundsMinX    = Math.Min(rootBounds.X, rootBounds.Right);
                    float viewBoundsMinX    = Math.Min(viewBounds.X, viewBounds.Right);
                    float boundsCenterX     = rootBoundsMinX + (rootBounds.Width / 2);
                    float viewBoundsCenterX = viewBoundsMinX + (viewBounds.Width / 2);
                    dx = viewBoundsCenterX - boundsCenterX;
                }

                if (viewBounds.Height > rootBounds.Height)                   // then center along y axis.
                {
                    float rootBoundsMinY    = Math.Min(rootBounds.Y, rootBounds.Right);
                    float viewBoundsMinY    = Math.Min(viewBounds.Y, viewBounds.Right);
                    float boundsCenterY     = rootBoundsMinY + (rootBounds.Height / 2);
                    float viewBoundsCenterY = viewBoundsMinY + (viewBounds.Height / 2);
                    dy = viewBoundsCenterY - boundsCenterY;
                }
                aCamera.TranslateViewBy(dx, dy);
            }
        }
예제 #2
0
        /// <summary>
        /// Return the delta required for the rectangle b1 to contain the rectangle b2.
        /// </summary>
        /// <param name="b1">The first rectangle.</param>
        /// <param name="b2">The second rectangle.</param>
        /// <returns>The delta required for b1 to contain b2.</returns>
        public static SizeFx DeltaRequiredToContain(RectangleFx b1, RectangleFx b2)
        {
            SizeFx result = SizeFx.Empty;

            if (!b1.Contains(b2))
            {
                float b1MaxX = Math.Max(b1.X, b1.Right);
                float b1MinX = Math.Min(b1.X, b1.Right);
                float b1MaxY = Math.Max(b1.Y, b1.Bottom);
                float b1MinY = Math.Min(b1.Y, b1.Bottom);

                float b2MaxX = Math.Max(b2.X, b2.Right);
                float b2MinX = Math.Min(b2.X, b2.Right);
                float b2MaxY = Math.Max(b2.Y, b2.Bottom);
                float b2MinY = Math.Min(b2.Y, b2.Bottom);

                if (!(b2MaxX > b1MaxX && b2MinX < b1MinX))
                {
                    if (b2MaxX > b1MaxX || b2MinX < b1MinX)
                    {
                        float difMaxX = b2MaxX - b1MaxX;
                        float difMinX = b2MinX - b1MinX;
                        if (Math.Abs(difMaxX) < Math.Abs(difMinX))
                        {
                            result.Width = difMaxX;
                        }
                        else
                        {
                            result.Width = difMinX;
                        }
                    }
                }

                if (!(b2MaxY > b1MaxY && b2MinY < b1MinY))
                {
                    if (b2MaxY > b1MaxY || b2MinY < b1MinY)
                    {
                        float difMaxY = b2MaxY - b1MaxY;
                        float difMinY = b2MinY - b1MinY;
                        if (Math.Abs(difMaxY) < Math.Abs(difMinY))
                        {
                            result.Height = difMaxY;
                        }
                        else
                        {
                            result.Height = difMinY;
                        }
                    }
                }
            }

            return(result);
        }