canvas.h 829 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <stdint.h>
  3. #include <u8g2.h>
  4. typedef enum {
  5. ColorWhite = 0x00,
  6. ColorBlack = 0x01,
  7. } Color;
  8. typedef const uint8_t* Font;
  9. typedef struct {
  10. Font primary;
  11. Font secondary;
  12. } Fonts;
  13. struct _CanvasApi;
  14. typedef struct _CanvasApi CanvasApi;
  15. // Canvas is private but we need its declaration here
  16. typedef struct {
  17. u8g2_t fb;
  18. uint8_t offset_x;
  19. uint8_t offset_y;
  20. uint8_t width;
  21. uint8_t height;
  22. } Canvas;
  23. struct _CanvasApi {
  24. Canvas canvas;
  25. Fonts* fonts;
  26. uint8_t (*width)(CanvasApi* canvas);
  27. uint8_t (*height)(CanvasApi* canvas);
  28. void (*clear)(CanvasApi* canvas);
  29. void (*set_color)(CanvasApi* canvas, Color color);
  30. void (*set_font)(CanvasApi* canvas, Font font);
  31. void (*draw_str)(CanvasApi* canvas, uint8_t x, uint8_t y, const char* str);
  32. };