2 * Copyright(c) 2017 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.
19 using Tizen.NUI.Binding;
27 [TypeConverter(typeof(ColorTypeConverter))]
28 public class Color : global::System.IDisposable
32 /// Gets the black colored Color class.
34 /// <since_tizen> 3 </since_tizen>
35 public static readonly Color Black = new Color(0.0f, 0.0f, 0.0f, 1.0f);
38 /// Gets the white colored Color class.
40 /// <since_tizen> 3 </since_tizen>
41 public static readonly Color White = new Color(1.0f, 1.0f, 1.0f, 1.0f);
44 /// Gets the red colored Color class.
46 /// <since_tizen> 3 </since_tizen>
47 public static readonly Color Red = new Color(1.0f, 0.0f, 0.0f, 1.0f);
50 /// Gets the green colored Color class.
52 /// <since_tizen> 3 </since_tizen>
53 public static readonly Color Green = new Color(0.0f, 1.0f, 0.0f, 1.0f);
56 /// Gets the blue colored Color class.
58 /// <since_tizen> 3 </since_tizen>
59 public static readonly Color Blue = new Color(0.0f, 0.0f, 1.0f, 1.0f);
62 /// Gets the yellow colored Color class.
64 /// <since_tizen> 3 </since_tizen>
65 public static readonly Color Yellow = new Color(1.0f, 1.0f, 0.0f, 1.0f);
68 /// Gets the magenta colored Color class.
70 /// <since_tizen> 3 </since_tizen>
71 public static readonly Color Magenta = new Color(1.0f, 0.0f, 1.0f, 1.0f);
74 /// Gets the cyan colored Color class.
76 /// <since_tizen> 3 </since_tizen>
77 public static readonly Color Cyan = new Color(0.0f, 1.0f, 1.0f, 1.0f);
80 /// Gets the transparent colored Color class.
82 /// <since_tizen> 3 </since_tizen>
83 public static readonly Color Transparent = new Color(0.0f, 0.0f, 0.0f, 0.0f);
88 /// <since_tizen> 3 </since_tizen>
89 protected bool swigCMemOwn;
92 /// A Flat to check if it is already disposed.
94 /// <since_tizen> 3 </since_tizen>
95 protected bool disposed = false;
97 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
98 //A Flag to check who called Dispose(). (By User or DisposeQueue)
99 private bool isDisposeQueued = false;
102 /// Default constructor
104 /// <since_tizen> 3 </since_tizen>
105 public Color() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true)
107 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114 /// <param name="r">The red component.</param>
115 /// <param name="g">The green component.</param>
116 /// <param name="b">The blue component.</param>
117 /// <param name="a">The alpha component.</param>
118 /// <since_tizen> 3 </since_tizen>
119 public Color(float r, float g, float b, float a) : this(NDalicPINVOKE.new_Vector4__SWIG_1(ValueCheck(r), ValueCheck(g), ValueCheck(b), ValueCheck(a)), true)
121 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
125 /// The conversion constructor from an array of four floats.
127 /// <param name="array">array Array of R,G,B,A.</param>
128 /// <since_tizen> 3 </since_tizen>
129 public Color(float[] array) : this(NDalicPINVOKE.new_Vector4__SWIG_2(ValueCheck(array)), true)
131 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134 internal Color(global::System.IntPtr cPtr, bool cMemoryOwn)
136 swigCMemOwn = cMemoryOwn;
137 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
143 /// <since_tizen> 3 </since_tizen>
146 if (!isDisposeQueued)
148 isDisposeQueued = true;
149 DisposeQueue.Instance.Add(this);
154 /// The red component.
156 /// <since_tizen> 3 </since_tizen>
161 NDalicPINVOKE.Vector4_r_set(swigCPtr, ValueCheck(value));
162 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
166 float ret = NDalicPINVOKE.Vector4_r_get(swigCPtr);
167 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173 /// The green component.
175 /// <since_tizen> 3 </since_tizen>
180 NDalicPINVOKE.Vector4_g_set(swigCPtr, ValueCheck(value));
181 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185 float ret = NDalicPINVOKE.Vector4_g_get(swigCPtr);
186 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
192 /// The blue component.
194 /// <since_tizen> 3 </since_tizen>
199 NDalicPINVOKE.Vector4_b_set(swigCPtr, ValueCheck(value));
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204 float ret = NDalicPINVOKE.Vector4_b_get(swigCPtr);
205 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211 /// The alpha component.
213 /// <since_tizen> 3 </since_tizen>
218 NDalicPINVOKE.Vector4_a_set(swigCPtr, ValueCheck(value));
219 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223 float ret = NDalicPINVOKE.Vector4_a_get(swigCPtr);
224 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230 /// The array subscript operator overload.
232 /// <param name="index">The subscript index.</param>
233 /// <returns>The float at the given index.</returns>
234 /// <since_tizen> 3 </since_tizen>
235 public float this[uint index]
239 return ValueOfIndex(index);
244 /// Converts the Color class to Vector4 class implicitly.
246 /// <param name="color">A color to be converted to Vector4</param>
247 /// <since_tizen> 3 </since_tizen>
248 public static implicit operator Vector4(Color color)
250 return new Vector4(color.R, color.G, color.B, color.A);
254 /// Converts Vector4 class to Color class implicitly.
256 /// <param name="vec">A Vector4 to be converted to color.</param>
257 /// <since_tizen> 3 </since_tizen>
258 public static implicit operator Color(Vector4 vec)
260 return new Color(vec.R, vec.G, vec.B, vec.A);
264 /// The addition operator.
266 /// <param name="arg1">The first value.</param>
267 /// <param name="arg2">The second value.</param>
268 /// <returns>The color containing the result of the addition.</returns>
269 /// <since_tizen> 3 </since_tizen>
270 public static Color operator +(Color arg1, Color arg2)
272 Color result = arg1.Add(arg2);
273 return ValueCheck(result);
277 /// The subtraction operator.
279 /// <param name="arg1">The first value.</param>
280 /// <param name="arg2">The second value.</param>
281 /// <returns>The color containing the result of the subtraction.</returns>
282 /// <since_tizen> 3 </since_tizen>
283 public static Color operator -(Color arg1, Color arg2)
285 Color result = arg1.Subtract(arg2);
286 return ValueCheck(result);
290 /// The unary negation operator.
292 /// <param name="arg1">The target value.</param>
293 /// <returns>The color containg the negation.</returns>
294 /// <since_tizen> 3 </since_tizen>
295 public static Color operator -(Color arg1)
297 Color result = arg1.Subtract();
298 return ValueCheck(result);
302 /// The multiplication operator.
304 /// <param name="arg1">The first value.</param>
305 /// <param name="arg2">The second value.</param>
306 /// <returns>The color containing the result of the multiplication.</returns>
307 /// <since_tizen> 3 </since_tizen>
308 public static Color operator *(Color arg1, Color arg2)
310 Color result = arg1.Multiply(arg2);
311 return ValueCheck(result);
315 /// The multiplication operator.
317 /// <param name="arg1">The first value.</param>
318 /// <param name="arg2">The second value.</param>
319 /// <returns>The color containing the result of the multiplication.</returns>
320 /// <since_tizen> 3 </since_tizen>
321 public static Color operator *(Color arg1, float arg2)
323 Color result = arg1.Multiply(arg2);
324 return ValueCheck(result);
328 /// The division operator.
330 /// <param name="arg1">The first value.</param>
331 /// <param name="arg2">The second value.</param>
332 /// <returns>The color containing the result of the division.</returns>
333 /// <since_tizen> 3 </since_tizen>
334 public static Color operator /(Color arg1, Color arg2)
336 Color result = arg1.Divide(arg2);
337 return ValueCheck(result);
341 /// The division operator.
343 /// <param name="arg1">The first value.</param>
344 /// <param name="arg2">The second value.</param>
345 /// <returns>The color containing the result of the division.</returns>
346 /// <since_tizen> 3 </since_tizen>
347 public static Color operator /(Color arg1, float arg2)
349 Color result = arg1.Divide(arg2);
350 return ValueCheck(result);
354 /// To make a color instance be disposed.
356 /// <since_tizen> 3 </since_tizen>
357 public void Dispose()
359 //Throw excpetion if Dispose() is called in separate thread.
360 if (!Window.IsInstalled())
362 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
367 Dispose(DisposeTypes.Implicit);
371 Dispose(DisposeTypes.Explicit);
372 System.GC.SuppressFinalize(this);
377 /// Checks if two color classes are same.
379 /// <param name="rhs">A color to be compared.</param>
380 /// <returns>If two colors are are same, then true.</returns>
381 /// <since_tizen> 3 </since_tizen>
382 public bool EqualTo(Color rhs)
384 bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, Color.getCPtr(rhs));
386 if (rhs == null) return false;
388 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
393 /// Checks if two color classes are different.
395 /// <param name="rhs">A color to be compared.</param>
396 /// <returns>If two colors are are different, then true.</returns>
397 /// <since_tizen> 3 </since_tizen>
398 public bool NotEqualTo(Color rhs)
400 bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, Color.getCPtr(rhs));
401 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Color obj)
407 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
410 internal static Color GetColorFromPtr(global::System.IntPtr cPtr)
412 Color ret = new Color(cPtr, false);
413 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
417 internal static Color ValueCheck(Color color)
422 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
424 else if (color.R > 1.0f)
427 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
432 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
434 else if (color.G > 1.0f)
437 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
442 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
444 else if (color.B > 1.0f)
447 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
452 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
454 else if (color.A > 1.0f)
457 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
462 internal static float ValueCheck(float value)
467 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
469 else if (value > 1.0f)
472 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
477 internal static float[] ValueCheck(float[] arr)
479 for (int i = 0; i < arr.Length; i++)
484 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
486 else if (arr[i] > 1.0f)
489 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
498 /// <since_tizen> 3 </since_tizen>
499 protected virtual void Dispose(DisposeTypes type)
506 if(type == DisposeTypes.Explicit)
509 //Release your own managed resources here.
510 //You should release all of your own disposable objects here.
513 //Release your own unmanaged resources here.
514 //You should not access any managed member here except static instance.
515 //because the execution order of Finalizes is non-deterministic.
517 if (swigCPtr.Handle != global::System.IntPtr.Zero)
522 NDalicPINVOKE.delete_Vector4(swigCPtr);
524 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
529 private Color Add(Color rhs)
531 Color ret = new Color(NDalicPINVOKE.Vector4_Add(swigCPtr, Color.getCPtr(rhs)), true);
532 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
536 private Color AddAssign(Vector4 rhs)
538 Color ret = new Color(NDalicPINVOKE.Vector4_AddAssign(swigCPtr, Color.getCPtr(rhs)), false);
539 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
543 private Color Subtract(Color rhs)
545 Color ret = new Color(NDalicPINVOKE.Vector4_Subtract__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
546 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
550 private Color SubtractAssign(Color rhs)
552 Color ret = new Color(NDalicPINVOKE.Vector4_SubtractAssign(swigCPtr, Color.getCPtr(rhs)), false);
553 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
557 private Color Multiply(Color rhs)
559 Color ret = new Color(NDalicPINVOKE.Vector4_Multiply__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
560 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
564 private Color Multiply(float rhs)
566 Color ret = new Color(NDalicPINVOKE.Vector4_Multiply__SWIG_1(swigCPtr, rhs), true);
567 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
571 private Color MultiplyAssign(Color rhs)
573 Color ret = new Color(NDalicPINVOKE.Vector4_MultiplyAssign__SWIG_0(swigCPtr, Color.getCPtr(rhs)), false);
574 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
578 private Color MultiplyAssign(float rhs)
580 Color ret = new Color(NDalicPINVOKE.Vector4_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
581 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
585 private Color Divide(Vector4 rhs)
587 Color ret = new Color(NDalicPINVOKE.Vector4_Divide__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
588 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
592 private Color Divide(float rhs)
594 Color ret = new Color(NDalicPINVOKE.Vector4_Divide__SWIG_1(swigCPtr, rhs), true);
595 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
599 private Color DivideAssign(Color rhs)
601 Color ret = new Color(NDalicPINVOKE.Vector4_DivideAssign__SWIG_0(swigCPtr, Color.getCPtr(rhs)), false);
602 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
606 private Color DivideAssign(float rhs)
608 Color ret = new Color(NDalicPINVOKE.Vector4_DivideAssign__SWIG_1(swigCPtr, rhs), false);
609 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
613 private Color Subtract()
615 Color ret = new Color(NDalicPINVOKE.Vector4_Subtract__SWIG_1(swigCPtr), true);
616 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
620 private float ValueOfIndex(uint index)
622 float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index);
623 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();