Skip to content
Snippets Groups Projects
Commit c13ee1f8 authored by Mateusz Zalega's avatar Mateusz Zalega
Browse files

gfx: textbuffer: redraw only if the buffer has changed

parent 497a0946
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ void txt_init(struct txt_buffer *txtb, struct gfx_region *reg, sFONT *f) ...@@ -12,6 +12,7 @@ void txt_init(struct txt_buffer *txtb, struct gfx_region *reg, sFONT *f)
txtb->bg_color = gfx_color_rgb_f(reg, .0f, .0f, .0f); txtb->bg_color = gfx_color_rgb_f(reg, .0f, .0f, .0f);
txtb->draw_cursor = 1; txtb->draw_cursor = 1;
txtb->auto_update = 1; txtb->auto_update = 1;
txtb->needs_redraw = 0;
txt_clear(txtb); txt_clear(txtb);
} }
...@@ -49,6 +50,8 @@ static void scrollup(struct txt_buffer *tm) ...@@ -49,6 +50,8 @@ static void scrollup(struct txt_buffer *tm)
g->fg_color = tm->fg_color; g->fg_color = tm->fg_color;
g->bg_color = tm->bg_color; g->bg_color = tm->bg_color;
} }
tm->needs_redraw = 1;
} }
static void newline(struct txt_buffer *tm) static void newline(struct txt_buffer *tm)
...@@ -71,6 +74,8 @@ static inline void advance_cursor(struct txt_buffer *tm) ...@@ -71,6 +74,8 @@ static inline void advance_cursor(struct txt_buffer *tm)
if (tm->cursor_row > last_row) if (tm->cursor_row > last_row)
newline(tm); newline(tm);
} }
tm->needs_redraw = 1;
} }
static void tab(struct txt_buffer *tm) static void tab(struct txt_buffer *tm)
...@@ -107,6 +112,7 @@ void txt_clear(struct txt_buffer *tm) ...@@ -107,6 +112,7 @@ void txt_clear(struct txt_buffer *tm)
tm->cursor_column = 0; tm->cursor_column = 0;
tm->cursor_row = 0; tm->cursor_row = 0;
tm->needs_redraw = 1;
if (tm->auto_update) if (tm->auto_update)
txt_update(tm); txt_update(tm);
} }
...@@ -131,6 +137,7 @@ void txt_putchar(struct txt_buffer *tm, char ch) ...@@ -131,6 +137,7 @@ void txt_putchar(struct txt_buffer *tm, char ch)
advance_cursor(tm); advance_cursor(tm);
} }
tm->needs_redraw = 1;
if (tm->auto_update) if (tm->auto_update)
txt_update(tm); txt_update(tm);
} }
...@@ -193,6 +200,8 @@ void txt_draw(struct txt_buffer *tm) ...@@ -193,6 +200,8 @@ void txt_draw(struct txt_buffer *tm)
if (tm->draw_cursor) if (tm->draw_cursor)
draw_cursor_(tm); draw_cursor_(tm);
tm->needs_redraw = 0;
} }
void txt_set_color_f( void txt_set_color_f(
...@@ -247,5 +256,7 @@ void txt_set_transparent(struct txt_buffer *tm) ...@@ -247,5 +256,7 @@ void txt_set_transparent(struct txt_buffer *tm)
void txt_update(struct txt_buffer *tm) void txt_update(struct txt_buffer *tm)
{ {
if (tm->needs_redraw)
txt_draw(tm);
gfx_update(tm->reg); gfx_update(tm->reg);
} }
...@@ -22,6 +22,7 @@ struct txt_buffer { ...@@ -22,6 +22,7 @@ struct txt_buffer {
Color bg_color; Color bg_color;
int draw_cursor; int draw_cursor;
int auto_update; int auto_update;
int needs_redraw;
struct txt_glyph text[TEXTBUFFER_MAX_HEIGHT][TEXTBUFFER_MAX_WIDTH]; struct txt_glyph text[TEXTBUFFER_MAX_HEIGHT][TEXTBUFFER_MAX_WIDTH];
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment