canvas.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. /** Canvas anonymous structure */
  57. typedef struct Canvas Canvas;
  58. /** Reset canvas drawing tools configuration
  59. *
  60. * @param canvas Canvas instance
  61. */
  62. void canvas_reset(Canvas* canvas);
  63. /** Commit canvas. Send buffer to display
  64. *
  65. * @param canvas Canvas instance
  66. */
  67. void canvas_commit(Canvas* canvas);
  68. /** Get Canvas width
  69. *
  70. * @param canvas Canvas instance
  71. *
  72. * @return width in pixels.
  73. */
  74. uint8_t canvas_width(Canvas* canvas);
  75. /** Get Canvas height
  76. *
  77. * @param canvas Canvas instance
  78. *
  79. * @return height in pixels.
  80. */
  81. uint8_t canvas_height(Canvas* canvas);
  82. /** Get current font height
  83. *
  84. * @param canvas Canvas instance
  85. *
  86. * @return height in pixels.
  87. */
  88. uint8_t canvas_current_font_height(Canvas* canvas);
  89. /** Get font parameters
  90. *
  91. * @param canvas Canvas instance
  92. * @param font Font
  93. *
  94. * @return pointer to CanvasFontParameters structure
  95. */
  96. CanvasFontParameters* canvas_get_font_params(Canvas* canvas, Font font);
  97. /** Clear canvas
  98. *
  99. * @param canvas Canvas instance
  100. */
  101. void canvas_clear(Canvas* canvas);
  102. /** Set drawing color
  103. *
  104. * @param canvas Canvas instance
  105. * @param color Color
  106. */
  107. void canvas_set_color(Canvas* canvas, Color color);
  108. /** Set font swap
  109. * Argument String Rotation Description
  110. *
  111. * @param canvas Canvas instance
  112. * @param dir Direction font
  113. */
  114. void canvas_set_font_direction(Canvas* canvas, CanvasDirection dir);
  115. /** Invert drawing color
  116. *
  117. * @param canvas Canvas instance
  118. */
  119. void canvas_invert_color(Canvas* canvas);
  120. /** Set drawing font
  121. *
  122. * @param canvas Canvas instance
  123. * @param font Font
  124. */
  125. void canvas_set_font(Canvas* canvas, Font font);
  126. /** Draw string at position of baseline defined by x, y.
  127. *
  128. * @param canvas Canvas instance
  129. * @param x anchor point x coordinate
  130. * @param y anchor point y coordinate
  131. * @param str C-string
  132. */
  133. void canvas_draw_str(Canvas* canvas, uint8_t x, uint8_t y, const char* str);
  134. /** Draw aligned string defined by x, y.
  135. *
  136. * Align calculated from position of baseline, string width and ascent (height
  137. * of the glyphs above the baseline)
  138. *
  139. * @param canvas Canvas instance
  140. * @param x anchor point x coordinate
  141. * @param y anchor point y coordinate
  142. * @param horizontal horizontal alignment
  143. * @param vertical vertical alignment
  144. * @param str C-string
  145. */
  146. void canvas_draw_str_aligned(
  147. Canvas* canvas,
  148. uint8_t x,
  149. uint8_t y,
  150. Align horizontal,
  151. Align vertical,
  152. const char* str);
  153. /** Get string width
  154. *
  155. * @param canvas Canvas instance
  156. * @param str C-string
  157. *
  158. * @return width in pixels.
  159. */
  160. uint16_t canvas_string_width(Canvas* canvas, const char* str);
  161. /** Get glyph width
  162. *
  163. * @param canvas Canvas instance
  164. * @param[in] symbol character
  165. *
  166. * @return width in pixels
  167. */
  168. uint8_t canvas_glyph_width(Canvas* canvas, char symbol);
  169. /** Draw bitmap picture at position defined by x,y.
  170. *
  171. * @param canvas Canvas instance
  172. * @param x x coordinate
  173. * @param y y coordinate
  174. * @param width width of bitmap
  175. * @param height height of bitmap
  176. * @param compressed_bitmap_data compressed bitmap data
  177. */
  178. void canvas_draw_bitmap(
  179. Canvas* canvas,
  180. uint8_t x,
  181. uint8_t y,
  182. uint8_t width,
  183. uint8_t height,
  184. const uint8_t* compressed_bitmap_data);
  185. /** Draw animation at position defined by x,y.
  186. *
  187. * @param canvas Canvas instance
  188. * @param x x coordinate
  189. * @param y y coordinate
  190. * @param icon_animation IconAnimation instance
  191. */
  192. void canvas_draw_icon_animation(
  193. Canvas* canvas,
  194. uint8_t x,
  195. uint8_t y,
  196. IconAnimation* icon_animation);
  197. /** Draw icon at position defined by x,y.
  198. *
  199. * @param canvas Canvas instance
  200. * @param x x coordinate
  201. * @param y y coordinate
  202. * @param icon Icon instance
  203. */
  204. void canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, const Icon* icon);
  205. /** Draw XBM bitmap
  206. *
  207. * @param canvas Canvas instance
  208. * @param x x coordinate
  209. * @param y y coordinate
  210. * @param w bitmap width
  211. * @param h bitmap height
  212. * @param bitmap pointer to XBM bitmap data
  213. */
  214. void canvas_draw_xbm(
  215. Canvas* canvas,
  216. uint8_t x,
  217. uint8_t y,
  218. uint8_t w,
  219. uint8_t h,
  220. const uint8_t* bitmap);
  221. /** Draw dot at x,y
  222. *
  223. * @param canvas Canvas instance
  224. * @param x x coordinate
  225. * @param y y coordinate
  226. */
  227. void canvas_draw_dot(Canvas* canvas, uint8_t x, uint8_t y);
  228. /** Draw box of width, height at x,y
  229. *
  230. * @param canvas Canvas instance
  231. * @param x x coordinate
  232. * @param y y coordinate
  233. * @param width box width
  234. * @param height box height
  235. */
  236. void canvas_draw_box(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  237. /** Draw frame of width, height at x,y
  238. *
  239. * @param canvas Canvas instance
  240. * @param x x coordinate
  241. * @param y y coordinate
  242. * @param width frame width
  243. * @param height frame height
  244. */
  245. void canvas_draw_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  246. /** Draw line from x1,y1 to x2,y2
  247. *
  248. * @param canvas Canvas instance
  249. * @param x1 x1 coordinate
  250. * @param y1 y1 coordinate
  251. * @param x2 x2 coordinate
  252. * @param y2 y2 coordinate
  253. */
  254. void canvas_draw_line(Canvas* canvas, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
  255. /** Draw circle at x,y with radius r
  256. *
  257. * @param canvas Canvas instance
  258. * @param x x coordinate
  259. * @param y y coordinate
  260. * @param r radius
  261. */
  262. void canvas_draw_circle(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  263. /** Draw disc at x,y with radius r
  264. *
  265. * @param canvas Canvas instance
  266. * @param x x coordinate
  267. * @param y y coordinate
  268. * @param r radius
  269. */
  270. void canvas_draw_disc(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  271. /** Draw triangle with given base and height lengths and their intersection coordinate
  272. *
  273. * @param canvas Canvas instance
  274. * @param x x coordinate of base and height intersection
  275. * @param y y coordinate of base and height intersection
  276. * @param base length of triangle side
  277. * @param height length of triangle height
  278. * @param dir CanvasDirection triangle orientation
  279. */
  280. void canvas_draw_triangle(
  281. Canvas* canvas,
  282. uint8_t x,
  283. uint8_t y,
  284. uint8_t base,
  285. uint8_t height,
  286. CanvasDirection dir);
  287. /** Draw glyph
  288. *
  289. * @param canvas Canvas instance
  290. * @param x x coordinate
  291. * @param y y coordinate
  292. * @param ch character
  293. */
  294. void canvas_draw_glyph(Canvas* canvas, uint8_t x, uint8_t y, uint16_t ch);
  295. /** Set transparency mode
  296. *
  297. * @param canvas Canvas instance
  298. * @param alpha transparency mode
  299. */
  300. void canvas_set_bitmap_mode(Canvas* canvas, bool alpha);
  301. /** Draw rounded-corner frame of width, height at x,y, with round value radius
  302. *
  303. * @param canvas Canvas instance
  304. * @param x x coordinate
  305. * @param y y coordinate
  306. * @param width frame width
  307. * @param height frame height
  308. * @param radius frame corner radius
  309. */
  310. void canvas_draw_rframe(
  311. Canvas* canvas,
  312. uint8_t x,
  313. uint8_t y,
  314. uint8_t width,
  315. uint8_t height,
  316. uint8_t radius);
  317. /** Draw rounded-corner box of width, height at x,y, with round value raduis
  318. *
  319. * @param canvas Canvas instance
  320. * @param x x coordinate
  321. * @param y y coordinate
  322. * @param width box width
  323. * @param height box height
  324. * @param radius box corner radius
  325. */
  326. void canvas_draw_rbox(
  327. Canvas* canvas,
  328. uint8_t x,
  329. uint8_t y,
  330. uint8_t width,
  331. uint8_t height,
  332. uint8_t radius);
  333. #ifdef __cplusplus
  334. }
  335. #endif