textui.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. unsigned c : 16;
  28. // 前景色
  29. unsigned FRcolor : 24; // rgb
  30. // 背景色
  31. unsigned BKcolor : 24; // rgb
  32. };
  33. // 注意!!! 请保持vline结构体的大小、成员变量命名相等!
  34. /**
  35. * @brief 单色显示的虚拟行结构体
  36. *
  37. */
  38. struct textui_vline_normal_t
  39. {
  40. struct textui_char_normal_t *chars; // 字符对象数组
  41. uint16_t index; // 当前操作的位置
  42. };
  43. /**
  44. * @brief 彩色显示的虚拟行结构体
  45. *
  46. */
  47. struct textui_vline_chromatic_t
  48. {
  49. struct textui_char_chromatic_t *chars;
  50. uint16_t index; // 当前操作的位置
  51. };
  52. /**
  53. * @brief textu ui 框架的文本窗口结构体
  54. *
  55. */
  56. struct textui_window_t
  57. {
  58. struct List list;
  59. uint32_t id; // 窗口id
  60. uint16_t vlines_num; // 虚拟行总数
  61. uint16_t vlines_used; // 当前已经使用了的虚拟行总数
  62. // 指向虚拟行的数组的指针(二选一)
  63. union
  64. {
  65. struct textui_vline_normal_t *normal;
  66. struct textui_vline_chromatic_t *chromatic;
  67. } vlines;
  68. uint16_t top_vline; // 位于最顶上的那一个虚拟行的行号
  69. uint16_t vline_operating; // 正在操作的vline
  70. uint16_t chars_per_line; // 每行最大容纳的字符数
  71. uint8_t flags; // 窗口flag
  72. spinlock_t lock; // 窗口操作锁
  73. };
  74. struct textui_private_info_t
  75. {
  76. uint16_t actual_line; // 真实行的数量
  77. struct textui_window_t *current_window; // 当前的主窗口
  78. struct textui_window_t *default_window; // 默认print到的窗口
  79. };
  80. /**
  81. * @brief 重新渲染整个虚拟行
  82. *
  83. * @param window 窗口结构体
  84. * @param vline_id 虚拟行号
  85. * @return int 错误码
  86. */
  87. int textui_refresh_vline(struct textui_window_t *window, uint16_t vline_id);
  88. int textui_refresh_vlines(struct textui_window_t *window, uint16_t start, uint16_t count);
  89. /**
  90. * @brief 刷新某个虚拟行的连续n个字符对象
  91. *
  92. * @param window 窗口结构体
  93. * @param vline_id 虚拟行号
  94. * @param start 起始字符号
  95. * @param count 要刷新的字符数量
  96. * @return int 错误码
  97. */
  98. int textui_refresh_characters(struct textui_window_t *window, uint16_t vline_id, uint16_t start, uint16_t count);
  99. /**
  100. * @brief 在指定窗口上输出一个字符
  101. *
  102. * @param window 窗口
  103. * @param character 字符
  104. * @param FRcolor 前景色(RGB)
  105. * @param BKcolor 背景色(RGB)
  106. * @return int
  107. */
  108. int textui_putchar_window(struct textui_window_t *window, uint16_t character, uint32_t FRcolor, uint32_t BKcolor);
  109. /**
  110. * @brief 在默认窗口上输出一个字符
  111. *
  112. * @param character 字符
  113. * @param FRcolor 前景色(RGB)
  114. * @param BKcolor 背景色(RGB)
  115. * @return int
  116. */
  117. int textui_putchar(uint16_t character, uint32_t FRcolor, uint32_t BKcolor);
  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();