console: add function to erase buffer

New function which helps erasing a whole region of the buffer.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-02-04 16:24:01 +01:00
parent d8ff83c5cb
commit 138c0aa5ee
2 changed files with 54 additions and 0 deletions

View File

@ -72,6 +72,8 @@ kmscon_symbol_t kmscon_buffer_read(struct kmscon_buffer *buf, unsigned int x,
unsigned int y);
void kmscon_buffer_scroll_down(struct kmscon_buffer *buf, unsigned int num);
void kmscon_buffer_scroll_up(struct kmscon_buffer *buf, unsigned int num);
void kmscon_buffer_erase_region(struct kmscon_buffer *buf, unsigned int x_from,
unsigned int y_from, unsigned int x_to, unsigned int y_to);
/* console objects */

View File

@ -137,6 +137,14 @@ static int init_cell(struct cell *cell)
return 0;
}
static void reset_cell(struct cell *cell)
{
if (!cell)
return;
memset(cell, 0, sizeof(*cell));
}
static void free_line(struct line *line)
{
unsigned int i;
@ -201,6 +209,21 @@ static int resize_line(struct line *line, unsigned int width)
return 0;
}
static struct line *get_line(struct kmscon_buffer *buf, unsigned int y)
{
if (y < buf->mtop_y) {
return buf->mtop_buf[y];
} else if (y < buf->mtop_y + buf->scroll_y) {
y -= buf->mtop_y;
return buf->scroll_buf[y];
} else if (y < buf->mtop_y + buf->scroll_y + buf->mbottom_y) {
y = y - buf->mtop_y - buf->scroll_y;
return buf->mbottom_buf[y];
}
return NULL;
}
int kmscon_buffer_new(struct kmscon_buffer **out, unsigned int x,
unsigned int y)
{
@ -878,3 +901,32 @@ void kmscon_buffer_scroll_up(struct kmscon_buffer *buf, unsigned int num)
num * sizeof(struct line*));
buf->scroll_fill = buf->scroll_y;
}
void kmscon_buffer_erase_region(struct kmscon_buffer *buf, unsigned int x_from,
unsigned int y_from, unsigned int x_to, unsigned int y_to)
{
unsigned int to;
struct line *line;
if (!buf)
return;
if (y_to >= buf->size_y)
y_to = buf->size_y - 1;
if (x_to >= buf->size_x)
x_to = buf->size_x - 1;
for ( ; y_from <= y_to; ++y_from) {
line = get_line(buf, y_from);
if (y_from == y_to)
to = x_to;
else
to = buf->size_x - 1;
for ( ; x_from <= to; ++x_from) {
if (x_from >= line->size)
break;
reset_cell(&line->cells[x_from]);
}
x_from = 0;
}
}