예제 #1
0
        protected override void InternalUpdateBounds(float x, float y, float width, float height)
        {
            if (updatingBoundsFromPath || points.Count == 0)
            {
                return;
            }

            if (resizePoints != null)
            {
                points.Clear();
                points.AddRange(resizePoints);
            }

            RectangleF pathBounds = PathBounds;

            TEMP_MATRIX.Reset();
            TEMP_MATRIX.TranslateBy(x, y);
            TEMP_MATRIX.ScaleBy(width / pathBounds.Width, height / pathBounds.Height);
            TEMP_MATRIX.TranslateBy(-pathBounds.X, -pathBounds.Y);

            for (int i = 0; i < points.Count; i++)
            {
                points[i] = TEMP_MATRIX.Transform((PointF)points[i]);
            }
        }
예제 #2
0
 /// <summary>
 /// Translate the view matrix that is applied to the camera's layers.
 /// </summary>
 /// <param name="dx">The amount to translate in the x direction.</param>
 /// <param name="dy">The amount to translate in the y direction.</param>
 public virtual void TranslateViewBy(float dx, float dy)
 {
     viewMatrix.TranslateBy(dx, dy);
     ApplyViewConstraints();
     InvalidatePaint();
     FirePropertyChangedEvent(PROPERTY_KEY_VIEWTRANSFORM, PROPERTY_CODE_VIEWTRANSFORM, null, viewMatrix);
 }
예제 #3
0
        /// <summary>
        /// Overridden.  Set the bounds of this path.
        /// </summary>
        /// <param name="x">The new x-coordinate of the bounds/</param>
        /// <param name="y">The new y-coordinate of the bounds.</param>
        /// <param name="width">The new width of the bounds.</param>
        /// <param name="height">The new height of the bounds.</param>
        /// <returns>True if the bounds have changed; otherwise, false.</returns>
        /// <remarks>
        /// This works by scaling the path to fit into the specified bounds.  This normally
        /// works well, but if the specified base bounds get too small then it is impossible
        /// to expand the path shape again since all its numbers have tended to zero, so
        /// application code may need to take this into consideration.
        /// </remarks>
        protected override void InternalUpdateBounds(float x, float y, float width, float height)
        {
            if (updatingBoundsFromPath || path == null)
            {
                return;
            }

            if (resizePath != null)
            {
                path.Reset();
                path.AddPath(resizePath, false);
            }

            RectangleF pathBounds = path.GetBounds();

            if (pen != null && path.PointCount > 0)
            {
                try
                {
                    TEMP_PATH.Reset();
                    TEMP_PATH.AddPath(path, false);

                    TEMP_PATH.Widen(pen);
                    RectangleF penPathBounds = TEMP_PATH.GetBounds();

                    float strokeOutset = Math.Max(penPathBounds.Width - pathBounds.Width,
                                                  penPathBounds.Height - pathBounds.Height);

                    x      += strokeOutset / 2;
                    y      += strokeOutset / 2;
                    width  -= strokeOutset;
                    height -= strokeOutset;
                }
                catch (OutOfMemoryException)
                {
                    // Catch the case where the path is a single point
                }
            }

            float scaleX = (width == 0 || pathBounds.Width == 0) ? 1 : width / pathBounds.Width;
            float scaleY = (height == 0 || pathBounds.Height == 0) ? 1 : height / pathBounds.Height;

            TEMP_MATRIX.Reset();
            TEMP_MATRIX.TranslateBy(x, y);
            TEMP_MATRIX.ScaleBy(scaleX, scaleY);
            TEMP_MATRIX.TranslateBy(-pathBounds.X, -pathBounds.Y);

            path.Transform(TEMP_MATRIX.MatrixReference);
        }
예제 #4
0
 public void LayoutCurrentPosition()
 {
     // Move the current position indicator to the new focus slide's spot in the slide bar
     if (focusSlide == null)
     {
         currentPosition.Visible = false;
     }
     else
     {
         PMatrix matrix = GetUnfocusedMatrix(currentPosition, (int)focusSlide.Tag);
         matrix.TranslateBy(0, -IMAGE_PADDING);
         currentPosition.AnimateToMatrix(matrix, ANIMATION_TIME_MILLIS);
         currentPosition.Visible = true;
     }
 }
예제 #5
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));
        }
예제 #6
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 PMatrix CacheViewBounds(RectangleF centerBounds, bool scaleToFit)
        {
            RectangleF viewBounds = ViewBounds;

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

            imageBounds = RectangleF.Union(imageBounds, centerBounds);

            AnimateViewToCenterBounds(imageBounds, scaleToFit, 0);

            imageAnimateBounds = ViewBounds;

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

            Image buffer = PaintBuffer;
            Brush fBrush = Brushes.White;

            if (Brush != null)
            {
                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

            SizeF   delta     = PUtil.DeltaRequiredToCenter(viewBounds, centerBounds);
            PMatrix newMatrix = ViewMatrix;

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

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

            return(newMatrix);
        }
예제 #7
0
        protected void CreateText(Random rnd)
        {
            // Create some text
            P3Text text = new P3Text("Direct3D Piccolo Renderer");

            text.Brush     = Brushes.Blue;
            text.TextBrush = Brushes.Yellow;
            text.Font      = new System.Drawing.Font("Arial", 120);
            canvas.Layer.AddChild(text);

            PMatrix tMatrix = text.Matrix;

            tMatrix.TranslateBy(canvas.Width - text.Width, 0);
            PTransformActivity translateActivity = text.AnimateToMatrix(tMatrix, 10000 + (long)(2000 * rnd.NextDouble()));

            translateActivity.LoopCount = 1000;
            translateActivity.Mode      = ActivityMode.SourceToDestinationToSource;
        }
예제 #8
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);
        }