Revert "[Tizen] Add value check to color."
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Color.cs
1 // Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 //
16 // This File has been auto-generated by SWIG and then modified using DALi Ruby Scripts
17 // Some have been manually changed
18
19 namespace Tizen.NUI
20 {
21
22     using System;
23
24     /// <summary>
25     /// Color class.
26     /// </summary>
27     public class Color : global::System.IDisposable
28     {
29         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30         protected bool swigCMemOwn;
31
32         internal Color(global::System.IntPtr cPtr, bool cMemoryOwn)
33         {
34             swigCMemOwn = cMemoryOwn;
35             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
36         }
37
38         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Color obj)
39         {
40             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
41         }
42
43         //NUI Dispose Pattern written by Jinwoo Nam(jjw.nam)
44
45         //A Flag to check who called Dispose(). (By User or DisposeQueue)
46         private bool isDisposeQueued = false;
47         //A Flat to check if it is already disposed.
48         protected bool disposed = false;
49
50         ~Color()
51         {
52             if(!isDisposeQueued)
53             {
54                 isDisposeQueued = true;
55                 DisposeQueue.Instance.Add(this);
56             }
57         }
58
59         /// <summary>
60         /// To make Color instance be disposed.
61         /// </summary>
62         public void Dispose()
63         {
64             //Throw excpetion if Dispose() is called in separate thread.
65             if (!Window.IsInstalled())
66             {
67                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
68             }
69
70             if (isDisposeQueued)
71             {
72                 Dispose(DisposeTypes.Implicit);
73             }
74             else
75             {
76                 Dispose(DisposeTypes.Explicit);
77                 System.GC.SuppressFinalize(this);
78             }
79         }
80
81         protected virtual void Dispose(DisposeTypes type)
82         {
83             if (disposed)
84             {
85                 return;
86             }
87
88             if(type == DisposeTypes.Explicit)
89             {
90                 //Called by User
91                 //Release your own managed resources here.
92                 //You should release all of your own disposable objects here.
93             }
94
95             //Release your own unmanaged resources here.
96             //You should not access any managed member here except static instance.
97             //because the execution order of Finalizes is non-deterministic.
98
99             if (swigCPtr.Handle != global::System.IntPtr.Zero)
100             {
101                 if (swigCMemOwn)
102                 {
103                     swigCMemOwn = false;
104                     NDalicPINVOKE.delete_Vector4(swigCPtr);
105                 }
106                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
107             }
108             disposed = true;
109         }
110
111         /// <summary>
112         /// Addition operator.
113         /// </summary>
114         /// <param name="arg1">First value</param>
115         /// <param name="arg2">Second value</param>
116         /// <returns>A Color containing the result of the addition</returns>
117         public static Color operator +(Color arg1, Color arg2)
118         {
119             return arg1.Add(arg2);
120         }
121
122         /// <summary>
123         /// Subtraction operator.
124         /// </summary>
125         /// <param name="arg1">First value</param>
126         /// <param name="arg2">Second value</param>
127         /// <returns>A Color containing the result of the subtraction</returns>
128         public static Color operator -(Color arg1, Color arg2)
129         {
130             return arg1.Subtract(arg2);
131         }
132
133         /// <summary>
134         /// Unary negation operator.
135         /// </summary>
136         /// <param name="arg1">Target Value</param>
137         /// <returns>A Color containg the negation</returns>
138         public static Color operator -(Color arg1)
139         {
140             return arg1.Subtract();
141         }
142
143         /// <summary>
144         /// Multiplication operator.
145         /// </summary>
146         /// <param name="arg1">First Value</param>
147         /// <param name="arg2">Second Value</param>
148         /// <returns>A Color containing the result of the multiplication</returns>
149         public static Color operator *(Color arg1, Color arg2)
150         {
151             return arg1.Multiply(arg2);
152         }
153
154         public static Color operator*(Color arg1, float arg2)
155         {
156             return arg1.Multiply(arg2);
157         }
158
159         /// <summary>
160         /// Division operator.
161         /// </summary>
162         /// <param name="arg1">First Value</param>
163         /// <param name="arg2">Second Value</param>
164         /// <returns>A Color containing the result of the division</returns>
165         public static Color operator /(Color arg1, Color arg2)
166         {
167             return arg1.Divide(arg2);
168         }
169
170         public static Color operator/(Color arg1, float arg2)
171         {
172             return arg1.Divide(arg2);
173         }
174
175         /// <summary>
176         /// Array subscript operator overload.
177         /// </summary>
178         /// <param name="index">Subscript index</param>
179         /// <returns>The float at the given index</returns>
180         public float this[uint index]
181         {
182             get
183             {
184                 return ValueOfIndex(index);
185             }
186         }
187
188         internal static Color GetColorFromPtr(global::System.IntPtr cPtr)
189         {
190             Color ret = new Color(cPtr, false);
191             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
192             return ret;
193         }
194
195         /// <summary>
196         /// Default constructor
197         /// </summary>
198         public Color() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true)
199         {
200             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201         }
202
203
204         /// <summary>
205         /// Constructor.
206         /// </summary>
207         /// <param name="r">red component</param>
208         /// <param name="g">green component</param>
209         /// <param name="b">blue component</param>
210         /// <param name="a">alpha component</param>
211         public Color(float r, float g, float b, float a) : this(NDalicPINVOKE.new_Vector4__SWIG_1(r, g, b, a), true)
212         {
213             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214         }
215
216         /// <summary>
217         /// Conversion constructor from an array of four floats.
218         /// </summary>
219         /// <param name="array">array Array of R,G,B,A</param>
220         public Color(float[] array) : this(NDalicPINVOKE.new_Vector4__SWIG_2(array), true)
221         {
222             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223         }
224
225         private Color Add(Color rhs)
226         {
227             Color ret = new Color(NDalicPINVOKE.Vector4_Add(swigCPtr, Color.getCPtr(rhs)), true);
228             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229             return ret;
230         }
231
232         private Color AddAssign(Vector4 rhs)
233         {
234             Color ret = new Color(NDalicPINVOKE.Vector4_AddAssign(swigCPtr, Color.getCPtr(rhs)), false);
235             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236             return ret;
237         }
238
239         private Color Subtract(Color rhs)
240         {
241             Color ret = new Color(NDalicPINVOKE.Vector4_Subtract__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
242             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243             return ret;
244         }
245
246         private Color SubtractAssign(Color rhs)
247         {
248             Color ret = new Color(NDalicPINVOKE.Vector4_SubtractAssign(swigCPtr, Color.getCPtr(rhs)), false);
249             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250             return ret;
251         }
252
253         private Color Multiply(Color rhs)
254         {
255             Color ret = new Color(NDalicPINVOKE.Vector4_Multiply__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
256             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257             return ret;
258         }
259
260         private Color Multiply(float rhs)
261         {
262             Color ret = new Color(NDalicPINVOKE.Vector4_Multiply__SWIG_1(swigCPtr, rhs), true);
263             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264             return ret;
265         }
266
267         private Color MultiplyAssign(Color rhs)
268         {
269             Color ret = new Color(NDalicPINVOKE.Vector4_MultiplyAssign__SWIG_0(swigCPtr, Color.getCPtr(rhs)), false);
270             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271             return ret;
272         }
273
274         private Color MultiplyAssign(float rhs)
275         {
276             Color ret = new Color(NDalicPINVOKE.Vector4_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
277             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278             return ret;
279         }
280
281         private Color Divide(Vector4 rhs)
282         {
283             Color ret = new Color(NDalicPINVOKE.Vector4_Divide__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
284             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285             return ret;
286         }
287
288         private Color Divide(float rhs)
289         {
290             Color ret = new Color(NDalicPINVOKE.Vector4_Divide__SWIG_1(swigCPtr, rhs), true);
291             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292             return ret;
293         }
294
295         private Color DivideAssign(Color rhs)
296         {
297             Color ret = new Color(NDalicPINVOKE.Vector4_DivideAssign__SWIG_0(swigCPtr, Color.getCPtr(rhs)), false);
298             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299             return ret;
300         }
301
302         private Color DivideAssign(float rhs)
303         {
304             Color ret = new Color(NDalicPINVOKE.Vector4_DivideAssign__SWIG_1(swigCPtr, rhs), false);
305             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306             return ret;
307         }
308
309         private Color Subtract()
310         {
311             Color ret = new Color(NDalicPINVOKE.Vector4_Subtract__SWIG_1(swigCPtr), true);
312             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313             return ret;
314         }
315
316         /// <summary>
317         /// Check if two Color classes are same.
318         /// </summary>
319         /// <param name="rhs">A Color to be compared</param>
320         /// <returns>If two Colors are are same, then true.</returns>
321         public bool EqualTo(Color rhs)
322         {
323             bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, Color.getCPtr(rhs));
324
325             if (rhs == null) return false;
326
327             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328             return ret;
329         }
330
331         /// <summary>
332         /// Check if two Color classes are different.
333         /// </summary>
334         /// <param name="rhs">A Color to be compared</param>
335         /// <returns>If two Colors are are different, then true.</returns>
336         public bool NotEqualTo(Color rhs)
337         {
338             bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, Color.getCPtr(rhs));
339             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340             return ret;
341         }
342
343
344         private float ValueOfIndex(uint index)
345         {
346             float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index);
347             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348             return ret;
349         }
350
351         /// <summary>
352         /// red component.
353         /// </summary>
354         public float R
355         {
356             set
357             {
358                 NDalicPINVOKE.Vector4_r_set(swigCPtr, value);
359                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360             }
361             get
362             {
363                 float ret = NDalicPINVOKE.Vector4_r_get(swigCPtr);
364                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
365                 return ret;
366             }
367         }
368
369         /// <summary>
370         /// green component.
371         /// </summary>
372         public float G
373         {
374             set
375             {
376                 NDalicPINVOKE.Vector4_g_set(swigCPtr, value);
377                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378             }
379             get
380             {
381                 float ret = NDalicPINVOKE.Vector4_g_get(swigCPtr);
382                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383                 return ret;
384             }
385         }
386
387         /// <summary>
388         /// blue component.
389         /// </summary>
390         public float B
391         {
392             set
393             {
394                 NDalicPINVOKE.Vector4_b_set(swigCPtr, value);
395                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396             }
397             get
398             {
399                 float ret = NDalicPINVOKE.Vector4_b_get(swigCPtr);
400                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
401                 return ret;
402             }
403         }
404
405         /// <summary>
406         /// alpha component.
407         /// </summary>
408         public float A
409         {
410             set
411             {
412                 NDalicPINVOKE.Vector4_a_set(swigCPtr, value);
413                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414             }
415             get
416             {
417                 float ret = NDalicPINVOKE.Vector4_a_get(swigCPtr);
418                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
419                 return ret;
420             }
421         }
422
423         /// <summary>
424         /// Get black colored Color class.
425         /// </summary>
426         public static Color Black
427         {
428             get
429             {
430                 global::System.IntPtr cPtr = NDalicPINVOKE.BLACK_get();
431                 Color ret = (cPtr == global::System.IntPtr.Zero) ? null : new Color(cPtr, false);
432                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
433                 return ret;
434             }
435         }
436
437         /// <summary>
438         /// Get white colored Color class.
439         /// </summary>
440         public static Color White
441         {
442             get
443             {
444                 global::System.IntPtr cPtr = NDalicPINVOKE.WHITE_get();
445                 Color ret = (cPtr == global::System.IntPtr.Zero) ? null : new Color(cPtr, false);
446                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
447                 return ret;
448             }
449         }
450
451         /// <summary>
452         /// Get red colored Color class.
453         /// </summary>
454         public static Color Red
455         {
456             get
457             {
458                 global::System.IntPtr cPtr = NDalicPINVOKE.RED_get();
459                 Color ret = (cPtr == global::System.IntPtr.Zero) ? null : new Color(cPtr, false);
460                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
461                 return ret;
462             }
463         }
464
465         /// <summary>
466         /// Get green colored Color class.
467         /// </summary>
468         public static Color Green
469         {
470             get
471             {
472                 global::System.IntPtr cPtr = NDalicPINVOKE.GREEN_get();
473                 Color ret = (cPtr == global::System.IntPtr.Zero) ? null : new Color(cPtr, false);
474                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
475                 return ret;
476             }
477         }
478
479         /// <summary>
480         /// Get blue colored Color class.
481         /// </summary>
482         public static Color Blue
483         {
484             get
485             {
486                 global::System.IntPtr cPtr = NDalicPINVOKE.BLUE_get();
487                 Color ret = (cPtr == global::System.IntPtr.Zero) ? null : new Color(cPtr, false);
488                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
489                 return ret;
490             }
491         }
492
493         /// <summary>
494         /// Get yellow colored Color class.
495         /// </summary>
496         public static Color Yellow
497         {
498             get
499             {
500                 global::System.IntPtr cPtr = NDalicPINVOKE.YELLOW_get();
501                 Color ret = (cPtr == global::System.IntPtr.Zero) ? null : new Color(cPtr, false);
502                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
503                 return ret;
504             }
505         }
506
507         /// <summary>
508         /// Get magenta colored Color class.
509         /// </summary>
510         public static Color Magenta
511         {
512             get
513             {
514                 global::System.IntPtr cPtr = NDalicPINVOKE.MAGENTA_get();
515                 Color ret = (cPtr == global::System.IntPtr.Zero) ? null : new Color(cPtr, false);
516                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
517                 return ret;
518             }
519         }
520
521         /// <summary>
522         /// Get cyan colored Color class.
523         /// </summary>
524         public static Color Cyan
525         {
526             get
527             {
528                 global::System.IntPtr cPtr = NDalicPINVOKE.CYAN_get();
529                 Color ret = (cPtr == global::System.IntPtr.Zero) ? null : new Color(cPtr, false);
530                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
531                 return ret;
532             }
533         }
534
535         /// <summary>
536         /// Get transparent colored Color class.
537         /// </summary>
538         public static Color Transparent
539         {
540             get
541             {
542                 global::System.IntPtr cPtr = NDalicPINVOKE.TRANSPARENT_get();
543                 Color ret = (cPtr == global::System.IntPtr.Zero) ? null : new Color(cPtr, false);
544                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
545                 return ret;
546             }
547         }
548
549         /// <summary>
550         /// convert Color class to Vector4 class implicitly.
551         /// </summary>
552         /// <param name="color">A Color to be converted to Vector4</param>
553         public static implicit operator Vector4(Color color)
554         {
555             return new Vector4(color.R, color.G, color.B, color.A);
556         }
557
558         /// <summary>
559         /// convert Vector4 class to Color class implicitly.
560         /// </summary>
561         /// <param name="vec">A Vector4 to be converted to Color</param></param>
562         public static implicit operator Color(Vector4 vec)
563         {
564             return new Color(vec.R, vec.G, vec.B, vec.A);
565         }
566
567     }
568
569 }
570
571