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