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