2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Globalization;
23 /// The Color is a struct to record the check's state.
25 /// <since_tizen> preview </since_tizen>
26 [Obsolete("This has been deprecated in API12")]
43 /// Gets a default Color instance.
46 /// In the default Color instance, the mode type is default with RGBA all set as -1.
48 /// <since_tizen> preview </since_tizen>
49 [Obsolete("This has been deprecated in API12")]
50 public static Color Default
52 get { return new Color(-1, -1, -1, -1, Mode.Default); }
56 /// Gets whether the Color instance's mode is default or not.
57 /// The return type is bool.
59 /// <since_tizen> preview </since_tizen>
60 [Obsolete("This has been deprecated in API12")]
63 get { return _mode == Mode.Default; }
67 /// Gets the A value of RGBA.
68 /// A means the Alpha in color.
70 /// <since_tizen> preview </since_tizen>
71 [Obsolete("This has been deprecated in API12")]
78 /// Gets the R value of RGBA.
79 /// R means the Red in color.
81 /// <since_tizen> preview </since_tizen>
82 [Obsolete("This has been deprecated in API12")]
89 /// Gets the G value of RGBA.
90 /// G means the Green in color.
92 /// <since_tizen> preview </since_tizen>
93 [Obsolete("This has been deprecated in API12")]
100 /// Gets the B value of RGBA.
101 /// B means the Blue in color.
103 /// <since_tizen> preview </since_tizen>
104 [Obsolete("This has been deprecated in API12")]
111 /// Creates and initializes a new instance of the Color class
112 /// with RGB parameters.
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)
124 /// Creates and initializes a new instance of the Color class
125 /// with RGBA parameters.
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)
137 Color(int r, int g, int b, int a, Mode mode)
140 if (mode == Mode.Rgb)
142 _r = Clamp(r, 0, 255);
143 _g = Clamp(g, 0, 255);
144 _b = Clamp(b, 0, 255);
145 _a = Clamp(a, 0, 255);
149 _r = _g = _b = _a = -1;
154 /// Returns the hash code for this instance.
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()
161 int hashcode = _r.GetHashCode();
162 hashcode = (hashcode * 397) ^ _g.GetHashCode();
163 hashcode = (hashcode * 397) ^ _b.GetHashCode();
164 hashcode = (hashcode * 397) ^ _a.GetHashCode();
169 /// Indicates whether this instance and a specified object are equal.
171 /// <param name="obj">The object to compare with the current instance.</param>
173 /// true if the object and this instance are of the same type and represent the same value.
174 /// otherwise, false.
176 /// <since_tizen> preview </since_tizen>
177 [Obsolete("This has been deprecated in API12")]
178 public override bool Equals(object obj)
182 return EqualsInner(this, (Color)obj);
184 return base.Equals(obj);
188 /// Compares whether the two Color instances are same or not.
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.
195 /// <since_tizen> preview </since_tizen>
196 [Obsolete("This has been deprecated in API12")]
197 public static bool operator ==(Color a, Color b)
199 return EqualsInner(a, b);
203 /// Compares whether the two Color instances are different or not.
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.
210 /// <since_tizen> preview </since_tizen>
211 [Obsolete("This has been deprecated in API12")]
212 public static bool operator !=(Color a, Color b)
217 static bool EqualsInner(Color color1, Color color2)
219 if (color1._mode == Mode.Default && color2._mode == Mode.Default)
221 return color1._r == color2._r && color1._g == color2._g && color1._b == color2._b && color1._a == color2._a;
225 /// Returns the fully qualified type name of this instance.
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()
232 return string.Format(CultureInfo.InvariantCulture, "[Color: R={0}, G={1}, B={2}, A={3}]", R, G, B, A);
236 /// Gets a Color instance with a hexadecimal string parameter.
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)
244 string ret = hex.Replace("#", "");
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]);
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]);
253 case 6: //#rrggbb => ffrrggbb
254 ret = string.Format("ff{0}", ret);
257 return FromUint(Convert.ToUInt32(ret.Replace("#", ""), 16));
261 /// Gets a Color instance with an unsigned integer parameter.
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)
269 return FromRgba((byte)((argb & 0x00ff0000) >> 0x10), (byte)((argb & 0x0000ff00) >> 0x8), (byte)(argb & 0x000000ff), (byte)((argb & 0xff000000) >> 0x18));
273 /// Gets a Color instance with R,G,B,A parameters.
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)
284 return new Color(r, g, b, a);
288 /// Gets a Color instance with R,G,B parameters.
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)
298 return FromRgba(r, g, b, 255);
301 internal static int Clamp(int self, int min, int max)
303 return Math.Min(max, Math.Max(self, min));
306 #region Color Definitions
308 /// The Tansparent is a predefined Color instance. It's RGBA value is (0, 0, 0, 0).
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);
314 /// The Aqua is a predefined Color instance. It's RGB value is (0, 255, 255).
316 /// <since_tizen> preview </since_tizen>
317 [Obsolete("This has been deprecated in API12")]
318 public static readonly Color Aqua = FromRgb(0, 255, 255);
320 /// The Black is a predefined Color instance. It's RGB value is (0, 0, 0).
322 /// <since_tizen> preview </since_tizen>
323 [Obsolete("This has been deprecated in API12")]
324 public static readonly Color Black = FromRgb(0, 0, 0);
326 /// The Blue is a predefined Color instance. It's RGB value is (0, 0, 255).
328 /// <since_tizen> preview </since_tizen>
329 [Obsolete("This has been deprecated in API12")]
330 public static readonly Color Blue = FromRgb(0, 0, 255);
332 /// The Fuchsia is a predefined Color instance. It's RGB value is (255, 0, 255).
334 /// <since_tizen> preview </since_tizen>
335 [Obsolete("This has been deprecated in API12")]
336 public static readonly Color Fuchsia = FromRgb(255, 0, 255);
338 /// The Gray is a predefined Color instance. It's RGB value is (128, 128, 128).
340 /// <since_tizen> preview </since_tizen>
341 [Obsolete("This has been deprecated in API12")]
342 public static readonly Color Gray = FromRgb(128, 128, 128);
344 /// The Green is a predefined Color instance. It's RGB value is (0, 128, 0).
346 /// <since_tizen> preview </since_tizen>
347 [Obsolete("This has been deprecated in API12")]
348 public static readonly Color Green = FromRgb(0, 128, 0);
350 /// The Lime is a predefined Color instance. It's RGB value is (0, 255, 0).
352 /// <since_tizen> preview </since_tizen>
353 [Obsolete("This has been deprecated in API12")]
354 public static readonly Color Lime = FromRgb(0, 255, 0);
356 /// The Maroon is a predefined Color instance. It's RGB value is (128, 0, 0).
358 /// <since_tizen> preview </since_tizen>
359 [Obsolete("This has been deprecated in API12")]
360 public static readonly Color Maroon = FromRgb(128, 0, 0);
362 /// The Navy is a predefined Color instance. It's RGB value is (0, 0, 128).
364 /// <since_tizen> preview </since_tizen>
365 [Obsolete("This has been deprecated in API12")]
366 public static readonly Color Navy = FromRgb(0, 0, 128);
368 /// The Olive is a predefined Color instance. It's RGB value is (128, 128, 0).
370 /// <since_tizen> preview </since_tizen>
371 [Obsolete("This has been deprecated in API12")]
372 public static readonly Color Olive = FromRgb(128, 128, 0);
374 /// The Orange is a predefined Color instance. It's RGB value is (255, 165, 0).
376 /// <since_tizen> preview </since_tizen>
377 [Obsolete("This has been deprecated in API12")]
378 public static readonly Color Orange = FromRgb(255, 165, 0);
380 /// The Purple is a predefined Color instance. It's RGB value is (128, 0, 128).
382 /// <since_tizen> preview </since_tizen>
383 [Obsolete("This has been deprecated in API12")]
384 public static readonly Color Purple = FromRgb(128, 0, 128);
386 /// The Pink is a predefined Color instance. It's RGB value is (255, 102, 255).
388 /// <since_tizen> preview </since_tizen>
389 [Obsolete("This has been deprecated in API12")]
390 public static readonly Color Pink = FromRgb(255, 102, 255);
392 /// The Red is a predefined Color instance. It's RGB value is (255, 0, 0).
394 /// <since_tizen> preview </since_tizen>
395 [Obsolete("This has been deprecated in API12")]
396 public static readonly Color Red = FromRgb(255, 0, 0);
398 /// The Silver is a predefined Color instance. It's RGB value is (192, 192, 192).
400 /// <since_tizen> preview </since_tizen>
401 [Obsolete("This has been deprecated in API12")]
402 public static readonly Color Silver = FromRgb(192, 192, 192);
404 /// The Teal is a predefined Color instance. It's RGB value is (0, 128, 128).
406 /// <since_tizen> preview </since_tizen>
407 [Obsolete("This has been deprecated in API12")]
408 public static readonly Color Teal = FromRgb(0, 128, 128);
410 /// The White is a predefined Color instance. It's RGB value is (255, 255, 255).
412 /// <since_tizen> preview </since_tizen>
413 [Obsolete("This has been deprecated in API12")]
414 public static readonly Color White = FromRgb(255, 255, 255);
416 /// The Yellow is a predefined Color instance. It's RGB value is (255, 255, 0).
418 /// <since_tizen> preview </since_tizen>
419 [Obsolete("This has been deprecated in API12")]
420 public static readonly Color Yellow = FromRgb(255, 255, 0);