Pixel.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef INCLUDE_PIXEL_H
  2. #define INCLUDE_PIXEL_H
  3. #include <cstdint>
  4. namespace WalrusRPG
  5. {
  6. namespace Graphics
  7. {
  8. /*
  9. * Pixel structure
  10. */
  11. class Pixel
  12. {
  13. public:
  14. union
  15. {
  16. std::uint16_t value;
  17. public: // hack to be able to do pixel.r. Clever!
  18. struct
  19. {
  20. unsigned b : 5;
  21. unsigned g : 6;
  22. unsigned r : 5;
  23. };
  24. };
  25. Pixel(std::uint16_t color);
  26. Pixel(Pixel &pix);
  27. Pixel(std::uint8_t red, std::uint8_t green, std::uint8_t blue);
  28. // Overloading (unsigned) typecast
  29. operator std::uint16_t() const;
  30. Pixel &operator=(unsigned value);
  31. };
  32. extern const Pixel Black;
  33. extern const Pixel White;
  34. extern const Pixel Red;
  35. extern const Pixel Green;
  36. extern const Pixel Blue;
  37. extern const Pixel Yellow;
  38. extern const Pixel Cyan;
  39. extern const Pixel Magenta;
  40. }
  41. }
  42. #endif