canvas.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 <gui/icon.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /** Color enumeration */
  13. typedef enum {
  14. ColorWhite = 0x00,
  15. ColorBlack = 0x01,
  16. ColorXOR = 0x02,
  17. } Color;
  18. /** Fonts enumeration */
  19. typedef enum {
  20. FontPrimary,
  21. FontSecondary,
  22. FontKeyboard,
  23. FontBigNumbers,
  24. // Keep last for fonts number calculation
  25. FontTotalNumber,
  26. } Font;
  27. /** Alignment enumeration */
  28. typedef enum {
  29. AlignLeft,
  30. AlignRight,
  31. AlignTop,
  32. AlignBottom,
  33. AlignCenter,
  34. } Align;
  35. /** Canvas Orientation */
  36. typedef enum {
  37. CanvasOrientationHorizontal,
  38. CanvasOrientationHorizontalFlip,
  39. CanvasOrientationVertical,
  40. CanvasOrientationVerticalFlip,
  41. } CanvasOrientation;
  42. /** Font Direction */
  43. typedef enum {
  44. CanvasDirectionLeftToRight,
  45. CanvasDirectionTopToBottom,
  46. CanvasDirectionRightToLeft,
  47. CanvasDirectionBottomToTop,
  48. } CanvasDirection;
  49. /** Font parameters */
  50. typedef struct {
  51. uint8_t leading_default;
  52. uint8_t leading_min;
  53. uint8_t height;
  54. uint8_t descender;
  55. } CanvasFontParameters;
  56. /** Icon flip */
  57. typedef enum {
  58. IconFlipNone,
  59. IconFlipHorizontal,
  60. IconFlipVertical,
  61. IconFlipBoth,
  62. } IconFlip;
  63. /** Icon rotation */
  64. typedef enum {
  65. IconRotation0,
  66. IconRotation90,
  67. IconRotation180,
  68. IconRotation270,
  69. } IconRotation;
  70. /** Canvas anonymous structure */
  71. typedef struct Canvas Canvas;
  72. /** Reset canvas drawing tools configuration
  73. *
  74. * @param canvas Canvas instance
  75. */
  76. void canvas_reset(Canvas* canvas);
  77. /** Commit canvas. Send buffer to display
  78. *
  79. * @param canvas Canvas instance
  80. */
  81. void canvas_commit(Canvas* canvas);
  82. /** Get Canvas width
  83. *
  84. * @param canvas Canvas instance
  85. *
  86. * @return width in pixels.
  87. */
  88. uint8_t canvas_width(const Canvas* canvas);
  89. /** Get Canvas height
  90. *
  91. * @param canvas Canvas instance
  92. *
  93. * @return height in pixels.
  94. */
  95. uint8_t canvas_height(const Canvas* canvas);
  96. /** Get current font height
  97. *
  98. * @param canvas Canvas instance
  99. *
  100. * @return height in pixels.
  101. */
  102. uint8_t canvas_current_font_height(const Canvas* canvas);
  103. /** Get font parameters
  104. *
  105. * @param canvas Canvas instance
  106. * @param font Font
  107. *
  108. * @return pointer to CanvasFontParameters structure
  109. */
  110. const CanvasFontParameters* canvas_get_font_params(const Canvas* canvas, Font font);
  111. /** Clear canvas
  112. *
  113. * @param canvas Canvas instance
  114. */
  115. void canvas_clear(Canvas* canvas);
  116. /** Set drawing color
  117. *
  118. * @param canvas Canvas instance
  119. * @param color Color
  120. */
  121. void canvas_set_color(Canvas* canvas, Color color);
  122. /** Set font swap
  123. * Argument String Rotation Description
  124. *
  125. * @param canvas Canvas instance
  126. * @param dir Direction font
  127. */
  128. void canvas_set_font_direction(Canvas* canvas, CanvasDirection dir);
  129. /** Invert drawing color
  130. *
  131. * @param canvas Canvas instance
  132. */
  133. void canvas_invert_color(Canvas* canvas);
  134. /** Set drawing font
  135. *
  136. * @param canvas Canvas instance
  137. * @param font Font
  138. */
  139. void canvas_set_font(Canvas* canvas, Font font);
  140. /** Set custom drawing font
  141. *
  142. * @param canvas Canvas instance
  143. * @param font Pointer to u8g2 const uint8_t* font array
  144. */
  145. void canvas_set_custom_u8g2_font(Canvas* canvas, const uint8_t* font);
  146. /** Draw string at position of baseline defined by x, y.
  147. *
  148. * @param canvas Canvas instance
  149. * @param x anchor point x coordinate
  150. * @param y anchor point y coordinate
  151. * @param str C-string
  152. */
  153. void canvas_draw_str(Canvas* canvas, uint8_t x, uint8_t y, const char* str);
  154. /** Draw aligned string defined by x, y.
  155. *
  156. * Align calculated from position of baseline, string width and ascent (height
  157. * of the glyphs above the baseline)
  158. *
  159. * @param canvas Canvas instance
  160. * @param x anchor point x coordinate
  161. * @param y anchor point y coordinate
  162. * @param horizontal horizontal alignment
  163. * @param vertical vertical alignment
  164. * @param str C-string
  165. */
  166. void canvas_draw_str_aligned(
  167. Canvas* canvas,
  168. uint8_t x,
  169. uint8_t y,
  170. Align horizontal,
  171. Align vertical,
  172. const char* str);
  173. /** Get string width
  174. *
  175. * @param canvas Canvas instance
  176. * @param str C-string
  177. *
  178. * @return width in pixels.
  179. */
  180. uint16_t canvas_string_width(Canvas* canvas, const char* str);
  181. /** Get glyph width
  182. *
  183. * @param canvas Canvas instance
  184. * @param[in] symbol character
  185. *
  186. * @return width in pixels
  187. */
  188. uint8_t canvas_glyph_width(Canvas* canvas, char symbol);
  189. /** Draw bitmap picture at position defined by x,y.
  190. *
  191. * @param canvas Canvas instance
  192. * @param x x coordinate
  193. * @param y y coordinate
  194. * @param width width of bitmap
  195. * @param height height of bitmap
  196. * @param compressed_bitmap_data compressed bitmap data
  197. */
  198. void canvas_draw_bitmap(
  199. Canvas* canvas,
  200. uint8_t x,
  201. uint8_t y,
  202. uint8_t width,
  203. uint8_t height,
  204. const uint8_t* compressed_bitmap_data);
  205. /** Draw icon at position defined by x,y with rotation and flip.
  206. *
  207. * @param canvas Canvas instance
  208. * @param x x coordinate
  209. * @param y y coordinate
  210. * @param icon Icon instance
  211. * @param flip IconFlip
  212. * @param rotation IconRotation
  213. */
  214. void canvas_draw_icon_ex(
  215. Canvas* canvas,
  216. uint8_t x,
  217. uint8_t y,
  218. const Icon* icon,
  219. IconRotation rotation);
  220. /** Draw animation at position defined by x,y.
  221. *
  222. * @param canvas Canvas instance
  223. * @param x x coordinate
  224. * @param y y coordinate
  225. * @param icon_animation IconAnimation instance
  226. */
  227. void canvas_draw_icon_animation(
  228. Canvas* canvas,
  229. uint8_t x,
  230. uint8_t y,
  231. IconAnimation* icon_animation);
  232. /** Draw icon at position defined by x,y.
  233. *
  234. * @param canvas Canvas instance
  235. * @param x x coordinate
  236. * @param y y coordinate
  237. * @param icon Icon instance
  238. */
  239. void canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, const Icon* icon);
  240. /** Draw XBM bitmap
  241. *
  242. * @param canvas Canvas instance
  243. * @param x x coordinate
  244. * @param y y coordinate
  245. * @param w bitmap width
  246. * @param h bitmap height
  247. * @param bitmap pointer to XBM bitmap data
  248. */
  249. void canvas_draw_xbm(
  250. Canvas* canvas,
  251. uint8_t x,
  252. uint8_t y,
  253. uint8_t w,
  254. uint8_t h,
  255. const uint8_t* bitmap);
  256. /** Draw dot at x,y
  257. *
  258. * @param canvas Canvas instance
  259. * @param x x coordinate
  260. * @param y y coordinate
  261. */
  262. void canvas_draw_dot(Canvas* canvas, uint8_t x, uint8_t y);
  263. /** Draw box of width, height at x,y
  264. *
  265. * @param canvas Canvas instance
  266. * @param x x coordinate
  267. * @param y y coordinate
  268. * @param width box width
  269. * @param height box height
  270. */
  271. void canvas_draw_box(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  272. /** Draw frame of width, height at x,y
  273. *
  274. * @param canvas Canvas instance
  275. * @param x x coordinate
  276. * @param y y coordinate
  277. * @param width frame width
  278. * @param height frame height
  279. */
  280. void canvas_draw_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  281. /** Draw line from x1,y1 to x2,y2
  282. *
  283. * @param canvas Canvas instance
  284. * @param x1 x1 coordinate
  285. * @param y1 y1 coordinate
  286. * @param x2 x2 coordinate
  287. * @param y2 y2 coordinate
  288. */
  289. void canvas_draw_line(Canvas* canvas, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
  290. /** Draw circle at x,y with radius r
  291. *
  292. * @param canvas Canvas instance
  293. * @param x x coordinate
  294. * @param y y coordinate
  295. * @param r radius
  296. */
  297. void canvas_draw_circle(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  298. /** Draw disc at x,y with radius r
  299. *
  300. * @param canvas Canvas instance
  301. * @param x x coordinate
  302. * @param y y coordinate
  303. * @param r radius
  304. */
  305. void canvas_draw_disc(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  306. /** Draw triangle with given base and height lengths and their intersection coordinate
  307. *
  308. * @param canvas Canvas instance
  309. * @param x x coordinate of base and height intersection
  310. * @param y y coordinate of base and height intersection
  311. * @param base length of triangle side
  312. * @param height length of triangle height
  313. * @param dir CanvasDirection triangle orientation
  314. */
  315. void canvas_draw_triangle(
  316. Canvas* canvas,
  317. uint8_t x,
  318. uint8_t y,
  319. uint8_t base,
  320. uint8_t height,
  321. CanvasDirection dir);
  322. /** Draw glyph
  323. *
  324. * @param canvas Canvas instance
  325. * @param x x coordinate
  326. * @param y y coordinate
  327. * @param ch character
  328. */
  329. void canvas_draw_glyph(Canvas* canvas, uint8_t x, uint8_t y, uint16_t ch);
  330. /** Set transparency mode
  331. *
  332. * @param canvas Canvas instance
  333. * @param alpha transparency mode
  334. */
  335. void canvas_set_bitmap_mode(Canvas* canvas, bool alpha);
  336. /** Draw rounded-corner frame of width, height at x,y, with round value radius
  337. *
  338. * @param canvas Canvas instance
  339. * @param x x coordinate
  340. * @param y y coordinate
  341. * @param width frame width
  342. * @param height frame height
  343. * @param radius frame corner radius
  344. */
  345. void canvas_draw_rframe(
  346. Canvas* canvas,
  347. uint8_t x,
  348. uint8_t y,
  349. uint8_t width,
  350. uint8_t height,
  351. uint8_t radius);
  352. /** Draw rounded-corner box of width, height at x,y, with round value raduis
  353. *
  354. * @param canvas Canvas instance
  355. * @param x x coordinate
  356. * @param y y coordinate
  357. * @param width box width
  358. * @param height box height
  359. * @param radius box corner radius
  360. */
  361. void canvas_draw_rbox(
  362. Canvas* canvas,
  363. uint8_t x,
  364. uint8_t y,
  365. uint8_t width,
  366. uint8_t height,
  367. uint8_t radius);
  368. #ifdef __cplusplus
  369. }
  370. #endif