Пример #1
0
 public static object ConvertFrom(object value)
 {
     if (value.GetType() == typeof(string))
     {
         string[]          vals = value.ToString().Split(' ');
         UrhoBackend.Color ret  = new UrhoBackend.Color();
         for (int i = 0; i < vals.Length; ++i)
         {
             float fval = 0.0f;
             float.TryParse(vals[i], out fval);
             ret.Set(i, fval);
         }
         return(ret);
     }
     else if (value.GetType() == typeof(System.Drawing.Color))
     {
         System.Drawing.Color c   = (System.Drawing.Color)value;
         UrhoBackend.Color    ret = new UrhoBackend.Color();
         ret.r = c.R / 255.0f;
         ret.g = c.G / 255.0f;
         ret.b = c.B / 255.0f;
         ret.a = c.A / 255.0f;
         return(ret);
     }
     return(value);
 }
Пример #2
0
 public static object ConvertTo(object value, Type destinationType)
 {
     if (destinationType == typeof(string))
     {
         UrhoBackend.Color col = value as UrhoBackend.Color;
         return(String.Format("{0} {1} {2} {3}", col.r, col.g, col.b, col.a));
     }
     else if (destinationType == typeof(System.Drawing.Color))
     {
         UrhoBackend.Color col = value as UrhoBackend.Color;
         return(System.Drawing.Color.FromArgb((byte)(col.a * 255), (byte)(col.r * 255), (byte)(col.g * 255), (byte)(col.b * 255)));
     }
     return(value);
 }