Pixel.h 1006 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. union
  14. {
  15. std::uint16_t value;
  16. public: // hack to be able to do pixel.r. Clever!
  17. struct
  18. {
  19. unsigned r : 5;
  20. unsigned g : 6;
  21. unsigned b : 5;
  22. };
  23. };
  24. public:
  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. }
  38. }
  39. #endif