Changed rencache to store font tab_width with font command

Fixes bug where text would be drawn/cached wrongly if more than one tab_width
was used in a given frame
This commit is contained in:
rxi 2020-09-05 15:06:12 +01:00
parent 2caa7f182d
commit 878c94a334
3 changed files with 10 additions and 0 deletions

View file

@ -18,6 +18,7 @@ typedef struct {
RenRect rect; RenRect rect;
RenColor color; RenColor color;
RenFont *font; RenFont *font;
int tab_width;
char text[0]; char text[0];
} Command; } Command;
@ -143,6 +144,7 @@ int rencache_draw_text(RenFont *font, const char *text, int x, int y, RenColor c
cmd->color = color; cmd->color = color;
cmd->font = font; cmd->font = font;
cmd->rect = rect; cmd->rect = rect;
cmd->tab_width = ren_get_font_tab_width(font);
} }
} }
@ -254,6 +256,7 @@ void rencache_end_frame(void) {
ren_draw_rect(cmd->rect, cmd->color); ren_draw_rect(cmd->rect, cmd->color);
break; break;
case DRAW_TEXT: case DRAW_TEXT:
ren_set_font_tab_width(cmd->font, cmd->tab_width);
ren_draw_text(cmd->font, cmd->text, cmd->rect.x, cmd->rect.y, cmd->color); ren_draw_text(cmd->font, cmd->text, cmd->rect.x, cmd->rect.y, cmd->color);
break; break;
} }

View file

@ -222,6 +222,12 @@ void ren_set_font_tab_width(RenFont *font, int n) {
} }
int ren_get_font_tab_width(RenFont *font) {
GlyphSet *set = get_glyphset(font, '\t');
return set->glyphs['\t'].xadvance;
}
int ren_get_font_width(RenFont *font, const char *text) { int ren_get_font_width(RenFont *font, const char *text) {
int x = 0; int x = 0;
const char *p = text; const char *p = text;

View file

@ -22,6 +22,7 @@ void ren_free_image(RenImage *image);
RenFont* ren_load_font(const char *filename, float size); RenFont* ren_load_font(const char *filename, float size);
void ren_free_font(RenFont *font); void ren_free_font(RenFont *font);
void ren_set_font_tab_width(RenFont *font, int n); void ren_set_font_tab_width(RenFont *font, int n);
int ren_get_font_tab_width(RenFont *font);
int ren_get_font_width(RenFont *font, const char *text); int ren_get_font_width(RenFont *font, const char *text);
int ren_get_font_height(RenFont *font); int ren_get_font_height(RenFont *font);