1 // --------------------------------------------------------------------------
2 // --
3 // -- Console classes methods
4 // --
5 // --
6 // --------------------------------------------------------------------------
7
8 // --------------------------------------------------------------------------
9 // -- Includes
10 // --------------------------------------------------------------------------
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <conio.h>
14 #include "defines.h"
15 #include "console.h"
16
17 // --------------------------------------------------------------------------
18 // -- Definitions
19 // --------------------------------------------------------------------------
20
21 // --------------------------------------------------------------------------
22 // -- Methods
23 // --------------------------------------------------------------------------
24
25 // --- Class: conWindow -----------------------------------------------------
26
27 // --- constructor ------------------
28 ConWindow::ConWindow(int Y, int sizeY) {
29
30 startY = Y;
31 endY = Y + (sizeY-1);
32
33 clear();
34
35 }
36
37
38 // --- put, character --------------
39 void ConWindow::putit(int X, int Y, char character) {
40
41 use();
42 gotoxy(X, Y);
43 putch(character);
44
45 }
46
47
48 // --- put, string, not line based --------------
49 void ConWindow::putit(int X, int Y, char *text ) {
50
51 use();
52
53 while(*text) {
54
55 gotoxy(X, Y);
56 putch(*text);
57 X++;
58 if (X > CON_MAX_X_SIZE) {
59 X = CON_START_X;
60 Y++;
61 };
62
63 text++;
64 }
65
66 }
67
68
69 // --- put, string, line based --------------
70 void ConWindow::putit(int X, int Y, char *text, Boolean lineBased ) {
71
72 use();
73 gotoxy(X,Y);
74 cputs(text);
75
76 }
77
78
79 // --- move everything up one line ----
80 void ConWindow::up(void) {
81
82 movetext(CON_START_X, startY+1, CON_END_X, endY,
83 CON_START_X, startY );
84 }
85
86
87 // --- move everything down one line --------------
88 void ConWindow::down(void) {
89
90 movetext(CON_START_X, startY, CON_END_X, endY-1,
91 CON_START_X, startY+1 );
92 }
93
94
95 // --- reset --------------
96 void ConWindow::reset(void) {
97
98 clear();
99
100 }
101
102
103 // --- Class: conWindow -----------------------------------------------------
104
105 // --- constructor -------------------
106 ConColorControl::ConColorControl( ColorT textColor, ColorTB bkgColor ) {
107
108 defaultTextColor = textColor;
109 defaultBkgColor = bkgColor;
110
111 }
112
113
114 // --- assert the colors --------------
115 void ConColorControl::colAssert(void) {
116 assertText();
117 assertBack();
118 }
119
120
121 // --- Class: conLBSWindow -------------------------------------------------
122
123 // --- constructor ------------------
124 ConLBSWindow::ConLBSWindow( int yStart, int ySize ) :
125 ConWindow( yStart, ySize),
126 ConColorControl( WHITE, BLACK ) {
127
128 cursorY = CON_START_Y;
129 }
130
131
132 // --- put string, no color control --
133 void ConLBSWindow::put(char *text) {
134
135 colAssert();
136 ConWindow::putit(CON_START_X, cursorY, text, TRUE);
137 cursorY = wherey();
138 }
139
140
141 // --- put string, assert back, set text color --
142 void ConLBSWindow::put(char *text, ColorT textColor) {
143
144 assertBack();
145 textcolor( textColor );
146 ConWindow::putit(CON_START_X, cursorY, text, TRUE);
147 cursorY = wherey();
148 }
149
150
151 // --- put string, assert text color, set background --
152 void ConLBSWindow::put(char *text, ColorTB backgroundColor) {
153
154 assertText();
155 textbackground( backgroundColor );
156 ConWindow::putit(CON_START_X, cursorY, text, TRUE);
157 cursorY = wherey();
158 }
159
160
161 // --- put string, set text color, set background --
162 void ConLBSWindow::put(char *text, ColorT textColor,
163 ColorTB backgroundColor ) {
164
165 textcolor( textColor );
166 textbackground( backgroundColor );
167 ConWindow::putit(CON_START_X, cursorY, text, TRUE);
168 cursorY = wherey();
169 }
170
171
172 // --- reset window --------------
173 void ConLBSWindow::reset(void) {
174
175 colAssert();
176 ConWindow::reset();
177 cursorY = CON_START_Y;
178
179 }
180
181
182 // --- scroll window up, fill in top line --------
183 void ConLBSWindow::scrollUp(char *text) {
184
185 down();
186 colAssert();
187 ConWindow::putit(CON_START_X, 1, text);
188
189 }
190
191
192 // --- scroll window up, fill in top line --------
193 void ConLBSWindow::scrollUp(char *text, ColorT textColor,
194 ColorTB backgroundColor ) {
195 down();
196 textcolor( textColor );
197 textbackground( backgroundColor );
198 ConWindow::putit(CON_START_X, 1, text);
199 }
200
201
202
203 // --- Class: conCBCWindow -------------------------------------------------
204
205 // --- punt the cursor to its next position ---
206 void ConCBCWindow::puntCursor(int &X, int &Y) {
207
208 // Adjust and possibly wrap X
209 X++;
210 if (X > CON_END_X) {
211 Y++;
212 X = CON_START_X;
213 }
214
215 // possibly wrap Y
216 if (Y > sizeY) {
217 Y = CON_START_Y;
218 }
219
220 }
221
222
223 // --- constructor ------------
224 ConCBCWindow::ConCBCWindow( int yStart, int ySize ) :
225 ConWindow( yStart, ySize),
226 ConColorControl( WHITE, BLACK ) {
227
228 cursorX = 1;
229 cursorY = 1;
230 sizeY = ySize;
231 }
232
233
234 // --- put character ----------
235 void ConCBCWindow::put(char theCharacter) {
236
237 int tempX;
238 int tempY;
239
240 // Put this character and find next spot
241 colAssert();
242 ConWindow::putit(cursorX, cursorY, theCharacter);
243
244 puntCursor(cursorX, cursorY);
245 tempX = cursorX;
246 tempY = cursorY;
247
248
249 // Put chaser dead-space
250 assertBack(BLACK);
251 ConWindow::putit(tempX, tempY, ' ');
252 puntCursor(tempX, tempY);
253 ConWindow::putit(tempX, tempY, ' ');
254
255
256 }
257
258
259 // --- put character ----------
260 void ConCBCWindow::put(char theCharacter, ColorT textColor,
261 ColorTB backgroundColor ) {
262
263 int tempX;
264 int tempY;
265
266 // Put this character and find next spot
267 assertText(textColor);
268 assertBack(backgroundColor);
269 ConWindow::putit(cursorX, cursorY, theCharacter);
270
271 puntCursor(cursorX, cursorY);
272 tempX = cursorX;
273 tempY = cursorY;
274
275
276 // Put chaser dead-space
277 assertBack(BLACK);
278 ConWindow::putit(tempX, tempY, ' ');
279 puntCursor(tempX, tempY);
280 ConWindow::putit(tempX, tempY, ' ');
281
282 }
283
284
285 // --- reset window --------------
286 void ConCBCWindow::reset(void) {
287
288 colAssert();
289 ConWindow::reset();
290 cursorX = CON_START_X;
291 cursorY = CON_START_Y;
292
293 }
294
295
296 // --- Class: conFreeWindow -------------------------------------------------
297
298 // --- constructor -------------
299 ConFreeWindow::ConFreeWindow( int yStart, int xStart, int ySize ) :
300 ConWindow( yStart, ySize),
301 ConColorControl( WHITE, BLACK ) {
302
303 startX = xStart;
304
305 }
306
307
308 // --- put character -----------
309 void ConFreeWindow::put(int atX, int atY, char character) {
310
311 colAssert();
312 ConWindow::putit(atX+startX, atY, character);
313 }
314
315
316 // --- put character -----------
317 void ConFreeWindow::put(int atX, int atY, char *text) {
318
319 colAssert();
320 ConWindow::putit(atX+startX, atY, text);
321 }
322
323
324 // --- put character -----------
325 void ConFreeWindow::put(int atX, int atY, char character,
326 ColorT textColor,
327 ColorTB backgroundColor ) {
328
329 assertText(textColor);
330 assertBack(backgroundColor);
331 ConWindow::putit(atX+startX, atY, character);
332 }
333
334
335 // --- put character -----------
336 void ConFreeWindow::put(int atX, int atY, char *text,
337 ColorT textColor,
338 ColorTB backgroundColor ) {
339
340 assertText(textColor);
341 assertBack(backgroundColor);
342 ConWindow::putit(atX+startX, atY, text);
343 }
344
345
346 // --- reset window --------------
347 void ConFreeWindow::reset(void) {
348
349 colAssert();
350 ConWindow::reset();
351 }
352
353
354 // --- Class: conSepLine -------------------------------------------------
355
356 // -- constructor
357 ConSepLine::ConSepLine( int atY, ColorT textColor,
358 ColorTB backgroundColor ) :
359 ConColorControl( textColor, backgroundColor ) {
360
361 Y = atY;
362
363 }
364
365 // -- constructor
366 void ConSepLine::reset( void ) {
367
368 colAssert();
369
370 window( CON_START_X, Y, CON_END_X, Y+1);
371 cputs("��������������������������������������������������������������������������������");
372
373 }
374
375
376 // --- Class: console -------------------------------------------------
377
378 // -- constructor
379 Console::Console(void) {
380 textmode(C4350);
381 _setcursortype(_NOCURSOR);
382 }
383
384 // -- destructor
385 Console::~Console() {
386 textmode(C4350);
387 }
388
389
|