1 #pragma once
2 
3 //#include "tnconfig.h"
4 
5 /* A diagram of the following values:
6  *
7  *           (0,0)
8  *              +----------------------------------------+
9  *              |                                        |
10  *              |                                        |
11  *              |                                        |
12  *              |                                        |
13  *              |                                        |
14  *              |                                        |
15  *              |                                        |
16  *              |                                        |
17  *              |                                        |
18  *              |                                        |
19  *              |                                        |
20  *              |                                        |
21  *              |                                        |
22  *              |          CON_TOP                       |
23  *              +---------------------------+.....?......|     ---
24  *              |              .            |            |      |
25  *              |              .            | <-- OR --> |      |
26  *              |              .            |            |      |
27  *  CON_LEFT    |              .            | CON_RIGHT  |
28  *    (=0)      |              .            | (=CON_     |  CON_LINES
29  *              |..............*            |   WIDTH)   |
30  *              |            (CON_CUR_X,    |            |      |
31  *              |             CON_CUR_Y)    |            |      |
32  *              |                           |            |      |
33  *              |                           |            |      |
34  *              |                           |            |      |
35  *              +---------------------------+------------+     ---
36  *                   CON_BOTTOM (=CON_TOP + CON_HEIGHT)
37  *
38  *              |--------- CON_COLS --------|
39  *
40  * Keep in mind that CON_TOP, CON_BOTTOM, CON_LEFT, and CON_RIGHT are relative
41  * to zero, but CON_CUR_X, CON_CUR_Y, CON_WIDTH, and CON_HEIGHT are relative to
42  * CON_TOP and CON_LEFT
43  */
44 
45 #define CON_TOP		ConsoleInfo.srWindow.Top
46 #define CON_BOTTOM	ConsoleInfo.srWindow.Bottom
47 
48 #define CON_LEFT	0
49 #define CON_RIGHT	(ConsoleInfo.dwSize.X - 1)
50 
51 #define CON_HEIGHT	(CON_BOTTOM - CON_TOP)
52 #define CON_WIDTH	(CON_RIGHT - CON_LEFT)
53 #define CON_LINES	(CON_HEIGHT + 1)
54 #define CON_COLS	(CON_WIDTH + 1)
55 
56 #define CON_CUR_X	(ConsoleInfo.dwCursorPosition.X - CON_LEFT)
57 #define CON_CUR_Y	(ConsoleInfo.dwCursorPosition.Y - CON_TOP)
58 
59 
60 class TConsole {
61 public:
62 	TConsole(HANDLE hConsole);
63 	~TConsole();
64 	void sync();
65 
66 	// Cursor movement routines
GetRawCursorX()67     int GetRawCursorX() {return CON_CUR_X;}
GetRawCursorY()68     int GetRawCursorY() {return CON_CUR_Y;}
GetCursorX()69     int GetCursorX() {return CON_CUR_X;}
GetCursorY()70     int GetCursorY() {
71 		if(iScrollStart != -1)
72 			return CON_CUR_Y - iScrollStart;
73 		return GetRawCursorY();
74 	}
75 	void SetRawCursorPosition(int x, int y);
76 	void SetCursorPosition(int x, int y);
77 	void SetCursorSize(int pct);
78 	void MoveCursorPosition(int x, int y);
79 
80 	// Screen mode/size routines
GetWidth()81     int GetWidth() {return CON_COLS;}
GetHeight()82     int GetHeight() {return CON_LINES;}
83 	void SetExtendedMode(int iFunction, BOOL bEnable);
84 	void SetWindowSize(int width, int height);	// Set the size of the window,
85 												// but not the buffer
86 
87 	// Color/attribute routines
SetAttrib(unsigned char wAttr)88 	void SetAttrib(unsigned char wAttr) {wAttributes = wAttr;}
GetAttrib()89     unsigned char GetAttrib() {return wAttributes;}
90     void Normal();								// Reset all attributes
91     void HighVideo();							// Aka "bold"
92     void LowVideo();
93     void SetForeground(unsigned char wAttrib);	// Set the foreground directly
94     void SetBackground(unsigned char wAttrib);
95     void BlinkOn();								// Blink on/off
96     void BlinkOff();
97 	void UnderlineOn();							// Underline on/off
98 	void UnderlineOff();
99 	void UlBlinkOn();							// Blink+Underline on/off
100 	void UlBlinkOff();
101     void ReverseOn();							// Reverse on/off
102     void ReverseOff();
103 	void Lightbg();								// High-intensity background
104 	void Darkbg();								// Low-intensity background
setDefaultFg(unsigned char u)105 	void setDefaultFg(unsigned char u) {defaultfg = u;}
setDefaultBg(unsigned char u)106 	void setDefaultBg(unsigned char u) {defaultbg = u;}
107 
108 	// Text output routines
109 	unsigned long WriteText(const char *pszString, unsigned long cbString);
110 	unsigned long WriteString(const char* pszString, unsigned long cbString);
111 	unsigned long WriteStringFast(const char *pszString, unsigned long cbString);
112 	unsigned long WriteCtrlString(const char* pszString, unsigned long cbString);
113 	unsigned long WriteCtrlChar(char c);
114 	unsigned long NetWriteString(const char* pszString, unsigned long cbString);
115 
116 	// Clear screen/screen area functions
117 	void ClearScreen(char c = ' ');
118 	void ClearWindow(int start, int end, char c = ' ');
119 	void ClearEOScreen(char c = ' ');
120 	void ClearBOScreen(char c = ' ');
121 	void ClearLine(char c = ' ');
122 	void ClearEOLine(char c = ' ');
123 	void ClearBOLine(char c = ' ');
124 
125 	// Scrolling and text output control functions
126 	void SetScroll(int start, int end);
127     void ScrollDown(int iStartRow , int iEndRow, int bUp);
ScrollAll(int bUp)128 	void ScrollAll(int bUp) {ScrollDown(iScrollStart, iScrollEnd, bUp);}
129 	void index();
130 	void reverse_index();
setLineWrap(bool bEnabled)131 	void setLineWrap(bool bEnabled){
132 		if(!ini.get_lock_linewrap())
133 			ini.set_value("Wrap_Line", bEnabled ? "true" : "false");
134 	}
getLineWrap()135 	bool getLineWrap() {return ini.get_wrapline();}
136 
137     // Insert/delete characters/lines
138 	void InsertLine(int numlines);			// Added by Titus von Boxberg 30/3/97
139     void InsertCharacter(int numchar);		// "
140     void DeleteCharacter(int numchar);		// "
InsertMode(int i)141 	void InsertMode(int i) {insert_mode = i;}
142 
143 	// Miscellaneous functions
144 	void Beep();
145 
146 protected:
147 	HANDLE hConsole;
148 
149 	CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo;
150 
151 	unsigned char wAttributes;
152 	unsigned char fg, bg;
153 	unsigned char defaultfg, defaultbg;
154 	unsigned char origfg, origbg;
155 
156 	bool blink;
157 	bool underline;
158 	bool reverse;
159 
160 	int iScrollStart;
161 	int iScrollEnd;
162 	int insert_mode;
163 };
164 
165 // Non-member functions for saving state -- used by the scrollback buffer viewer
166 void saveScreen(CHAR_INFO* chiBuffer);
167 void restoreScreen(CHAR_INFO* chiBuffer);
168 CHAR_INFO* newBuffer();
169 void deleteBuffer(CHAR_INFO* chiBuffer);
170