diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index ab9465963..c1fab6161 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -1157,7 +1157,9 @@ API struct ncplane* ncplane_below(struct ncplane* n); // Rotate the plane π/2 radians clockwise or counterclockwise. This cannot // be performed on arbitrary planes, because glyphs cannot be arbitrarily // rotated. The glyphs which can be rotated are limited: line-drawing -// characters, spaces, half blocks, and full blocks. +// characters, spaces, half blocks, and full blocks. The plane must have +// an even number of columns. Use the ncvisual rotation for a more +// flexible approach. API int ncplane_rotate_cw(struct ncplane* n); API int ncplane_rotate_ccw(struct ncplane* n); diff --git a/src/demo/normal.c b/src/demo/normal.c index e2a096a6a..ac26ca052 100644 --- a/src/demo/normal.c +++ b/src/demo/normal.c @@ -81,6 +81,13 @@ int normal_demo(struct notcurses* nc){ if(n == NULL){ return -1; } + // we can't rotate a plane unless it has an even number of columns :/ + int nx; + if((nx = ncplane_dim_x(n)) % 2){ + if(ncplane_resize_simple(n, ncplane_dim_y(n), --nx)){ + goto err; + } + } ncplane_erase(nstd); cell c = CELL_SIMPLE_INITIALIZER(' '); cell_set_fg_rgb(&c, 0xff, 0xff, 0xff); diff --git a/src/lib/fill.c b/src/lib/fill.c index 1a4f0209c..b2af27faf 100644 --- a/src/lib/fill.c +++ b/src/lib/fill.c @@ -519,6 +519,22 @@ rotate_merge(ncplane* n, ncplane* newp){ return ret; } +// generate a temporary plane that can hold the contents of n, rotated 90° +static ncplane* +rotate_plane(const ncplane* n){ + int absy, absx; + ncplane_yx(n, &absy, &absx); + int dimy, dimx; + ncplane_dim_yx(n, &dimy, &dimx); + if(dimx % 2 != 0){ + return NULL; + } + const int newy = dimx / 2; + const int newx = dimy * 2; + ncplane* newp = ncplane_new(n->nc, newy, newx, absy, absx, n->userptr); + return newp; +} + int ncplane_rotate_cw(ncplane* n){ ncplane* newp = rotate_plane(n); if(newp == NULL){ diff --git a/src/lib/internal.h b/src/lib/internal.h index 8f907162d..4babfb470 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -638,9 +638,6 @@ memdup(const void* src, size_t len){ return ret; } -// generate a temporary plane that can hold the contents of n, rotated 90° -ncplane* rotate_plane(const ncplane* n); - void* bgra_to_rgba(const void* data, int rows, int rowstride, int cols); // find the "center" cell of two lengths. in the case of even rows/columns, we diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index cfbb8f970..710f580bb 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -2013,21 +2013,6 @@ int notcurses_inputready_fd(notcurses* n){ return fileno(n->ttyinfp); } -// generate a temporary plane that can hold the contents of n, rotated 90° -ncplane* rotate_plane(const ncplane* n){ - int absy, absx; - ncplane_yx(n, &absy, &absx); - int dimy, dimx; - ncplane_dim_yx(n, &dimy, &dimx); - if(dimx % 2 != 0){ - return NULL; - } - const int newy = dimx / 2; - const int newx = dimy * 2; - ncplane* newp = ncplane_new(n->nc, newy, newx, absy, absx, n->userptr); - return newp; -} - uint32_t* ncplane_rgba(const ncplane* nc, int begy, int begx, int leny, int lenx){ if(begy < 0 || begx < 0){ return NULL;