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.
26 /// <since_tizen> 3 </since_tizen>
27 public class Color : global::System.IDisposable
29 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
33 /// <since_tizen> 3 </since_tizen>
34 protected bool swigCMemOwn;
36 internal Color(global::System.IntPtr cPtr, bool cMemoryOwn)
38 swigCMemOwn = cMemoryOwn;
39 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
42 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Color obj)
44 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
47 //A Flag to check who called Dispose(). (By User or DisposeQueue)
48 private bool isDisposeQueued = false;
51 /// A Flat to check if it is already disposed.
53 /// <since_tizen> 3 </since_tizen>
54 protected bool disposed = false;
59 /// <since_tizen> 3 </since_tizen>
64 isDisposeQueued = true;
65 DisposeQueue.Instance.Add(this);
70 /// To make a color instance be disposed.
72 /// <since_tizen> 3 </since_tizen>
75 //Throw excpetion if Dispose() is called in separate thread.
76 if (!Window.IsInstalled())
78 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
83 Dispose(DisposeTypes.Implicit);
87 Dispose(DisposeTypes.Explicit);
88 System.GC.SuppressFinalize(this);
95 /// <since_tizen> 3 </since_tizen>
96 protected virtual void Dispose(DisposeTypes type)
103 if(type == DisposeTypes.Explicit)
106 //Release your own managed resources here.
107 //You should release all of your own disposable objects here.
110 //Release your own unmanaged resources here.
111 //You should not access any managed member here except static instance.
112 //because the execution order of Finalizes is non-deterministic.
114 if (swigCPtr.Handle != global::System.IntPtr.Zero)
119 NDalicPINVOKE.delete_Vector4(swigCPtr);
121 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
127 /// The addition operator.
129 /// <param name="arg1">The first value.</param>
130 /// <param name="arg2">The second value.</param>
131 /// <returns>The color containing the result of the addition.</returns>
132 /// <since_tizen> 3 </since_tizen>
133 public static Color operator +(Color arg1, Color arg2)
135 Color result = arg1.Add(arg2);
136 return ValueCheck(result);
140 /// The subtraction operator.
142 /// <param name="arg1">The first value.</param>
143 /// <param name="arg2">The second value.</param>
144 /// <returns>The color containing the result of the subtraction.</returns>
145 /// <since_tizen> 3 </since_tizen>
146 public static Color operator -(Color arg1, Color arg2)
148 Color result = arg1.Subtract(arg2);
149 return ValueCheck(result);
153 /// The unary negation operator.
155 /// <param name="arg1">The target value.</param>
156 /// <returns>The color containg the negation.</returns>
157 /// <since_tizen> 3 </since_tizen>
158 public static Color operator -(Color arg1)
160 Color result = arg1.Subtract();
161 return ValueCheck(result);
165 /// The multiplication operator.
167 /// <param name="arg1">The first value.</param>
168 /// <param name="arg2">The second value.</param>
169 /// <returns>The color containing the result of the multiplication.</returns>
170 /// <since_tizen> 3 </since_tizen>
171 public static Color operator *(Color arg1, Color arg2)
173 Color result = arg1.Multiply(arg2);
174 return ValueCheck(result);
178 /// The multiplication operator.
180 /// <param name="arg1">The first value.</param>
181 /// <param name="arg2">The second value.</param>
182 /// <returns>The color containing the result of the multiplication.</returns>
183 /// <since_tizen> 3 </since_tizen>
184 public static Color operator*(Color arg1, float arg2)
186 Color result = arg1.Multiply(arg2);
187 return ValueCheck(result);
191 /// The division operator.
193 /// <param name="arg1">The first value.</param>
194 /// <param name="arg2">The second value.</param>
195 /// <returns>The color containing the result of the division.</returns>
196 /// <since_tizen> 3 </since_tizen>
197 public static Color operator /(Color arg1, Color arg2)
199 Color result = arg1.Divide(arg2);
200 return ValueCheck(result);
204 /// The division operator.
206 /// <param name="arg1">The first value.</param>
207 /// <param name="arg2">The second value.</param>
208 /// <returns>The color containing the result of the division.</returns>
209 /// <since_tizen> 3 </since_tizen>
210 public static Color operator/(Color arg1, float arg2)
212 Color result = arg1.Divide(arg2);
213 return ValueCheck(result);
217 /// The array subscript operator overload.
219 /// <param name="index">The subscript index.</param>
220 /// <returns>The float at the given index.</returns>
221 /// <since_tizen> 3 </since_tizen>
222 public float this[uint index]
226 return ValueOfIndex(index);
230 internal static Color GetColorFromPtr(global::System.IntPtr cPtr)
232 Color ret = new Color(cPtr, false);
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 /// Default constructor
240 /// <since_tizen> 3 </since_tizen>
241 public Color() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true)
243 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250 /// <param name="r">The red component.</param>
251 /// <param name="g">The green component.</param>
252 /// <param name="b">The blue component.</param>
253 /// <param name="a">The alpha component.</param>
254 /// <since_tizen> 3 </since_tizen>
255 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)
257 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 /// The conversion constructor from an array of four floats.
263 /// <param name="array">array Array of R,G,B,A.</param>
264 /// <since_tizen> 3 </since_tizen>
265 public Color(float[] array) : this(NDalicPINVOKE.new_Vector4__SWIG_2(ValueCheck(array)), true)
267 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270 private Color Add(Color rhs)
272 Color ret = new Color(NDalicPINVOKE.Vector4_Add(swigCPtr, Color.getCPtr(rhs)), true);
273 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277 private Color AddAssign(Vector4 rhs)
279 Color ret = new Color(NDalicPINVOKE.Vector4_AddAssign(swigCPtr, Color.getCPtr(rhs)), false);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284 private Color Subtract(Color rhs)
286 Color ret = new Color(NDalicPINVOKE.Vector4_Subtract__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
287 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 private Color SubtractAssign(Color rhs)
293 Color ret = new Color(NDalicPINVOKE.Vector4_SubtractAssign(swigCPtr, Color.getCPtr(rhs)), false);
294 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298 private Color Multiply(Color rhs)
300 Color ret = new Color(NDalicPINVOKE.Vector4_Multiply__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
301 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305 private Color Multiply(float rhs)
307 Color ret = new Color(NDalicPINVOKE.Vector4_Multiply__SWIG_1(swigCPtr, rhs), true);
308 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312 private Color MultiplyAssign(Color rhs)
314 Color ret = new Color(NDalicPINVOKE.Vector4_MultiplyAssign__SWIG_0(swigCPtr, Color.getCPtr(rhs)), false);
315 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319 private Color MultiplyAssign(float rhs)
321 Color ret = new Color(NDalicPINVOKE.Vector4_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
322 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
326 private Color Divide(Vector4 rhs)
328 Color ret = new Color(NDalicPINVOKE.Vector4_Divide__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
329 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333 private Color Divide(float rhs)
335 Color ret = new Color(NDalicPINVOKE.Vector4_Divide__SWIG_1(swigCPtr, rhs), true);
336 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340 private Color DivideAssign(Color rhs)
342 Color ret = new Color(NDalicPINVOKE.Vector4_DivideAssign__SWIG_0(swigCPtr, Color.getCPtr(rhs)), false);
343 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
347 private Color DivideAssign(float rhs)
349 Color ret = new Color(NDalicPINVOKE.Vector4_DivideAssign__SWIG_1(swigCPtr, rhs), false);
350 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
354 private Color Subtract()
356 Color ret = new Color(NDalicPINVOKE.Vector4_Subtract__SWIG_1(swigCPtr), true);
357 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 /// Checks if two color classes are same.
364 /// <param name="rhs">A color to be compared.</param>
365 /// <returns>If two colors are are same, then true.</returns>
366 /// <since_tizen> 3 </since_tizen>
367 public bool EqualTo(Color rhs)
369 bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, Color.getCPtr(rhs));
371 if (rhs == null) return false;
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 /// Checks if two color classes are different.
380 /// <param name="rhs">A color to be compared.</param>
381 /// <returns>If two colors are are different, then true.</returns>
382 /// <since_tizen> 3 </since_tizen>
383 public bool NotEqualTo(Color rhs)
385 bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, Color.getCPtr(rhs));
386 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391 private float ValueOfIndex(uint index)
393 float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index);
394 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
399 /// The red component.
401 /// <since_tizen> 3 </since_tizen>
406 NDalicPINVOKE.Vector4_r_set(swigCPtr, ValueCheck(value));
407 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
411 float ret = NDalicPINVOKE.Vector4_r_get(swigCPtr);
412 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
418 /// The green component.
420 /// <since_tizen> 3 </since_tizen>
425 NDalicPINVOKE.Vector4_g_set(swigCPtr, ValueCheck(value));
426 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
430 float ret = NDalicPINVOKE.Vector4_g_get(swigCPtr);
431 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
437 /// The blue component.
439 /// <since_tizen> 3 </since_tizen>
444 NDalicPINVOKE.Vector4_b_set(swigCPtr, ValueCheck(value));
445 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
449 float ret = NDalicPINVOKE.Vector4_b_get(swigCPtr);
450 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
456 /// The alpha component.
458 /// <since_tizen> 3 </since_tizen>
463 NDalicPINVOKE.Vector4_a_set(swigCPtr, ValueCheck(value));
464 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
468 float ret = NDalicPINVOKE.Vector4_a_get(swigCPtr);
469 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
475 /// Gets the black colored Color class.
477 /// <since_tizen> 3 </since_tizen>
478 public static readonly Color Black = new Color(0.0f, 0.0f, 0.0f, 1.0f);
481 /// Gets the white colored Color class.
483 /// <since_tizen> 3 </since_tizen>
484 public static readonly Color White = new Color(1.0f, 1.0f, 1.0f, 1.0f);
487 /// Gets the red colored Color class.
489 /// <since_tizen> 3 </since_tizen>
490 public static readonly Color Red = new Color(1.0f, 0.0f, 0.0f, 1.0f);
493 /// Gets the green colored Color class.
495 /// <since_tizen> 3 </since_tizen>
496 public static readonly Color Green = new Color(0.0f, 1.0f, 0.0f, 1.0f);
499 /// Gets the blue colored Color class.
501 /// <since_tizen> 3 </since_tizen>
502 public static readonly Color Blue = new Color(0.0f, 0.0f, 1.0f, 1.0f);
505 /// Gets the yellow colored Color class.
507 /// <since_tizen> 3 </since_tizen>
508 public static readonly Color Yellow = new Color(1.0f, 1.0f, 0.0f, 1.0f);
511 /// Gets the magenta colored Color class.
513 /// <since_tizen> 3 </since_tizen>
514 public static readonly Color Magenta = new Color(1.0f, 0.0f, 1.0f, 1.0f);
517 /// Gets the cyan colored Color class.
519 /// <since_tizen> 3 </since_tizen>
520 public static readonly Color Cyan = new Color(0.0f, 1.0f, 1.0f, 1.0f);
523 /// Gets the transparent colored Color class.
525 /// <since_tizen> 3 </since_tizen>
526 public static readonly Color Transparent = new Color(0.0f, 0.0f, 0.0f, 0.0f);
529 /// Converts the Color class to Vector4 class implicitly.
531 /// <param name="color">A color to be converted to Vector4</param>
532 /// <since_tizen> 3 </since_tizen>
533 public static implicit operator Vector4(Color color)
535 return new Vector4(color.R, color.G, color.B, color.A);
539 /// Converts Vector4 class to Color class implicitly.
541 /// <param name="vec">A Vector4 to be converted to color.</param>
542 /// <since_tizen> 3 </since_tizen>
543 public static implicit operator Color(Vector4 vec)
545 return new Color(vec.R, vec.G, vec.B, vec.A);
548 internal static Color ValueCheck(Color color)
553 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
555 else if (color.R > 1.0f)
558 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
563 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
565 else if (color.G > 1.0f)
568 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
573 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
575 else if (color.B > 1.0f)
578 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
583 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
585 else if (color.A > 1.0f)
588 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
593 internal static float ValueCheck(float value)
598 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
600 else if (value > 1.0f)
603 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
608 internal static float[] ValueCheck(float[] arr)
610 for(int i = 0; i < arr.Length; i++)
615 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
617 else if (arr[i] > 1.0f)
620 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");