canvas.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 struct Canvas Canvas;
  26. /*
  27. * Canvas width
  28. * @return width in pixels.
  29. */
  30. uint8_t canvas_width(Canvas* canvas);
  31. /*
  32. * Canvas height
  33. * @return height in pixels.
  34. */
  35. uint8_t canvas_height(Canvas* canvas);
  36. /*
  37. * Get current font height
  38. * @return height in pixels.
  39. */
  40. uint8_t canvas_current_font_height(Canvas* canvas);
  41. /*
  42. * Clear canvas, clear rendering buffer
  43. */
  44. void canvas_clear(Canvas* canvas);
  45. /*
  46. * Set drawing color
  47. */
  48. void canvas_set_color(Canvas* canvas, Color color);
  49. /*
  50. * Invert drawing color
  51. */
  52. void canvas_invert_color(Canvas* canvas);
  53. /*
  54. * Set drawing font
  55. */
  56. void canvas_set_font(Canvas* canvas, Font font);
  57. /*
  58. * Draw string at position of baseline defined by x, y.
  59. */
  60. void canvas_draw_str(Canvas* canvas, uint8_t x, uint8_t y, const char* str);
  61. /*
  62. * Draw aligned string defined by x, y.
  63. * Align calculated from position of baseline, string width and ascent (height of the glyphs above the baseline)
  64. */
  65. void canvas_draw_str_aligned(
  66. Canvas* canvas,
  67. uint8_t x,
  68. uint8_t y,
  69. Align horizontal,
  70. Align vertical,
  71. const char* str);
  72. /*
  73. * Get string width
  74. * @return width in pixels.
  75. */
  76. uint16_t canvas_string_width(Canvas* canvas, const char* str);
  77. /*
  78. * Draw stateful icon at position defined by x,y.
  79. */
  80. void canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, Icon* icon);
  81. /*
  82. * Draw stateless icon at position defined by x,y.
  83. */
  84. void canvas_draw_icon_name(Canvas* canvas, uint8_t x, uint8_t y, IconName name);
  85. /*
  86. * Draw xbm icon of width, height at position defined by x,y.
  87. */
  88. void canvas_draw_xbm(
  89. Canvas* canvas,
  90. uint8_t x,
  91. uint8_t y,
  92. uint8_t w,
  93. uint8_t h,
  94. const uint8_t* bitmap);
  95. /*
  96. * Draw dot at x,y
  97. */
  98. void canvas_draw_dot(Canvas* canvas, uint8_t x, uint8_t y);
  99. /*
  100. * Draw box of width, height at x,y
  101. */
  102. void canvas_draw_box(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  103. /*
  104. * Draw frame of width, height at x,y
  105. */
  106. void canvas_draw_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  107. /*
  108. * Draw line from x1,y1 to x2,y2
  109. */
  110. void canvas_draw_line(Canvas* canvas, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
  111. /*
  112. * Draw glyph
  113. */
  114. void canvas_draw_glyph(Canvas* canvas, uint8_t x, uint8_t y, uint16_t ch);
  115. #ifdef __cplusplus
  116. }
  117. #endif