canvas.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #pragma once
  2. #include <stdint.h>
  3. #include <gui/icon_animation.h>
  4. #include <assets_icons.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. typedef enum {
  9. ColorWhite = 0x00,
  10. ColorBlack = 0x01,
  11. } Color;
  12. typedef enum { FontPrimary, FontSecondary, FontKeyboard } Font;
  13. typedef enum {
  14. AlignLeft,
  15. AlignRight,
  16. AlignTop,
  17. AlignBottom,
  18. AlignCenter,
  19. } Align;
  20. typedef enum {
  21. CanvasOrientationHorizontal,
  22. CanvasOrientationVertical,
  23. } CanvasOrientation;
  24. typedef struct Canvas Canvas;
  25. /*
  26. * Canvas width
  27. * @return width in pixels.
  28. */
  29. uint8_t canvas_width(Canvas* canvas);
  30. /*
  31. * Canvas height
  32. * @return height in pixels.
  33. */
  34. uint8_t canvas_height(Canvas* canvas);
  35. /*
  36. * Get current font height
  37. * @return height in pixels.
  38. */
  39. uint8_t canvas_current_font_height(Canvas* canvas);
  40. /*
  41. * Clear canvas, clear rendering buffer
  42. */
  43. void canvas_clear(Canvas* canvas);
  44. /*
  45. * Set drawing color
  46. */
  47. void canvas_set_color(Canvas* canvas, Color color);
  48. /*
  49. * Invert drawing color
  50. */
  51. void canvas_invert_color(Canvas* canvas);
  52. /*
  53. * Set drawing font
  54. */
  55. void canvas_set_font(Canvas* canvas, Font font);
  56. /*
  57. * Draw string at position of baseline defined by x, y.
  58. */
  59. void canvas_draw_str(Canvas* canvas, uint8_t x, uint8_t y, const char* str);
  60. /*
  61. * Draw aligned string defined by x, y.
  62. * Align calculated from position of baseline, string width and ascent (height of the glyphs above the baseline)
  63. */
  64. void canvas_draw_str_aligned(
  65. Canvas* canvas,
  66. uint8_t x,
  67. uint8_t y,
  68. Align horizontal,
  69. Align vertical,
  70. const char* str);
  71. /*
  72. * Get string width
  73. * @return width in pixels.
  74. */
  75. uint16_t canvas_string_width(Canvas* canvas, const char* str);
  76. /** Get glyph width
  77. * @return width in pixels
  78. */
  79. uint8_t canvas_glyph_width(Canvas* canvas, char symbol);
  80. /** Draw animation at position defined by x,y.
  81. * @param canvas - canvas instance
  82. * @param x - x coordinate
  83. * @param y - y coordinate
  84. * @param icon_animation - data pointer to IconAnimation
  85. */
  86. void canvas_draw_icon_animation(
  87. Canvas* canvas,
  88. uint8_t x,
  89. uint8_t y,
  90. IconAnimation* icon_animation);
  91. /** Draw icon at position defined by x,y.
  92. * @param canvas - canvas instance
  93. * @param x - x coordinate
  94. * @param y - y coordinate
  95. * @param icon - data pointer to Icon
  96. */
  97. void canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, const Icon* icon);
  98. /*
  99. * Draw xbm icon of width, height at position defined by x,y.
  100. */
  101. void canvas_draw_xbm(
  102. Canvas* canvas,
  103. uint8_t x,
  104. uint8_t y,
  105. uint8_t w,
  106. uint8_t h,
  107. const uint8_t* bitmap);
  108. /*
  109. * Draw dot at x,y
  110. */
  111. void canvas_draw_dot(Canvas* canvas, uint8_t x, uint8_t y);
  112. /*
  113. * Draw box of width, height at x,y
  114. */
  115. void canvas_draw_box(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  116. /*
  117. * Draw frame of width, height at x,y
  118. */
  119. void canvas_draw_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  120. /*
  121. * Draw line from x1,y1 to x2,y2
  122. */
  123. void canvas_draw_line(Canvas* canvas, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
  124. /*
  125. * Draw circle at x,y with radius r
  126. */
  127. void canvas_draw_circle(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  128. /*
  129. * Draw disc at x,y with radius r
  130. */
  131. void canvas_draw_disc(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  132. /*
  133. * Draw glyph
  134. */
  135. void canvas_draw_glyph(Canvas* canvas, uint8_t x, uint8_t y, uint16_t ch);
  136. /*
  137. * Set transparency mode
  138. */
  139. void canvas_set_bitmap_mode(Canvas* canvas, bool alpha);
  140. /*
  141. * Draw rounded-corner frame of width, height at x,y, with round value raduis
  142. */
  143. void canvas_draw_rframe(
  144. Canvas* canvas,
  145. uint8_t x,
  146. uint8_t y,
  147. uint8_t width,
  148. uint8_t height,
  149. uint8_t radius);
  150. /*
  151. * Draw rounded-corner box of width, height at x,y, with round value raduis
  152. */
  153. void canvas_draw_rbox(
  154. Canvas* canvas,
  155. uint8_t x,
  156. uint8_t y,
  157. uint8_t width,
  158. uint8_t height,
  159. uint8_t radius);
  160. #ifdef __cplusplus
  161. }
  162. #endif