tb_color.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #ifndef TB_COLOR_H
  6. #define TB_COLOR_H
  7. #include "tb_types.h"
  8. namespace tb {
  9. /** TBColor contains a 32bit color. */
  10. class TBColor
  11. {
  12. public:
  13. TBColor() : b(0), g(0), r(0), a(255) {}
  14. TBColor(int r, int g, int b, int a = 255) : b(b), g(g), r(r), a(a) {}
  15. uint8 b, g, r, a;
  16. void Set(const TBColor &color) { *this = color; }
  17. /** Set the color from string in any of the following formats:
  18. "#rrggbbaa", "#rrggbb", "#rgba", "#rgb" */
  19. void SetFromString(const char *str, int len);
  20. operator uint32 () const { return *((uint32*)this); }
  21. bool operator == (const TBColor &c) const { return *this == (uint32)c; }
  22. bool operator != (const TBColor &c) const { return !(*this == c); }
  23. };
  24. }; // namespace tb
  25. #endif // TB_COLOR_H