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 public class Color : global::System.IDisposable
28 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32 protected bool swigCMemOwn;
34 internal Color(global::System.IntPtr cPtr, bool cMemoryOwn)
36 swigCMemOwn = cMemoryOwn;
37 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
40 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Color obj)
42 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
45 //A Flag to check who called Dispose(). (By User or DisposeQueue)
46 private bool isDisposeQueued = false;
49 /// A Flat to check if it is already disposed.
51 /// <since_tizen> 3 </since_tizen>
52 protected bool disposed = false;
57 /// <since_tizen> 3 </since_tizen>
62 isDisposeQueued = true;
63 DisposeQueue.Instance.Add(this);
68 /// To make a color instance be disposed.
70 /// <since_tizen> 3 </since_tizen>
73 //Throw excpetion if Dispose() is called in separate thread.
74 if (!Window.IsInstalled())
76 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
81 Dispose(DisposeTypes.Implicit);
85 Dispose(DisposeTypes.Explicit);
86 System.GC.SuppressFinalize(this);
93 /// <since_tizen> 3 </since_tizen>
94 protected virtual void Dispose(DisposeTypes type)
101 if(type == DisposeTypes.Explicit)
104 //Release your own managed resources here.
105 //You should release all of your own disposable objects here.
108 //Release your own unmanaged resources here.
109 //You should not access any managed member here except static instance.
110 //because the execution order of Finalizes is non-deterministic.
112 if (swigCPtr.Handle != global::System.IntPtr.Zero)
117 NDalicPINVOKE.delete_Vector4(swigCPtr);
119 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
125 /// The addition operator.
127 /// <param name="arg1">The first value.</param>
128 /// <param name="arg2">The second value.</param>
129 /// <returns>The color containing the result of the addition.</returns>
130 /// <since_tizen> 3 </since_tizen>
131 public static Color operator +(Color arg1, Color arg2)
133 Color result = arg1.Add(arg2);
139 /// The subtraction operator.
141 /// <param name="arg1">The first value.</param>
142 /// <param name="arg2">The second value.</param>
143 /// <returns>The color containing the result of the subtraction.</returns>
144 /// <since_tizen> 3 </since_tizen>
145 public static Color operator -(Color arg1, Color arg2)
147 Color result = arg1.Subtract(arg2);
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();
166 /// The multiplication operator.
168 /// <param name="arg1">The first value.</param>
169 /// <param name="arg2">The second value.</param>
170 /// <returns>The color containing the result of the multiplication.</returns>
171 /// <since_tizen> 3 </since_tizen>
172 public static Color operator *(Color arg1, Color arg2)
174 Color result = arg1.Multiply(arg2);
180 /// The multiplication operator.
182 /// <param name="arg1">The first value.</param>
183 /// <param name="arg2">The second value.</param>
184 /// <returns>The color containing the result of the multiplication.</returns>
185 /// <since_tizen> 3 </since_tizen>
186 public static Color operator*(Color arg1, float arg2)
188 Color result = arg1.Multiply(arg2);
194 /// The division operator.
196 /// <param name="arg1">The first value.</param>
197 /// <param name="arg2">The second value.</param>
198 /// <returns>The color containing the result of the division.</returns>
199 /// <since_tizen> 3 </since_tizen>
200 public static Color operator /(Color arg1, Color arg2)
202 Color result = arg1.Divide(arg2);
208 /// The division operator.
210 /// <param name="arg1">The first value.</param>
211 /// <param name="arg2">The second value.</param>
212 /// <returns>The color containing the result of the division.</returns>
213 /// <since_tizen> 3 </since_tizen>
214 public static Color operator/(Color arg1, float arg2)
216 Color result = arg1.Divide(arg2);
222 /// The array subscript operator overload.
224 /// <param name="index">The subscript index.</param>
225 /// <returns>The float at the given index.</returns>
226 /// <since_tizen> 3 </since_tizen>
227 public float this[uint index]
231 return ValueOfIndex(index);
235 internal static Color GetColorFromPtr(global::System.IntPtr cPtr)
237 Color ret = new Color(cPtr, false);
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243 /// Default constructor
245 /// <since_tizen> 3 </since_tizen>
246 public Color() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true)
248 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255 /// <param name="r">The red component.</param>
256 /// <param name="g">The green component.</param>
257 /// <param name="b">The blue component.</param>
258 /// <param name="a">The alpha component.</param>
259 /// <since_tizen> 3 </since_tizen>
260 public Color(float r, float g, float b, float a) : this(NDalicPINVOKE.new_Vector4__SWIG_1(r, g, b, a), true)
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270 /// The conversion constructor from an array of four floats.
272 /// <param name="array">array Array of R,G,B,A.</param>
273 /// <since_tizen> 3 </since_tizen>
274 public Color(float[] array) : this(NDalicPINVOKE.new_Vector4__SWIG_2(array), true)
276 ValueCheck(ref array[0]);
277 ValueCheck(ref array[1]);
278 ValueCheck(ref array[2]);
279 ValueCheck(ref array[3]);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
283 private Color Add(Color rhs)
285 Color ret = new Color(NDalicPINVOKE.Vector4_Add(swigCPtr, Color.getCPtr(rhs)), true);
286 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
290 private Color AddAssign(Vector4 rhs)
292 Color ret = new Color(NDalicPINVOKE.Vector4_AddAssign(swigCPtr, Color.getCPtr(rhs)), false);
293 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297 private Color Subtract(Color rhs)
299 Color ret = new Color(NDalicPINVOKE.Vector4_Subtract__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
300 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 private Color SubtractAssign(Color rhs)
306 Color ret = new Color(NDalicPINVOKE.Vector4_SubtractAssign(swigCPtr, Color.getCPtr(rhs)), false);
307 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311 private Color Multiply(Color rhs)
313 Color ret = new Color(NDalicPINVOKE.Vector4_Multiply__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
314 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318 private Color Multiply(float rhs)
320 Color ret = new Color(NDalicPINVOKE.Vector4_Multiply__SWIG_1(swigCPtr, rhs), true);
321 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325 private Color MultiplyAssign(Color rhs)
327 Color ret = new Color(NDalicPINVOKE.Vector4_MultiplyAssign__SWIG_0(swigCPtr, Color.getCPtr(rhs)), false);
328 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332 private Color MultiplyAssign(float rhs)
334 Color ret = new Color(NDalicPINVOKE.Vector4_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339 private Color Divide(Vector4 rhs)
341 Color ret = new Color(NDalicPINVOKE.Vector4_Divide__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
342 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346 private Color Divide(float rhs)
348 Color ret = new Color(NDalicPINVOKE.Vector4_Divide__SWIG_1(swigCPtr, rhs), true);
349 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353 private Color DivideAssign(Color rhs)
355 Color ret = new Color(NDalicPINVOKE.Vector4_DivideAssign__SWIG_0(swigCPtr, Color.getCPtr(rhs)), false);
356 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360 private Color DivideAssign(float rhs)
362 Color ret = new Color(NDalicPINVOKE.Vector4_DivideAssign__SWIG_1(swigCPtr, rhs), false);
363 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367 private Color Subtract()
369 Color ret = new Color(NDalicPINVOKE.Vector4_Subtract__SWIG_1(swigCPtr), true);
370 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
375 /// Checks if two color classes are same.
377 /// <param name="rhs">A color to be compared.</param>
378 /// <returns>If two colors are are same, then true.</returns>
379 /// <since_tizen> 3 </since_tizen>
380 public bool EqualTo(Color rhs)
382 bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, Color.getCPtr(rhs));
384 if (rhs == null) return false;
386 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391 /// Checks if two color classes are different.
393 /// <param name="rhs">A color to be compared.</param>
394 /// <returns>If two colors are are different, then true.</returns>
395 /// <since_tizen> 3 </since_tizen>
396 public bool NotEqualTo(Color rhs)
398 bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, Color.getCPtr(rhs));
399 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
404 private float ValueOfIndex(uint index)
406 float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index);
407 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
412 /// The red component.
414 /// <since_tizen> 3 </since_tizen>
419 ValueCheck(ref value);
420 NDalicPINVOKE.Vector4_r_set(swigCPtr, value);
421 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425 float ret = NDalicPINVOKE.Vector4_r_get(swigCPtr);
426 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
432 /// The green component.
434 /// <since_tizen> 3 </since_tizen>
439 ValueCheck(ref value);
440 NDalicPINVOKE.Vector4_g_set(swigCPtr, value);
441 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
445 float ret = NDalicPINVOKE.Vector4_g_get(swigCPtr);
446 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
452 /// The blue component.
454 /// <since_tizen> 3 </since_tizen>
459 ValueCheck(ref value);
460 NDalicPINVOKE.Vector4_b_set(swigCPtr, value);
461 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
465 float ret = NDalicPINVOKE.Vector4_b_get(swigCPtr);
466 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
472 /// The alpha component.
474 /// <since_tizen> 3 </since_tizen>
479 ValueCheck(ref value);
480 NDalicPINVOKE.Vector4_a_set(swigCPtr, value);
481 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
485 float ret = NDalicPINVOKE.Vector4_a_get(swigCPtr);
486 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
492 /// Gets the black colored Color class.
494 /// <since_tizen> 3 </since_tizen>
495 public static readonly Color Black = new Color(0.0f, 0.0f, 0.0f, 1.0f);
498 /// Gets the white colored Color class.
500 /// <since_tizen> 3 </since_tizen>
501 public static readonly Color White = new Color(1.0f, 1.0f, 1.0f, 1.0f);
504 /// Gets the red colored Color class.
506 /// <since_tizen> 3 </since_tizen>
507 public static readonly Color Red = new Color(1.0f, 0.0f, 0.0f, 1.0f);
510 /// Gets the green colored Color class.
512 /// <since_tizen> 3 </since_tizen>
513 public static readonly Color Green = new Color(0.0f, 1.0f, 0.0f, 1.0f);
516 /// Gets the blue colored Color class.
518 /// <since_tizen> 3 </since_tizen>
519 public static readonly Color Blue = new Color(0.0f, 0.0f, 1.0f, 1.0f);
522 /// Gets the yellow colored Color class.
524 /// <since_tizen> 3 </since_tizen>
525 public static readonly Color Yellow = new Color(1.0f, 1.0f, 0.0f, 1.0f);
528 /// Gets the magenta colored Color class.
530 /// <since_tizen> 3 </since_tizen>
531 public static readonly Color Magenta = new Color(1.0f, 0.0f, 1.0f, 1.0f);
534 /// Gets the cyan colored Color class.
536 /// <since_tizen> 3 </since_tizen>
537 public static readonly Color Cyan = new Color(0.0f, 1.0f, 1.0f, 1.0f);
540 /// Gets the transparent colored Color class.
542 /// <since_tizen> 3 </since_tizen>
543 public static readonly Color Transparent = new Color(0.0f, 0.0f, 0.0f, 0.0f);
546 /// Converts the Color class to Vector4 class implicitly.
548 /// <param name="color">A color to be converted to Vector4</param>
549 /// <since_tizen> 3 </since_tizen>
550 public static implicit operator Vector4(Color color)
552 return new Vector4(color.R, color.G, color.B, color.A);
556 /// Converts Vector4 class to Color class implicitly.
558 /// <param name="vec">A Vector4 to be converted to color.</param>
559 /// <since_tizen> 3 </since_tizen>
560 public static implicit operator Color(Vector4 vec)
562 return new Color(vec.R, vec.G, vec.B, vec.A);
565 internal static void ValueCheck(Color color)
570 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
572 else if (color.R > 1.0f)
575 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
580 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
582 else if (color.G > 1.0f)
585 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
590 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
592 else if (color.B > 1.0f)
595 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
600 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
602 else if (color.A > 1.0f)
605 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
609 internal static void ValueCheck(ref float value)
614 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
616 else if (value > 1.0f)
619 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");