[ACR-564] deprecate unused API
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Color.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Globalization;
19
20 namespace ElmSharp
21 {
22     /// <summary>
23     /// The Color is a struct to record the check's state.
24     /// </summary>
25     /// <since_tizen> preview </since_tizen>
26     [Obsolete("This has been deprecated in API12")]
27     public struct Color
28     {
29         readonly int _a;
30         readonly int _r;
31         readonly int _g;
32         readonly int _b;
33
34         readonly Mode _mode;
35
36         enum Mode
37         {
38             Default,
39             Rgb
40         }
41
42         /// <summary>
43         /// Gets a default Color instance.
44         /// </summary>
45         /// <remarks>
46         /// In the default Color instance, the mode type is default with RGBA all set as -1.
47         /// </remarks>
48         /// <since_tizen> preview </since_tizen>
49         [Obsolete("This has been deprecated in API12")]
50         public static Color Default
51         {
52             get { return new Color(-1, -1, -1, -1, Mode.Default); }
53         }
54
55         /// <summary>
56         /// Gets whether the Color instance's mode is default or not.
57         /// The return type is bool.
58         /// </summary>
59         /// <since_tizen> preview </since_tizen>
60         [Obsolete("This has been deprecated in API12")]
61         public bool IsDefault
62         {
63             get { return _mode == Mode.Default; }
64         }
65
66         /// <summary>
67         /// Gets the A value of RGBA.
68         /// A means the Alpha in color.
69         /// </summary>
70         /// <since_tizen> preview </since_tizen>
71         [Obsolete("This has been deprecated in API12")]
72         public int A
73         {
74             get { return _a; }
75         }
76
77         /// <summary>
78         /// Gets the R value of RGBA.
79         /// R means the Red in color.
80         /// </summary>
81         /// <since_tizen> preview </since_tizen>
82         [Obsolete("This has been deprecated in API12")]
83         public int R
84         {
85             get { return _r; }
86         }
87
88         /// <summary>
89         /// Gets the G value of RGBA.
90         /// G means the Green in color.
91         /// </summary>
92         /// <since_tizen> preview </since_tizen>
93         [Obsolete("This has been deprecated in API12")]
94         public int G
95         {
96             get { return _g; }
97         }
98
99         /// <summary>
100         /// Gets the B value of RGBA.
101         /// B means the Blue in color.
102         /// </summary>
103         /// <since_tizen> preview </since_tizen>
104         [Obsolete("This has been deprecated in API12")]
105         public int B
106         {
107             get { return _b; }
108         }
109
110         /// <summary>
111         /// Creates and initializes a new instance of the Color class
112         /// with RGB parameters.
113         /// </summary>
114         /// <param name="r">Red of RGB.</param>
115         /// <param name="g">Green of RGB.</param>
116         /// <param name="b">Blue of RGB.</param>
117         /// <since_tizen> preview </since_tizen>
118         [Obsolete("This has been deprecated in API12")]
119         public Color(int r, int g, int b) : this(r, g, b, 255)
120         {
121         }
122
123         /// <summary>
124         /// Creates and initializes a new instance of the Color class
125         /// with RGBA parameters.
126         /// </summary>
127         /// <param name="r">Red of RGBA.</param>
128         /// <param name="g">Green of RGBA.</param>
129         /// <param name="b">Blue of RGBA.</param>
130         /// <param name="a">Alpha of RGBA.</param>
131         /// <since_tizen> preview </since_tizen>
132         [Obsolete("This has been deprecated in API12")]
133         public Color(int r, int g, int b, int a) : this(r, g, b, a, Mode.Rgb)
134         {
135         }
136
137         Color(int r, int g, int b, int a, Mode mode)
138         {
139             _mode = mode;
140             if (mode == Mode.Rgb)
141             {
142                 _r = Clamp(r, 0, 255);
143                 _g = Clamp(g, 0, 255);
144                 _b = Clamp(b, 0, 255);
145                 _a = Clamp(a, 0, 255);
146             }
147             else // Default
148             {
149                 _r = _g = _b = _a = -1;
150             }
151         }
152
153         /// <summary>
154         /// Returns the hash code for this instance.
155         /// </summary>
156         /// <returns>A 32-bit signed integer hash code.</returns>
157         /// <since_tizen> preview </since_tizen>
158         [Obsolete("This has been deprecated in API12")]
159         public override int GetHashCode()
160         {
161             int hashcode = _r.GetHashCode();
162             hashcode = (hashcode * 397) ^ _g.GetHashCode();
163             hashcode = (hashcode * 397) ^ _b.GetHashCode();
164             hashcode = (hashcode * 397) ^ _a.GetHashCode();
165             return hashcode;
166         }
167
168         /// <summary>
169         /// Indicates whether this instance and a specified object are equal.
170         /// </summary>
171         /// <param name="obj">The object to compare with the current instance.</param>
172         /// <returns>
173         /// true if the object and this instance are of the same type and represent the same value.
174         /// otherwise, false.
175         /// </returns>
176         /// <since_tizen> preview </since_tizen>
177         [Obsolete("This has been deprecated in API12")]
178         public override bool Equals(object obj)
179         {
180             if (obj is Color)
181             {
182                 return EqualsInner(this, (Color)obj);
183             }
184             return base.Equals(obj);
185         }
186
187         /// <summary>
188         /// Compares whether the two Color instances are same or not.
189         /// </summary>
190         /// <param name="a">A Color instance.</param>
191         /// <param name="b">A Color instance.</param>
192         /// <returns>The result whether the two instances are the same or not.
193         /// Return type is bool. If they are same, return true.
194         /// </returns>
195         /// <since_tizen> preview </since_tizen>
196         [Obsolete("This has been deprecated in API12")]
197         public static bool operator ==(Color a, Color b)
198         {
199             return EqualsInner(a, b);
200         }
201
202         /// <summary>
203         /// Compares whether the two Color instances are different or not.
204         /// </summary>
205         /// <param name="a">A Color instance.</param>
206         /// <param name="b">A Color instance.</param>
207         /// <returns>The result whether the two instances are different or not.
208         /// Return type is bool. If they are different, return true.
209         /// </returns>
210         /// <since_tizen> preview </since_tizen>
211         [Obsolete("This has been deprecated in API12")]
212         public static bool operator !=(Color a, Color b)
213         {
214             return !(a == b);
215         }
216
217         static bool EqualsInner(Color color1, Color color2)
218         {
219             if (color1._mode == Mode.Default && color2._mode == Mode.Default)
220                 return true;
221             return color1._r == color2._r && color1._g == color2._g && color1._b == color2._b && color1._a == color2._a;
222         }
223
224         /// <summary>
225         /// Returns the fully qualified type name of this instance.
226         /// </summary>
227         /// <returns>The fully qualified type name.</returns>
228         /// <since_tizen> preview </since_tizen>
229         [Obsolete("This has been deprecated in API12")]
230         public override string ToString()
231         {
232             return string.Format(CultureInfo.InvariantCulture, "[Color: R={0}, G={1}, B={2}, A={3}]", R, G, B, A);
233         }
234
235         /// <summary>
236         /// Gets a Color instance with a hexadecimal string parameter.
237         /// </summary>
238         /// <param name="hex">Hexadecimal string.</param>
239         /// <returns>New instance of the Color struct.</returns>
240         /// <since_tizen> preview </since_tizen>
241         [Obsolete("This has been deprecated in API12")]
242         public static Color FromHex(string hex)
243         {
244             string ret = hex.Replace("#", "");
245             switch (ret.Length)
246             {
247                 case 3: //#rgb => ffrrggbb
248                     ret = string.Format("ff{0}{1}{2}{3}{4}{5}", ret[0], ret[0], ret[1], ret[1], ret[2], ret[2]);
249                     break;
250                 case 4: //#argb => aarrggbb
251                     ret = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}", ret[0], ret[0], ret[1], ret[1], ret[2], ret[2], ret[3], ret[3]);
252                     break;
253                 case 6: //#rrggbb => ffrrggbb
254                     ret = string.Format("ff{0}", ret);
255                     break;
256             }
257             return FromUint(Convert.ToUInt32(ret.Replace("#", ""), 16));
258         }
259
260         /// <summary>
261         /// Gets a Color instance with an unsigned integer parameter.
262         /// </summary>
263         /// <param name="argb">Unsigned integer indicates RGBA.</param>
264         /// <returns>New instance of the Color struct.</returns>
265         /// <since_tizen> preview </since_tizen>
266         [Obsolete("This has been deprecated in API12")]
267         public static Color FromUint(uint argb)
268         {
269             return FromRgba((byte)((argb & 0x00ff0000) >> 0x10), (byte)((argb & 0x0000ff00) >> 0x8), (byte)(argb & 0x000000ff), (byte)((argb & 0xff000000) >> 0x18));
270         }
271
272         /// <summary>
273         /// Gets a Color instance with R,G,B,A parameters.
274         /// </summary>
275         /// <param name="r">Red of RGBA.</param>
276         /// <param name="g">Green of RGBA.</param>
277         /// <param name="b">Blue of RGBA.</param>
278         /// <param name="a">Alpha of RGBA.</param>
279         /// <returns>New instance of the Color struct.</returns>
280         /// <since_tizen> preview </since_tizen>
281         [Obsolete("This has been deprecated in API12")]
282         public static Color FromRgba(int r, int g, int b, int a)
283         {
284             return new Color(r, g, b, a);
285         }
286
287         /// <summary>
288         /// Gets a Color instance with R,G,B parameters.
289         /// </summary>
290         /// <param name="r">Red of RGB.</param>
291         /// <param name="g">Green of RGB.</param>
292         /// <param name="b">Blue of RGB.</param>
293         /// <returns>New instance of the Color struct.</returns>
294         /// <since_tizen> preview </since_tizen>
295         [Obsolete("This has been deprecated in API12")]
296         public static Color FromRgb(int r, int g, int b)
297         {
298             return FromRgba(r, g, b, 255);
299         }
300
301         internal static int Clamp(int self, int min, int max)
302         {
303             return Math.Min(max, Math.Max(self, min));
304         }
305
306         #region Color Definitions
307         /// <summary>
308         /// The Tansparent is a predefined Color instance. It's RGBA value is (0, 0, 0, 0).
309         /// </summary>
310         /// <since_tizen> preview </since_tizen>
311         [Obsolete("This has been deprecated in API12")]
312         public static readonly Color Transparent = FromRgba(0, 0, 0, 0);
313         /// <summary>
314         /// The Aqua is a predefined Color instance. It's RGB value is (0, 255, 255).
315         /// </summary>
316         /// <since_tizen> preview </since_tizen>
317         [Obsolete("This has been deprecated in API12")]
318         public static readonly Color Aqua = FromRgb(0, 255, 255);
319         /// <summary>
320         /// The Black is a predefined Color instance. It's RGB value is (0, 0, 0).
321         /// </summary>
322         /// <since_tizen> preview </since_tizen>
323         [Obsolete("This has been deprecated in API12")]
324         public static readonly Color Black = FromRgb(0, 0, 0);
325         /// <summary>
326         /// The Blue is a predefined Color instance. It's RGB value is (0, 0, 255).
327         /// </summary>
328         /// <since_tizen> preview </since_tizen>
329         [Obsolete("This has been deprecated in API12")]
330         public static readonly Color Blue = FromRgb(0, 0, 255);
331         /// <summary>
332         /// The Fuchsia is a predefined Color instance. It's RGB value is (255, 0, 255).
333         /// </summary>
334         /// <since_tizen> preview </since_tizen>
335         [Obsolete("This has been deprecated in API12")]
336         public static readonly Color Fuchsia = FromRgb(255, 0, 255);
337         /// <summary>
338         /// The Gray is a predefined Color instance. It's RGB value is (128, 128, 128).
339         /// </summary>
340         /// <since_tizen> preview </since_tizen>
341         [Obsolete("This has been deprecated in API12")]
342         public static readonly Color Gray = FromRgb(128, 128, 128);
343         /// <summary>
344         /// The Green is a predefined Color instance. It's RGB value is (0, 128, 0).
345         /// </summary>
346         /// <since_tizen> preview </since_tizen>
347         [Obsolete("This has been deprecated in API12")]
348         public static readonly Color Green = FromRgb(0, 128, 0);
349         /// <summary>
350         /// The Lime is a predefined Color instance. It's RGB value is (0, 255, 0).
351         /// </summary>
352         /// <since_tizen> preview </since_tizen>
353         [Obsolete("This has been deprecated in API12")]
354         public static readonly Color Lime = FromRgb(0, 255, 0);
355         /// <summary>
356         /// The Maroon is a predefined Color instance. It's RGB value is (128, 0, 0).
357         /// </summary>
358         /// <since_tizen> preview </since_tizen>
359         [Obsolete("This has been deprecated in API12")]
360         public static readonly Color Maroon = FromRgb(128, 0, 0);
361         /// <summary>
362         /// The Navy is a predefined Color instance. It's RGB value is (0, 0, 128).
363         /// </summary>
364         /// <since_tizen> preview </since_tizen>
365         [Obsolete("This has been deprecated in API12")]
366         public static readonly Color Navy = FromRgb(0, 0, 128);
367         /// <summary>
368         /// The Olive is a predefined Color instance. It's RGB value is (128, 128, 0).
369         /// </summary>
370         /// <since_tizen> preview </since_tizen>
371         [Obsolete("This has been deprecated in API12")]
372         public static readonly Color Olive = FromRgb(128, 128, 0);
373         /// <summary>
374         /// The Orange is a predefined Color instance. It's RGB value is (255, 165, 0).
375         /// </summary>
376         /// <since_tizen> preview </since_tizen>
377         [Obsolete("This has been deprecated in API12")]
378         public static readonly Color Orange = FromRgb(255, 165, 0);
379         /// <summary>
380         /// The Purple is a predefined Color instance. It's RGB value is (128, 0, 128).
381         /// </summary>
382         /// <since_tizen> preview </since_tizen>
383         [Obsolete("This has been deprecated in API12")]
384         public static readonly Color Purple = FromRgb(128, 0, 128);
385         /// <summary>
386         /// The Pink is a predefined Color instance. It's RGB value is (255, 102, 255).
387         /// </summary>
388         /// <since_tizen> preview </since_tizen>
389         [Obsolete("This has been deprecated in API12")]
390         public static readonly Color Pink = FromRgb(255, 102, 255);
391         /// <summary>
392         /// The Red is a predefined Color instance. It's RGB value is (255, 0, 0).
393         /// </summary>
394         /// <since_tizen> preview </since_tizen>
395         [Obsolete("This has been deprecated in API12")]
396         public static readonly Color Red = FromRgb(255, 0, 0);
397         /// <summary>
398         /// The Silver is a predefined Color instance. It's RGB value is (192, 192, 192).
399         /// </summary>
400         /// <since_tizen> preview </since_tizen>
401         [Obsolete("This has been deprecated in API12")]
402         public static readonly Color Silver = FromRgb(192, 192, 192);
403         /// <summary>
404         /// The Teal is a predefined Color instance. It's RGB value is (0, 128, 128).
405         /// </summary>
406         /// <since_tizen> preview </since_tizen>
407         [Obsolete("This has been deprecated in API12")]
408         public static readonly Color Teal = FromRgb(0, 128, 128);
409         /// <summary>
410         /// The White is a predefined Color instance. It's RGB value is (255, 255, 255).
411         /// </summary>
412         /// <since_tizen> preview </since_tizen>
413         [Obsolete("This has been deprecated in API12")]
414         public static readonly Color White = FromRgb(255, 255, 255);
415         /// <summary>
416         /// The Yellow is a predefined Color instance. It's RGB value is (255, 255, 0).
417         /// </summary>
418         /// <since_tizen> preview </since_tizen>
419         [Obsolete("This has been deprecated in API12")]
420         public static readonly Color Yellow = FromRgb(255, 255, 0);
421         #endregion
422     }
423 }