diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index c1fab6161..9c2316e89 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -1232,6 +1232,9 @@ API char* ncplane_contents(const struct ncplane* nc, int begy, int begx, API void* ncplane_set_userptr(struct ncplane* n, void* opaque); API void* ncplane_userptr(struct ncplane* n); +API void ncplane_center_abs(const struct ncplane* n, int* RESTRICT y, + int* RESTRICT x); + // Return the column at which 'c' cols ought start in order to be aligned // according to 'align' within ncplane 'n'. Returns INT_MAX on invalid 'align'. // Undefined behavior on negative 'c'. diff --git a/src/demo/normal.c b/src/demo/normal.c index ac26ca052..8d905f4d2 100644 --- a/src/demo/normal.c +++ b/src/demo/normal.c @@ -96,16 +96,30 @@ int normal_demo(struct notcurses* nc){ cell_release(nstd, &c); for(int i = 0 ; i < 16 ; ++i){ demo_nanosleep(nc, &scaled); + int centy, centx; + ncplane_center_abs(n, ¢y, ¢x); if(ncplane_rotate_cw(n)){ goto err; } + int cent2y, cent2x; + int absy, absx; + ncplane_center_abs(n, ¢2y, ¢2x); + ncplane_yx(n, &absy, &absx); + ncplane_move_yx(n, absy + centy - cent2y, absx + centx - cent2x); DEMO_RENDER(nc); } for(int i = 0 ; i < 16 ; ++i){ demo_nanosleep(nc, &scaled); + int centy, centx; + ncplane_center_abs(n, ¢y, ¢x); if(ncplane_rotate_ccw(n)){ goto err; } + int cent2y, cent2x; + int absy, absx; + ncplane_center_abs(n, ¢2y, ¢2x); + ncplane_yx(n, &absy, &absx); + ncplane_move_yx(n, absy + centy - cent2y, absx + centx - cent2x); DEMO_RENDER(nc); } ncplane_destroy(n); diff --git a/src/lib/fill.c b/src/lib/fill.c index b2af27faf..01975fce1 100644 --- a/src/lib/fill.c +++ b/src/lib/fill.c @@ -563,11 +563,6 @@ int ncplane_rotate_cw(ncplane* n){ } int ret = rotate_merge(n, newp); ret |= ncplane_destroy(newp); - int cent2y, cent2x; - int absy, absx; - ncplane_center_abs(n, ¢2y, ¢2x); - ncplane_yx(n, &absy, &absx); - ncplane_move_yx(n, absy + centy - cent2y, absx + centx - cent2x); return ret; } @@ -578,8 +573,6 @@ int ncplane_rotate_ccw(ncplane* n){ } int dimy, dimx, targdimy, targdimx; ncplane_dim_yx(n, &dimy, &dimx); - int centy, centx; - ncplane_center_abs(n, ¢y, ¢x); ncplane_dim_yx(newp, &targdimy, &targdimx); int x = dimx - 2, y; // Each row of the target plane is taken from a column of the source plane. @@ -597,11 +590,6 @@ int ncplane_rotate_ccw(ncplane* n){ } int ret = rotate_merge(n, newp); ret |= ncplane_destroy(newp); - int cent2y, cent2x; - int absy, absx; - ncplane_center_abs(n, ¢2y, ¢2x); - ncplane_yx(n, &absy, &absx); - ncplane_move_yx(n, absy + centy - cent2y, absx + centx - cent2x); return ret; } diff --git a/src/lib/internal.h b/src/lib/internal.h index ad4b58262..668500a69 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -648,21 +648,6 @@ ncplane_center(const ncplane* n, int* RESTRICT y, int* RESTRICT x){ center_box(y, x); } -// find the center coordinate of a plane, preferring the top/left in the -// case of an even number of rows/columns (in such a case, there will be one -// more cell to the bottom/right of the center than the top/left). the -// center is then modified relative to the plane's origin. -static inline void -ncplane_center_abs(const ncplane* n, int* RESTRICT y, int* RESTRICT x){ - ncplane_center(n, y, x); - if(y){ - *y += n->absy; - } - if(x){ - *x += n->absx; - } -} - int ncvisual_bounding_box(const struct ncvisual* ncv, int* leny, int* lenx, int* offy, int* offx); diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index d63f15f8d..74ec04462 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -2003,3 +2003,17 @@ int cells_rounded_box(struct ncplane* n, uint32_t attr, uint64_t channels, } return cells_ascii_box(n, attr, channels, ul, ur, ll, lr, hl, vl); } + +// find the center coordinate of a plane, preferring the top/left in the +// case of an even number of rows/columns (in such a case, there will be one +// more cell to the bottom/right of the center than the top/left). the +// center is then modified relative to the plane's origin. +void ncplane_center_abs(const ncplane* n, int* RESTRICT y, int* RESTRICT x){ + ncplane_center(n, y, x); + if(y){ + *y += n->absy; + } + if(x){ + *x += n->absx; + } +}