[bitmapstates] properly use ncplane_erase_region()

This commit is contained in:
nick black 2021-09-21 00:47:19 -04:00 committed by nick black
parent ad2b806444
commit 69e58667c7
3 changed files with 9 additions and 3 deletions

View File

@ -2103,6 +2103,7 @@ void ncplane_yx(const ncplane* n, int* y, int* x){
}
void ncplane_erase(ncplane* n){
loginfo("erasing plane\n");
if(n->sprite){
sprixel_hide(n->sprite);
}
@ -2156,13 +2157,17 @@ int ncplane_erase_region(ncplane* n, int ystart, int xstart, int ylen, int xlen)
if(ystart + ylen > ncplane_dim_y(n)){
ylen = ncplane_dim_y(n) - ystart;
}
loginfo("erasing %d/%d - %d/%d\n", ystart, xstart, ystart + ylen, xstart + xlen);
// special-case the full plane erasure, as it's powerfully optimized (O(1))
if(ystart == 0 && xstart == 0 &&
ylen == ncplane_dim_y(n) && xlen == ncplane_dim_x(n)){
int tmpy = n->y; // preserve cursor location
int tmpx = n->x;
ncplane_erase(n);
n->y = tmpy;
n->x = tmpx;
return 0;
}
loginfo("erasing %d/%d - %d/%d\n", ystart, xstart, ystart + ylen, xstart + xlen);
for(int y = ystart ; y < ystart + ylen ; ++y){
for(int x = xstart ; x < xstart + xlen ; ++x){
nccell_release(n, &n->fb[nfbcellidx(n, y, x)]);

View File

@ -4,7 +4,7 @@
static void
emit(struct ncplane* n, const char* str){
fprintf(stderr, "\n\n\n%s\n", str);
ncplane_erase_region(n, 6, 0, 0, 0);
ncplane_erase_region(n, 6, 0, INT_MAX, 0);
ncplane_putstr_yx(n, 6, 0, str);
}

View File

@ -49,7 +49,8 @@ draw_grid(struct ncplane* stdn){
int main(void){
struct notcurses_options opts = {
.flags = NCOPTION_NO_ALTERNATE_SCREEN |
NCOPTION_DRAIN_INPUT,
NCOPTION_DRAIN_INPUT |
NCOPTION_NO_CLEAR_BITMAPS,
// .loglevel = NCLOGLEVEL_TRACE,
};
struct notcurses* nc = notcurses_init(&opts, NULL);