Пример #1
0
        //****************************************************************
        // Animation - Methods to animate the camera's view.
        //****************************************************************

        /// <summary>
        /// Animate the camera's view from its current matrix when the activity starts
        /// to a new matrix that centers the given bounds in the camera layers' coordinate
        /// system into the camera's view bounds.
        /// </summary>
        /// <param name="centerBounds">The bounds to center the view on.</param>
        /// <param name="shouldScaleToFit">
        /// Indicates whether the camera should scale it's view when necessary to fully fit
        /// the given bounds within the camera's view bounds.
        /// </param>
        /// <param name="duration">The amount of time that the animation should take.</param>
        /// <returns>
        /// The newly scheduled activity, if the duration is greater than 0; else null.
        /// </returns>
        /// <remarks>
        /// If the duration is 0 then the view will be transformed immediately, and null will
        /// be returned.  Else a new PTransformActivity will get returned that is set to
        /// animate the camera’s view matrix to the new bounds. If shouldScaleToFit is true,
        /// then the camera will also scale its view so that the given bounds fit fully within
        /// the camera's view bounds, else the camera will maintain its original scale.
        /// </remarks>
        public virtual PTransformActivity AnimateViewToCenterBounds(RectangleF centerBounds, bool shouldScaleToFit, long duration)
        {
            SizeF   delta     = PUtil.DeltaRequiredToCenter(ViewBounds, centerBounds);
            PMatrix newMatrix = ViewMatrix;

            newMatrix.TranslateBy(delta.Width, delta.Height);

            if (shouldScaleToFit)
            {
                float  s = Math.Min(ViewBounds.Width / centerBounds.Width, ViewBounds.Height / centerBounds.Height);
                PointF c = PUtil.CenterOfRectangle(centerBounds);
                newMatrix.ScaleBy(s, c.X, c.Y);
            }

            return(AnimateViewToMatrix(newMatrix, duration));
        }
Пример #2
0
        /// <summary>
        /// Caches the information necessary to animate from the current view bounds to the
        /// specified centerBounds
        /// </summary>
        /// <param name="centerBounds">The bounds to center the view on.</param>
        /// <param name="scaleToFit">
        /// Indicates whether the camera should scale it's view when necessary to fully fit
        /// the given bounds within the camera's view bounds.
        /// </param>
        /// <returns>The new view matrix to center the specified bounds.</returns>
        private Matrix CacheViewBounds(RectangleFx centerBounds, bool scaleToFit)
        {
            RectangleFx viewBounds = ViewBounds;

            // Initialize the image to the union of the current and destination bounds
            RectangleFx imageBounds = viewBounds;

            imageBounds = RectangleFxtensions.Union(imageBounds, centerBounds);

            AnimateViewToCenterBounds(imageBounds, scaleToFit, 0);

            imageAnimateBounds = ViewBounds;

            // Now create the actual cache image that we will use to animate fast

            System.Drawing.Image buffer = PaintBuffer;
            Color fBrush = Color.White;

            if (Brush != Color.Transparent)
            {
                fBrush = Brush;
            }
            ToImage(buffer, fBrush);

            // Do this after the painting above!
            imageAnimate = true;

            // Return the bounds to the previous viewbounds
            AnimateViewToCenterBounds(viewBounds, scaleToFit, 0);

            // The code below is just copied from animateViewToCenterBounds to create the
            // correct transform to center the specified bounds

            SizeFx delta     = PUtil.DeltaRequiredToCenter(viewBounds, centerBounds);
            Matrix newMatrix = ViewMatrix;

            newMatrix = MatrixExtensions.TranslateBy(newMatrix, delta.Width, delta.Height);

            if (scaleToFit)
            {
                float   s      = Math.Min(viewBounds.Width / centerBounds.Width, viewBounds.Height / centerBounds.Height);
                PointFx center = PUtil.CenterOfRectangle(centerBounds);
                newMatrix = MatrixExtensions.ScaleBy(newMatrix, s, center.X, center.Y);
            }

            return(newMatrix);
        }
Пример #3
0
        //****************************************************************
        // Animation - Methods to animate the camera's view.
        //****************************************************************

        /// <summary>
        /// Animate the camera's view from its current matrix when the activity starts
        /// to a new matrix that centers the given bounds in the camera layers' coordinate
        /// system into the camera's view bounds.
        /// </summary>
        /// <param name="centerBounds">The bounds to center the view on.</param>
        /// <param name="shouldScaleToFit">
        /// Indicates whether the camera should scale it's view when necessary to fully fit
        /// the given bounds within the camera's view bounds.
        /// </param>
        /// <param name="duration">The amount of time that the animation should take.</param>
        /// <returns>
        /// The newly scheduled activity, if the duration is greater than 0; else null.
        /// </returns>
        /// <remarks>
        /// If the duration is 0 then the view will be transformed immediately, and null will
        /// be returned.  Else a new PTransformActivity will get returned that is set to
        /// animate the camera’s view matrix to the new bounds. If shouldScaleToFit is true,
        /// then the camera will also scale its view so that the given bounds fit fully within
        /// the camera's view bounds, else the camera will maintain its original scale.
        /// </remarks>
        public virtual PTransformActivity AnimateViewToCenterBounds(RectangleFx centerBounds, bool shouldScaleToFit, long duration)
        {
            SizeFx delta     = PUtil.DeltaRequiredToCenter(ViewBounds, centerBounds);
            Matrix newMatrix = ViewMatrix;

            newMatrix = MatrixExtensions.TranslateBy(newMatrix, delta.Width, delta.Height);

            if (shouldScaleToFit)
            {
                float s = Math.Min(ViewBounds.Width / centerBounds.Width, ViewBounds.Height / centerBounds.Height);
                if (s != float.PositiveInfinity && s != 0)
                {
                    PointFx c = PUtil.CenterOfRectangle(centerBounds);
                    MatrixExtensions.ScaleBy(newMatrix, s, c.X, c.Y);
                }
            }

            return(AnimateViewToMatrix(newMatrix, duration));
        }