Graphics.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef INCLUDE_GRAPHICS_H
  2. #define INCLUDE_GRAPHICS_H
  3. #include <cstdint>
  4. namespace WalrusRPG{ namespace Graphics {
  5. /*
  6. * Pixel structure
  7. * TODO?: Convert this into a class to hide value?
  8. */
  9. union Pixel {
  10. std::uint16_t value;
  11. struct {
  12. unsigned r : 5;
  13. unsigned g : 6;
  14. unsigned b : 5;
  15. };
  16. Pixel(std::uint16_t color) : value(color) {
  17. }
  18. Pixel(Pixel &pix) : value(pix.value) {
  19. }
  20. Pixel(std::uint8_t red, std::uint8_t green, std::uint8_t blue) : r(red>>3), g(green>>2), b(blue>>3) {
  21. }
  22. // Overloading (unsigned) typecast
  23. operator std::uint16_t() {
  24. return value;
  25. }
  26. Pixel& operator=(unsigned value) {
  27. this->value = value;
  28. return *this;
  29. }
  30. };
  31. typedef struct Rect Rect_t;
  32. struct Rect
  33. {
  34. int x, y;
  35. unsigned w, h;
  36. };
  37. /*
  38. * Buffer management
  39. */
  40. void buffer_allocate();
  41. void buffer_free();
  42. void buffer_swap();
  43. void buffer_fill(unsigned color);
  44. /*
  45. * Misc LCD functions
  46. */
  47. void lcd_vsync();
  48. /*
  49. * Drawing
  50. */
  51. void draw_pixel(unsigned x, unsigned y, unsigned short color);
  52. void draw_sprite_sheet(const unsigned short *sheet, int x, int y, const Rect_t *window);
  53. /*
  54. * Sprite manipulation
  55. */
  56. unsigned short sprite_pixel_get(const unsigned short *sprite, unsigned x, unsigned y);
  57. }
  58. }
  59. #endif