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);
134 return ValueCheck(result);
138 /// The subtraction operator.
140 /// <param name="arg1">The first value.</param>
141 /// <param name="arg2">The second value.</param>
142 /// <returns>The color containing the result of the subtraction.</returns>
143 /// <since_tizen> 3 </since_tizen>
144 public static Color operator -(Color arg1, Color arg2)
146 Color result = arg1.Subtract(arg2);
147 return ValueCheck(result);
151 /// The unary negation operator.
153 /// <param name="arg1">The target value.</param>
154 /// <returns>The color containg the negation.</returns>
155 /// <since_tizen> 3 </since_tizen>
156 public static Color operator -(Color arg1)
158 Color result = arg1.Subtract();
159 return ValueCheck(result);
163 /// The multiplication operator.
165 /// <param name="arg1">The first value.</param>
166 /// <param name="arg2">The second value.</param>
167 /// <returns>The color containing the result of the multiplication.</returns>
168 /// <since_tizen> 3 </since_tizen>
169 public static Color operator *(Color arg1, Color arg2)
171 Color result = arg1.Multiply(arg2);
172 return ValueCheck(result);
176 /// The multiplication operator.
178 /// <param name="arg1">The first value.</param>
179 /// <param name="arg2">The second value.</param>
180 /// <returns>The color containing the result of the multiplication.</returns>
181 /// <since_tizen> 3 </since_tizen>
182 public static Color operator*(Color arg1, float arg2)
184 Color result = arg1.Multiply(arg2);
185 return ValueCheck(result);
189 /// The division operator.
191 /// <param name="arg1">The first value.</param>
192 /// <param name="arg2">The second value.</param>
193 /// <returns>The color containing the result of the division.</returns>
194 /// <since_tizen> 3 </since_tizen>
195 public static Color operator /(Color arg1, Color arg2)
197 Color result = arg1.Divide(arg2);
198 return ValueCheck(result);
202 /// The division operator.
204 /// <param name="arg1">The first value.</param>
205 /// <param name="arg2">The second value.</param>
206 /// <returns>The color containing the result of the division.</returns>
207 /// <since_tizen> 3 </since_tizen>
208 public static Color operator/(Color arg1, float arg2)
210 Color result = arg1.Divide(arg2);
211 return ValueCheck(result);
215 /// The array subscript operator overload.
217 /// <param name="index">The subscript index.</param>
218 /// <returns>The float at the given index.</returns>
219 /// <since_tizen> 3 </since_tizen>
220 public float this[uint index]
224 return ValueOfIndex(index);
228 internal static Color GetColorFromPtr(global::System.IntPtr cPtr)
230 Color ret = new Color(cPtr, false);
231 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236 /// Default constructor
238 /// <since_tizen> 3 </since_tizen>
239 public Color() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true)
241 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248 /// <param name="r">The red component.</param>
249 /// <param name="g">The green component.</param>
250 /// <param name="b">The blue component.</param>
251 /// <param name="a">The alpha component.</param>
252 /// <since_tizen> 3 </since_tizen>
253 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)
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 /// The conversion constructor from an array of four floats.
261 /// <param name="array">array Array of R,G,B,A.</param>
262 /// <since_tizen> 3 </since_tizen>
263 public Color(float[] array) : this(NDalicPINVOKE.new_Vector4__SWIG_2(ValueCheck(array)), true)
265 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268 private Color Add(Color rhs)
270 Color ret = new Color(NDalicPINVOKE.Vector4_Add(swigCPtr, Color.getCPtr(rhs)), true);
271 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 private Color AddAssign(Vector4 rhs)
277 Color ret = new Color(NDalicPINVOKE.Vector4_AddAssign(swigCPtr, Color.getCPtr(rhs)), false);
278 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282 private Color Subtract(Color rhs)
284 Color ret = new Color(NDalicPINVOKE.Vector4_Subtract__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
285 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 private Color SubtractAssign(Color rhs)
291 Color ret = new Color(NDalicPINVOKE.Vector4_SubtractAssign(swigCPtr, Color.getCPtr(rhs)), false);
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
296 private Color Multiply(Color rhs)
298 Color ret = new Color(NDalicPINVOKE.Vector4_Multiply__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
299 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
303 private Color Multiply(float rhs)
305 Color ret = new Color(NDalicPINVOKE.Vector4_Multiply__SWIG_1(swigCPtr, rhs), true);
306 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310 private Color MultiplyAssign(Color rhs)
312 Color ret = new Color(NDalicPINVOKE.Vector4_MultiplyAssign__SWIG_0(swigCPtr, Color.getCPtr(rhs)), false);
313 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 private Color MultiplyAssign(float rhs)
319 Color ret = new Color(NDalicPINVOKE.Vector4_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 private Color Divide(Vector4 rhs)
326 Color ret = new Color(NDalicPINVOKE.Vector4_Divide__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
327 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331 private Color Divide(float rhs)
333 Color ret = new Color(NDalicPINVOKE.Vector4_Divide__SWIG_1(swigCPtr, rhs), true);
334 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338 private Color DivideAssign(Color rhs)
340 Color ret = new Color(NDalicPINVOKE.Vector4_DivideAssign__SWIG_0(swigCPtr, Color.getCPtr(rhs)), false);
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 private Color DivideAssign(float rhs)
347 Color ret = new Color(NDalicPINVOKE.Vector4_DivideAssign__SWIG_1(swigCPtr, rhs), false);
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352 private Color Subtract()
354 Color ret = new Color(NDalicPINVOKE.Vector4_Subtract__SWIG_1(swigCPtr), true);
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360 /// Checks if two color classes are same.
362 /// <param name="rhs">A color to be compared.</param>
363 /// <returns>If two colors are are same, then true.</returns>
364 /// <since_tizen> 3 </since_tizen>
365 public bool EqualTo(Color rhs)
367 bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, Color.getCPtr(rhs));
369 if (rhs == null) return false;
371 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 /// Checks if two color classes are different.
378 /// <param name="rhs">A color to be compared.</param>
379 /// <returns>If two colors are are different, then true.</returns>
380 /// <since_tizen> 3 </since_tizen>
381 public bool NotEqualTo(Color rhs)
383 bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, Color.getCPtr(rhs));
384 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
389 private float ValueOfIndex(uint index)
391 float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index);
392 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397 /// The red component.
399 /// <since_tizen> 3 </since_tizen>
404 NDalicPINVOKE.Vector4_r_set(swigCPtr, ValueCheck(value));
405 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
409 float ret = NDalicPINVOKE.Vector4_r_get(swigCPtr);
410 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
416 /// The green component.
418 /// <since_tizen> 3 </since_tizen>
423 NDalicPINVOKE.Vector4_g_set(swigCPtr, ValueCheck(value));
424 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
428 float ret = NDalicPINVOKE.Vector4_g_get(swigCPtr);
429 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435 /// The blue component.
437 /// <since_tizen> 3 </since_tizen>
442 NDalicPINVOKE.Vector4_b_set(swigCPtr, ValueCheck(value));
443 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
447 float ret = NDalicPINVOKE.Vector4_b_get(swigCPtr);
448 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
454 /// The alpha component.
456 /// <since_tizen> 3 </since_tizen>
461 NDalicPINVOKE.Vector4_a_set(swigCPtr, ValueCheck(value));
462 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
466 float ret = NDalicPINVOKE.Vector4_a_get(swigCPtr);
467 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
473 /// Gets the black colored Color class.
475 /// <since_tizen> 3 </since_tizen>
476 public static readonly Color Black = new Color(0.0f, 0.0f, 0.0f, 1.0f);
479 /// Gets the white colored Color class.
481 /// <since_tizen> 3 </since_tizen>
482 public static readonly Color White = new Color(1.0f, 1.0f, 1.0f, 1.0f);
485 /// Gets the red colored Color class.
487 /// <since_tizen> 3 </since_tizen>
488 public static readonly Color Red = new Color(1.0f, 0.0f, 0.0f, 1.0f);
491 /// Gets the green colored Color class.
493 /// <since_tizen> 3 </since_tizen>
494 public static readonly Color Green = new Color(0.0f, 1.0f, 0.0f, 1.0f);
497 /// Gets the blue colored Color class.
499 /// <since_tizen> 3 </since_tizen>
500 public static readonly Color Blue = new Color(0.0f, 0.0f, 1.0f, 1.0f);
503 /// Gets the yellow colored Color class.
505 /// <since_tizen> 3 </since_tizen>
506 public static readonly Color Yellow = new Color(1.0f, 1.0f, 0.0f, 1.0f);
509 /// Gets the magenta colored Color class.
511 /// <since_tizen> 3 </since_tizen>
512 public static readonly Color Magenta = new Color(1.0f, 0.0f, 1.0f, 1.0f);
515 /// Gets the cyan colored Color class.
517 /// <since_tizen> 3 </since_tizen>
518 public static readonly Color Cyan = new Color(0.0f, 1.0f, 1.0f, 1.0f);
521 /// Gets the transparent colored Color class.
523 /// <since_tizen> 3 </since_tizen>
524 public static readonly Color Transparent = new Color(0.0f, 0.0f, 0.0f, 0.0f);
527 /// Converts the Color class to Vector4 class implicitly.
529 /// <param name="color">A color to be converted to Vector4</param>
530 /// <since_tizen> 3 </since_tizen>
531 public static implicit operator Vector4(Color color)
533 return new Vector4(color.R, color.G, color.B, color.A);
537 /// Converts Vector4 class to Color class implicitly.
539 /// <param name="vec">A Vector4 to be converted to color.</param>
540 /// <since_tizen> 3 </since_tizen>
541 public static implicit operator Color(Vector4 vec)
543 return new Color(vec.R, vec.G, vec.B, vec.A);
546 internal static Color ValueCheck(Color color)
551 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
553 else if (color.R > 1.0f)
556 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
561 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
563 else if (color.G > 1.0f)
566 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
571 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
573 else if (color.B > 1.0f)
576 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
581 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
583 else if (color.A > 1.0f)
586 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
591 internal static float ValueCheck(float value)
596 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
598 else if (value > 1.0f)
601 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
606 internal static float[] ValueCheck(float[] arr)
608 for(int i = 0; i < arr.Length; i++)
613 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
615 else if (arr[i] > 1.0f)
618 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");