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:
Leroy Hopson 2021-07-12 22:24:21 +07:00 committed by Leroy Hopson
parent 683b0e3304
commit e13bc7e082
2 changed files with 10 additions and 7 deletions

View file

@ -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);
}

View file

@ -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);