/// <summary>
        /// Creates a new instance of the <see cref="StretchableImage9"/> class.
        /// </summary>
        /// <param name="texture">The asset identifier of the texture that contains the image.</param>
        /// <param name="x">The x-coordinate of the region on the image's texture that contains the image.</param>
        /// <param name="y">The y-coordinate of the region on the image's texture that contains the image.</param>
        /// <param name="width">The width of the region on the image's texture that contains the image.</param>
        /// <param name="height">The height of the region on the image's texture that contains the image.</param>
        /// <param name="left">The distance in pixels between the left edge of the image and the left edge of the image's center segment.</param>
        /// <param name="top">The distance in pixels between the top edge of the image and the top edge of the image's center segment.</param>
        /// <param name="right">The distance in pixels between the right edge of the image and the right edge of the image's center segment.</param>
        /// <param name="bottom">The distance in pixels between the bottom edge of the image and the bottom edge of the image's center segment.</param>
        /// <returns>The new instance of <see cref="StretchableImage9"/> that was created.</returns>
        public static StretchableImage9 Create(AssetID texture, Int32 x, Int32 y, Int32 width, Int32 height, Int32 left, Int32 top, Int32 right, Int32 bottom)
        {
            var img = new StretchableImage9();

            img.TextureID     = texture;
            img.TextureRegion = new Rectangle(x, y, width, height);
            img.Left          = left;
            img.Top           = top;
            img.Right         = right;
            img.Bottom        = bottom;
            return(img);
        }
Пример #2
0
        /// <summary>
        /// Resolves a string into an instance of the <see cref="TextureImage"/> class.
        /// </summary>
        /// <param name="value">The string value to resolve.</param>
        /// <param name="provider">An object that supplies culture-specific formatting information.</param>
        /// <returns>The resolved object.</returns>
        private static Object ImageResolver(String value, IFormatProvider provider)
        {
            var numericComponents = CountNumericComponents(value);

            switch (numericComponents)
            {
            case 4:
                return(StaticImage.Parse(value, NumberStyles.Integer, provider));

            case 6:
                return(StretchableImage3.Parse(value, NumberStyles.Integer, provider));

            case 8:
                return(StretchableImage9.Parse(value, NumberStyles.Integer, provider));
            }

            throw new FormatException();
        }
        /// <summary>
        /// Converts the string representation of a stretchable image into an instance of the <see cref="StretchableImage9"/> class.
        /// A return value indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="s">A string containing the image to convert.</param>
        /// <param name="style">A set of <see cref="NumberStyles"/> values indicating which elements are present in <paramref name="s"/>.</param>
        /// <param name="provider">A format provider that provides culture-specific formatting information.</param>
        /// <param name="image">A variable to populate with the converted value.</param>
        /// <returns><see langword="true"/> if <paramref name="s"/> was converted successfully; otherwise, <see langword="false"/>.</returns>
        public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out StretchableImage9 image)
        {
            Contract.Require(s, nameof(s));

            var components = s.Split((Char[])null, StringSplitOptions.RemoveEmptyEntries);

            var texture = AssetID.Invalid;
            var x = 0;
            var y = 0;
            var width = 0;
            var height = 0;
            var left = 0;
            var top = 0;
            var right = 0;
            var bottom = 0;
            var tileCenter = false;
            var tileEdges = false;

            image = null;

            switch (components.Length)
            {
                case 9:
                case 10:
                case 11:
                    if (!AssetID.TryParse(components[0], out texture))
                        return false;
                    if (!Int32.TryParse(components[1], out x))
                        return false;
                    if (!Int32.TryParse(components[2], out y))
                        return false;
                    if (!Int32.TryParse(components[3], out width))
                        return false;
                    if (!Int32.TryParse(components[4], out height))
                        return false;
                    if (!Int32.TryParse(components[5], out left))
                        return false;
                    if (!Int32.TryParse(components[6], out top))
                        return false;
                    if (!Int32.TryParse(components[7], out right))
                        return false;
                    if (!Int32.TryParse(components[8], out bottom))
                        return false;
                    if (components.Length > 9)
                    {
                        if (!ParseTilingParameter(components[9], ref tileCenter, ref tileEdges))
                            return false;
                    }
                    if (components.Length > 10)
                    {
                        if (!ParseTilingParameter(components[10], ref tileCenter, ref tileEdges))
                            return false;
                    }
                    break;

                default:
                    return false;
            }

            image = Create(texture, x, y, width, height, left, top, right, bottom);
            image.TileCenter = tileCenter;
            image.TileEdges = tileEdges;
            return true;
        }
 /// <summary>
 /// Converts the string representation of a stretchable image into an instance of the <see cref="StretchableImage9"/> class.
 /// A return value indicates whether the conversion succeeded.
 /// </summary>
 /// <param name="s">A string containing the image to convert.</param>
 /// <param name="image">A variable to populate with the converted value.</param>
 /// <returns><see langword="true"/> if <paramref name="s"/> was converted successfully; otherwise, <see langword="false"/>.</returns>
 public static Boolean TryParse(String s, out StretchableImage9 image)
 {
     return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out image);
 }