(ded4a3e0a) v0.9.0.7

This commit is contained in:
Joonas Rikkonen
2019-06-25 16:00:44 +03:00
parent e5ae622c77
commit 4a51db77b5
1777 changed files with 421528 additions and 917 deletions
@@ -0,0 +1,72 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.ComponentModel;
using System.Globalization;
namespace Microsoft.Xna.Framework.Design
{
public class Vector2TypeConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (VectorConversion.CanConvertTo(context, destinationType))
return true;
if (destinationType == typeof(string))
return true;
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
var vec = (Vector2)value;
if (VectorConversion.CanConvertTo(context, destinationType))
{
var vec4 = new Vector4(vec.X, vec.Y, 0.0f, 0.0f);
return VectorConversion.ConvertToFromVector4(context, culture, vec4, destinationType);
}
if (destinationType == typeof(string))
{
var terms = new string[2];
terms[0] = vec.X.ToString("R", culture);
terms[1] = vec.Y.ToString("R", culture);
return string.Join(culture.TextInfo.ListSeparator + " ", terms);
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
return true;
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var sourceType = value.GetType();
var vec = Vector2.Zero;
if (sourceType == typeof(string))
{
var str = (string)value;
var words = str.Split(culture.TextInfo.ListSeparator.ToCharArray());
vec.X = float.Parse(words[0], culture);
vec.Y = float.Parse(words[1], culture);
return vec;
}
return base.ConvertFrom(context, culture, value);
}
}
}
@@ -0,0 +1,74 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.ComponentModel;
using System.Globalization;
namespace Microsoft.Xna.Framework.Design
{
public class Vector3TypeConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (VectorConversion.CanConvertTo(context, destinationType))
return true;
if (destinationType == typeof(string))
return true;
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
var vec = (Vector3)value;
if (VectorConversion.CanConvertTo(context, destinationType))
{
var vec4 = new Vector4(vec.X, vec.Y, vec.Z, 0.0f);
return VectorConversion.ConvertToFromVector4(context, culture, vec4, destinationType);
}
if (destinationType == typeof(string))
{
var terms = new string[3];
terms[0] = vec.X.ToString("R", culture);
terms[1] = vec.Y.ToString("R", culture);
terms[2] = vec.Z.ToString("R", culture);
return string.Join(culture.TextInfo.ListSeparator + " ", terms);
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
return true;
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var sourceType = value.GetType();
var vec = Vector3.Zero;
if (sourceType == typeof(string))
{
var str = (string)value;
var words = str.Split(culture.TextInfo.ListSeparator.ToCharArray());
vec.X = float.Parse(words[0], culture);
vec.Y = float.Parse(words[1], culture);
vec.Z = float.Parse(words[2], culture);
return vec;
}
return base.ConvertFrom(context, culture, value);
}
}
}
@@ -0,0 +1,76 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.ComponentModel;
using System.Globalization;
namespace Microsoft.Xna.Framework.Design
{
public class Vector4TypeConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (VectorConversion.CanConvertTo(context, destinationType))
return true;
if (destinationType == typeof(string))
return true;
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
var vec = (Vector4)value;
if (VectorConversion.CanConvertTo(context, destinationType))
{
return VectorConversion.ConvertToFromVector4(context, culture, vec, destinationType);
}
if (destinationType == typeof(string))
{
var terms = new string[4];
terms[0] = vec.X.ToString("R", culture);
terms[1] = vec.Y.ToString("R", culture);
terms[2] = vec.Z.ToString("R", culture);
terms[3] = vec.W.ToString("R", culture);
return string.Join(culture.TextInfo.ListSeparator + " ", terms);
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
return true;
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var sourceType = value.GetType();
var vec = Vector4.Zero;
if (sourceType == typeof(string))
{
var str = (string)value;
var words = str.Split(culture.TextInfo.ListSeparator.ToCharArray());
vec.X = float.Parse(words[0], culture);
vec.Y = float.Parse(words[1], culture);
vec.Z = float.Parse(words[2], culture);
vec.W = float.Parse(words[3], culture);
return vec;
}
return base.ConvertFrom(context, culture, value);
}
}
}
@@ -0,0 +1,46 @@
using System;
using System.ComponentModel;
using System.Globalization;
using Microsoft.Xna.Framework.Graphics.PackedVector;
namespace Microsoft.Xna.Framework.Design
{
internal static class VectorConversion
{
public static bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(float))
return true;
if (destinationType == typeof(Vector2))
return true;
if (destinationType == typeof(Vector3))
return true;
if (destinationType == typeof(Vector4))
return true;
if (destinationType.GetInterface("IPackedVector") != null)
return true;
return false;
}
public static object ConvertToFromVector4(ITypeDescriptorContext context, CultureInfo culture, Vector4 value, Type destinationType)
{
if (destinationType == typeof(float))
return value.X;
if (destinationType == typeof(Vector2))
return new Vector2(value.X, value.Y);
if (destinationType == typeof(Vector3))
return new Vector3(value.X, value.Y, value.Z);
if (destinationType == typeof(Vector4))
return new Vector4(value.X, value.Y, value.Z, value.W);
if (destinationType.GetInterface("IPackedVector") != null)
{
var packedVec = (IPackedVector)Activator.CreateInstance(destinationType);
packedVec.PackFromVector4(value);
return packedVec;
}
return null;
}
}
}