canvas.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /**
  2. * @file canvas.h
  3. * GUI: Canvas API
  4. */
  5. #pragma once
  6. #include <stdint.h>
  7. #include <gui/icon_animation.h>
  8. #include <assets_icons.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /** Color enumeration */
  13. typedef enum {
  14. ColorWhite = 0x00,
  15. ColorBlack = 0x01,
  16. } Color;
  17. /** Fonts enumeration */
  18. typedef enum { FontPrimary, FontSecondary, FontKeyboard, FontBigNumbers } Font;
  19. /** Alignment enumeration */
  20. typedef enum {
  21. AlignLeft,
  22. AlignRight,
  23. AlignTop,
  24. AlignBottom,
  25. AlignCenter,
  26. } Align;
  27. /** Canvas Orientation */
  28. typedef enum {
  29. CanvasOrientationHorizontal,
  30. CanvasOrientationVertical,
  31. } CanvasOrientation;
  32. /** Font Direction */
  33. typedef enum {
  34. CanvasFontDirectionLeftToRight,
  35. CanvasFontDirectionTopToDown,
  36. CanvasFontDirectionRightToLeft,
  37. CanvasFontDirectionDownToTop,
  38. } CanvasFontDirection;
  39. /** Canvas anonymouse structure */
  40. typedef struct Canvas Canvas;
  41. /** Get Canvas width
  42. *
  43. * @param canvas Canvas instance
  44. *
  45. * @return width in pixels.
  46. */
  47. uint8_t canvas_width(Canvas* canvas);
  48. /** Get Canvas height
  49. *
  50. * @param canvas Canvas instance
  51. *
  52. * @return height in pixels.
  53. */
  54. uint8_t canvas_height(Canvas* canvas);
  55. /** Get current font height
  56. *
  57. * @param canvas Canvas instance
  58. *
  59. * @return height in pixels.
  60. */
  61. uint8_t canvas_current_font_height(Canvas* canvas);
  62. /** Clear canvas
  63. *
  64. * @param canvas Canvas instance
  65. */
  66. void canvas_clear(Canvas* canvas);
  67. /** Set drawing color
  68. *
  69. * @param canvas Canvas instance
  70. * @param color Color
  71. */
  72. void canvas_set_color(Canvas* canvas, Color color);
  73. /** Set font swap
  74. * Argument String Rotation Description
  75. *
  76. * @param canvas Canvas instance
  77. * @param dir Direction font
  78. */
  79. void canvas_set_font_direction(Canvas* canvas, CanvasFontDirection dir);
  80. /** Invert drawing color
  81. *
  82. * @param canvas Canvas instance
  83. */
  84. void canvas_invert_color(Canvas* canvas);
  85. /** Set drawing font
  86. *
  87. * @param canvas Canvas instance
  88. * @param font Font
  89. */
  90. void canvas_set_font(Canvas* canvas, Font font);
  91. /** Draw string at position of baseline defined by x, y.
  92. *
  93. * @param canvas Canvas instance
  94. * @param x anchor point x coordinate
  95. * @param y anchor point y coordinate
  96. * @param str C-string
  97. */
  98. void canvas_draw_str(Canvas* canvas, uint8_t x, uint8_t y, const char* str);
  99. /** Draw aligned string defined by x, y.
  100. *
  101. * Align calculated from position of baseline, string width and ascent (height
  102. * of the glyphs above the baseline)
  103. *
  104. * @param canvas Canvas instance
  105. * @param x anchor point x coordinate
  106. * @param y anchor point y coordinate
  107. * @param horizontal horizontal alignment
  108. * @param vertical vertical alignment
  109. * @param str C-string
  110. */
  111. void canvas_draw_str_aligned(
  112. Canvas* canvas,
  113. uint8_t x,
  114. uint8_t y,
  115. Align horizontal,
  116. Align vertical,
  117. const char* str);
  118. /** Get string width
  119. *
  120. * @param canvas Canvas instance
  121. * @param str C-string
  122. *
  123. * @return width in pixels.
  124. */
  125. uint16_t canvas_string_width(Canvas* canvas, const char* str);
  126. /** Get glyph width
  127. *
  128. * @param canvas Canvas instance
  129. * @param[in] symbol character
  130. *
  131. * @return width in pixels
  132. */
  133. uint8_t canvas_glyph_width(Canvas* canvas, char symbol);
  134. /** Draw animation at position defined by x,y.
  135. *
  136. * @param canvas Canvas instance
  137. * @param x x coordinate
  138. * @param y y coordinate
  139. * @param icon_animation IconAnimation instance
  140. */
  141. void canvas_draw_icon_animation(
  142. Canvas* canvas,
  143. uint8_t x,
  144. uint8_t y,
  145. IconAnimation* icon_animation);
  146. /** Draw icon at position defined by x,y.
  147. *
  148. * @param canvas Canvas instance
  149. * @param x x coordinate
  150. * @param y y coordinate
  151. * @param icon Icon instance
  152. */
  153. void canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, const Icon* icon);
  154. /** Draw XBM bitmap
  155. *
  156. * @param canvas Canvas instance
  157. * @param x x coordinate
  158. * @param y y coordinate
  159. * @param w bitmap width
  160. * @param h bitmap height
  161. * @param bitmap pointer to XBM bitmap data
  162. */
  163. void canvas_draw_xbm(
  164. Canvas* canvas,
  165. uint8_t x,
  166. uint8_t y,
  167. uint8_t w,
  168. uint8_t h,
  169. const uint8_t* bitmap);
  170. /** Draw dot at x,y
  171. *
  172. * @param canvas Canvas instance
  173. * @param x x coordinate
  174. * @param y y coordinate
  175. */
  176. void canvas_draw_dot(Canvas* canvas, uint8_t x, uint8_t y);
  177. /** Draw box of width, height at x,y
  178. *
  179. * @param canvas Canvas instance
  180. * @param x x coordinate
  181. * @param y y coordinate
  182. * @param width box width
  183. * @param height box height
  184. */
  185. void canvas_draw_box(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  186. /** Draw frame of width, height at x,y
  187. *
  188. * @param canvas Canvas instance
  189. * @param x x coordinate
  190. * @param y y coordinate
  191. * @param width frame width
  192. * @param height frame height
  193. */
  194. void canvas_draw_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  195. /** Draw line from x1,y1 to x2,y2
  196. *
  197. * @param canvas Canvas instance
  198. * @param x1 x1 coordinate
  199. * @param y1 y1 coordinate
  200. * @param x2 x2 coordinate
  201. * @param y2 y2 coordinate
  202. */
  203. void canvas_draw_line(Canvas* canvas, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
  204. /** Draw circle at x,y with radius r
  205. *
  206. * @param canvas Canvas instance
  207. * @param x x coordinate
  208. * @param y y coordinate
  209. * @param r radius
  210. */
  211. void canvas_draw_circle(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  212. /** Draw disc at x,y with radius r
  213. *
  214. * @param canvas Canvas instance
  215. * @param x x coordinate
  216. * @param y y coordinate
  217. * @param r radius
  218. */
  219. void canvas_draw_disc(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  220. /** Draw glyph
  221. *
  222. * @param canvas Canvas instance
  223. * @param x x coordinate
  224. * @param y y coordinate
  225. * @param ch character
  226. */
  227. void canvas_draw_glyph(Canvas* canvas, uint8_t x, uint8_t y, uint16_t ch);
  228. /** Set transparency mode
  229. *
  230. * @param canvas Canvas instance
  231. * @param alpha transparency mode
  232. */
  233. void canvas_set_bitmap_mode(Canvas* canvas, bool alpha);
  234. /** Draw rounded-corner frame of width, height at x,y, with round value raduis
  235. *
  236. * @param canvas Canvas instance
  237. * @param x x coordinate
  238. * @param y y coordinate
  239. * @param width frame width
  240. * @param height frame height
  241. * @param radius frame corner radius
  242. */
  243. void canvas_draw_rframe(
  244. Canvas* canvas,
  245. uint8_t x,
  246. uint8_t y,
  247. uint8_t width,
  248. uint8_t height,
  249. uint8_t radius);
  250. /** Draw rounded-corner box of width, height at x,y, with round value raduis
  251. *
  252. * @param canvas Canvas instance
  253. * @param x x coordinate
  254. * @param y y coordinate
  255. * @param width box width
  256. * @param height box height
  257. * @param radius box corner radius
  258. */
  259. void canvas_draw_rbox(
  260. Canvas* canvas,
  261. uint8_t x,
  262. uint8_t y,
  263. uint8_t width,
  264. uint8_t height,
  265. uint8_t radius);
  266. #ifdef __cplusplus
  267. }
  268. #endif