Color.h 979 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Color.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. /// An object that represents RGBA color
  13. class ColorRGBA
  14. {
  15. public:
  16. enum : uint8_t
  17. {
  18. ALPHA_OPAQUE = 255,
  19. ALPHA_TRANSPARENT = 0,
  20. };
  21. uint8_t r;
  22. uint8_t g;
  23. uint8_t b;
  24. uint8_t a;
  25. //constructors
  26. constexpr ColorRGBA()
  27. :r(0)
  28. ,g(0)
  29. ,b(0)
  30. ,a(0)
  31. {
  32. }
  33. constexpr ColorRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
  34. : r(r)
  35. , g(g)
  36. , b(b)
  37. , a(a)
  38. {}
  39. constexpr ColorRGBA(uint8_t r, uint8_t g, uint8_t b)
  40. : r(r)
  41. , g(g)
  42. , b(b)
  43. , a(ALPHA_OPAQUE)
  44. {}
  45. template <typename Handler>
  46. void serialize(Handler &h)
  47. {
  48. h & r;
  49. h & g;
  50. h & b;
  51. h & a;
  52. }
  53. bool operator==(ColorRGBA const& rhs) const
  54. {
  55. return r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a;
  56. }
  57. };
  58. VCMI_LIB_NAMESPACE_END