Example #1
0
        public override string ConvertToString(object value)
        {
            if (value == null)
            {
                return(string.Empty);
            }

            var    shadow = (Shadow)value;
            string result = shadow.BlurRadius.ToString() + " | " + shadow.Color.ToString();

            result += " | " + (shadow.Offset == null ? "0, 0" : Vector2TypeConverter.ToString(shadow.Offset));
            result += " | " + (shadow.Extents == null ? "0, 0" : Vector2TypeConverter.ToString(shadow.Extents));

            return(result);
        }
Example #2
0
        public override string ConvertToString(object value)
        {
            if (value == null)
            {
                return(string.Empty);
            }

            var    imageShadow = (ImageShadow)value;
            string result      = imageShadow.Url;

            result += " / " + (imageShadow.Offset == null ? "0, 0" : Vector2TypeConverter.ToString(imageShadow.Offset));
            result += " / " + (imageShadow.Extents == null ? "0, 0" : Vector2TypeConverter.ToString(imageShadow.Extents));

            return(result);
        }
Example #3
0
        public override object ConvertFromInvariantString(string value)
        {
            // "blurRadius | color [| offset] [| extents]"
            // Examples
            // "1.0 | #AABBCCFF"
            // "6.2 | #AABBCC | 5, 5"
            // "8.0 | #AABBCC | 5, 5 | 7, 8"

            if (string.IsNullOrEmpty(value))
            {
                return(new Shadow(0.0f, Color.Transparent));
            }

            var items = value.Split('|');

            if (items.Length < 2 || items.Length > 4)
            {
                return(new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Shadow)}"));
            }

            var     blurRadius = Single.Parse(items[0].Trim(), CultureInfo.InvariantCulture);
            var     color      = new Color(items[1].Trim());
            Vector2 offset     = null;
            Vector2 extents    = null;

            if (items.Length > 2)
            {
                offset = Vector2TypeConverter.FromString(items[2].Trim());
            }

            if (items.Length == 4)
            {
                extents = Vector2TypeConverter.FromString(items[3].Trim());
            }

            return(new Shadow(blurRadius, color, offset, extents));
        }
Example #4
0
        public override object ConvertFromInvariantString(string value)
        {
            // "imageUrl [| offset] [| extents]"
            // Examples
            // "*Resource*/image.9.png"
            // "*Resource*/image.9.png | 5, 5"
            // "*Resource*/image.9.png | 5, 5 | 7, 8"

            if (string.IsNullOrEmpty(value))
            {
                return(new ImageShadow(String.Empty));
            }

            var items = value.Split('|');

            if (items.Length < 1 || items.Length > 3)
            {
                return(new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(ImageShadow)}"));
            }

            var     url     = items[0].Trim();
            Vector2 offset  = null;
            Vector2 extents = null;

            if (items.Length > 1)
            {
                offset = Vector2TypeConverter.FromString(items[1].Trim());
            }

            if (items.Length == 3)
            {
                extents = Vector2TypeConverter.FromString(items[2].Trim());
            }

            return(new ImageShadow(url, offset, extents));
        }