normal demo: work with odd number of columns :/

pull/632/head
nick black 4 years ago
parent bad0ea9127
commit e80ac4ddb9
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -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);

@ -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);

@ -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){

@ -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

@ -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;

Loading…
Cancel
Save