FreeBASIC  0.91.0
io_cls.c
Go to the documentation of this file.
1 /* console CLS statement */
2 
3 #include "../fb.h"
4 #include "fb_private_console.h"
5 
6 void fb_ConsoleClearViewRawEx( HANDLE hConsole, int x1, int y1, int x2, int y2 )
7 {
8  WORD attr = (WORD) fb_ConsoleGetColorAttEx( hConsole );
9  int width = x2 - x1 + 1, lines = y2 - y1 + 1;
10 
11  if( width==0 || lines==0 )
12  return;
13 
14  DBG_ASSERT(width > 0);
15  DBG_ASSERT(lines > 0);
16 
17  while (lines--) {
18  DWORD written;
19  COORD coord = { x1, y1 + lines };
20  FillConsoleOutputAttribute( hConsole, attr, width, coord, &written);
21  FillConsoleOutputCharacter( hConsole, ' ', width, coord, &written );
22  }
23 
24  fb_ConsoleLocateRawEx( hConsole, y1, x1, -1 );
25 }
26 
27 void fb_ConsoleClear( int mode )
28 {
29  /* This is the view in screen buffer coordinates (0-based) */
30  int view_left, view_top, view_right, view_bottom;
31 
32  /* This is the window in screen buffer coordinates (0-based) */
33  int win_left, win_top, win_right, win_bottom;
34 
36 
37  if( FB_CONSOLE_WINDOW_EMPTY() || mode==1 )
38  return;
39 
40  win_top = __fb_con.window.Top;
41  win_left = __fb_con.window.Left;
42  win_right = __fb_con.window.Right;
43  win_bottom = __fb_con.window.Bottom;
44 
45  if( (mode == 2) || (mode == 0xFFFF0000) ) /* same as gfxlib's DEFAULT_COLOR */
46  {
47  /* Just fill the view */
48  fb_ConsoleGetView( &view_top, &view_bottom );
49 
50  /* Translate the rows of the view to screen buffer coordinates (0-based) */
51  fb_hConvertToConsole( NULL, &view_top, NULL, &view_bottom );
52  view_left = win_left;
53  view_right = win_right;
54 
55  } else {
56  /* Fill the whole window? */
57  view_top = win_top;
58  view_left = win_left;
59  view_right = win_right;
60  view_bottom = win_bottom;
61  }
62 
63  DBG_ASSERT(view_left <= view_right);
64  DBG_ASSERT(view_top <= view_bottom);
65 
66  fb_ConsoleClearViewRawEx( __fb_out_handle, view_left, view_top, view_right, view_bottom );
67 }