📄 window.cpp
字号:
*
* ******************************************************************** */
void Window::AtSayReverse(int c, int r, // column and row to
char *s) // display string
{
GotoXY(c, r); // set up at the right place
textcolor(FG(cr_color)); // set up foreground
textbackground(BG(cr_color)); // ..and background colors
cprintf("%s", s); // display string in window
cursor_col = wherex(); // save cursor column..
cursor_row = wherey(); // ..and cursor row
textcolor(FG(cn_color)); // then set colors back to
textbackground(BG(cn_color)); // ..their normal settings
}
/* ******************************************************************** *
*
* Display -- display a character in a window
*
* ******************************************************************** */
void Window::Display(char c) // character to display
{
MakeCurrent(); // make this window current
cprintf("%c", c); // display string in window
cursor_col = wherex(); // save cursor column..
cursor_row = wherey(); // ..and cursor row
}
/* ******************************************************************** *
*
* Display -- display string in window
*
* ******************************************************************** */
void Window::Display(char *s) // string to display
{
MakeCurrent(); // make this window current
cprintf("%s", s); // display string in window
cursor_col = wherex(); // save cursor column..
cursor_row = wherey(); // ..and cursor row
}
/* ******************************************************************** *
*
* DisplayReverse -- display string in reverse video
*
* ******************************************************************** */
void Window::DisplayReverse(char *s) // string to display
{
MakeCurrent(); // make this window current
textcolor(FG(cr_color)); // set up foreground
textbackground(BG(cr_color)); // ..and background colors
cprintf("%s", s); // display string in window
cursor_col = wherex(); // save cursor column..
cursor_row = wherey(); // ..and cursor row
textcolor(FG(cn_color)); // then set colors back to
textbackground(BG(cn_color)); // ..their normal settings
}
/* ******************************************************************** *
*
* Clear -- clear current window
*
* ******************************************************************** */
void Window::Clear(void)
{
MakeCurrent(); // make this window current
clrscr(); // ..then clear it
cursor_col = wherex(); // save cursor column..
cursor_row = wherey(); // ..and cursor row
}
/* ******************************************************************** *
*
* GotoXY -- position cursor in window
*
* ******************************************************************** */
void Window::GotoXY(int c, int r) // column and row
{
MakeCurrent(); // make this window current
gotoxy(c, r); // goto requested location
cursor_col = wherex(); // save cursor column..
cursor_row = wherey(); // ..and cursor row
}
/* ******************************************************************** *
*
* Close -- close window and restore screen
*
* ******************************************************************** */
void Window::Close(void)
{
if (NOT open_flag) // q. window already closed?
return; // a. yes .. just return
open_flag = 0; // clear opened flag
puttext(ul_col, ul_row, lr_col, lr_row, // restore old screen data
old_data); // ..from temp buffer
}
/* ******************************************************************** *
*
* ~Window -- destructor
*
* ******************************************************************** */
Window::~Window()
{
if (open_flag) // q. window still open?
Close(); // a. yes .. close window
last_window = 0; // clear window pointer
delete old_data; // de-allocate screen buffer
window(1, 1, 80, max_lines); // set whole screen as window
}
/* ******************************************************************** *
*
* MakeCurrent -- make this window current
*
* ******************************************************************** */
void Window::MakeCurrent(void)
{
if (last_window != this) // q. same window?
{
last_window = this; // a. no .. use this window
if (scroll_flag) // q. user want scrolling?
_wrapon(_GWRAPON); // a. yes .. enable scrolling
else
_wrapon(_GWRAPOFF); // else .. disable scrolling
if (border_flag == none) // q. any border?
window(ul_col, ul_row, // a. no .. set up window
lr_col, lr_row); // ..using entire area
else
window(ul_col + 1, ul_row + 1, // else .. set up the window
lr_col - 1, lr_row - 1); // ..allowing for the border
gotoxy(cursor_col, cursor_row); // ..and re-place cursor
textcolor(FG(cn_color)); // ..and set up foreground
textbackground(BG(cn_color)); // ..and background colors
}
}
/* ******************************************************************** *
* wherex() -- determine column number *
* ******************************************************************** */
int wherex(void)
{
struct rccoord pos; // row and col coordinates
pos = _gettextposition(); // get current cursor ..
return(pos.col); // ..and return the column
}
/* ******************************************************************** *
* wherey() -- determine row number *
* ******************************************************************** */
int wherey(void)
{
struct rccoord pos; // row and col coordinates
pos = _gettextposition(); // get current cursor ..
return(pos.row); // ..and return the row nbr
}
/* ******************************************************************** *
* cprintf() -- handle outputing text to screen *
* ******************************************************************** */
int cprintf(char *msg, ...) // message to format/display
{
char buf[100]; // string buffer
va_list list; // variable list
va_start(list, msg); // set up variable list
vsprintf(buf, msg, list); // ..format buffer
_outtext(buf); // ..then display message
return(strlen(buf)); // ..and rtn w/string length
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -