rename stdscr->stdplane to work around ncurses.h #806

This commit is contained in:
nick black 2020-07-20 00:34:08 -04:00
parent 17f1323c20
commit e768fb1509
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
4 changed files with 41 additions and 41 deletions

View File

@ -277,9 +277,9 @@ typedef struct ncdirect {
} ncdirect;
typedef struct notcurses {
ncplane* top; // topmost plane, never NULL
ncplane* bottom;// bottommost plane, never NULL
ncplane* stdscr;// aliases some plane from the z-buffer, covers screen
ncplane* top; // topmost plane, never NULL
ncplane* bottom; // bottommost plane, never NULL
ncplane* stdplane;// standard plane, covers screen
// the style state of the terminal is carried across render runs
renderstate rstate;

View File

@ -338,17 +338,17 @@ ncplane* ncplane_create(notcurses* nc, ncplane* n, int rows, int cols,
// the z-buffer. clear out all cells. this is for a wholly new context.
static ncplane*
create_initial_ncplane(notcurses* nc, int dimy, int dimx){
nc->stdscr = ncplane_create(nc, NULL, dimy - (nc->margin_t + nc->margin_b),
nc->stdplane = ncplane_create(nc, NULL, dimy - (nc->margin_t + nc->margin_b),
dimx - (nc->margin_l + nc->margin_r), 0, 0, NULL);
return nc->stdscr;
return nc->stdplane;
}
ncplane* notcurses_stdplane(notcurses* nc){
return nc->stdscr;
return nc->stdplane;
}
const ncplane* notcurses_stdplane_const(const notcurses* nc){
return nc->stdscr;
return nc->stdplane;
}
ncplane* ncplane_new(notcurses* nc, int rows, int cols, int yoff, int xoff, void* opaque){
@ -428,7 +428,7 @@ ncplane* ncplane_dup(const ncplane* n, void* opaque){
return newn;
}
// can be used on stdscr, unlike ncplane_resize() which prohibits it.
// can be used on stdplane, unlike ncplane_resize() which prohibits it.
int ncplane_resize_internal(ncplane* n, int keepy, int keepx, int keepleny,
int keeplenx, int yoff, int xoff, int ylen, int xlen){
if(keepleny < 0 || keeplenx < 0){ // can't retain negative size
@ -524,7 +524,7 @@ int ncplane_resize_internal(ncplane* n, int keepy, int keepx, int keepleny,
int ncplane_resize(ncplane* n, int keepy, int keepx, int keepleny,
int keeplenx, int yoff, int xoff, int ylen, int xlen){
if(n == n->nc->stdscr){
if(n == n->nc->stdplane){
//fprintf(stderr, "Can't resize standard plane\n");
return -1;
}
@ -536,7 +536,7 @@ int ncplane_destroy(ncplane* ncp){
if(ncp == NULL){
return 0;
}
if(ncp->nc->stdscr == ncp){
if(ncp->nc->stdplane == ncp){
logerror(ncp->nc, "Won't destroy standard plane\n");
return -1;
}
@ -662,7 +662,7 @@ init_banner(const notcurses* nc){
printf("\n %d rows, %d columns (%sB), %d colors (%s)\n"
" compiled with gcc-%s\n"
" terminfo from %s\n",
nc->stdscr->leny, nc->stdscr->lenx,
nc->stdplane->leny, nc->stdplane->lenx,
bprefix(nc->stats.fbbytes, 1, prefixbuf, 0),
nc->tcache.colors, nc->tcache.RGBflag ? "direct" : "palette",
__VERSION__, curses_version());
@ -889,11 +889,11 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
terminfostr(&ret->tcache.smcup, "smcup");
terminfostr(&ret->tcache.rmcup, "rmcup");
}
ret->bottom = ret->top = ret->stdscr = NULL;
ret->bottom = ret->top = ret->stdplane = NULL;
if(ncvisual_init(ffmpeg_log_level(ret->loglevel))){
goto err;
}
if((ret->stdscr = create_initial_ncplane(ret, dimy, dimx)) == NULL){
if((ret->stdplane = create_initial_ncplane(ret, dimy, dimx)) == NULL){
goto err;
}
if(ret->ttyfd >= 0){
@ -935,13 +935,13 @@ void notcurses_drop_planes(notcurses* nc){
ncplane* p = nc->top;
while(p){
ncplane* tmp = p->below;
if(nc->stdscr != p){
if(nc->stdplane != p){
free_plane(p);
}
p = tmp;
}
nc->top = nc->bottom = nc->stdscr;
nc->stdscr->above = nc->stdscr->below = NULL;
nc->top = nc->bottom = nc->stdplane;
nc->stdplane->above = nc->stdplane->below = NULL;
}
int notcurses_stop(notcurses* nc){
@ -1829,7 +1829,7 @@ move_bound_planes(ncplane* n, int dy, int dx){
}
int ncplane_move_yx(ncplane* n, int y, int x){
if(n == n->nc->stdscr){
if(n == n->nc->stdplane){
return -1;
}
int dy, dx; // amount moved
@ -1837,8 +1837,8 @@ int ncplane_move_yx(ncplane* n, int y, int x){
dy = (n->boundto->absy + y) - n->absy;
dx = (n->boundto->absx + x) - n->absx;
}else{
dy = (n->nc->stdscr->absy + y) - n->absy;
dx = (n->nc->stdscr->absx + x) - n->absx;
dy = (n->nc->stdplane->absy + y) - n->absy;
dx = (n->nc->stdplane->absx + x) - n->absx;
}
n->absx += dx;
n->absy += dy;
@ -1849,14 +1849,14 @@ int ncplane_move_yx(ncplane* n, int y, int x){
void ncplane_yx(const ncplane* n, int* y, int* x){
if(y){
if(n->boundto == NULL){
*y = n->absy - n->nc->stdscr->absy;
*y = n->absy - n->nc->stdplane->absy;
}else{
*y = n->absy - n->boundto->absy;
}
}
if(x){
if(n->boundto == NULL){
*x = n->absx - n->nc->stdscr->absx;
*x = n->absx - n->nc->stdplane->absx;
}else{
*x = n->absx - n->boundto->absx;
}
@ -2020,7 +2020,7 @@ const notcurses* ncplane_notcurses_const(const ncplane* n){
}
ncplane* ncplane_reparent(ncplane* n, ncplane* newparent){
if(n == n->nc->stdscr){
if(n == n->nc->stdplane){
return NULL; // can't reparent standard plane
}
if(n->boundto == newparent){

View File

@ -6,7 +6,7 @@
#include "internal.h"
// Check whether the terminal geometry has changed, and if so, copies what can
// be copied from the old stdscr. Assumes that the screen is always anchored at
// be copied from the old stdplane. Assumes that the screen is always anchored at
// the same origin. Also syncs up lastframe.
static int
notcurses_resize(notcurses* n, int* restrict rows, int* restrict cols){
@ -17,8 +17,8 @@ notcurses_resize(notcurses* n, int* restrict rows, int* restrict cols){
if(cols == NULL){
cols = &c;
}
int oldrows = n->stdscr->leny;
int oldcols = n->stdscr->lenx;
int oldrows = n->stdplane->leny;
int oldcols = n->stdplane->lenx;
*rows = oldrows;
*cols = oldcols;
if(update_term_dimensions(n->ttyfd, rows, cols)){
@ -58,7 +58,7 @@ notcurses_resize(notcurses* n, int* restrict rows, int* restrict cols){
if(keepx > oldcols){
keepx = oldcols;
}
if(ncplane_resize_internal(n->stdscr, 0, 0, keepy, keepx, 0, 0, *rows, *cols)){
if(ncplane_resize_internal(n->stdplane, 0, 0, keepy, keepx, 0, 0, *rows, *cols)){
return -1;
}
return 0;
@ -438,7 +438,7 @@ postpaint(cell* fb, cell* lastframe, int dimy, int dimx,
int ncplane_mergedown(ncplane* restrict src, ncplane* restrict dst){
notcurses* nc = src->nc;
if(dst == NULL){
dst = nc->stdscr;
dst = nc->stdplane;
}
int dimy, dimx;
ncplane_dim_yx(dst, &dimy, &dimx);
@ -776,10 +776,10 @@ notcurses_rasterize(notcurses* nc, const struct crender* rvec, FILE* out){
// we explicitly move the cursor at the beginning of each output line, so no
// need to home it expliticly.
update_palette(nc, out);
for(y = nc->stdscr->absy ; y < nc->stdscr->leny + nc->stdscr->absy ; ++y){
const int innery = y - nc->stdscr->absy;
for(x = nc->stdscr->absx ; x < nc->stdscr->lenx + nc->stdscr->absx ; ++x){
const int innerx = x - nc->stdscr->absx;
for(y = nc->stdplane->absy ; y < nc->stdplane->leny + nc->stdplane->absy ; ++y){
const int innery = y - nc->stdplane->absy;
for(x = nc->stdplane->absx ; x < nc->stdplane->lenx + nc->stdplane->absx ; ++x){
const int innerx = x - nc->stdplane->absx;
const size_t damageidx = innery * nc->lfdimx + innerx;
unsigned r, g, b, br, bg, bb, palfg, palbg;
const cell* srccell = &nc->lastframe[damageidx];
@ -968,8 +968,8 @@ int notcurses_refresh(notcurses* nc, int* restrict dimy, int* restrict dimx){
if(home_cursor(nc, true)){
return -1;
}
const int count = (nc->lfdimx > nc->stdscr->lenx ? nc->lfdimx : nc->stdscr->lenx) *
(nc->lfdimy > nc->stdscr->leny ? nc->lfdimy : nc->stdscr->leny);
const int count = (nc->lfdimx > nc->stdplane->lenx ? nc->lfdimx : nc->stdplane->lenx) *
(nc->lfdimy > nc->stdplane->leny ? nc->lfdimy : nc->stdplane->leny);
struct crender* rvec = malloc(count * sizeof(*rvec));
if(rvec == NULL){
return -1;
@ -996,8 +996,8 @@ int notcurses_render_to_file(struct notcurses* nc, FILE* fp){
if(out == NULL){
return -1;
}
const int count = (nc->lfdimx > nc->stdscr->lenx ? nc->lfdimx : nc->stdscr->lenx) *
(nc->lfdimy > nc->stdscr->leny ? nc->lfdimy : nc->stdscr->leny);
const int count = (nc->lfdimx > nc->stdplane->lenx ? nc->lfdimx : nc->stdplane->lenx) *
(nc->lfdimy > nc->stdplane->leny ? nc->lfdimy : nc->stdplane->leny);
struct crender* rvec = malloc(count * sizeof(*rvec));
if(rvec == NULL){
fclose(out);
@ -1031,14 +1031,14 @@ int notcurses_render_to_file(struct notcurses* nc, FILE* fp){
static int
notcurses_render_internal(notcurses* nc, struct crender* rvec){
int dimy, dimx;
ncplane_dim_yx(nc->stdscr, &dimy, &dimx);
ncplane_dim_yx(nc->stdplane, &dimy, &dimx);
cell* fb = malloc(sizeof(*fb) * dimy * dimx);
init_fb(fb, dimy, dimx);
ncplane* p = nc->top;
while(p){
if(paint(p, nc->lastframe, rvec, fb, &nc->pool,
nc->stdscr->leny, nc->stdscr->lenx,
nc->stdscr->absy, nc->stdscr->absx, nc->lfdimx)){
nc->stdplane->leny, nc->stdplane->lenx,
nc->stdplane->absy, nc->stdplane->absx, nc->lfdimx)){
free(fb);
return -1;
}
@ -1056,7 +1056,7 @@ int notcurses_render(notcurses* nc){
int dimy, dimx;
notcurses_resize(nc, &dimy, &dimx);
int bytes = -1;
const size_t crenderlen = sizeof(struct crender) * nc->stdscr->leny * nc->stdscr->lenx;
const size_t crenderlen = sizeof(struct crender) * nc->stdplane->leny * nc->stdplane->lenx;
struct crender* crender = malloc(crenderlen);
memset(crender, 0, crenderlen);
if(notcurses_render_internal(nc, crender) == 0){

View File

@ -37,8 +37,8 @@ auto ncvisual_geom(const notcurses* nc, const ncvisual* n,
*y = n->rows;
*x = n->cols;
}else{
int rows = vopts->n ? ncplane_dim_y(vopts->n) : ncplane_dim_y(nc->stdscr);
int cols = vopts->n ? ncplane_dim_x(vopts->n) : ncplane_dim_x(nc->stdscr);
int rows = vopts->n ? ncplane_dim_y(vopts->n) : ncplane_dim_y(nc->stdplane);
int cols = vopts->n ? ncplane_dim_x(vopts->n) : ncplane_dim_x(nc->stdplane);
*y = rows * encoding_y_scale(bset);
*x = cols * encoding_x_scale(bset);
}