Release 4.0.0-preview1-00051
[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             Color result = arg1.Add(arg2);
118             ValueCheck(result);
119             return result;
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             Color result = arg1.Subtract(arg2);
131             ValueCheck(result);
132             return result;
133         }
134
135         /// <summary>
136         /// Unary negation operator.
137         /// </summary>
138         /// <param name="arg1">Target Value</param>
139         /// <returns>A Color containg the negation</returns>
140         public static Color operator -(Color arg1)
141         {
142             Color result = arg1.Subtract();
143             ValueCheck(result);
144             return result;
145         }
146
147         /// <summary>
148         /// Multiplication operator.
149         /// </summary>
150         /// <param name="arg1">First Value</param>
151         /// <param name="arg2">Second Value</param>
152         /// <returns>A Color containing the result of the multiplication</returns>
153         public static Color operator *(Color arg1, Color arg2)
154         {
155             Color result = arg1.Multiply(arg2);
156             ValueCheck(result);
157             return result;
158         }
159
160         public static Color operator*(Color arg1, float arg2)
161         {
162             Color result = arg1.Multiply(arg2);
163             ValueCheck(result);
164             return result;
165         }
166
167         /// <summary>
168         /// Division operator.
169         /// </summary>
170         /// <param name="arg1">First Value</param>
171         /// <param name="arg2">Second Value</param>
172         /// <returns>A Color containing the result of the division</returns>
173         public static Color operator /(Color arg1, Color arg2)
174         {
175             Color result = arg1.Divide(arg2);
176             ValueCheck(result);
177             return result;
178         }
179
180         public static Color operator/(Color arg1, float arg2)
181         {
182             Color result = arg1.Divide(arg2);
183             ValueCheck(result);
184             return result;
185         }
186
187         /// <summary>
188         /// Array subscript operator overload.
189         /// </summary>
190         /// <param name="index">Subscript index</param>
191         /// <returns>The float at the given index</returns>
192         public float this[uint index]
193         {
194             get
195             {
196                 return ValueOfIndex(index);
197             }
198         }
199
200         internal static Color GetColorFromPtr(global::System.IntPtr cPtr)
201         {
202             Color ret = new Color(cPtr, false);
203             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204             return ret;
205         }
206
207         /// <summary>
208         /// Default constructor
209         /// </summary>
210         public Color() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true)
211         {
212             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213         }
214
215
216         /// <summary>
217         /// Constructor.
218         /// </summary>
219         /// <param name="r">red component</param>
220         /// <param name="g">green component</param>
221         /// <param name="b">blue component</param>
222         /// <param name="a">alpha component</param>
223         public Color(float r, float g, float b, float a) : this(NDalicPINVOKE.new_Vector4__SWIG_1(r, g, b, a), true)
224         {
225             ValueCheck(ref r);
226             ValueCheck(ref g);
227             ValueCheck(ref b);
228             ValueCheck(ref a);
229             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230         }
231
232         /// <summary>
233         /// Conversion constructor from an array of four floats.
234         /// </summary>
235         /// <param name="array">array Array of R,G,B,A</param>
236         public Color(float[] array) : this(NDalicPINVOKE.new_Vector4__SWIG_2(array), true)
237         {
238             ValueCheck(ref array[0]);
239             ValueCheck(ref array[1]);
240             ValueCheck(ref array[2]);
241             ValueCheck(ref array[3]);
242             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243         }
244
245         private Color Add(Color rhs)
246         {
247             Color ret = new Color(NDalicPINVOKE.Vector4_Add(swigCPtr, Color.getCPtr(rhs)), true);
248             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249             return ret;
250         }
251
252         private Color AddAssign(Vector4 rhs)
253         {
254             Color ret = new Color(NDalicPINVOKE.Vector4_AddAssign(swigCPtr, Color.getCPtr(rhs)), false);
255             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256             return ret;
257         }
258
259         private Color Subtract(Color rhs)
260         {
261             Color ret = new Color(NDalicPINVOKE.Vector4_Subtract__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
262             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263             return ret;
264         }
265
266         private Color SubtractAssign(Color rhs)
267         {
268             Color ret = new Color(NDalicPINVOKE.Vector4_SubtractAssign(swigCPtr, Color.getCPtr(rhs)), false);
269             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270             return ret;
271         }
272
273         private Color Multiply(Color rhs)
274         {
275             Color ret = new Color(NDalicPINVOKE.Vector4_Multiply__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
276             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277             return ret;
278         }
279
280         private Color Multiply(float rhs)
281         {
282             Color ret = new Color(NDalicPINVOKE.Vector4_Multiply__SWIG_1(swigCPtr, rhs), true);
283             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284             return ret;
285         }
286
287         private Color MultiplyAssign(Color rhs)
288         {
289             Color ret = new Color(NDalicPINVOKE.Vector4_MultiplyAssign__SWIG_0(swigCPtr, Color.getCPtr(rhs)), false);
290             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291             return ret;
292         }
293
294         private Color MultiplyAssign(float rhs)
295         {
296             Color ret = new Color(NDalicPINVOKE.Vector4_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
297             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298             return ret;
299         }
300
301         private Color Divide(Vector4 rhs)
302         {
303             Color ret = new Color(NDalicPINVOKE.Vector4_Divide__SWIG_0(swigCPtr, Color.getCPtr(rhs)), true);
304             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305             return ret;
306         }
307
308         private Color Divide(float rhs)
309         {
310             Color ret = new Color(NDalicPINVOKE.Vector4_Divide__SWIG_1(swigCPtr, rhs), true);
311             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312             return ret;
313         }
314
315         private Color DivideAssign(Color rhs)
316         {
317             Color ret = new Color(NDalicPINVOKE.Vector4_DivideAssign__SWIG_0(swigCPtr, Color.getCPtr(rhs)), false);
318             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319             return ret;
320         }
321
322         private Color DivideAssign(float rhs)
323         {
324             Color ret = new Color(NDalicPINVOKE.Vector4_DivideAssign__SWIG_1(swigCPtr, rhs), false);
325             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
326             return ret;
327         }
328
329         private Color Subtract()
330         {
331             Color ret = new Color(NDalicPINVOKE.Vector4_Subtract__SWIG_1(swigCPtr), true);
332             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333             return ret;
334         }
335
336         /// <summary>
337         /// Check if two Color classes are same.
338         /// </summary>
339         /// <param name="rhs">A Color to be compared</param>
340         /// <returns>If two Colors are are same, then true.</returns>
341         public bool EqualTo(Color rhs)
342         {
343             bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, Color.getCPtr(rhs));
344
345             if (rhs == null) return false;
346
347             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348             return ret;
349         }
350
351         /// <summary>
352         /// Check if two Color classes are different.
353         /// </summary>
354         /// <param name="rhs">A Color to be compared</param>
355         /// <returns>If two Colors are are different, then true.</returns>
356         public bool NotEqualTo(Color rhs)
357         {
358             bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, Color.getCPtr(rhs));
359             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360             return ret;
361         }
362
363
364         private float ValueOfIndex(uint index)
365         {
366             float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index);
367             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368             return ret;
369         }
370
371         /// <summary>
372         /// red component.
373         /// </summary>
374         public float R
375         {
376             set
377             {
378                 ValueCheck(ref value);
379                 NDalicPINVOKE.Vector4_r_set(swigCPtr, value);
380                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
381             }
382             get
383             {
384                 float ret = NDalicPINVOKE.Vector4_r_get(swigCPtr);
385                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
386                 return ret;
387             }
388         }
389
390         /// <summary>
391         /// green component.
392         /// </summary>
393         public float G
394         {
395             set
396             {
397                 ValueCheck(ref value);
398                 NDalicPINVOKE.Vector4_g_set(swigCPtr, value);
399                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400             }
401             get
402             {
403                 float ret = NDalicPINVOKE.Vector4_g_get(swigCPtr);
404                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405                 return ret;
406             }
407         }
408
409         /// <summary>
410         /// blue component.
411         /// </summary>
412         public float B
413         {
414             set
415             {
416                 ValueCheck(ref value);
417                 NDalicPINVOKE.Vector4_b_set(swigCPtr, value);
418                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
419             }
420             get
421             {
422                 float ret = NDalicPINVOKE.Vector4_b_get(swigCPtr);
423                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424                 return ret;
425             }
426         }
427
428         /// <summary>
429         /// alpha component.
430         /// </summary>
431         public float A
432         {
433             set
434             {
435                 ValueCheck(ref value);
436                 NDalicPINVOKE.Vector4_a_set(swigCPtr, value);
437                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
438             }
439             get
440             {
441                 float ret = NDalicPINVOKE.Vector4_a_get(swigCPtr);
442                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443                 return ret;
444             }
445         }
446
447         /// <summary>
448         /// Get black colored Color class.
449         /// </summary>
450         public static readonly Color Black = new Color(0.0f, 0.0f, 0.0f, 1.0f);
451
452         /// <summary>
453         /// Get white colored Color class.
454         /// </summary>
455         public static readonly Color White = new Color(1.0f, 1.0f, 1.0f, 1.0f);
456
457         /// <summary>
458         /// Get red colored Color class.
459         /// </summary>
460         public static readonly Color Red = new Color(1.0f, 0.0f, 0.0f, 1.0f);
461
462         /// <summary>
463         /// Get green colored Color class.
464         /// </summary>
465         public static readonly Color Green = new Color(0.0f, 1.0f, 0.0f, 1.0f);
466
467         /// <summary>
468         /// Get blue colored Color class.
469         /// </summary>
470         public static readonly Color Blue = new Color(0.0f, 0.0f, 1.0f, 1.0f);
471
472         /// <summary>
473         /// Get yellow colored Color class.
474         /// </summary>
475         public static readonly Color Yellow = new Color(1.0f, 1.0f, 0.0f, 1.0f);
476
477         /// <summary>
478         /// Get magenta colored Color class.
479         /// </summary>
480         public static readonly Color Magenta = new Color(1.0f, 0.0f, 1.0f, 1.0f);
481
482         /// <summary>
483         /// Get cyan colored Color class.
484         /// </summary>
485         public static readonly Color Cyan = new Color(0.0f, 1.0f, 1.0f, 1.0f);
486
487         /// <summary>
488         /// Get transparent colored Color class.
489         /// </summary>
490         public static readonly Color Transparent = new Color(0.0f, 0.0f, 0.0f, 0.0f);
491
492         /// <summary>
493         /// convert Color class to Vector4 class implicitly.
494         /// </summary>
495         /// <param name="color">A Color to be converted to Vector4</param>
496         public static implicit operator Vector4(Color color)
497         {
498             return new Vector4(color.R, color.G, color.B, color.A);
499         }
500
501         /// <summary>
502         /// convert Vector4 class to Color class implicitly.
503         /// </summary>
504         /// <param name="vec">A Vector4 to be converted to Color</param></param>
505         public static implicit operator Color(Vector4 vec)
506         {
507             return new Color(vec.R, vec.G, vec.B, vec.A);
508         }
509
510         internal static void ValueCheck(Color color)
511         {
512             if (color.R < 0.0f)
513             {
514                 color.R = 0.0f;
515                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
516             }
517             else if (color.R > 1.0f)
518             {
519                 color.R = 1.0f;
520                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
521             }
522             if (color.G < 0.0f)
523             {
524                 color.G = 0.0f;
525                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
526             }
527             else if (color.G > 1.0f)
528             {
529                 color.G = 1.0f;
530                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
531             }
532             if (color.B < 0.0f)
533             {
534                 color.B = 0.0f;
535                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
536             }
537             else if (color.B > 1.0f)
538             {
539                 color.B = 1.0f;
540                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
541             }
542             if (color.A < 0.0f)
543             {
544                 color.A = 0.0f;
545                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
546             }
547             else if (color.A > 1.0f)
548             {
549                 color.A = 1.0f;
550                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
551             }
552         }
553
554         internal static void ValueCheck(ref float value)
555         {
556             if (value < 0.0f)
557             {
558                 value = 0.0f;
559                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
560             }
561             else if (value > 1.0f)
562             {
563                 value = 1.0f;
564                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
565             }
566         }
567
568     }
569
570 }
571
572