📄 screen.cpp
字号:
//////////////////////////////////////////////
// //
// Screen.cpp //
// 打印界面模块 //
// 包括界面打印部分和其它公用打印函数 //
// 最后更新时间:2004年4月23日16:04 //
// //
//////////////////////////////////////////////
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include "Screen.h"
#include "Paint.h"
extern Window winEdit;
extern Menu mnuCool[Menu::TotMenu];
void ShowScreen()
{
// 打印界面
clrscr();
// 打印编辑窗口
winEdit.Show();
SetColor(WHITE, BLUE);
// 打印光标坐标
ShowPosition();
// 打印存盘标志
ShowSaved(true);
// 打印菜单标题
PrintMenu();
// 打印底部信息栏
PrintMessages();
SetColor(GREEN,BLUE);
if (ShowAbout)
{
// 显示关于窗口
AboutCBasic();
}
}
void PrintMenu()
{
// 打印菜单
// 清空顶部
gotoxy(1, 1);
SetColor(BLACK, WHITE);
clreol();
// 打印菜单
for (int i = 0;i < Menu::TotMenu; i++)
{
mnuCool[i].PrintMenuName();
}
}
void PrintMessages()
{
// 打印底部信息栏
// 清空底部
gotoxy(1, 25);
SetColor(BLACK, WHITE);
clreol();
// 先打印快捷键
gotoxy(2, 25);
SetColor(RED, WHITE);
cprintf("F1 F2 F3 Ctrl+F9 Alt+F6 Alt+X");
// 再打印功能
SetColor(BLACK, WHITE);
gotoxy(5, 25);
cprintf("Help");
gotoxy(16, 25);
cprintf("Save");
gotoxy(27, 25);
cprintf("Open");
gotoxy(43, 25);
cprintf("Run");
gotoxy(57, 25);
cprintf("Output");
gotoxy(73, 25);
cprintf("Quit");
}
void PrintChar
(
const int x, // 行号
const int y, // 列号
const char Chr // 字符
)
{
// 在指定位置打印字符
gotoxy(y, x);
cprintf("%c", Chr);
}
void SetColor
(
const int ColorFront, // 前景色
const int ColorBack // 背景色
)
{
// 设置前景色和背景色
textcolor(ColorFront);
textbackground(ColorBack);
}
void ShowPosition()
{
// 打印光标在编辑窗口中的位置
// 先清除原来的位置
SetColor(WHITE, BLUE);
gotoxy(8, winEdit.Bottom());
cprintf("屯屯:屯屯");
// 存储行号字符串
char strTemp[4];
// 在合适位置打印
itoa(TextX + 1, strTemp, 10);
gotoxy(11 - strlen(strTemp), winEdit.Bottom());
cprintf(" %s", strTemp);
gotoxy(13, winEdit.Bottom());
cprintf("%d ", TextY + 1);
}
void ShowSaved(const bool State)
{
// 打印存盘标志
// 修改存盘标志
Saved = State;
// 打印标志
gotoxy(5, winEdit.Bottom());
SetColor(WHITE, BLUE);
if (Saved)
{
cprintf("?);
}
else
{
cprintf("?);
}
}
void ShowInsert(const bool Mode)
{
// 打印编辑模式标志
// 修改编辑模式
Insert = Mode;
// 打印标志
gotoxy(64, winEdit.Bottom());
SetColor(WHITE, BLUE);
if (Insert)
{
cprintf(" Insert ");
_setcursortype(_NORMALCURSOR);
}
else
{
cprintf(" Rewrite ");
_setcursortype(_SOLIDCURSOR);
}
}
void PrintText(const int StartLine)
{
// 从指定行开始打印编辑窗口中的文本
// const int StartLine 在编辑窗口中的行号,不是文本行的行号
int Temp;
for (int i = StartLine; i < winEdit.Bottom(); i++)
{
// 打印开始行以后的各行
if ((Temp = i - winEdit.Top() - 1 + x0) <= EndLine + 1)
{
// 当前行有文本可以打印
PrintLine(Temp);
}
else
{
// 当前行无文本可以打,打印空格
gotoxy(winEdit.Left() + 1, i);
textbackground(BLUE);
cprintf("%78s", " ");
}
}
}
void PrintLine(const int Line)
{
// 打印指定行文本
// const int Line 文本行号
// 修改窗口设置,方便打印
window(1, 1, 79, 25);
// 隐藏窗口
_setcursortype(_NOCURSOR);
// 到该行所在的打印位置
gotoxy(winEdit.Left() + 1, Line + winEdit.Top() + 1 - x0);
if (Line == RunLineNo)
{
// 该行是正要单步执行的行,使用特殊颜色
SetColor(BLACK, WHITE);
cprintf("%s ", Text[Line]->Line);
return;
}
else if (Line == EndLine + 1)
{
SetColor(BLACK, BLUE);
cprintf("%-78s", "<The End>");
return;
}
else if (Line > TotRoomLine)
{
// 超出最大空间行,空行
textbackground(BLUE);
}
else if (Text[Line]->Break)
{
// 当前是断点行
SetColor(WHITE, RED);
}
else if (Text[Line]->Mark)
{
// 当前是标记行
SetColor(WHITE, CYAN);
}
else
{
// 普通行
textbackground(BLUE);
}
if (Line <= TotRoomLine)
{
if (Text[Line]->Sign[0] == ' ')
{
// 未着色,进行着色预处理
PrePaint(Line, Text[Line]->Sign);
}
for (int i = 0; i < LengthOf(Line); i++)
{
// 根据着色特征串打印该行文本
switch (Text[Line]->Sign[i])
{
case chSignKeyWord:
// 关键字
textcolor(WHITE);
break;
case chSignVar:
// 变量
textcolor(LIGHTGREEN);
break;
case chSignSymbol:
// 符号
textcolor(YELLOW);
break;
case chSignREM:
// 注释
textcolor(LIGHTCYAN);
break;
case chSignString:
// 字符串
textcolor(LIGHTRED);
break;
case chSignNumber:
// 数字
textcolor(LIGHTMAGENTA);
break;
}
// 打印当前字符
cprintf("%c", Text[Line]->Line[i]);
}
// 清除尾部空格
clreol();
}
else
{
// 打印空行
cprintf("%78s", " ");
}
}
void SetCursor()
{
// 设置光标
if (Insert)
{
// 普通光标
_setcursortype(_NORMALCURSOR);
}
else
{
// 方块光标
_setcursortype(_SOLIDCURSOR);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -