6 追记内容(1)(harib11h)

我们已经进行到了这个阶段,就想稍稍放松一下了。你看,光标也能闪烁了,窗口也有了。

我们先把程序放在一边,来看一看画面的截图吧。

6 追记内容(1)(harib11h) - 图1

我们都能实现这样的功能了

当这个画面出现的时候,笔者感到一股成功的喜悦。

虽然看起来有了不小的进步,但实际上我们也只是在窗口中添加了一些画,改变了鼠标和字符的显示位置以及颜色而已。如果我们按下退格键(BackSpace键),还可以改写已输入的字符哦。大家试着输入自己喜欢的信息吧。

■■■■■

程序如下。笔者只修改了bootpack.c。

本次的HariMain节选

  1. int cursor_x, cursor_c;
  2. make_textbox8(sht_win, 8, 28, 144, 16, COL8_FFFFFF);
  3. cursor_x = 8;
  4. cursor_c = COL8_FFFFFF;
  5. (中略)
  6. for (;;) {
  7. io_cli();
  8. if (fifo32_status(&fifo) == 0) {
  9. io_stihlt();
  10. } else {
  11. i = fifo32_get(&fifo);
  12. io_sti();
  13. if (256 <= i && i <= 511) { /* 键盘数据 */
  14. sprintf(s, "%02X", i - 256);
  15. putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2);
  16. if (i < 0x54 + 256) {
  17. if (keytable[i - 256] != 0 && cursor_x < 144) { /* 一般字符 */
  18. /* 显示1个字符就前移1次光标 */
  19. s[0] = keytable[i - 256];
  20. s[1] = 0;
  21. putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1);
  22. cursor_x += 8;
  23. }
  24. }
  25. if (i == 256 + 0x0e && cursor_x > 8) { /* 退格键 */
  26. /* 用空格键把光标消去后,后移1次光标 */
  27. putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1);
  28. cursor_x -= 8;
  29. }
  30. /* 光标再显示 */
  31. boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43);
  32. sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44);
  33. } else if (512 <= i && i <= 767) { /* 鼠标数据 */
  34. (中略)
  35. } else if (i == 10) { /* 10秒定时器 */
  36. putfonts8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7);
  37. } else if (i == 3) { /* 3秒定时器 */
  38. putfonts8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6);
  39. } else if (i <= 1) { /* 光标用定时器 */
  40. if (i != 0) {
  41. timer_init(timer3, &fifo, 0); /* 下面设定0 */
  42. cursor_c = COL8_000000;
  43. } else {
  44. timer_init(timer3, &fifo, 1); /* 下面设定1 */
  45. cursor_c = COL8_FFFFFF;
  46. }
  47. timer_settime(timer3, 50);
  48. boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43);
  49. sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44);
  50. }
  51. }
  52. }

cursor_x是用来记住光标显示位置的变量,输入一个字符后,这个变量就递增“8”。而cursor_c变量则表示现在光标的颜色。它每0.5秒变化一次。

make_textb0x8函数是用来描绘文字输入背景的,内容如下。这个函数没什么特别难的东西,大家大致读一下就可以了。

本次的bootpack.c节选

  1. void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c)
  2. {
  3. int x1 = x0 + sx, y1 = y0 + sy;
  4. boxfill8(sht->buf, sht->bxsize, COL8_848484, x0 - 2, y0 - 3, x1 + 1, y0 - 3);
  5. boxfill8(sht->buf, sht->bxsize, COL8_848484, x0 - 3, y0 - 3, x0 - 3, y1 + 1);
  6. boxfill8(sht->buf, sht->bxsize, COL8_FFFFFF, x0 - 3, y1 + 2, x1 + 1, y1 + 2);
  7. boxfill8(sht->buf, sht->bxsize, COL8_FFFFFF, x1 + 2, y0 - 3, x1 + 2, y1 + 2);
  8. boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 1, y0 - 2, x1 + 0, y0 - 2);
  9. boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 2, y0 - 2, x0 - 2, y1 + 0);
  10. boxfill8(sht->buf, sht->bxsize, COL8_C6C6C6, x0 - 2, y1 + 1, x1 + 0, y1 + 1);
  11. boxfill8(sht->buf, sht->bxsize, COL8_C6C6C6, x1 + 1, y0 - 2, x1 + 1, y1 + 1);
  12. boxfill8(sht->buf, sht->bxsize, c, x0 - 1, y0 - 1, x1 + 0, y1 + 0);
  13. return;
  14. }