ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/client/render_glyph.cpp
Revision: 1.6
Committed: Sun Oct 24 20:31:53 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +2 -2 lines
Log Message:
use EV and plain sockets instead of asio

File Contents

# Content
1 #include "dclient/render_glyph.h"
2
3 #include <ndk/color.hh>
4 #include <ndk/pen.hh>
5
6 #include "adt/array_size.h"
7
8 #include <cassert>
9 #include <utility>
10
11 struct color_attr
12 {
13 int color;
14 attr_t attr;
15 };
16
17 static color_attr const foreground[] = {
18 { COLOR_WHITE, WA_NORMAL }, // black => 0,
19 { COLOR_WHITE, WA_BOLD }, // white => 1,
20 { COLOR_BLUE, WA_NORMAL }, // navy => 2,
21 { COLOR_RED, WA_NORMAL }, // red => 3,
22 { COLOR_RED, WA_BOLD }, // orange => 4,
23 { COLOR_BLUE, WA_BOLD }, // blue => 5,
24 { COLOR_RED, WA_NORMAL }, // darkorange => 6,
25 { COLOR_GREEN, WA_NORMAL }, // green => 7,
26 { COLOR_GREEN, WA_BOLD }, // lightgreen => 8,
27 { COLOR_BLACK, WA_BOLD }, // grey => 9,
28 { COLOR_YELLOW, WA_NORMAL }, // brown => 10,
29 { COLOR_YELLOW, WA_BOLD }, // gold => 11,
30 { COLOR_CYAN, WA_NORMAL }, // tan => 12,
31 { COLOR_WHITE, WA_NORMAL }, // none => 13,
32 { }, // => 14,
33 { }, // => 15,
34 };
35
36 static color_attr const background[] = {
37 { COLOR_BLACK, WA_NORMAL }, // black => 0,
38 { COLOR_WHITE, WA_BOLD }, // white => 1,
39 { COLOR_BLUE, WA_NORMAL }, // navy => 2,
40 { COLOR_RED, WA_NORMAL }, // red => 3,
41 { COLOR_RED, WA_BOLD }, // orange => 4,
42 { COLOR_BLUE, WA_BOLD }, // blue => 5,
43 { COLOR_RED, WA_NORMAL }, // darkorange => 6,
44 { COLOR_GREEN, WA_NORMAL }, // green => 7,
45 { COLOR_GREEN, WA_BOLD }, // lightgreen => 8,
46 { COLOR_BLACK, WA_BOLD }, // grey => 9,
47 { COLOR_YELLOW, WA_NORMAL }, // brown => 10,
48 { COLOR_YELLOW, WA_BOLD }, // gold => 11,
49 { COLOR_CYAN, WA_NORMAL }, // tan => 12,
50 { COLOR_BLACK, WA_NORMAL }, // none => 13,
51 { }, // => 14,
52 { }, // => 15,
53 };
54
55 static ndk::color colors[array_size (foreground) * array_size (background)];
56
57 static struct color_initialiser
58 {
59 color_initialiser ()
60 {
61 static_assert (array_size (foreground) == 16, "invalid size of foreground table");
62 static_assert (array_size (background) == 16, "invalid size of background table");
63 for (size_t fg = 0; fg < array_size (foreground); fg++)
64 for (size_t bg = 0; bg < array_size (background); bg++)
65 {
66 color_attr fgpair = foreground[fg];
67 color_attr bgpair = background[bg];
68
69 colors[fg + bg * array_size (foreground)] = {
70 fgpair.color,
71 bgpair.color,
72 fgpair.attr | bgpair.attr,
73 };
74 }
75 }
76 } initialiser;
77
78
79 ndk::color
80 ndi_color (int fg, int bg)
81 {
82 assert (fg < int (array_size (foreground)));
83 assert (bg < int (array_size (background)));
84 return colors[fg + bg * array_size (foreground)];
85 }
86
87 static void
88 write (ndk::pen &pen, data::glyph::part const &part, u16 darkness)
89 {
90 pen.write (darkness < 50 ? ndi_color (9, 0) : ndi_color (part.fg, part.bg), part.text);
91 }
92
93 void
94 write (ndk::pen &pen, data::glyph const &glyph, u16 darkness)
95 {
96 write (pen, glyph[0], darkness);
97 write (pen, glyph[1], darkness);
98 }