FreeBASIC  0.91.0
io_color.c
Go to the documentation of this file.
1 /* console COLOR statement */
2 
3 #include "../fb.h"
4 #include "fb_private_console.h"
5 
6 static int colorlut[16] = { FB_COLOR_BLACK, FB_COLOR_BLUE,
14 
16 
17 void fb_ConsoleColorEx( HANDLE hConsole, int fc, int bc )
18 {
19  int last_attr = fb_ConsoleGetColorAttEx( hConsole );
20  int last_bc = (last_attr >> 4) & 0xF, last_fc = (last_attr & 0xF);
21 
22  if( fc >= 0 ) {
23  fc = colorlut[fc & 15];
24  } else {
25  fc = last_fc;
26  }
27 
28  if( bc >= 0 ) {
29  bc = colorlut[bc & 15];
30  } else {
31  bc = last_bc;
32  }
33 
34  SetConsoleTextAttribute( hConsole, fc + (bc << 4) );
35 }
36 
37 int fb_ConsoleColor( int fc, int bc, int flags )
38 {
39  int cur = last_fc | (last_bc << 16);
40 
41  if( !( flags & FB_COLOR_FG_DEFAULT ) ) {
42  last_fc = (fc & 0xF);
43  fc = colorlut[last_fc];
44  } else {
45  fc = last_fc;
46  }
47 
48  if( !( flags & FB_COLOR_BG_DEFAULT ) ) {
49  last_bc = (bc & 0xF);
50  bc = colorlut[last_bc];
51  } else {
52  bc = last_bc;
53  }
54 
55  SetConsoleTextAttribute( __fb_out_handle, fc + (bc << 4) );
56 
57  return cur;
58 }
59 
61 {
62  CONSOLE_SCREEN_BUFFER_INFO info;
63  if( GetConsoleScreenBufferInfo( hConsole, &info )==0 )
64  return 7;
65  return info.wAttributes;
66 
67 }
68 
70 {
72 }