FreeBASIC  0.91.0
io_pageset.c
Go to the documentation of this file.
1 /* console 'screen , pg, pg' function */
2 
3 #include "../fb.h"
4 #include "fb_private_console.h"
5 
7 {
8  HANDLE hnd = CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE,
9  0,
10  NULL,
11  CONSOLE_TEXTMODE_BUFFER,
12  NULL );
13  if( hnd == NULL )
14  return NULL;
15 
16  /* size must be the stdout ones */
17  CONSOLE_SCREEN_BUFFER_INFO csbi;
18  GetConsoleScreenBufferInfo( __fb_con.outHandle, &csbi );
19  SetConsoleScreenBufferSize( hnd, csbi.dwSize );
20 
21  return hnd;
22 }
23 
24 static void hHideCursor( int pg1, int pg2 )
25 {
26  CONSOLE_CURSOR_INFO cci;
27 
28  GetConsoleCursorInfo( __fb_con.outHandle, &cci );
29  cci.bVisible = FALSE;
30 
31  SetConsoleCursorInfo( __fb_con.pgHandleTb[pg1], &cci );
32  if( pg2 >= 0 )
33  SetConsoleCursorInfo( __fb_con.pgHandleTb[pg2], &cci );
34 }
35 
36 int fb_ConsolePageSet ( int active, int visible )
37 {
39 
40  int res = __fb_con.active | (__fb_con.visible << 8);
41 
42  if( active >= 0 )
43  {
44  if( __fb_con.pgHandleTb[active] == NULL )
45  {
47  if( hnd == NULL )
48  return -1;
49  else
50  __fb_con.pgHandleTb[active] = hnd;
51  }
52 
53  /* if page isn't visible, hide the cursor */
54  if( active != __fb_con.visible )
55  {
56  hHideCursor( active, -1 );
57  }
58 
59  __fb_con.active = active;
60  }
61 
62  if( visible >= 0 )
63  {
64  if( __fb_con.pgHandleTb[visible] == NULL )
65  {
67  if( hnd == NULL )
68  return -1;
69  else
70  __fb_con.pgHandleTb[visible] = hnd;
71  }
72 
73  if( __fb_con.visible != visible )
74  {
75  SetConsoleActiveScreenBuffer( __fb_con.pgHandleTb[visible] );
76 
77  /* if pages aren't the same, hide the cursor */
78  if( visible != __fb_con.active )
79  {
80  hHideCursor( __fb_con.active, visible );
81  }
82 
83  __fb_con.visible = visible;
84  }
85  }
86 
87  return res;
88 }