Merge "DALi C# binding - Write pure C# Color & Position classes and use typemaps...
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / manual / csharp / Color.cs
1 namespace Dali {
2   namespace CSharp {
3
4     using System;
5
6     public enum Colors
7     {
8       Red,
9       White,
10       Blue,
11       Green,
12       Black,
13       Grey,
14       Yellow,
15       Azure,
16       Rose
17     }
18
19     public class Color
20     {
21
22       public float[] v;
23
24       /**
25        * @brief constructor
26        *
27        * @since 1.0.0
28        */
29       public Color()
30       {
31         v = new float[4];
32       }
33
34       /**
35        * @brief constructor
36        *
37        * @since 1.0.0
38        * @param [in] red The Color r.
39        * @param [in] green The Color g.
40        * @param [in] blue The Color b.
41        * @param [in] alpha The Color a.
42        */
43       public Color(float red, float green, float blue, float alpha):this()
44       {
45         v[0] = red;
46         v[1] = green;
47         v[2] = blue;
48         v[3] = alpha;
49       }
50
51
52       /**
53        * @brief constructor
54        *
55        * @since 1.0.0
56        * @param [in] color as enum Colors.
57        */
58       public Color(Colors color)
59         : this(0, 0, 0, 0)
60       {
61         switch (color)
62         {
63           case Colors.Red:
64             SetColor(255, 0, 0, 255);
65             break;
66           case Colors.White:
67             SetColor(255, 255, 255, 255);
68             break;
69           case Colors.Blue:
70             SetColor(0, 0, 255, 255);
71             break;
72           case Colors.Green:
73             SetColor(0, 255, 0, 255);
74             break;
75           case Colors.Black:
76             SetColor(0, 0, 0, 255);
77             break;
78           case Colors.Grey:
79             SetColor(128, 128, 128, 255);
80             break;
81           case Colors.Yellow:
82             SetColor(255, 255, 0, 255);
83             break;
84           case Colors.Azure:
85             SetColor(0, 255, 255, 255);
86             break;
87           case Colors.Rose:
88             SetColor(255, 0, 255, 255);
89             break;
90         }
91       }
92
93
94
95       /**
96        * @brief SetColor
97        *
98        * @since 1.0.0
99        * @param [in] red The Color r.
100        * @param [in] green The Color g.
101        * @param [in] blue The Color b.
102        * @param [in] alpha The Color a.
103        */
104       public void SetColor(float red, float green, float blue, float alpha)
105       {
106         R = red;
107         G = green;
108         B = blue;
109         A = alpha;
110       }
111
112       /**
113        * @brief name "R", type float (Color's Red component)
114        * @SINCE_1_0.0
115        */
116
117       public float R
118       {
119         get { return v[0]; }
120         set { v[0] = value; }
121       }
122
123       /**
124        * @brief name "G", type float (Color's Green component)
125        * @SINCE_1_0.0
126        */
127       public float G
128       {
129         get { return v[1]; }
130         set { v[1] = value; }
131       }
132
133       /**
134        * @brief name "B", type float (Color's Blue component)
135        * @SINCE_1_0.0
136        */
137       public float B
138       {
139         get { return v[2]; }
140         set { v[2] = value; }
141       }
142
143       /**
144        * @brief name "A", type float (Color's Alpha value)
145        * @SINCE_1_0.0
146        */
147       public float A
148       {
149         get { return v[3]; }
150         set { v[3] = value; }
151       }
152
153       /**
154        * @brief operator+
155        *
156        * @since 1.0.0
157        * @param [in] l The Color to add.
158        * @param [in] r The Color to add
159        * @return A reference to this
160        */
161       public static Color operator +(Color l, Color r)
162       {
163         return new Color(l.R + r.R, l.G + r.G, l.B + r.B, l.A + r.A);
164       }
165
166       /**
167        * @brief operator-
168        *
169        * @since 1.0.0
170        * @param [in] l The Color to substract.
171        * @param [in] r The Color to substract
172        * @return A reference to this
173        */
174       public static Color operator -(Color l, Color r)
175       {
176         return new Color(l.R - r.R, l.G - r.G, l.B - r.B, l.A - r.A);
177       }
178
179       /**
180        * @brief operator*
181        *
182        * @since 1.0.0
183        * @param [in] a The Color to multiply.
184        * @param [in] b The Color to multiply
185        * @return A reference to this
186        */
187       public static Color operator *(Color a, double b)
188       {
189         return new Color((float)(a.R * b),(float)(a.G * b), (float)(a.B * b), (float)(a.A * b));
190       }
191
192       /**
193        * @brief operator/
194        *
195        * @since 1.0.0
196        * @param [in] a The Color to divide.
197        * @param [in] b The Color to divide
198        * @return float value of division operation
199        */
200       public static float operator /(Color a, Color b)
201       {
202         return (float)System.Math.Sqrt((a.R / b.R) * (a.G / b.G) * (a.B / b.B) * (a.A / b.A));
203       }
204
205       /**
206        * @brief Equals
207        *
208        * @since 1.0.0
209        * @param [in] o The Color object to compare.
210        * @param [in] r The Color to add
211        * @return bool, whether object equal or not
212        */
213       public override bool Equals(object obj)
214       {
215         Color l = this;
216         Color r = obj as Color;
217         if (r == null)
218         {
219           return false;
220         }
221         return l.R == r.R && l.G == r.G && l.B == r.B && l.A == r.A;
222       }
223
224       /**
225        * @brief Clone
226        *
227        * @since 1.0.0
228        * @return Color object
229        */
230       public Color Clone()
231       {
232         Color copy = new Color(R, G, B, A);
233         return copy;
234       }
235     }
236   }
237
238 }