canvas.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. CanvasDirectionLeftToRight,
  42. CanvasDirectionTopToBottom,
  43. CanvasDirectionRightToLeft,
  44. CanvasDirectionBottomToTop,
  45. } CanvasDirection;
  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, CanvasDirection 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 bitmap picture at position defined by x,y.
  157. *
  158. * @param canvas Canvas instance
  159. * @param x x coordinate
  160. * @param y y coordinate
  161. * @param width width of bitmap
  162. * @param height height of bitmap
  163. * @param compressed_bitmap_data compressed bitmap data
  164. */
  165. void canvas_draw_bitmap(
  166. Canvas* canvas,
  167. uint8_t x,
  168. uint8_t y,
  169. uint8_t width,
  170. uint8_t height,
  171. const uint8_t* compressed_bitmap_data);
  172. /** Draw animation at position defined by x,y.
  173. *
  174. * @param canvas Canvas instance
  175. * @param x x coordinate
  176. * @param y y coordinate
  177. * @param icon_animation IconAnimation instance
  178. */
  179. void canvas_draw_icon_animation(
  180. Canvas* canvas,
  181. uint8_t x,
  182. uint8_t y,
  183. IconAnimation* icon_animation);
  184. /** Draw icon at position defined by x,y.
  185. *
  186. * @param canvas Canvas instance
  187. * @param x x coordinate
  188. * @param y y coordinate
  189. * @param icon Icon instance
  190. */
  191. void canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, const Icon* icon);
  192. /** Draw XBM bitmap
  193. *
  194. * @param canvas Canvas instance
  195. * @param x x coordinate
  196. * @param y y coordinate
  197. * @param w bitmap width
  198. * @param h bitmap height
  199. * @param bitmap pointer to XBM bitmap data
  200. */
  201. void canvas_draw_xbm(
  202. Canvas* canvas,
  203. uint8_t x,
  204. uint8_t y,
  205. uint8_t w,
  206. uint8_t h,
  207. const uint8_t* bitmap);
  208. /** Draw dot at x,y
  209. *
  210. * @param canvas Canvas instance
  211. * @param x x coordinate
  212. * @param y y coordinate
  213. */
  214. void canvas_draw_dot(Canvas* canvas, uint8_t x, uint8_t y);
  215. /** Draw box of width, height at x,y
  216. *
  217. * @param canvas Canvas instance
  218. * @param x x coordinate
  219. * @param y y coordinate
  220. * @param width box width
  221. * @param height box height
  222. */
  223. void canvas_draw_box(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  224. /** Draw frame of width, height at x,y
  225. *
  226. * @param canvas Canvas instance
  227. * @param x x coordinate
  228. * @param y y coordinate
  229. * @param width frame width
  230. * @param height frame height
  231. */
  232. void canvas_draw_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  233. /** Draw line from x1,y1 to x2,y2
  234. *
  235. * @param canvas Canvas instance
  236. * @param x1 x1 coordinate
  237. * @param y1 y1 coordinate
  238. * @param x2 x2 coordinate
  239. * @param y2 y2 coordinate
  240. */
  241. void canvas_draw_line(Canvas* canvas, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
  242. /** Draw circle at x,y with radius r
  243. *
  244. * @param canvas Canvas instance
  245. * @param x x coordinate
  246. * @param y y coordinate
  247. * @param r radius
  248. */
  249. void canvas_draw_circle(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  250. /** Draw disc at x,y with radius r
  251. *
  252. * @param canvas Canvas instance
  253. * @param x x coordinate
  254. * @param y y coordinate
  255. * @param r radius
  256. */
  257. void canvas_draw_disc(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  258. /** Draw triangle with given base and height lengths and their intersection coordinate
  259. *
  260. * @param canvas Canvas instance
  261. * @param x x coordinate of base and height intersection
  262. * @param y y coordinate of base and height intersection
  263. * @param base length of triangle side
  264. * @param height length of triangle height
  265. * @param dir CanvasDirection triangle orientaion
  266. */
  267. void canvas_draw_triangle(
  268. Canvas* canvas,
  269. uint8_t x,
  270. uint8_t y,
  271. uint8_t base,
  272. uint8_t height,
  273. CanvasDirection dir);
  274. /** Draw glyph
  275. *
  276. * @param canvas Canvas instance
  277. * @param x x coordinate
  278. * @param y y coordinate
  279. * @param ch character
  280. */
  281. void canvas_draw_glyph(Canvas* canvas, uint8_t x, uint8_t y, uint16_t ch);
  282. /** Set transparency mode
  283. *
  284. * @param canvas Canvas instance
  285. * @param alpha transparency mode
  286. */
  287. void canvas_set_bitmap_mode(Canvas* canvas, bool alpha);
  288. /** Draw rounded-corner frame of width, height at x,y, with round value raduis
  289. *
  290. * @param canvas Canvas instance
  291. * @param x x coordinate
  292. * @param y y coordinate
  293. * @param width frame width
  294. * @param height frame height
  295. * @param radius frame corner radius
  296. */
  297. void canvas_draw_rframe(
  298. Canvas* canvas,
  299. uint8_t x,
  300. uint8_t y,
  301. uint8_t width,
  302. uint8_t height,
  303. uint8_t radius);
  304. /** Draw rounded-corner box of width, height at x,y, with round value raduis
  305. *
  306. * @param canvas Canvas instance
  307. * @param x x coordinate
  308. * @param y y coordinate
  309. * @param width box width
  310. * @param height box height
  311. * @param radius box corner radius
  312. */
  313. void canvas_draw_rbox(
  314. Canvas* canvas,
  315. uint8_t x,
  316. uint8_t y,
  317. uint8_t width,
  318. uint8_t height,
  319. uint8_t radius);
  320. #ifdef __cplusplus
  321. }
  322. #endif