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