canvas.h 3.5 KB

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