canvas.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 { 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. /*
  77. * Draw stateful icon at position defined by x,y.
  78. */
  79. void canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, Icon* icon);
  80. /*
  81. * Draw stateless icon at position defined by x,y.
  82. */
  83. void canvas_draw_icon_name(Canvas* canvas, uint8_t x, uint8_t y, IconName name);
  84. /*
  85. * Draw xbm icon of width, height at position defined by x,y.
  86. */
  87. void canvas_draw_xbm(
  88. Canvas* canvas,
  89. uint8_t x,
  90. uint8_t y,
  91. uint8_t w,
  92. uint8_t h,
  93. const uint8_t* bitmap);
  94. /*
  95. * Draw dot at x,y
  96. */
  97. void canvas_draw_dot(Canvas* canvas, uint8_t x, uint8_t y);
  98. /*
  99. * Draw box of width, height at x,y
  100. */
  101. void canvas_draw_box(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  102. /*
  103. * Draw frame of width, height at x,y
  104. */
  105. void canvas_draw_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  106. /*
  107. * Draw line from x1,y1 to x2,y2
  108. */
  109. void canvas_draw_line(Canvas* canvas, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
  110. /*
  111. * Draw circle at x,y with radius r
  112. */
  113. void canvas_draw_circle(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  114. /*
  115. * Draw disc at x,y with radius r
  116. */
  117. void canvas_draw_disc(Canvas* canvas, uint8_t x, uint8_t y, uint8_t r);
  118. /*
  119. * Draw glyph
  120. */
  121. void canvas_draw_glyph(Canvas* canvas, uint8_t x, uint8_t y, uint16_t ch);
  122. /*
  123. * Set transparency mode
  124. */
  125. void canvas_set_bitmap_mode(Canvas* canvas, bool alpha);
  126. /*
  127. * Draw rounded-corner frame of width, height at x,y, with round value raduis
  128. */
  129. void canvas_draw_rframe(
  130. Canvas* canvas,
  131. uint8_t x,
  132. uint8_t y,
  133. uint8_t width,
  134. uint8_t height,
  135. uint8_t radius);
  136. /*
  137. * Draw rounded-corner box of width, height at x,y, with round value raduis
  138. */
  139. void canvas_draw_rbox(
  140. Canvas* canvas,
  141. uint8_t x,
  142. uint8_t y,
  143. uint8_t width,
  144. uint8_t height,
  145. uint8_t radius);
  146. #ifdef __cplusplus
  147. }
  148. #endif