コード例 #1
0
        /// <summary>
        /// Creates a new instance of the <see cref="StaticImage"/> 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>
        /// <returns>The new instance of <see cref="StaticImage"/> that was created.</returns>
        public static StaticImage Create(Texture2D texture, Int32 x, Int32 y, Int32 width, Int32 height)
        {
            var img = new StaticImage();

            img.Texture       = texture;
            img.TextureRegion = new Rectangle(x, y, width, height);
            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();
        }
コード例 #3
0
        /// <summary>
        /// Converts the string representation of a static image into an instance of the <see cref="StaticImage"/> 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 StaticImage 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;

            image = null;

            if (components.Length != 5)
            {
                return(false);
            }

            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);
            }

            image = Create(texture, x, y, width, height);
            return(true);
        }
コード例 #4
0
 /// <summary>
 /// Converts the string representation of a static image into an instance of the <see cref="StaticImage"/> 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 StaticImage image)
 {
     return(TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out image));
 }