textui.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #pragma once
  2. #include <common/glib.h>
  3. #include <common/sys/types.h>
  4. #include <common/spinlock.h>
  5. // 文本窗口标志位
  6. // 文本窗口是否为彩色
  7. #define TEXTUI_WF_CHROMATIC (1 << 0)
  8. // 窗口是否启用彩色字符
  9. #define textui_is_chromatic(flag) ((flag)&TEXTUI_WF_CHROMATIC)
  10. // 每个字符的宽度和高度(像素)
  11. #define TEXTUI_CHAR_WIDTH 8
  12. #define TEXTUI_CHAR_HEIGHT 16
  13. /**
  14. * @brief 黑白字符对象
  15. *
  16. */
  17. struct textui_char_normal_t
  18. {
  19. char c;
  20. };
  21. /**
  22. * @brief 彩色字符对象
  23. *
  24. */
  25. struct textui_char_chromatic_t
  26. {
  27. uint16_t c; // 字符
  28. // 前景色
  29. uint8_t Fr; // 红
  30. uint8_t Fg; // 绿
  31. uint8_t Fb; // 蓝
  32. // 背景色
  33. uint8_t Br;
  34. uint8_t Bg;
  35. uint8_t Bb;
  36. };
  37. // 注意!!! 请保持vline结构体的大小、成员变量命名相等!
  38. /**
  39. * @brief 单色显示的虚拟行结构体
  40. *
  41. */
  42. struct textui_vline_normal_t
  43. {
  44. struct textui_char_normal_t *chars; // 字符对象数组
  45. uint16_t index; // 当前操作的位置
  46. };
  47. /**
  48. * @brief 彩色显示的虚拟行结构体
  49. *
  50. */
  51. struct textui_vline_chromatic_t
  52. {
  53. struct textui_char_chromatic_t *chars;
  54. uint16_t index; // 当前操作的位置
  55. };
  56. /**
  57. * @brief textu ui 框架的文本窗口结构体
  58. *
  59. */
  60. struct textui_window_t
  61. {
  62. struct List list;
  63. uint32_t id; // 窗口id
  64. uint16_t vlines_num; // 虚拟行总数
  65. uint16_t vlines_used; // 当前已经使用了的虚拟行总数
  66. // 指向虚拟行的数组的指针(二选一)
  67. union
  68. {
  69. struct textui_vline_normal_t *normal;
  70. struct textui_vline_chromatic_t *chromatic;
  71. } vlines;
  72. uint16_t top_vline; // 位于最顶上的那一个虚拟行的行号
  73. uint16_t vline_operating; // 正在操作的vline
  74. uint16_t chars_per_line; // 每行最大容纳的字符数
  75. uint8_t flags; // 窗口flag
  76. spinlock_t lock; // 窗口操作锁
  77. };
  78. struct textui_private_info_t
  79. {
  80. uint16_t actual_line; // 真实行的数量
  81. struct textui_window_t *current_window; // 当前的主窗口
  82. struct textui_window_t *default_window; // 默认print到的窗口
  83. };
  84. /**
  85. * @brief 重新渲染整个虚拟行
  86. *
  87. * @param window 窗口结构体
  88. * @param vline_id 虚拟行号
  89. * @return int 错误码
  90. */
  91. int textui_refresh_vline(struct textui_window_t *window, uint16_t vline_id);
  92. int textui_refresh_vlines(struct textui_window_t *window, uint16_t start, uint16_t count);
  93. /**
  94. * @brief 刷新某个虚拟行的连续n个字符对象
  95. *
  96. * @param window 窗口结构体
  97. * @param vline_id 虚拟行号
  98. * @param start 起始字符号
  99. * @param count 要刷新的字符数量
  100. * @return int 错误码
  101. */
  102. int textui_refresh_characters(struct textui_window_t *window, uint16_t vline_id, uint16_t start, uint16_t count);
  103. /**
  104. * @brief 在指定窗口上输出一个字符
  105. *
  106. * @param window 窗口
  107. * @param character 字符
  108. * @return int
  109. */
  110. int textui_putchar_window(struct textui_window_t *window, uint16_t character);
  111. /**
  112. * @brief 在默认窗口上输出一个字符
  113. *
  114. * @param character 字符
  115. * @return int
  116. */
  117. int textui_putchar(uint16_t character);
  118. /**
  119. * @brief 获取textui的帧缓冲区能容纳的内容的行数
  120. *
  121. * @return uint16_t
  122. */
  123. uint16_t __textui_get_actual_lines();
  124. /**
  125. * @brief 获取当前渲染的窗口的id
  126. *
  127. * @return uint16_t
  128. */
  129. uint32_t __textui_get_current_window_id();
  130. /**
  131. * @brief 初始化text ui框架
  132. *
  133. * @return int
  134. */
  135. int textui_init();