Doxygenate src/terminal/
[elinks/kon.git] / src / terminal / draw.h
blob988a27b0043298ad196abfc7c28cbab5cbfef941
1 #ifndef EL__TERMINAL_DRAW_H
2 #define EL__TERMINAL_DRAW_H
4 #include "intl/charsets.h" /* unicode_val_T */
6 struct color_pair;
7 struct box;
8 struct terminal;
10 /** How many bytes we need for the colors of one character cell. */
11 #if defined(CONFIG_TRUE_COLOR)
12 /* 0, 1, 2 - rgb foreground; 3, 4, 5 - rgb background */
13 #define SCREEN_COLOR_SIZE 6
14 #elif defined(CONFIG_88_COLORS) || defined(CONFIG_256_COLORS)
15 /* 0 is foreground; 1 is background */
16 #define SCREEN_COLOR_SIZE 2
17 #else
18 #define SCREEN_COLOR_SIZE 1
19 #endif
21 /** Attributes of a character on the screen.
22 * All attributes should fit inside an unsigned char.
24 * XXX: The bold mask is used as part of the color encoding. */
25 enum screen_char_attr {
26 SCREEN_ATTR_UNSEARCHABLE = 0x01,
27 SCREEN_ATTR_BOLD = 0x08,
28 SCREEN_ATTR_ITALIC = 0x10,
29 SCREEN_ATTR_UNDERLINE = 0x20,
30 SCREEN_ATTR_STANDOUT = 0x40,
31 SCREEN_ATTR_FRAME = 0x80,
34 /** One position in the terminal screen's image. */
35 struct screen_char {
36 /** Contains either character value or frame data.
37 * - If #attr includes ::SCREEN_ATTR_FRAME, then @c data is
38 * enum border_char.
39 * - Otherwise, if the charset of the terminal is UTF-8, then
40 * @c data is a character value in UCS-4. This is possible
41 * only if CONFIG_UTF8 is defined.
42 * - Otherwise, the charset of the terminal is assumed to be
43 * unibyte, and @c data is a byte in that charset. */
44 #ifdef CONFIG_UTF8
45 unicode_val_T data;
46 #else
47 unsigned char data;
48 #endif /* CONFIG_UTF8 */
50 /** Attributes are ::screen_char_attr bits. */
51 unsigned char attr;
53 /** The fore- and background color. */
54 unsigned char color[SCREEN_COLOR_SIZE];
57 /** @relates screen_char */
58 #define copy_screen_chars(to, from, amount) \
59 do { memcpy(to, from, (amount) * sizeof(struct screen_char)); } while (0)
61 /** @name Linux frame symbols table.
62 * It is magically converted to other terminals when needed.
63 * In the screen image, they have attribute SCREEN_ATTR_FRAME;
64 * you should drop them to the image using draw_border_char().
66 * \todo TODO: When we'll support internal Unicode, this should be
67 * changed to some Unicode sequences. --pasky
69 * Codes extracted from twin-0.4.6 GPL project, a Textmode WINdow environment,
70 * by Massimiliano Ghilardi http://linuz.sns.it/~max/
71 * @{ */
73 /* Not yet used
74 #define T_UTF_16_BOX_DRAWINGS_LIGHT_VERTICAL 0x2502
75 #define T_UTF_16_BOX_DRAWINGS_LIGHT_VERTICAL_AND_LEFT 0x2524
76 #define T_UTF_16_BOX_DRAWINGS_VERTICAL_SINGLE_AND_LEFT_DOUBLE 0x2561
77 #define T_UTF_16_BOX_DRAWINGS_VERTICAL_DOUBLE_AND_LEFT_SINGLE 0x2562
78 #define T_UTF_16_BOX_DRAWINGS_DOWN_DOUBLE_AND_LEFT_SINGLE 0x2556
79 #define T_UTF_16_BOX_DRAWINGS_DOWN_SINGLE_AND_LEFT_DOUBLE 0x2555
80 #define T_UTF_16_BOX_DRAWINGS_DOUBLE_VERTICAL_AND_LEFT 0x2563
81 #define T_UTF_16_BOX_DRAWINGS_DOUBLE_VERTICAL 0x2551
82 #define T_UTF_16_BOX_DRAWINGS_DOUBLE_DOWN_AND_LEFT 0x2557
83 #define T_UTF_16_BOX_DRAWINGS_DOUBLE_UP_AND_LEFT 0x255D
84 #define T_UTF_16_BOX_DRAWINGS_UP_DOUBLE_AND_LEFT_SINGLE 0x255C
85 #define T_UTF_16_BOX_DRAWINGS_UP_SINGLE_AND_LEFT_DOUBLE 0x255B
86 #define T_UTF_16_BOX_DRAWINGS_LIGHT_DOWN_AND_LEFT 0x2510
87 #define T_UTF_16_BOX_DRAWINGS_LIGHT_UP_AND_RIGHT 0x2514
88 #define T_UTF_16_BOX_DRAWINGS_LIGHT_UP_AND_HORIZONTAL 0x2534
89 #define T_UTF_16_BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL 0x252C
90 #define T_UTF_16_BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT 0x251C
91 #define T_UTF_16_BOX_DRAWINGS_LIGHT_HORIZONTAL 0x2500
92 #define T_UTF_16_BOX_DRAWINGS_LIGHT_VERTICAL_AND_HORIZONTAL 0x253C
93 #define T_UTF_16_BOX_DRAWINGS_VERTICAL_SINGLE_AND_RIGHT_DOUBLE 0x255E
94 #define T_UTF_16_BOX_DRAWINGS_VERTICAL_DOUBLE_AND_RIGHT_SINGLE 0x255F
95 #define T_UTF_16_BOX_DRAWINGS_DOUBLE_UP_AND_RIGHT 0x255A
96 #define T_UTF_16_BOX_DRAWINGS_DOUBLE_DOWN_AND_RIGHT 0x2554
97 #define T_UTF_16_BOX_DRAWINGS_DOUBLE_UP_AND_HORIZONTAL 0x2569
98 #define T_UTF_16_BOX_DRAWINGS_DOUBLE_DOWN_AND_HORIZONTAL 0x2566
99 #define T_UTF_16_BOX_DRAWINGS_DOUBLE_VERTICAL_AND_RIGHT 0x2560
100 #define T_UTF_16_BOX_DRAWINGS_DOUBLE_HORIZONTAL 0x2550
101 #define T_UTF_16_BOX_DRAWINGS_DOUBLE_VERTICAL_AND_HORIZONTAL 0x256C
102 #define T_UTF_16_BOX_DRAWINGS_UP_SINGLE_AND_HORIZONTAL_DOUBLE 0x2567
103 #define T_UTF_16_BOX_DRAWINGS_UP_DOUBLE_AND_HORIZONTAL_SINGLE 0x2568
104 #define T_UTF_16_BOX_DRAWINGS_DOWN_SINGLE_AND_HORIZONTAL_DOUBLE 0x2564
105 #define T_UTF_16_BOX_DRAWINGS_DOWN_DOUBLE_AND_HORIZONTAL_SINGLE 0x2565
106 #define T_UTF_16_BOX_DRAWINGS_UP_DOUBLE_AND_RIGHT_SINGLE 0x2559
107 #define T_UTF_16_BOX_DRAWINGS_UP_SINGLE_AND_RIGHT_DOUBLE 0x2558
108 #define T_UTF_16_BOX_DRAWINGS_DOWN_SINGLE_AND_RIGHT_DOUBLE 0x2552
109 #define T_UTF_16_BOX_DRAWINGS_DOWN_DOUBLE_AND_RIGHT_SINGLE 0x2553
110 #define T_UTF_16_BOX_DRAWINGS_VERTICAL_DOUBLE_AND_HORIZONTAL_SINGLE 0x256B
111 #define T_UTF_16_BOX_DRAWINGS_VERTICAL_SINGLE_AND_HORIZONTAL_DOUBLE 0x256A
112 #define T_UTF_16_BOX_DRAWINGS_LIGHT_UP_AND_LEFT 0x2518
113 #define T_UTF_16_BOX_DRAWINGS_LIGHT_DOWN_AND_RIGHT 0x250C
116 /* CP437 is used by default */
117 #define T_CP437_BOX_DRAWINGS_LIGHT_VERTICAL 0x00B3
118 #define T_CP437_BOX_DRAWINGS_LIGHT_VERTICAL_AND_LEFT 0x00B4
119 #define T_CP437_BOX_DRAWINGS_VERTICAL_SINGLE_AND_LEFT_DOUBLE 0x00B5
120 #define T_CP437_BOX_DRAWINGS_VERTICAL_DOUBLE_AND_LEFT_SINGLE 0x00B6
121 #define T_CP437_BOX_DRAWINGS_DOWN_DOUBLE_AND_LEFT_SINGLE 0x00B7
122 #define T_CP437_BOX_DRAWINGS_DOWN_SINGLE_AND_LEFT_DOUBLE 0x00B8
123 #define T_CP437_BOX_DRAWINGS_DOUBLE_VERTICAL_AND_LEFT 0x00B9
124 #define T_CP437_BOX_DRAWINGS_DOUBLE_VERTICAL 0x00BA
125 #define T_CP437_BOX_DRAWINGS_DOUBLE_DOWN_AND_LEFT 0x00BB
126 #define T_CP437_BOX_DRAWINGS_DOUBLE_UP_AND_LEFT 0x00BC
127 #define T_CP437_BOX_DRAWINGS_UP_DOUBLE_AND_LEFT_SINGLE 0x00BD
128 #define T_CP437_BOX_DRAWINGS_UP_SINGLE_AND_LEFT_DOUBLE 0x00BE
129 #define T_CP437_BOX_DRAWINGS_LIGHT_DOWN_AND_LEFT 0x00BF
130 #define T_CP437_BOX_DRAWINGS_LIGHT_UP_AND_RIGHT 0x00C0
131 #define T_CP437_BOX_DRAWINGS_LIGHT_UP_AND_HORIZONTAL 0x00C1
132 #define T_CP437_BOX_DRAWINGS_LIGHT_DOWN_AND_HORIZONTAL 0x00C2
133 #define T_CP437_BOX_DRAWINGS_LIGHT_VERTICAL_AND_RIGHT 0x00C3
134 #define T_CP437_BOX_DRAWINGS_LIGHT_HORIZONTAL 0x00C4
135 #define T_CP437_BOX_DRAWINGS_LIGHT_VERTICAL_AND_HORIZONTAL 0x00C5
136 #define T_CP437_BOX_DRAWINGS_VERTICAL_SINGLE_AND_RIGHT_DOUBLE 0x00C6
137 #define T_CP437_BOX_DRAWINGS_VERTICAL_DOUBLE_AND_RIGHT_SINGLE 0x00C7
138 #define T_CP437_BOX_DRAWINGS_DOUBLE_UP_AND_RIGHT 0x00C8
139 #define T_CP437_BOX_DRAWINGS_DOUBLE_DOWN_AND_RIGHT 0x00C9
140 #define T_CP437_BOX_DRAWINGS_DOUBLE_UP_AND_HORIZONTAL 0x00CA
141 #define T_CP437_BOX_DRAWINGS_DOUBLE_DOWN_AND_HORIZONTAL 0x00CB
142 #define T_CP437_BOX_DRAWINGS_DOUBLE_VERTICAL_AND_RIGHT 0x00CC
143 #define T_CP437_BOX_DRAWINGS_DOUBLE_HORIZONTAL 0x00CD
144 #define T_CP437_BOX_DRAWINGS_DOUBLE_VERTICAL_AND_HORIZONTAL 0x00CE
145 #define T_CP437_BOX_DRAWINGS_UP_SINGLE_AND_HORIZONTAL_DOUBLE 0x00CF
146 #define T_CP437_BOX_DRAWINGS_UP_DOUBLE_AND_HORIZONTAL_SINGLE 0x00D0
147 #define T_CP437_BOX_DRAWINGS_DOWN_SINGLE_AND_HORIZONTAL_DOUBLE 0x00D1
148 #define T_CP437_BOX_DRAWINGS_DOWN_DOUBLE_AND_HORIZONTAL_SINGLE 0x00D2
149 #define T_CP437_BOX_DRAWINGS_UP_DOUBLE_AND_RIGHT_SINGLE 0x00D3
150 #define T_CP437_BOX_DRAWINGS_UP_SINGLE_AND_RIGHT_DOUBLE 0x00D4
151 #define T_CP437_BOX_DRAWINGS_DOWN_SINGLE_AND_RIGHT_DOUBLE 0x00D5
152 #define T_CP437_BOX_DRAWINGS_DOWN_DOUBLE_AND_RIGHT_SINGLE 0x00D6
153 #define T_CP437_BOX_DRAWINGS_VERTICAL_DOUBLE_AND_HORIZONTAL_SINGLE 0x00D7
154 #define T_CP437_BOX_DRAWINGS_VERTICAL_SINGLE_AND_HORIZONTAL_DOUBLE 0x00D8
155 #define T_CP437_BOX_DRAWINGS_LIGHT_UP_AND_LEFT 0x00D9
156 #define T_CP437_BOX_DRAWINGS_LIGHT_DOWN_AND_RIGHT 0x00DA
158 /** @} */
161 #define BD_LIGHT(XXX) T_CP437_BOX_DRAWINGS_LIGHT_##XXX
162 #define BD_DOUBLE(XXX) T_CP437_BOX_DRAWINGS_DOUBLE_##XXX
163 #define BD_MIXED(XXX) T_CP437_BOX_DRAWINGS_##XXX
165 enum border_char {
166 BORDER_NONE = 0x0000,
168 /* single-lined */
169 BORDER_SULCORNER = BD_LIGHT(DOWN_AND_RIGHT),
170 BORDER_SURCORNER = BD_LIGHT(DOWN_AND_LEFT),
171 BORDER_SDLCORNER = BD_LIGHT(UP_AND_RIGHT),
172 BORDER_SDRCORNER = BD_LIGHT(UP_AND_LEFT),
173 BORDER_SLTEE = BD_LIGHT(VERTICAL_AND_LEFT), /* => the tee points to the left => -| */
174 BORDER_SRTEE = BD_LIGHT(VERTICAL_AND_RIGHT),
175 BORDER_SDTEE = BD_LIGHT(DOWN_AND_HORIZONTAL),
176 BORDER_SUTEE = BD_LIGHT(UP_AND_HORIZONTAL),
177 BORDER_SVLINE = BD_LIGHT(VERTICAL),
178 BORDER_SHLINE = BD_LIGHT(HORIZONTAL),
179 BORDER_SCROSS = BD_LIGHT(VERTICAL_AND_HORIZONTAL), /* + */
181 /* double-lined */
182 BORDER_DULCORNER = BD_DOUBLE(DOWN_AND_RIGHT),
183 BORDER_DURCORNER = BD_DOUBLE(DOWN_AND_LEFT),
184 BORDER_DDLCORNER = BD_DOUBLE(UP_AND_RIGHT),
185 BORDER_DDRCORNER = BD_DOUBLE(UP_AND_LEFT),
186 BORDER_DLTEE = BD_DOUBLE(VERTICAL_AND_LEFT),
187 BORDER_DRTEE = BD_DOUBLE(VERTICAL_AND_RIGHT),
188 BORDER_DDTEE = BD_DOUBLE(DOWN_AND_HORIZONTAL),
189 BORDER_DUTEE = BD_DOUBLE(UP_AND_HORIZONTAL),
190 BORDER_DVLINE = BD_DOUBLE(VERTICAL),
191 BORDER_DHLINE = BD_DOUBLE(HORIZONTAL),
192 BORDER_DCROSS = BD_DOUBLE(VERTICAL_AND_HORIZONTAL),
194 /* Mixed single then double */
195 BORDER_SDULCORNER = BD_MIXED(DOWN_SINGLE_AND_RIGHT_DOUBLE),
196 BORDER_SDURCORNER = BD_MIXED(DOWN_SINGLE_AND_LEFT_DOUBLE),
197 BORDER_SDDLCORNER = BD_MIXED(UP_SINGLE_AND_RIGHT_DOUBLE),
198 BORDER_SDDRCORNER = BD_MIXED(UP_SINGLE_AND_LEFT_DOUBLE),
199 BORDER_SDLTEE = BD_MIXED(VERTICAL_SINGLE_AND_LEFT_DOUBLE),
200 BORDER_SDRTEE = BD_MIXED(VERTICAL_SINGLE_AND_RIGHT_DOUBLE),
201 BORDER_SDDTEE = BD_MIXED(DOWN_SINGLE_AND_HORIZONTAL_DOUBLE),
202 BORDER_SDUTEE = BD_MIXED(UP_SINGLE_AND_HORIZONTAL_DOUBLE),
203 BORDER_SDCROSS = BD_MIXED(VERTICAL_SINGLE_AND_HORIZONTAL_DOUBLE),
205 /* Mixed double then single */
206 BORDER_DSULCORNER = BD_MIXED(DOWN_DOUBLE_AND_RIGHT_SINGLE),
207 BORDER_DSURCORNER = BD_MIXED(DOWN_DOUBLE_AND_LEFT_SINGLE),
208 BORDER_DSDLCORNER = BD_MIXED(UP_DOUBLE_AND_RIGHT_SINGLE),
209 BORDER_DSDRCORNER = BD_MIXED(UP_DOUBLE_AND_LEFT_SINGLE),
210 BORDER_DSLTEE = BD_MIXED(VERTICAL_DOUBLE_AND_LEFT_SINGLE),
211 BORDER_DSRTEE = BD_MIXED(VERTICAL_DOUBLE_AND_RIGHT_SINGLE),
212 BORDER_DSDTEE = BD_MIXED(DOWN_DOUBLE_AND_HORIZONTAL_SINGLE),
213 BORDER_DSUTEE = BD_MIXED(UP_DOUBLE_AND_HORIZONTAL_SINGLE),
214 BORDER_DSCROSS = BD_MIXED(VERTICAL_DOUBLE_AND_HORIZONTAL_SINGLE),
217 /* 0 -> 1 <- 2 v 3 ^ */
218 enum border_cross_direction {
219 BORDER_X_RIGHT = 0,
220 BORDER_X_LEFT,
221 BORDER_X_DOWN,
222 BORDER_X_UP
225 /** Extracts a char from the screen. */
226 struct screen_char *get_char(struct terminal *, int x, int y);
228 /** Sets the color of a screen position. */
229 void draw_char_color(struct terminal *term, int x, int y,
230 struct color_pair *color);
232 /** Sets the data of a screen position. */
233 #ifdef CONFIG_UTF8
234 void draw_char_data(struct terminal *term, int x, int y, unicode_val_T data);
235 #else
236 void draw_char_data(struct terminal *term, int x, int y, unsigned char data);
237 #endif /* CONFIG_UTF8 */
239 /** Sets the data to @a border and of a screen position. */
240 void draw_border_char(struct terminal *term, int x, int y,
241 enum border_char border, struct color_pair *color);
243 /** Sets the cross position of two borders. */
244 void draw_border_cross(struct terminal *, int x, int y,
245 enum border_cross_direction, struct color_pair *color);
247 /** Draws a char. */
248 #ifdef CONFIG_UTF8
249 void draw_char(struct terminal *term, int x, int y,
250 unicode_val_T data, enum screen_char_attr attr,
251 struct color_pair *color);
252 #else
253 void draw_char(struct terminal *term, int x, int y,
254 unsigned char data, enum screen_char_attr attr,
255 struct color_pair *color);
256 #endif /* CONFIG_UTF8 */
258 /** Draws area defined by @a box using the same colors and attributes. */
259 void draw_box(struct terminal *term, struct box *box,
260 unsigned char data, enum screen_char_attr attr,
261 struct color_pair *color);
263 /** Draws a shadow of @a width and @a height with color @a color
264 * around @a box. */
265 void draw_shadow(struct terminal *term, struct box *box,
266 struct color_pair *color, int width, int height);
268 /** Draw borders. */
269 void draw_border(struct terminal *term, struct box *box,
270 struct color_pair *color, int width);
272 #ifdef CONFIG_UTF8
273 void fix_dwchar_around_box(struct terminal *term, struct box *box, int border,
274 int shadow_width, int shadow_height);
275 #endif /* CONFIG_UTF8 */
277 /** Draws @a length chars from @a text. */
278 void draw_text(struct terminal *term, int x, int y,
279 unsigned char *text, int length,
280 enum screen_char_attr attr,
281 struct color_pair *color);
283 /** Draws @a length chars from @a line on the screen. */
284 void draw_line(struct terminal *term, int x, int y, int length,
285 struct screen_char *line);
287 /** Updates the terminals cursor position. When @a blockable is set the
288 * block_cursor terminal option decides whether the cursor should be put at the
289 * bottom right corner of the screen. */
290 void set_cursor(struct terminal *term, int x, int y, int blockable);
292 /** Blanks the screen. */
293 void clear_terminal(struct terminal *);
295 #endif