-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen.cpp
More file actions
438 lines (395 loc) · 9.91 KB
/
Copy pathscreen.cpp
File metadata and controls
438 lines (395 loc) · 9.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
/*---------------------------------------------------------------------
Dieter Neubacher Vers.: 1.0 25.06.96
Vers.: 2.0 01.02.97
-------------------------------------------------------------------
screen.cpp
Version 2.0 WIN32
-----------------------------------------------------------------------
*/
#ifdef WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef WIN32
#include <wincon.h>
/* used to set our initial console screen buffer size */
#define CONX 80
#define CONY 25
#else
#ifdef __MS_DOS__
#include <graph.h>
#else
#error screen.cpp only for MSDOS implemented
#endif /* __MS_DOS__ */
#endif /* WIN32 */
#include "debug.h"
#include "screen.h"
#include "rameau.h"
screen Screen(0,79,0,24); // Output Screen
#ifdef WIN32
const int BackBlack = 0;
const int TextBlack = 0;
const int TextWhite = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
const int BackWhite = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE;
const int TextBlue = FOREGROUND_BLUE;
const int BackBlue = BACKGROUND_BLUE;
const int TextRed = FOREGROUND_RED | FOREGROUND_INTENSITY;
const int BackRed = BACKGROUND_RED | BACKGROUND_INTENSITY;
#endif
const int Black = 0;
const int Blue = 1;
const int Green = 2;
const int Cyan = 3;
const int Red = 4;
const int Maganta = 5;
const int Brown = 6;
const int White = 7;
const int Gray = 8;
const int LightBlue = 9;
const int LightGreen = 10;
const int LightCyan = 11;
const int LightRed = 12;
const int LightMagenta = 13;
const int Yellow = 14;
const int BrightWhite = 15;
#ifdef WIN32
int ToWinColor( int TextColor, int BackColor )
{
int color = 0;
switch( TextColor )
{
case White :
color |= TextWhite;
break;
case Blue :
color |= TextBlue;
break;
case Red :
color |= TextRed;
break;
case Black :
color |= TextBlack;
break;
}
switch( BackColor )
{
case White :
color |= BackWhite;
break;
case Red :
color |= BackRed;
break;
case Blue :
color |= BackBlue;
break;
case Black :
color |= BackBlack;
break;
}
return color;
}
#endif // WIN32
screen::screen(int MinX,int MaxX,int MinY,int MaxY)
{
this->MinX = MinX;
this->MinY = MinY;
this->MaxX = MaxX;
this->MaxY = MaxY;
BackColor = White;
TextColor = Black;
PosX = MinX; PosY = MinY;
StatusLine =MaxY;
ScreenBuf = new int[(MaxX-MinX+1)*(MaxY-MinY+1) + 256 /*save*/ ];
EmtyLine = new char[MaxX-MinX+2];
memset( EmtyLine, ' ', MaxX-MinX+1 );
EmtyLine[MaxX-MinX] = 0;
#ifdef WIN32
AllocConsole();
HandelStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
Screen.Normal();
#else
OldTextColor = _gettextcolor ();
OldBackColor = (int) _getbkcolor ();
#endif
NoCursor();
#ifdef SCREEN_DEBUG
Pos( 0,0 );
DispVideoConfig();
DispError( "hit any key to continue" );
#endif
}
screen::~screen()
{
delete ScreenBuf;
delete EmtyLine;
#ifdef WIN32
// close windows console
// FreeConsole();
system( "cls" );
#else
Color( OldBackColor, OldTextColor );
NormalCursor();
#endif
#ifdef SCREEN_DEBUG
Pos( 0,0 );
DispVideoConfig();
DispError( "hit any key to continue" );
#endif
}
int screen::Clear()
{
#ifdef WIN32
int i;
for ( i=MinY; i <= MaxY; i++ )
{
ScSetPos( 0, i);
ScWriteText( EmtyLine );
}
#else
_clearscreen( _GCLEARSCREEN );
#endif
memset( ScreenBuf, ' ', 2 * (MaxX-MinX+1)*(MaxY-MinY+1) );
return 0;
}
int screen::Clear(int y)
{
Pos( MinX,y );
ScWriteText( EmtyLine );
memset( ScreenBufP, ' ', 2 * (MaxY-MinY+1) );
return 0;
}
int screen::Clear(int x,int y)
{
char help[2];
Pos( x,y );
help[0]=' ';
help[1]=0;
ScWriteText( help );
return 0;
}
int screen::ClearStatus()
{
Pos( MinX,MaxY );
ScWriteText( EmtyLine );
return 0;
}
int screen::Put(char ch)
{
char help[2];
help[0]=ch;
help[1]=0;
ScWriteText( help );
return 0;
}
int screen::Put(int x,int y,char ch)
{
char help[2];
help[0]=ch;
help[1]=0;
Pos( x,y );
ScWriteText( help );
return 0;
}
int screen::Put( char *str)
{
ScWriteText( str );
return 0;
}
int screen::Put(int x,int y,char *str)
{
Pos( x,y );
ScWriteText( str );
return 0;
}
int screen::Pos(int x,int y )
{
if( x >= MaxX ) PosX = MaxX; else PosX = x;
if( y >= MaxY ) PosY = MaxY; else PosY = y;
ScSetPos( PosX,PosY );
return 0;
}
int screen::GetPos(int x,int y )
{
return 0;
}
int screen::Status( char *str)
{
Pos( MinX,MaxY );
Put( str );
return 0;
}
/*--------------------------------------------------------------------------
Funktion whitch use spacific Graphic Funktions
----------------------------------------------------------------------------
*/
void screen::NormalCursor()
{
#ifdef WIN32
CONSOLE_CURSOR_INFO mode;
CursorMode = 1;
mode.dwSize = 15; mode.bVisible = 1;
SetConsoleCursorInfo( HandelStdOut, &mode );
#else
CursorMode = 1; _settextcursor (0x0707);
#endif
}
void screen::BigCursor()
{
#ifdef WIN32
CONSOLE_CURSOR_INFO mode;
CursorMode = 2;
mode.dwSize = 99; mode.bVisible = 1;
SetConsoleCursorInfo( HandelStdOut, &mode );
#else
CursorMode = 2; _settextcursor (0x0007);
#endif
}
void screen::NoCursor()
{
#ifdef WIN32
CONSOLE_CURSOR_INFO mode;
CursorMode = 0;
mode.dwSize = 50; mode.bVisible = 0;
SetConsoleCursorInfo( HandelStdOut, &mode );
#else
CursorMode = 0; _settextcursor (0x2000);
#endif
}
void screen::Normal(void)
{
#ifdef WIN32
SetConsoleTextAttribute( HandelStdOut, ToWinColor( TextColor, BackColor ) );
#else
_setbkcolor( BackColor); _settextcolor( TextColor);
#endif
}
void screen::Invert(void)
{
#ifdef WIN32
SetConsoleTextAttribute( HandelStdOut, ToWinColor( BackColor, TextColor ) );
#else
_setbkcolor( TextColor); _settextcolor( BackColor);
#endif
}
void screen::Color( int Mode )
{
switch( Mode )
{
case 2: // Black White
Color( White, Black);
break;
case 1: // Blue White
Color( Blue, White);
break;
}
}
#pragma optimize( "", on )
inline void screen::ScWriteText( char *str )
{
int i, x, y;
x = PosX; y=PosY;
#ifdef WIN32
printf( str );
#else
_outtext( str );
#endif
for( i=0; i<80; i++,x++ )
{
if( x > MaxX ) break;
if( str[i] == 0 ) break;
ScreenBuf[ y*(MaxX-MinX+1)+x ] = str[i];
}
}
#pragma optimize( "", on )
inline void screen::ScSetPos( int x, int y )
{
ScreenBufP = &ScreenBuf[ y*(MaxX-MinX+1)+x ];
#ifdef WIN32
COORD pos;
pos.X = x; pos.Y = y;
SetConsoleCursorPosition( HandelStdOut, pos);
#else
_settextposition( y+1, x+1 );
#endif
}
void screen::ToFile( char *FileName )
{
FILE *stream;
int x,y;
if( (stream = fopen( FileName, "a" )) != NULL )
{
fprintf( stream,"-------------------- new page --------------------\n" );
for( y=MinY;y<=MaxY; y++ )
{
for( x=MinX; x<=MaxX; x++ )
{
fputc( ScreenBuf[ y*(MaxX-MinX+1)+x ], stream );
}
fputc( '\n', stream );
}
fclose( stream );
}
}
#ifdef SCREEN_DEBUG
/*--------------------------------------------------------------------------
----------------------------------------------------------------------------
*/
void screen::DispVideoConfig()
{
struct _videoconfig vc;
short c;
char b[500]; /* Buffer for string */
_getvideoconfig( &vc );
/* Write all information to a string, then output string. */
c = sprintf( b, "X pixels: %d\n", vc.numxpixels );
c += sprintf( b + c, "Y pixels: %d\n", vc.numypixels );
c += sprintf( b + c, "Text columns: %d\n", vc.numtextcols );
c += sprintf( b + c, "Text rows: %d\n", vc.numtextrows );
c += sprintf( b + c, "Colors: %d\n", vc.numcolors );
c += sprintf( b + c, "Bits/pixel: %d\n", vc.bitsperpixel );
c += sprintf( b + c, "Video pages: %d\n", vc.numvideopages );
c += sprintf( b + c, "Mode: %d\n", vc.mode );
c += sprintf( b + c, "Adapter: %d\n", vc.adapter );
c += sprintf( b + c, "Monitor: %d\n", vc.monitor );
c += sprintf( b + c, "Memory: %d\n", vc.memory );
_outtext( b );
}
#endif
/*--------------------------------------------------------------------------
disp error masssge in the last screen line
----------------------------------------------------------------------------
*/
int screen::DispError(char *str)
{
int ret,color;
NoCursor();
color = GetBackColor();
SetBackColor( Red );
ClearStatus();
Status(str);
ret = GetKey();
SetBackColor( color );
ClearStatus();
Normal();
return (ret);
}
/*---------------------------------------------------------------------
display working massage
-----------------------------------------------------------------------
*/
int screen::Massage (FILE * stream, char *str, int flag)
{
if (flag == 0)
{
fprintf (stream, "%s\n", str);
}
else
{
Invert ();
Status( str );
Normal();
}
return 0;
}