예제 #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>
        /// 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);
        }