Color.h 978 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. bool operator <(const ColorRGBA &val) const
  46. {
  47. return (r + g + b) < (val.r + val.g + val.b);
  48. }
  49. template <typename Handler>
  50. void serialize(Handler &h)
  51. {
  52. h & r;
  53. h & g;
  54. h & b;
  55. h & a;
  56. }
  57. };
  58. VCMI_LIB_NAMESPACE_END