buffer.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #include <furi.h>
  3. #include <gui/canvas.h>
  4. #include "vector.h"
  5. enum DrawMode {
  6. WhiteOnly,
  7. BlackOnly,
  8. WhiteAsBlack,
  9. BlackAsWhite,
  10. WhiteAsInverted,
  11. BlackAsInverted,
  12. };
  13. typedef struct {
  14. uint8_t *data;
  15. uint8_t *back_buffer;
  16. uint8_t width;
  17. uint8_t height;
  18. bool double_buffered;
  19. } Buffer;
  20. enum PixelColor {
  21. Black, //or
  22. White, //
  23. Flip //not
  24. };
  25. typedef struct {
  26. const Vector anchor;
  27. enum DrawMode drawMode;
  28. } RenderSettings;
  29. #define SCREEN_WIDTH 128
  30. #define SCREEN_HEIGHT 64
  31. #define DEFAULT_RENDER (RenderSettings){.anchor={.x=0.5f, .y=0.5f}, .drawMode=BlackOnly}
  32. Buffer *buffer_create(uint8_t width, uint8_t height, bool double_buffered);
  33. void buffer_release(Buffer *buffer);
  34. bool buffer_test_coordinate(Buffer *const buffer, int x, int y);
  35. bool buffer_get_pixel(Buffer *const buffer, int x, int y);
  36. void buffer_set_pixel(Buffer *buffer, int16_t x, int16_t y, enum PixelColor draw_mode);
  37. Buffer *buffer_copy(Buffer *buffer);
  38. void buffer_swap_back(Buffer *buffer);
  39. void buffer_swap_with(Buffer *buffer_a, Buffer *buffer_b);
  40. void buffer_draw_all(Buffer *target, Buffer *const sprite, Vector *position, float rotation);
  41. void buffer_draw(Buffer *target, Buffer *const sprite, Vector *position, uint8_t x_cap, uint8_t y_cap, float rotation, RenderSettings *settings);
  42. //void buffer_draw_internal(Buffer *target, Buffer* sprite, bool is_black, enum PixelColor color, Vector *const position, uint8_t x_cap, uint8_t y_cap, float rotation);
  43. void buffer_render(Buffer *buffer, Canvas *const canvas);
  44. void buffer_clear(Buffer *buffer);
  45. void buffer_draw_line(Buffer *buffer, int x0, int y0, int x1, int y1, enum PixelColor draw_mode);
  46. void buffer_draw_rbox(Buffer *buffer, int16_t x0, int16_t y0, int16_t x1, int16_t y1, enum PixelColor draw_mode);
  47. void buffer_draw_rbox_frame(Buffer *buffer, int16_t x0, int16_t y0, int16_t x1, int16_t y1, enum PixelColor draw_mode);
  48. void buffer_draw_box(Buffer *buffer, int16_t x0, int16_t y0, int16_t x1, int16_t y1, enum PixelColor draw_mode);
  49. void buffer_draw_circle(Buffer *buffer, int x, int y, int r, enum PixelColor draw_mode);