mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-10 04:40:25 +01:00
Draw wide characters correctly
Draw the full background for wide characters as soon as they are encountered. Don't draw any foreground or background if width is zero as this means the previous character was wide. Fixes #17
This commit is contained in:
parent
683b0e3304
commit
e13bc7e082
2 changed files with 10 additions and 7 deletions
|
@ -253,15 +253,18 @@ static int text_draw_cb(struct tsm_screen *con, uint64_t id, const uint32_t *ch,
|
|||
age <= terminal->framebuffer_age)
|
||||
return 0;
|
||||
|
||||
std::pair<Color, Color> color_pair = terminal->get_cell_colors(attr);
|
||||
terminal->draw_background(row, col, color_pair.first);
|
||||
if (width < 1) // No foreground or background to draw.
|
||||
return 0;
|
||||
|
||||
size_t ulen;
|
||||
char buf[5] = {0};
|
||||
std::pair<Color, Color> color_pair = terminal->get_cell_colors(attr);
|
||||
terminal->draw_background(row, col, color_pair.first, width);
|
||||
|
||||
if (len < 1) // No foreground to draw.
|
||||
return 0;
|
||||
|
||||
size_t ulen;
|
||||
char buf[5] = {0};
|
||||
|
||||
char *utf8 = tsm_ucs4_to_utf8_alloc(ch, len, &ulen);
|
||||
memcpy(buf, utf8, ulen);
|
||||
terminal->draw_foreground(row, col, buf, attr, color_pair.second);
|
||||
|
@ -473,10 +476,10 @@ void Terminal::update_theme() {
|
|||
update_size();
|
||||
}
|
||||
|
||||
void Terminal::draw_background(int row, int col, Color bgcolor) {
|
||||
void Terminal::draw_background(int row, int col, Color bgcolor, int width = 1) {
|
||||
/* Draw the background */
|
||||
Vector2 background_pos = Vector2(col * cell_size.x, row * cell_size.y);
|
||||
Rect2 background_rect = Rect2(background_pos, cell_size);
|
||||
Rect2 background_rect = Rect2(background_pos, cell_size * Vector2(width, 1));
|
||||
draw_rect(background_rect, bgcolor);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ private:
|
|||
|
||||
public:
|
||||
std::pair<Color, Color> get_cell_colors(const tsm_screen_attr *attr);
|
||||
void draw_background(int row, int col, Color bgcol);
|
||||
void draw_background(int row, int col, Color bgcol, int width);
|
||||
void draw_foreground(int row, int col, char *ch, const tsm_screen_attr *attr,
|
||||
Color fgcol);
|
||||
|
||||
|
|
Loading…
Reference in a new issue