FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
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
,
7
FB_COLOR_GREEN
,
FB_COLOR_CYAN
,
8
FB_COLOR_RED
,
FB_COLOR_MAGENTA
,
9
FB_COLOR_BROWN
,
FB_COLOR_WHITE
,
10
FB_COLOR_GREY
,
FB_COLOR_LBLUE
,
11
FB_COLOR_LGREEN
,
FB_COLOR_LCYAN
,
12
FB_COLOR_LRED
,
FB_COLOR_LMAGENTA
,
13
FB_COLOR_YELLOW
,
FB_COLOR_BWHITE
};
14
15
static
int
last_bc
=
FB_COLOR_BLACK
,
last_fc
=
FB_COLOR_WHITE
;
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
60
int
fb_ConsoleGetColorAttEx
(
HANDLE
hConsole )
61
{
62
CONSOLE_SCREEN_BUFFER_INFO info;
63
if
( GetConsoleScreenBufferInfo( hConsole, &info )==0 )
64
return
7;
65
return
info.wAttributes;
66
67
}
68
69
int
fb_ConsoleGetColorAtt
(
void
)
70
{
71
return
fb_ConsoleGetColorAttEx
(
__fb_out_handle
);
72
}
rtlib
win32
io_color.c
Generated on Thu Jan 23 2014 19:40:09 for FreeBASIC by
1.8.4