canvas.h 7.7 KB

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