scrolling: implement partial scrolling

This commit is contained in:
Daniel Eklöf 2019-07-01 19:20:21 +02:00
parent 63e46b7b0b
commit 24395cf4cd
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -86,6 +86,7 @@ damage_adjust_after_scroll(struct terminal *term, enum damage_type damage_type,
struct scroll_region region, int lines) struct scroll_region region, int lines)
{ {
tll_foreach(term->grid->damage, it) { tll_foreach(term->grid->damage, it) {
#if 0
if (it->item.range.start < term->grid->offset) { if (it->item.range.start < term->grid->offset) {
int end = it->item.range.start + it->item.range.length; int end = it->item.range.start + it->item.range.length;
if (end >= term->grid->offset) { if (end >= term->grid->offset) {
@ -95,6 +96,12 @@ damage_adjust_after_scroll(struct terminal *term, enum damage_type damage_type,
tll_remove(term->grid->damage, it); tll_remove(term->grid->damage, it);
} }
} }
#endif
int start = it->item.range.start;
int end = start + it->item.range.length;
if (start -
} }
} }
#endif #endif
@ -190,37 +197,52 @@ void
term_scroll_partial(struct terminal *term, struct scroll_region region, int rows) term_scroll_partial(struct terminal *term, struct scroll_region region, int rows)
{ {
LOG_DBG("scroll: %d rows", rows); LOG_DBG("scroll: %d rows", rows);
if (rows >= region.end - region.start) {
assert(false && "untested"); if (region.start > 0) {
return; /* TODO: check if it's worth memoving the scroll area instead,
* under certain circumstances */
grid_memmove(term->grid, rows * term->cols, 0, region.start * term->cols);
tll_foreach(term->grid->damage, it) {
int start = it->item.range.start - term->grid->offset;
int end = start + it->item.range.length;
if (start < region.start) {
assert(end <= region.start);
it->item.range.start += rows * term->cols;
}
}
} }
#if 0 if (region.end < term->rows) {
int cell_dst = (region.start + 0) * term->cols; /* Copy scrolled-up bottom region to new bottom region */
int cell_src = (region.start + rows) * term->cols; grid_memmove(
int cell_count = (region.end - region.start - rows) * term->cols; term->grid,
(region.end + rows) * term->cols,
region.end * term->cols,
(term->rows - region.end) * term->cols);
LOG_DBG("moving %d lines from row %d to row %d", cell_count / term->cols, tll_foreach(term->grid->damage, it) {
cell_src / term->cols, cell_dst / term->cols); int start = it->item.range.start - term->grid->offset;
int end = start + it->item.range.length;
const int bytes = cell_count * sizeof(term->grid->cells[0]); if (end > region.end) {
memmove( assert(start >= region.end);
&term->grid->cells[cell_dst], &term->grid->cells[cell_src], it->item.range.start += rows * term->cols;
bytes); }
}
memset(&term->grid->cells[(region.end - rows) * term->cols], 0, }
rows * term->cols * sizeof(term->grid->cells[0]));
term_damage_scroll(term, DAMAGE_SCROLL, region, rows);
#else
/* TODO */
assert(region.start == 0 && region.end == term->rows);
assert(rows < term->rows);
/* Offset grid origin */
term->grid->offset += rows * term->cols; term->grid->offset += rows * term->cols;
grid_memset(term->grid, (region.end - rows) * term->cols, 0, rows * term->cols);
/* Clear scrolled-in lines */
grid_memset(
term->grid,
max(0, region.end - rows) * term->cols, 0, rows * term->cols);
term_damage_scroll(term, DAMAGE_SCROLL, region, rows); term_damage_scroll(term, DAMAGE_SCROLL, region, rows);
#endif
} }
void void