canvas.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #pragma once
  2. #include <stdint.h>
  3. #include <gui/icon_animation.h>
  4. #include <assets_icons.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. typedef enum {
  9. ColorWhite = 0x00,
  10. ColorBlack = 0x01,
  11. } Color;
  12. typedef enum { FontPrimary, FontSecondary, FontKeyboard } Font;
  13. typedef enum {
  14. AlignLeft,
  15. AlignRight,
  16. AlignTop,
  17. AlignBottom,
  18. AlignCenter,
  19. } Align;
  20. typedef enum {
  21. CanvasOrientationHorizontal,
  22. CanvasOrientationVertical,
  23. } CanvasOrientation;
  24. typedef struct Canvas Canvas;
  25. /*
  26. * Canvas width
  27. * @return width in pixels.
  28. */
  29. uint8_t canvas_width(Canvas* canvas);
  30. /*
  31. * Canvas height
  32. * @return height in pixels.
  33. */
  34. uint8_t canvas_height(Canvas* canvas);
  35. /*
  36. * Get current font height
  37. * @return height in pixels.
  38. */
  39. uint8_t canvas_current_font_height(Canvas* canvas);
  40. /*
  41. * Clear canvas, clear rendering buffer
  42. */
  43. void canvas_clear(Canvas* canvas);
  44. /*
  45. * Set drawing color
  46. */
  47. void canvas_set_color(Canvas* canvas, Color color);
  48. /*
  49. * Invert drawing color
  50. */
  51. void canvas_invert_color(Canvas* canvas);
  52. /*
  53. * Set drawing font
  54. */
  55. void canvas_set_font(Canvas* canvas, Font font);
  56. /*
  57. * Draw string at position of baseline defined by x, y.
  58. */
  59. void canvas_draw_str(Canvas* canvas, uint8_t x, uint8_t y, const char* str);
  60. /*
  61. * Draw aligned string defined by x, y.
  62. * Align calculated from position of baseline, string width and ascent (height of the glyphs above the baseline)
  63. */
  64. void canvas_draw_str_aligned(
  65. Canvas* canvas,
  66. uint8_t x,
  67. uint8_t y,
  68. Align horizontal,
  69. Align vertical,
  70. const char* str);
  71. /*
  72. * Get string width
  73. * @return width in pixels.
  74. */
  75. uint16_t canvas_string_width(Canvas* canvas, const char* str);
  76. /** Draw animation at position defined by x,y.
  77. * @param canvas - canvas instance
  78. * @param x - x coordinate
  79. * @param y - y coordinate
  80. * @param icon_animation - data pointer to IconAnimation
  81. */
  82. void canvas_draw_icon_animation(
  83. Canvas* canvas,
  84. uint8_t x,
  85. uint8_t y,
  86. IconAnimation* icon_animation);
  87. /** Draw icon at position defined by x,y.
  88. * @param canvas - canvas instance
  89. * @param x - x coordinate
  90. * @param y - y coordinate
  91. * @param icon - data pointer to Icon
  92. */
  93. void canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, const Icon* icon);
  94. /*
  95. * Draw xbm icon of width, height at position defined by x,y.
  96. */
  97. void canvas_draw_xbm(
  98. Canvas* canvas,
  99. uint8_t x,
  100. uint8_t y,
  101. uint8_t w,
  102. uint8_t h,
  103. const uint8_t* bitmap);
  104. /*
  105. * Draw dot at x,y
  106. */
  107. void canvas_draw_dot(Canvas* canvas, uint8_t x, uint8_t y);
  108. /*
  109. * Draw box of width, height at x,y
  110. */
  111. void canvas_draw_box(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  112. /*
  113. * Draw frame of width, height at x,y
  114. */
  115. void canvas_draw_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  116. /*
  117. * Draw line from x1,y1 to x2,y2
  118. */
  119. void canvas_draw_line(Canvas* canvas, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
  120. /*
  121. * Draw circle at x,y with radius r
  122. */
  123. void canvas_draw_circle(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  124. /*
  125. * Draw disc at x,y with radius r
  126. */
  127. void canvas_draw_disc(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  128. /*
  129. * Draw glyph
  130. */
  131. void canvas_draw_glyph(Canvas* canvas, uint8_t x, uint8_t y, uint16_t ch);
  132. /*
  133. * Set transparency mode
  134. */
  135. void canvas_set_bitmap_mode(Canvas* canvas, bool alpha);
  136. /*
  137. * Draw rounded-corner frame of width, height at x,y, with round value raduis
  138. */
  139. void canvas_draw_rframe(
  140. Canvas* canvas,
  141. uint8_t x,
  142. uint8_t y,
  143. uint8_t width,
  144. uint8_t height,
  145. uint8_t radius);
  146. /*
  147. * Draw rounded-corner box of width, height at x,y, with round value raduis
  148. */
  149. void canvas_draw_rbox(
  150. Canvas* canvas,
  151. uint8_t x,
  152. uint8_t y,
  153. uint8_t width,
  154. uint8_t height,
  155. uint8_t radius);
  156. #ifdef __cplusplus
  157. }
  158. #endif