Exemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of the <see cref="StretchableImage3"/> class.
        /// </summary>
        /// <param name="texture">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="right">The distance in pixels between the right edge of the image and the right edge of the image's center segment.</param>
        /// <returns>The new instance of <see cref="StretchableImage3"/> that was created.</returns>
        public static StretchableImage3 Create(Texture2D texture, Int32 x, Int32 y, Int32 width, Int32 height, Int32 left, Int32 right)
        {
            var img = new StretchableImage3();

            img.Texture       = texture;
            img.TextureRegion = new Rectangle(x, y, width, height);
            img.Left          = left;
            img.Right         = right;
            return(img);
        }
Exemplo n.º 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();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Converts the string representation of a stretchable image into an instance of the <see cref="StretchableImage3"/> 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 StretchableImage3 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 right      = 0;
            var tileCenter = false;
            var tileEdges  = false;
            var vertical   = false;

            image = null;

            switch (components.Length)
            {
            case 7:
            case 8:
            case 9:
            case 10:
                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 right))
                {
                    return(false);
                }
                if (components.Length > 7)
                {
                    if (!ParseTilingParameter3(components[7], ref tileCenter, ref tileEdges, ref vertical))
                    {
                        return(false);
                    }
                }
                if (components.Length > 8)
                {
                    if (!ParseTilingParameter3(components[8], ref tileCenter, ref tileEdges, ref vertical))
                    {
                        return(false);
                    }
                }
                if (components.Length > 9)
                {
                    if (!ParseTilingParameter3(components[9], ref tileCenter, ref tileEdges, ref vertical))
                    {
                        return(false);
                    }
                }
                break;

            default:
                return(false);
            }

            image            = Create(texture, x, y, width, height, left, right);
            image.TileCenter = tileCenter;
            image.TileEdges  = tileEdges;
            image.Vertical   = vertical;
            return(true);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Converts the string representation of a stretchable image into an instance of the <see cref="StretchableImage3"/> 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 StretchableImage3 image)
 {
     return(TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out image));
 }