Graphics.h 1.1 KB

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