2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 * @brief This is the header file for the %Color class.
22 * This header file contains the declarations of the %Color class.
26 #ifndef _FGRP_COLOR_H_
27 #define _FGRP_COLOR_H_
29 #include <FBaseTypes.h>
30 #include <FBaseObject.h>
32 namespace Tizen { namespace Graphics
37 * @brief This template code makes a 32-bit combination from each color component
40 * The following example demonstrates how to use this template code
44 * #include <FGraphics.h>
46 * using namespace Tizen::Graphics;
48 * // 0xFFFF00FF: Opaque magenta
49 * const unsigned int MY_COLOR1 = Color32<255, 0, 255>::Value;
51 * // 0x80FF0000: Red with 50% opacity
52 * const unsigned int MY_COLOR2 = Color32<255, 0, 0, 128>::Value;
56 template <unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 0xFF>
61 Value = static_cast<unsigned int>(alpha) << 24 |
62 static_cast<unsigned int>(red) << 16 |
63 static_cast<unsigned int>(green) << 8 |
64 static_cast<unsigned int>(blue)
71 * Defines the color ID.
77 COLOR_ID_BLACK, /**< This attribute is pre-defined. Its value is black. */
78 COLOR_ID_BLUE, /**< This attribute is pre-defined. Its value is blue. */
79 COLOR_ID_CYAN, /**< This attribute is pre-defined. Its value is cyan. */
80 COLOR_ID_GREEN, /**< This attribute is pre-defined. Its value is green. */
81 COLOR_ID_GREY, /**< This attribute is pre-defined. Its value is grey. */
82 COLOR_ID_MAGENTA, /**< This attribute is pre-defined. Its value is magenta. */
83 COLOR_ID_RED, /**< This attribute is pre-defined. Its value is red. */
84 COLOR_ID_VIOLET, /**< This attribute is pre-defined. Its value is violet. */
85 COLOR_ID_YELLOW, /**< This attribute is pre-defined. Its value is yellow. */
86 COLOR_ID_WHITE /**< This attribute is pre-defined. Its value is white. */
91 * @brief This class encapsulates a color.
95 * @final This class is not intended for extension.
97 * The %Color class provides an ARGB (Alpha, Red, Green, Blue) color model.
99 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/graphics/color.htm">Color</a>.
101 class _OSP_EXPORT_ Color
102 : public Tizen::Base::Object
107 * This is the default constructor for this class.
114 * This is the copy constructor for the %Color class. @n
115 * This constructor initializes the instance of %Color with the attributes of the specified instance of %Color.
119 * @param[in] rhs An instance of %Color
121 Color(const Color& rhs);
124 * Initializes the instance of %Color with the specified ARGB values.
128 * @param[in] r The red component
129 * @param[in] g The green component
130 * @param[in] b The blue component
131 * @param[in] a The alpha component
133 Color(byte r, byte g, byte b, byte a = 0xFF);
136 * Initializes the instance of %Color with the specified RGB value.
140 * @param[in] rgb The RGB color value
141 * @param[in] hasAlpha Set to @c true if @c rgb contains an alpha value, @n
144 Color(unsigned int rgb, bool hasAlpha = true);
147 * This is the destructor for this class.
151 virtual ~Color(void);
156 * Checks whether the two instances of %Color are equal.
160 * @return @c true if the values of the two instances of %Color are equal, @n
162 * @param[in] rhs An instance of %Color
164 bool operator ==(const Color& rhs) const;
167 * Checks whether the two instances of %Color are not equal.
171 * @return @c true if the values of the two instances of %Color are not equal, @n
173 * @param[in] rhs An instance of %Color
176 bool operator !=(const Color& rhs) const;
179 * Assigns the values of the RGB components of the specified instance to the current instance of %Color.
183 * @return The reference to the instance of %Color
184 * @param[in] rhs An instance of %Color
186 Color& operator =(const Color& rhs);
191 * Checks whether the current instance of %Color equals the specified instance of %Color.
195 * @return @c true if the values of the current instance is equal to the value of the specified instance, @n
197 * @param[in] rhs An instance of %Color
198 * @remarks This method overrides Tizen::Base::Object::Equals(). This method uses the values of the RGB components to compare the two instances.
200 virtual bool Equals(const Tizen::Base::Object& rhs) const;
203 * Gets the hash value of the current instance of %Color.
207 * @return The hash value of the current instance
208 * @remarks Two equal instances must return the same hash value. For better performance,
209 * the used hash function must generate a random distribution for all inputs.
211 virtual int GetHashCode(void) const;
216 * Gets the value of the alpha component of the current instance of %Color.
220 * @return A @c byte representation of the alpha component of the current instance of %Color
222 byte GetAlpha(void) const;
225 * Gets the value of the red component of the current instance of %Color.
229 * @return A @c byte representation of the red component of the current instance of %Color
231 byte GetRed(void) const;
234 * Gets the value of the blue component of the current instance of %Color.
238 * @return A @c byte representation of the blue component of the current instance of %Color
240 byte GetBlue(void) const;
243 * Gets the value of the green component of the current instance of %Color.
247 * @return A @c byte representation of the green component of the current instance of %Color
249 byte GetGreen(void) const;
252 * Gets the ARGB components of the current instance of %Color.
256 * @param[out] r The red component
257 * @param[out] g The green component
258 * @param[out] b The blue component
259 * @param[out] a The alpha component
261 void GetColorComponents(byte& r, byte& g, byte& b, byte& a) const;
264 * Gets the 32-bit integer value of the current instance of %Color.
268 * @return An @c unsigned integer value representing the current instance of %Color
270 unsigned int GetRGB32(void) const;
273 * Sets the value of the alpha component of the current instance of %Color.
277 * @param[in] a The new value of the alpha component
279 void SetAlpha(byte a);
282 * Sets the value of the red component of the current instance of %Color.
286 * @param[in] r The new value of the red component
291 * Sets the value of the green component of the current instance of %Color.
295 * @param[in] g The new value of the green component
297 void SetGreen(byte g);
300 * Sets the value of the blue component of the current instance of %Color.
304 * @param[in] b The new value of the blue component
306 void SetBlue(byte b);
309 * Sets the values of the ARGB components of the current instance of %Color.
313 * @param[in] r The red component
314 * @param[in] g The green component
315 * @param[in] b The blue component
316 * @param[in] a The alpha component
318 void SetColorComponents(byte r, byte g, byte b, byte a = 0xFF);
321 * Sets the current instance of %Color to the specified 32-bit integer value.
325 * @param[in] rgb The new RGB color value
326 * @param[in] hasAlpha @c true if @c rgb contains alpha value, @n
329 void SetRGB32(unsigned int rgb, bool hasAlpha = true);
332 * Return the Color object for the specified color
335 * @return The Color object
336 * @param[in] colorId The enum value for the specified color
338 static Color GetColor(ColorId colorId);
344 * This attribute is pre-defined. Its value is black.
346 * @brief <i> [Deprecated] </i>
349 * @deprecated This object is provided only for backward compatibility and will be deleted in a future release
350 * Instead of using this static constant, it is recommended to use GetColor(COLOR_ID_BLACK)
353 const static Color COLOR_BLACK;
357 * This attribute is pre-defined. Its value is blue.
359 * @brief <i> [Deprecated] </i>
362 * @deprecated This object is provided only for backward compatibility and will be deleted in a future release
363 * Instead of using this static constant, it is recommended to use GetColor(COLOR_ID_BLUE)
366 const static Color COLOR_BLUE;
370 * This attribute is pre-defined. Its value is cyan.
372 * @brief <i> [Deprecated] </i>
375 * @deprecated This object is provided only for backward compatibility and will be deleted in a future release
376 * Instead of using this static constant, it is recommended to use GetColor(COLOR_ID_CYAN)
379 const static Color COLOR_CYAN;
383 * This attribute is pre-defined. Its value is green.
385 * @brief <i> [Deprecated] </i>
388 * @deprecated This object is provided only for backward compatibility and will be deleted in a future release
389 * Instead of using this static constant, it is recommended to use GetColor(COLOR_ID_GREEN)
392 const static Color COLOR_GREEN;
396 * This attribute is pre-defined. Its value is grey.
398 * @brief <i> [Deprecated] </i>
401 * @deprecated This object is provided only for backward compatibility and will be deleted in a future release
402 * Instead of using this static constant, it is recommended to use GetColor(COLOR_ID_GREY)
405 const static Color COLOR_GREY;
409 * This attribute is pre-defined. Its value is magenta.
411 * @brief <i> [Deprecated] </i>
414 * @deprecated This object is provided only for backward compatibility and will be deleted in a future release
415 * Instead of using this static constant, it is recommended to use GetColor(COLOR_ID_MAGENTA)
418 const static Color COLOR_MAGENTA;
422 * This attribute is pre-defined. Its value is red.
424 * @brief <i> [Deprecated] </i>
427 * @deprecated This object is provided only for backward compatibility and will be deleted in a future release
428 * Instead of us ing this static constant, it is recommended to use GetColor(COLOR_ID_RED)
431 const static Color COLOR_RED;
435 * This attribute is pre-defined. Its value is violet.
437 * @brief <i> [Deprecated] </i>
440 * @deprecated This object is provided only for backward compatibility and will be deleted in a future release
441 * Instead of using this static constant, it is recommended to use GetColor(COLOR_ID_VIOLET)
444 const static Color COLOR_VIOLET;
448 * This attribute is pre-defined. Its value is yellow.
450 * @brief <i> [Deprecated] </i>
453 * @deprecated This object is provided only for backward compatibility and will be deleted in a future release
454 * Instead of using this static constant, it is recommended to use GetColor(COLOR_ID_YELLOW)
457 const static Color COLOR_YELLOW;
461 * This attribute is pre-defined. Its value is cwhite.
463 * @brief <i> [Deprecated] </i>
466 * @deprecated This object is provided only for backward compatibility and will be deleted in a future release
467 * Instead of using this static constant, it is recommended to use GetColor(COLOR_ID_WHITE)
470 const static Color COLOR_WHITE;
474 unsigned int __color;
476 friend class _ColorImpl;
479 // This variable is for internal use only.
480 // Using this variable can cause behavioral, security-related, and consistency-related issues in the application.
484 class _ColorImpl * __pImpl;
488 }} // Tizen::Graphics
490 #endif //_FGRP_COLOR_H_