canvas.h 8.9 KB

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