2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 using System.Reflection;
21 using System.Globalization;
24 using System.ComponentModel;
26 namespace Tizen.NUI.Binding
28 //Internal used, will never open
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 public class Vector2TypeConverter : TypeConverter
32 //Internal used, will never open
33 [EditorBrowsable(EditorBrowsableState.Never)]
34 public override object ConvertFromInvariantString(string value)
38 return FromString(value);
41 throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector2)}");
44 //Internal used, will never open
45 [EditorBrowsable(EditorBrowsableState.Never)]
46 public override string ConvertToString(object value)
48 return ToString(value as Vector2);
51 internal static Vector2 FromString(string value)
53 var parts = value.Split(',');
55 if (parts.Length != 2)
57 throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector2)}");
60 return new Vector2(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture));
63 internal static string ToString(Vector2 value)
67 return value.X.ToString() + " " + value.Y.ToString();
76 //Internal used, will never open
77 [EditorBrowsable(EditorBrowsableState.Never)]
78 public class Vector3TypeConverter : TypeConverter
80 //Internal used, will never open
81 [EditorBrowsable(EditorBrowsableState.Never)]
82 public override object ConvertFromInvariantString(string value)
86 string[] parts = value.Split(',');
87 if (parts.Length == 3)
89 return new Vector3(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture),
90 Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture),
91 Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture));
95 throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector3)}");
98 //Internal used, will never open
99 [EditorBrowsable(EditorBrowsableState.Never)]
100 public override string ConvertToString(object value)
102 Vector3 vector = value as Vector3;
105 return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString();
114 //Internal used, will never open
115 [EditorBrowsable(EditorBrowsableState.Never)]
116 public class Vector4TypeConverter : TypeConverter
118 //Internal used, will never open
119 [EditorBrowsable(EditorBrowsableState.Never)]
120 public override object ConvertFromInvariantString(string value)
124 string[] parts = value.Split(',');
125 if (parts.Length == 4)
127 return new Vector4(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture),
128 Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture),
129 Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture),
130 Single.Parse(parts[3].Trim(), CultureInfo.InvariantCulture));
134 throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Vector4)}");
137 //Internal used, will never open
138 [EditorBrowsable(EditorBrowsableState.Never)]
139 public override string ConvertToString(object value)
141 Vector4 vector = value as Vector4;
144 return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString() + " " + vector.W.ToString();
153 //Internal used, will never open
154 [EditorBrowsable(EditorBrowsableState.Never)]
155 public class RelativeVector2TypeConverter : TypeConverter
157 //Internal used, will never open
158 [EditorBrowsable(EditorBrowsableState.Never)]
159 public override object ConvertFromInvariantString(string value)
163 string[] parts = value.Split(',');
164 if (parts.Length == 2)
166 return new RelativeVector2(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture),
167 Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture));
171 throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(RelativeVector2)}");
174 //Internal used, will never open
175 [EditorBrowsable(EditorBrowsableState.Never)]
176 public override string ConvertToString(object value)
178 RelativeVector2 vector = value as RelativeVector2;
181 return vector.X.ToString() + " " + vector.Y.ToString();
190 //Internal used, will never open
191 [EditorBrowsable(EditorBrowsableState.Never)]
192 public class RelativeVector3TypeConverter : TypeConverter
194 //Internal used, will never open
195 [EditorBrowsable(EditorBrowsableState.Never)]
196 public override object ConvertFromInvariantString(string value)
200 string[] parts = value.Split(',');
201 if (parts.Length == 3)
203 return new RelativeVector3(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture),
204 Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture),
205 Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture));
209 throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(RelativeVector3)}");
212 //Internal used, will never open
213 [EditorBrowsable(EditorBrowsableState.Never)]
214 public override string ConvertToString(object value)
216 RelativeVector3 vector = value as RelativeVector3;
219 return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString();
228 //Internal used, will never open
229 [EditorBrowsable(EditorBrowsableState.Never)]
230 public class RelativeVector4TypeConverter : TypeConverter
232 //Internal used, will never open
233 [EditorBrowsable(EditorBrowsableState.Never)]
234 public override object ConvertFromInvariantString(string value)
238 string[] parts = value.Split(',');
239 if (parts.Length == 4)
241 return new RelativeVector4(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture),
242 Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture),
243 Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture),
244 Single.Parse(parts[3].Trim(), CultureInfo.InvariantCulture));
248 throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(RelativeVector4)}");
251 //Internal used, will never open
252 [EditorBrowsable(EditorBrowsableState.Never)]
253 public override string ConvertToString(object value)
255 RelativeVector4 vector = value as RelativeVector4;
258 return vector.X.ToString() + " " + vector.Y.ToString() + " " + vector.Z.ToString() + " " + vector.W.ToString();