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