示例#1
0
        /// <summary>
        /// Applies a previously set constraint to the camera's view matrix.
        /// </summary>
        public virtual void ApplyViewConstraints()
        {
            if (viewConstraint == CameraViewConstraint.None)
            {
                return;
            }

            RectangleF layerBounds     = GlobalToLocal(UnionOfLayerFullBounds);
            SizeF      constraintDelta = new SizeF(0, 0);

            switch (viewConstraint)
            {
            case CameraViewConstraint.All:
                constraintDelta = PUtil.DeltaRequiredToContain(ViewBounds, layerBounds);
                break;

            case CameraViewConstraint.Center:
                layerBounds.Location = PUtil.CenterOfRectangle(layerBounds);
                layerBounds.Width    = 0;
                layerBounds.Height   = 0;
                constraintDelta      = PUtil.DeltaRequiredToContain(ViewBounds, layerBounds);
                break;
            }

            viewMatrix.TranslateBy(-constraintDelta.Width, -constraintDelta.Height);
        }
示例#2
0
        /// <summary>
        /// Applies a previously set constraint to the camera's view matrix.
        /// </summary>
        public virtual void ApplyViewConstraints()
        {
            if (viewConstraint == CameraViewConstraint.None)
            {
                return;
            }

            RectangleFx layerBounds     = GlobalToLocal(UnionOfLayerFullBounds);
            SizeFx      constraintDelta = new SizeFx(0, 0);

            switch (viewConstraint)
            {
            case CameraViewConstraint.All:
                constraintDelta = PUtil.DeltaRequiredToContain(ViewBounds, layerBounds);
                break;

            case CameraViewConstraint.Center:
                PointFx layerLocation = PUtil.CenterOfRectangle(layerBounds);
                //layerBounds.Width = 0;
                //layerBounds.Height = 0;
                layerBounds     = new RectangleFx(layerLocation.X, layerLocation.Y, 0, 0);
                constraintDelta = PUtil.DeltaRequiredToContain(ViewBounds, layerBounds);
                break;
            }

            this.viewMatrix = MatrixExtensions.TranslateBy(viewMatrix, -constraintDelta.Width, -constraintDelta.Height);
        }
示例#3
0
        /// <summary>
        /// Pan the camera's view from its current matrix when the activity starts to a new
        /// matrix so that the view bounds will contain (if possible, intersect if not
        /// possible) the new bounds in the camera layers' coordinate system.
        /// </summary>
        /// <param name="panToBounds">The bounds to pan the view to.</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.
        /// </remarks>
        public virtual PTransformActivity AnimateViewToPanToBounds(RectangleF panToBounds, long duration)
        {
            SizeF delta = PUtil.DeltaRequiredToContain(ViewBounds, panToBounds);

            if (delta.Width != 0 || delta.Height != 0)
            {
                if (duration == 0)
                {
                    TranslateViewBy(-delta.Width, -delta.Height);
                }
                else
                {
                    PMatrix m = ViewMatrix;
                    m.TranslateBy(-delta.Width, -delta.Height);
                    return(AnimateViewToMatrix(m, duration));
                }
            }

            return(null);
        }