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:
parent
2caa7f182d
commit
878c94a334
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue