canvas.h 8.8 KB

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