migrate sprixels across sprixelcaches when reparenting across piles #1608

This commit is contained in:
nick black 2021-04-30 12:20:04 -04:00 committed by Nick Black
parent b557db381a
commit f701271c27

View File

@ -2346,6 +2346,36 @@ unsplice_zaxis_recursive(ncplane* n){
} }
} }
// unsplice our sprixel from the pile's sprixellist, and then unsplice all
// children, recursively. call before unbinding. returns a doubly-linked
// list of any sprixels found.
static sprixel*
unsplice_sprixels_recursive(ncplane* n, sprixel* prev){
sprixel* s = n->sprite;
if(s){
if(s->prev){
s->prev->next = s->next;
}else{
ncplane_pile(n)->sprixelcache = s->next;
}
if(s->next){
s->next->prev = s->prev;
}
if( (s->prev = prev) ){
prev->next = s;
}
s->next = NULL;
prev = s;
}
for(ncplane* child = n->blist ; child ; child = child->bnext){
unsplice_sprixels_recursive(child, prev);
while(prev->next){ // FIXME lame
prev = prev->next;
}
}
return prev;
}
// recursively splice 'n' and children into the z-axis, above 'n->boundto'. // recursively splice 'n' and children into the z-axis, above 'n->boundto'.
// handles 'n' == 'n->boundto'. to be called after binding 'n' into new pile. // handles 'n' == 'n->boundto'. to be called after binding 'n' into new pile.
static void static void
@ -2380,9 +2410,11 @@ ncplane* ncplane_reparent_family(ncplane* n, ncplane* newparent){
n->bnext->bprev = n->bprev; n->bnext->bprev = n->bprev;
} }
} }
// if leaving a pile, extract n from the old zaxis // if leaving a pile, extract n from the old zaxis, and also any sprixel
sprixel* s = NULL;
if(n == newparent || ncplane_pile(n) != ncplane_pile(newparent)){ if(n == newparent || ncplane_pile(n) != ncplane_pile(newparent)){
unsplice_zaxis_recursive(n); unsplice_zaxis_recursive(n);
s = unsplice_sprixels_recursive(n, NULL);
} }
n->boundto = newparent; n->boundto = newparent;
if(n == n->boundto){ // we're a new root plane if(n == n->boundto){ // we're a new root plane
@ -2407,6 +2439,16 @@ ncplane* ncplane_reparent_family(ncplane* n, ncplane* newparent){
splice_zaxis_recursive(n); splice_zaxis_recursive(n);
} }
} }
if(s){ // must be on new plane, with sprixels to donate
sprixel* lame = s;
while(lame->next){
lame = lame->next;
}
if( (lame->next = n->pile->sprixelcache) ){
n->pile->sprixelcache->prev = lame;
}
n->pile->sprixelcache = s;
}
return n; return n;
} }