abcb02015ccc9282d55c269d599d43bbe774552e
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / manual / csharp / Color.cs
1 namespace Dali
2 {
3   using System;
4
5   public enum Colors
6   {
7     Red,
8     White,
9     Blue,
10     Green,
11     Black,
12     Yellow,
13     Magenta,
14     Cyan
15   }
16
17
18   public class Color
19   {
20
21     private float r;
22     private float g;
23     private float b;
24     private float a;
25
26     /**
27      * @brief constructor
28      *
29      * @since 1.0.0
30      */
31     public Color()
32     {
33       r = 0.0f;
34       g = 0.0f;
35       b = 0.0f;
36       a = 0.0f;
37     }
38
39     /**
40      * @brief constructor
41      *
42      * @since 1.0.0
43      * @param [in] red The Color r.
44      * @param [in] green The Color g.
45      * @param [in] blue The Color b.
46      * @param [in] alpha The Color a.
47      */
48     public Color(float red, float green, float blue, float alpha)
49     {
50       r = red;
51       g = green;
52       b = blue;
53       a = alpha;
54     }
55
56     /**
57      * @brief constructor
58      *
59      * @since 1.0.0
60      * @param [in] o The Vector4 having r g b a components
61      */
62     public Color(Vector4 o)
63     {
64       r = o.r;
65       g = o.g;
66       b = o.b;
67       a = o.a;
68     }
69
70
71     /**
72      * @brief constructor
73      *
74      * @since 1.0.0
75      * @param [in] color as enum Colors.
76      */
77     public Color(Colors color)
78     {
79       switch (color)
80       {
81         case Colors.Red:
82           SetColor(1.0f, 0.0f, 0.0f, 1.0f);
83           break;
84         case Colors.White:
85           SetColor(1.0f, 1.0f, 1.0f, 1.0f);
86           break;
87         case Colors.Blue:
88           SetColor(0.0f, 0.0f, 1.0f, 1.0f);
89           break;
90         case Colors.Green:
91           SetColor(0.0f, 1.0f, 0.0f, 1.0f);
92           break;
93         case Colors.Black:
94           SetColor(0.0f, 0.0f, 0.0f, 1.0f);
95           break;
96         case Colors.Yellow:
97           SetColor(1.0f, 1.0f, 0.0f, 1.0f);
98           break;
99         case Colors.Cyan:
100           SetColor(0.0f, 1.0f, 1.0f, 1.0f);
101           break;
102         case Colors.Magenta:
103           SetColor(1.0f, 0.0f, 1.0f, 1.0f);
104           break;
105       }
106     }
107
108
109     /**
110      * @brief SetColor
111      *
112      * @since 1.0.0
113      * @param [in] red The Color r.
114      * @param [in] green The Color g.
115      * @param [in] blue The Color b.
116      * @param [in] alpha The Color a.
117      */
118     public void SetColor(float red, float green, float blue, float alpha)
119     {
120       r = red;
121       g = green;
122       b = blue;
123       a = alpha;
124     }
125
126     /**
127      * @brief name "R", type float (Color's Red component)
128      * @SINCE_1_0.0
129      */
130
131     public float R
132     {
133       get { return r; }
134       set { r = value; }
135     }
136
137     /**
138      * @brief name "G", type float (Color's Green component)
139      * @SINCE_1_0.0
140      */
141     public float G
142     {
143       get { return g; }
144       set { g = value; }
145     }
146
147     /**
148      * @brief name "B", type float (Color's Blue component)
149      * @SINCE_1_0.0
150      */
151     public float B
152     {
153       get { return b; }
154       set { b = value; }
155     }
156
157     /**
158      * @brief name "A", type float (Color's Alpha value)
159      * @SINCE_1_0.0
160      */
161     public float A
162     {
163       get { return a; }
164       set { a = value; }
165     }
166
167     /**
168      * @brief operator+
169      *
170      * @since 1.0.0
171      * @param [in] l The Color to add.
172      * @param [in] r The Color to add
173      * @return A reference to this
174      */
175     public static Color operator +(Color l, Color r)
176     {
177       return new Color(l.R + r.R, l.G + r.G, l.B + r.B, l.A + r.A);
178     }
179
180     /**
181      * @brief operator-
182      *
183      * @since 1.0.0
184      * @param [in] l The Color to substract.
185      * @param [in] r The Color to substract
186      * @return A reference to this
187      */
188     public static Color operator -(Color l, Color r)
189     {
190       return new Color(l.R - r.R, l.G - r.G, l.B - r.B, l.A - r.A);
191     }
192
193     /**
194      * @brief operator*
195      *
196      * @since 1.0.0
197      * @param [in] a The Color to multiply.
198      * @param [in] b The constant double to multiply.
199      * @return A reference to this
200      */
201     public static Color operator *(Color a, double b)
202     {
203       return new Color((float)(a.R * b), (float)(a.G * b), (float)(a.B * b), (float)(a.A * b));
204     }
205
206     /**
207      * @brief operator/
208      *
209      * @since 1.0.0
210      * @param [in] a The Color to divide.
211      * @param [in] b The Color to divide
212      * @return float value of division operation
213      */
214     public static float operator /(Color a, Color b)
215     {
216       return (float)System.Math.Sqrt((a.R / b.R) * (a.G / b.G) * (a.B / b.B) * (a.A / b.A));
217     }
218
219     /**
220      * @brief Operator ==
221      *
222      * @since 1.0.0
223      * @param [in] x The Color object to compare.
224      * @param [in] y The Color object to compare.
225      * @return bool, whether colors are equal or not
226      */
227     public static bool operator == (Color x, Color y)
228     {
229       return x.R == y.R && x.G == y.G && x.B == y.B && x.A == y.A;
230     }
231
232     /**
233      * @brief Operator !=
234      *
235      * @since 1.0.0
236      * @param [in] x The Color object to compare.
237      * @param [in] y The Color object to compare.
238      * @return bool, whether colors are equal or not
239      */
240     public static bool operator != (Color x, Color y)
241     {
242       return x.R != y.R || x.G != y.G || x.B != y.B || x.A != y.A;
243     }
244
245     /**
246      * @brief GetHashCode
247      *
248      * @since 1.0.0
249      * @return int, hascode of Color
250      */
251     public override int GetHashCode()
252     {
253       return base.GetHashCode();
254     }
255
256     /**
257      * @brief Clone
258      *
259      * @since 1.0.0
260      * @return Color object
261      */
262     public Color Clone()
263     {
264       Color copy = new Color(R, G, B, A);
265       return copy;
266     }
267
268     // Create a color for RGBA values ranging from 0..255, useful when dealing with HTML colors
269     static Color FromRgbaByte( byte red, byte green, byte blue, byte alpha )
270     {
271       return new Color ( red / 255,  green / 255, blue / 255, alpha / 255 );
272     }
273
274     // User-defined conversion from Color to Vector4
275     public static implicit operator Vector4(Color color)
276     {
277       return new Vector4(color.r, color.g, color.b, color.a);
278     }
279
280     public static implicit operator Color(Vector4 vec)
281     {
282       return new Color(vec.r, vec.g, vec.b, vec.a);
283     }
284
285     /**
286      * @brief name "White", type Color (White Color object)
287      * @SINCE_1_0.0
288      */
289     public static Color White
290     {
291       get
292       {
293         return new Color(Colors.White);
294       }
295     }
296
297     /**
298      * @brief name "Black", type Color (Black Color object)
299      * @SINCE_1_0.0
300      */
301     public static Color Black
302     {
303       get
304       {
305         return new Color(Colors.Black);
306       }
307     }
308
309     /**
310      * @brief name "Red", type Color (Red Color object)
311      * @SINCE_1_0.0
312      */
313     public static Color Red
314     {
315       get
316       {
317         return new Color(Colors.Red);
318       }
319     }
320
321     /**
322      * @brief name "Green", type Color (Green Color object)
323      * @SINCE_1_0.0
324      */
325     public static Color Green
326     {
327       get
328       {
329         return new Color(Colors.Green);
330       }
331     }
332
333     /**
334      * @brief name "Blue", type Color (Blue Color object)
335      * @SINCE_1_0.0
336      */
337     public static Color Blue
338     {
339       get
340       {
341         return new Color(Colors.Blue);
342       }
343     }
344
345     /**
346      * @brief name "Yellow", type Color (Yellow Color object)
347      * @SINCE_1_0.0
348      */
349     public static Color Yellow
350     {
351       get
352       {
353         return new Color(Colors.Yellow);
354       }
355     }
356
357     /**
358      * @brief name "Magenta", type Color (Magenta Color object)
359      * @SINCE_1_0.0
360      */
361     public static Color Magenta
362     {
363       get
364       {
365         return new Color(Colors.Magenta);
366       }
367     }
368
369     /**
370      * @brief name "Cyan", type Color (Cyan Color object)
371      * @SINCE_1_0.0
372      */
373     public static Color Cyan
374     {
375       get
376       {
377         return new Color(Colors.Cyan);
378       }
379     }
380   }
381 }