mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
[bitmap] on move, clear old OPAQUE cells #1527
This commit is contained in:
parent
c9cf30c31a
commit
416806c42c
@ -547,7 +547,7 @@ ncdirect_render_visual(ncdirect* n, ncvisual* ncv, ncblitter_e blitfxn,
|
||||
bargs.u.pixel.colorregs = n->tcache.color_registers;
|
||||
int cols = lenx / bargs.u.pixel.celldimx + !!(lenx % bargs.u.pixel.celldimx);
|
||||
int rows = leny / bargs.u.pixel.celldimy + !!(leny % bargs.u.pixel.celldimy);
|
||||
if((bargs.u.pixel.spx = sprixel_alloc(ncdv, ncv, rows, cols)) == NULL){
|
||||
if((bargs.u.pixel.spx = sprixel_alloc(ncdv, ncv, rows, cols, 0, 0)) == NULL){
|
||||
free_plane(ncdv);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -111,7 +111,8 @@ typedef enum {
|
||||
//
|
||||
// when a sprixel is removed from the rendering pile, in Sixel all cells it
|
||||
// covered must be marked damaged, so that they are rendered, obliterating
|
||||
// the bitmap. in Kitty the bitmap can simply be deleted.
|
||||
// the bitmap. in Kitty the bitmap can simply be deleted, except for those
|
||||
// cells which were SPRIXCELL_OPAQUE (they must be damaged).
|
||||
//
|
||||
// when a sprixel is moved, its TAM must be updated. OPAQUE, MIXED, and
|
||||
// TRANSPARENT cells retain their entries. ANNIHILATED cells remain
|
||||
@ -922,7 +923,8 @@ int sprite_draw(const notcurses* n, const ncpile *p, sprixel* s, FILE* out);
|
||||
int kitty_draw(const notcurses* n, const ncpile *p, sprixel* s, FILE* out);
|
||||
int sixel_draw(const notcurses* n, const ncpile *p, sprixel* s, FILE* out);
|
||||
// dimy and dimx are cell geometry, not pixel. takes ownership of s on success.
|
||||
sprixel* sprixel_alloc(ncplane* n, struct ncvisual* ncv, int dimy, int dimx);
|
||||
sprixel* sprixel_alloc(ncplane* n, struct ncvisual* ncv, int dimy, int dimx,
|
||||
int placey, int placex);
|
||||
sprixel* sprixel_recycle(ncplane* n, struct ncvisual* ncv);
|
||||
int sprixel_load(sprixel* spx, char* s, int bytes, int placey, int placex,
|
||||
int pixy, int pixx, int parse_start);
|
||||
|
@ -209,7 +209,7 @@ int sprite_kitty_cell_wipe(const notcurses* nc, sprixel* s, int ycell, int xcell
|
||||
if(thisrow == 0){
|
||||
//fprintf(stderr, "CLEARED ROW, TARGY: %d\n", targy - 1);
|
||||
if(--targy == 0){
|
||||
s->invalidated = SPRIXEL_INVALIDATED;
|
||||
//s->invalidated = SPRIXEL_INVALIDATED;
|
||||
return 0;
|
||||
}
|
||||
thisrow = targx;
|
||||
@ -367,13 +367,27 @@ int kitty_blit(ncplane* n, int linesize, const void* data,
|
||||
return 1;
|
||||
}
|
||||
|
||||
// removes the kitty bitmap graphic identified by s->id
|
||||
// removes the kitty bitmap graphic identified by s->id, and damages those
|
||||
// cells which were SPRIXCEL_OPAQUE
|
||||
int sprite_kitty_annihilate(const notcurses* nc, const ncpile* p, FILE* out, sprixel* s){
|
||||
(void)p;
|
||||
(void)nc;
|
||||
if(fprintf(out, "\e_Ga=d,d=i,i=%d\e\\", s->id) < 0){
|
||||
return 0;
|
||||
}
|
||||
//fprintf(stderr, "MOVED FROM: %d/%d\n", s->movedfromy, s->movedfromx);
|
||||
for(int yy = s->movedfromy ; yy < s->movedfromy + s->dimy && yy < p->dimy ; ++yy){
|
||||
for(int xx = s->movedfromx ; xx < s->movedfromx + s->dimx && xx < p->dimx ; ++xx){
|
||||
struct crender *r = &p->crender[yy * p->dimx + xx];
|
||||
if(s->n){
|
||||
//fprintf(stderr, "CHECKING %d/%d\n", yy - s->movedfromy, xx - s->movedfromx);
|
||||
if(s->n->tacache[(yy - s->movedfromy) * s->dimx + (xx - s->movedfromx)] == SPRIXCELL_OPAQUE){
|
||||
//fprintf(stderr, "DAMAGING %d/%d!\n", yy, xx);
|
||||
r->s.damaged = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -866,7 +866,10 @@ clean_sprixels(notcurses* nc, const ncpile* p, FILE* out){
|
||||
ret = -1;
|
||||
}
|
||||
}else if(s->invalidated == SPRIXEL_MOVED || s->invalidated == SPRIXEL_INVALIDATED){
|
||||
// FIXME clean this up, don't use sprite_draw, don't always move, etc.
|
||||
// FIXME clean this up, don't use sprite_draw, etc.
|
||||
if(s->invalidated == SPRIXEL_MOVED){
|
||||
sprite_destroy(nc, p, out, s);
|
||||
}
|
||||
int y, x;
|
||||
ncplane_yx(s->n, &y, &x);
|
||||
y += s->y;
|
||||
|
@ -24,8 +24,10 @@ sprixel* sprixel_recycle(ncplane* n, ncvisual* ncv){
|
||||
assert(hides);
|
||||
int dimy = hides->dimy;
|
||||
int dimx = hides->dimx;
|
||||
int y = hides->y;
|
||||
int x = hides->x;
|
||||
sprixel_hide(hides);
|
||||
return sprixel_alloc(n, ncv, dimy, dimx);
|
||||
return sprixel_alloc(n, ncv, dimy, dimx, y, x);
|
||||
}
|
||||
return n->sprite;
|
||||
}
|
||||
@ -35,6 +37,7 @@ sprixel* sprixel_recycle(ncplane* n, ncvisual* ncv){
|
||||
void sprixel_movefrom(sprixel* s, int y, int x){
|
||||
if(s->invalidated != SPRIXEL_HIDE){
|
||||
if(s->invalidated != SPRIXEL_MOVED){
|
||||
//fprintf(stderr, "SETTING TO MOVE: %d/%d was: %d\n", y, x, s->invalidated);
|
||||
s->invalidated = SPRIXEL_MOVED;
|
||||
s->movedfromy = y;
|
||||
s->movedfromx = x;
|
||||
@ -83,7 +86,8 @@ sprixel* sprixel_by_id(const notcurses* nc, uint32_t id){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sprixel* sprixel_alloc(ncplane* n, ncvisual* ncv, int dimy, int dimx){
|
||||
sprixel* sprixel_alloc(ncplane* n, ncvisual* ncv, int dimy, int dimx,
|
||||
int placey, int placex){
|
||||
sprixel* ret = malloc(sizeof(sprixel));
|
||||
if(ret){
|
||||
memset(ret, 0, sizeof(*ret));
|
||||
@ -91,6 +95,8 @@ sprixel* sprixel_alloc(ncplane* n, ncvisual* ncv, int dimy, int dimx){
|
||||
ret->ncv = ncv;
|
||||
ret->dimy = dimy;
|
||||
ret->dimx = dimx;
|
||||
ret->y = placey;
|
||||
ret->x = placex;
|
||||
ret->id = ++sprixelid_nonce;
|
||||
//fprintf(stderr, "LOOKING AT %p (p->n = %p)\n", ret, ret->n);
|
||||
if(ncplane_pile(ret->n)){
|
||||
|
@ -694,7 +694,7 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits
|
||||
if(n->sprite){
|
||||
sprixel_hide(n->sprite);
|
||||
}
|
||||
if((ncv->spx = sprixel_alloc(n, ncv, rows, cols)) == NULL){
|
||||
if((ncv->spx = sprixel_alloc(n, ncv, rows, cols, placey, placex)) == NULL){
|
||||
goto err;
|
||||
}
|
||||
}else{
|
||||
|
Loading…
x
Reference in New Issue
Block a user