don't allow moving a plane above/below itself #71

This commit is contained in:
nick black 2019-12-16 18:13:38 -05:00 committed by Nick Black
parent 599b7a6d9a
commit c5acdaaef0
2 changed files with 27 additions and 6 deletions

View File

@ -345,11 +345,32 @@ API void ncplane_yx(const struct ncplane* n, int* RESTRICT y, int* RESTRICT x);
API int ncplane_move_top(struct ncplane* n); API int ncplane_move_top(struct ncplane* n);
API int ncplane_move_bottom(struct ncplane* n); API int ncplane_move_bottom(struct ncplane* n);
// Splice ncplane 'n' out of the z-buffer, and reinsert it below 'below'.
API int ncplane_move_below(struct ncplane* RESTRICT n, struct ncplane* RESTRICT below);
// Splice ncplane 'n' out of the z-buffer, and reinsert it above 'above'. // Splice ncplane 'n' out of the z-buffer, and reinsert it above 'above'.
API int ncplane_move_above(struct ncplane* RESTRICT n, struct ncplane* RESTRICT above); API int ncplane_move_above_unsafe(struct ncplane* RESTRICT n,
struct ncplane* RESTRICT above);
static inline int
ncplane_move_above(struct ncplane* n, struct ncplane* above){
if(n == above){
return -1;
}
return ncplane_move_above_unsafe(n, above);
}
// Splice ncplane 'n' out of the z-buffer, and reinsert it below 'below'.
API int ncplane_move_below_unsafe(struct ncplane* RESTRICT n,
struct ncplane* RESTRICT below);
static inline int
ncplane_move_below(struct ncplane* n, struct ncplane* below){
if(n == below){
return -1;
}
return ncplane_move_below_unsafe(n, below);
}
// Return the plane above this one, or NULL if this is at the top.
API struct ncplane* ncplane_below(struct ncplane* n);
// Return the plane below this one, or NULL if this is at the bottom. // Return the plane below this one, or NULL if this is at the bottom.
API struct ncplane* ncplane_below(struct ncplane* n); API struct ncplane* ncplane_below(struct ncplane* n);

View File

@ -1174,7 +1174,7 @@ visible_cell(cell* c, int y, int x, ncplane* n, bool* damage){
// Call with c->gcluster == 3, falpha == 3, balpha == 0, *retp == topplane. // Call with c->gcluster == 3, falpha == 3, balpha == 0, *retp == topplane.
// 'n' ends up above 'above' // 'n' ends up above 'above'
int ncplane_move_above(ncplane* restrict n, ncplane* restrict above){ int ncplane_move_above_unsafe(ncplane* restrict n, ncplane* restrict above){
ncplane** an = find_above_ncplane(n); ncplane** an = find_above_ncplane(n);
if(an == NULL){ if(an == NULL){
return -1; return -1;
@ -1190,7 +1190,7 @@ int ncplane_move_above(ncplane* restrict n, ncplane* restrict above){
} }
// 'n' ends up below 'below' // 'n' ends up below 'below'
int ncplane_move_below(ncplane* restrict n, ncplane* restrict below){ int ncplane_move_below_unsafe(ncplane* restrict n, ncplane* restrict below){
ncplane** an = find_above_ncplane(n); ncplane** an = find_above_ncplane(n);
if(an == NULL){ if(an == NULL){
return -1; return -1;