demo: convert to new notcurses_stddim_yx() where appropriate #365

pull/369/head
nick black 5 years ago
parent f9d98dd05c
commit 126145e417
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -33,7 +33,8 @@ reload_corners(struct ncplane* n, cell* ul, cell* ur, cell* ll, cell* lr){
}
int box_demo(struct notcurses* nc){
struct ncplane* n = notcurses_stdplane(nc);
int ylen, xlen;
struct ncplane* n = notcurses_stddim_yx(nc, &ylen, &xlen);
ncplane_erase(n);
cell ul = CELL_TRIVIAL_INITIALIZER, ll = CELL_TRIVIAL_INITIALIZER;
cell lr = CELL_TRIVIAL_INITIALIZER, ur = CELL_TRIVIAL_INITIALIZER;
@ -41,8 +42,6 @@ int box_demo(struct notcurses* nc){
if(cells_double_box(n, 0, 0, &ul, &ur, &ll, &lr, &hl, &vl)){
return -1;
}
int ylen, xlen;
ncplane_dim_yx(n, &ylen, &xlen);
// target grid is 7x7
const int targx = 7;
const int targy = 7;

@ -64,8 +64,7 @@ int highcontrast_demo(struct notcurses* nc){
const int STEP = 16;
int ret = -1;
int dimy, dimx;
struct ncplane* n = notcurses_stdplane(nc);
ncplane_dim_yx(n, &dimy, &dimx);
struct ncplane* n = notcurses_stddim_yx(nc, &dimy, &dimx);
int totcells = (dimy - 1) * dimx;
unsigned* scrcolors = malloc(sizeof(*scrcolors) * totcells);
if(scrcolors == NULL){

@ -20,10 +20,8 @@ fader(struct notcurses* nc, struct ncplane* ncp, void* curry){
}
int intro(struct notcurses* nc){
struct ncplane* ncp;
ncp = notcurses_stdplane(nc);
int rows, cols;
ncplane_dim_yx(ncp, &rows, &cols);
struct ncplane* ncp = notcurses_stddim_yx(nc, &rows, &cols);
uint64_t cul, cur, cll, clr;
cul = cur = cll = clr = 0;
channels_set_fg_rgb(&cul, 0, 0xd0, 0);

@ -26614,9 +26614,8 @@ int jungle_demo(struct notcurses* nc){
if(out < ORIGWIDTH * ORIGHEIGHT){ // uh-oh
return -1;
}
struct ncplane* n = notcurses_stdplane(nc);
int dimx, dimy;
ncplane_dim_yx(n, &dimy, &dimx);
struct ncplane* n = notcurses_stddim_yx(nc, &dimy, &dimx);
dimy *= 2; // use half blocks
const int xiter = ORIGWIDTH / dimx + !!(ORIGWIDTH % dimx);
const int yiter = ORIGHEIGHT / dimy + !!(ORIGHEIGHT % dimy);

@ -146,7 +146,8 @@ int luigi_demo(struct notcurses* nc){
if(!notcurses_canopen(nc)){
return 0;
}
struct ncplane* n = notcurses_stdplane(nc);
int rows, cols;
struct ncplane* n = notcurses_stddim_yx(nc, &rows, &cols);
int averr = 0;
char* map = find_data("megaman2.bmp");
struct ncvisual* nv = ncplane_visual_open(n, map, &averr);
@ -164,8 +165,6 @@ int luigi_demo(struct notcurses* nc){
#ifdef USE_FFMPEG
assert(averr == AVERROR_EOF);
#endif
int rows, cols;
ncplane_dim_yx(n, &rows, &cols);
// he should be walking on the platform ~4/5 of the way down
const int height = 32;
int yoff = rows * 4 / 5 - height + 1; // tuned

@ -25,7 +25,8 @@ perframe(struct notcurses* nc, struct ncvisual* ncv __attribute__ ((unused)), vo
static void*
fadethread(void* vnc){
struct notcurses* nc = vnc;
struct ncplane* ncp = notcurses_stdplane(nc);
int rows, cols;
struct ncplane* ncp = notcurses_stddim_yx(nc, &rows, &cols);
struct timespec fade;
timespec_mul(&demodelay, 2, &fade);
ncplane_fadeout(ncp, &fade, demo_fader, NULL);
@ -37,8 +38,6 @@ fadethread(void* vnc){
if(ncv == NULL){
return NULL;
}
int rows, cols;
notcurses_term_dim_yx(nc, &rows, &cols);
struct ncplane* apiap = ncplane_new(nc, 1, cols, rows - 1, 0, NULL);
ncplane_set_fg_rgb(apiap, 0xc0, 0x40, 0x80);
ncplane_set_bg_rgb(apiap, 0, 0, 0);
@ -126,13 +125,9 @@ int outro(struct notcurses* nc){
if(!notcurses_canopen(nc)){
return 0;
}
struct ncplane* ncp;
if((ncp = notcurses_stdplane(nc)) == NULL){
return -1;
}
int rows, cols;
struct ncplane* ncp = notcurses_stddim_yx(nc, &rows, &cols);
ncplane_erase(ncp);
ncplane_dim_yx(ncp, &rows, &cols);
int averr = 0;
char* path = find_data("changes.jpg");
chncv = ncplane_visual_open(ncp, path, &averr);

@ -293,13 +293,13 @@ ncreel_demo_core(struct notcurses* nc, int efdr, int efdw){
if(channels_set_bg_alpha(&popts.bgchannel, CELL_ALPHA_TRANSPARENT)){
return -1;
}
struct ncplane* w = notcurses_stdplane(nc);
int dimy;
struct ncplane* w = notcurses_stddim_yx(nc, &dimy, NULL);
struct ncreel* pr = ncreel_create(w, &popts, efdw);
if(pr == NULL){
fprintf(stderr, "Error creating ncreel\n");
return -1;
}
int dimy = ncplane_dim_y(w);
// Press a for a new nc above the current, c for a new one below the
// current, and b for a new block at arbitrary placement.
ncplane_styles_on(w, NCSTYLE_BOLD | NCSTYLE_ITALIC);

@ -144,8 +144,8 @@ draw_bounding_box(struct ncplane* n, int yoff, int xoff, int chunky, int chunkx)
int sliding_puzzle_demo(struct notcurses* nc){
int ret = -1, z;
int maxx, maxy;
struct ncplane* n = notcurses_stddim_yx(nc, &maxy, &maxx);
int chunky, chunkx;
notcurses_term_dim_yx(nc, &maxy, &maxx);
// want at least 2x2 for each sliding chunk
if(maxy < CHUNKS_VERT * 2 || maxx < CHUNKS_HORZ * 2){
return -1;
@ -161,7 +161,6 @@ int sliding_puzzle_demo(struct notcurses* nc){
}
int wastey = ((maxy - 2) - (CHUNKS_VERT * chunky)) / 2;
int wastex = ((maxx - 2) - (CHUNKS_HORZ * chunkx)) / 2;
struct ncplane* n = notcurses_stdplane(nc);
const int chunkcount = CHUNKS_VERT * CHUNKS_HORZ;
struct ncplane** chunks = malloc(sizeof(*chunks) * chunkcount);
if(chunks == NULL){

@ -235,8 +235,7 @@ slidepanel(struct notcurses* nc){
// and that we can write to every coordinate.
int trans_demo(struct notcurses* nc){
int maxx, maxy;
notcurses_term_dim_yx(nc, &maxy, &maxx);
struct ncplane* n = notcurses_stdplane(nc);
struct ncplane* n = notcurses_stddim_yx(nc, &maxy, &maxx);
ncplane_set_fg_rgb(n, 255, 255, 255);
uint64_t channels = 0;
channels_set_fg_rgb(&channels, 0, 128, 128);

@ -81,9 +81,8 @@ draw_block(struct ncplane* nn, uint32_t blockstart){
}
int unicodeblocks_demo(struct notcurses* nc){
struct ncplane* n = notcurses_stdplane(nc);
int maxx, maxy;
notcurses_term_dim_yx(nc, &maxy, &maxx);
struct ncplane* n = notcurses_stddim_yx(nc, &maxy, &maxx);
// some blocks are good for the printing, some less so. some are only
// marginally covered by mainstream fonts, some not at all. we explicitly
// list the ones we want.

@ -16,9 +16,8 @@ watch_for_keystroke(struct notcurses* nc, struct ncvisual* ncv __attribute__ ((u
static int
view_video_demo(struct notcurses* nc){
struct ncplane* ncp = notcurses_stdplane(nc);
int dimy, dimx;
ncplane_dim_yx(ncp, &dimy, &dimx);
struct ncplane* ncp = notcurses_stddim_yx(nc, &dimy, &dimx);
int averr;
struct ncvisual* ncv;
char* fm6 = find_data("fm6.mkv");
@ -69,9 +68,8 @@ int view_demo(struct notcurses* nc){
if(!notcurses_canopen(nc)){
return 0;
}
struct ncplane* ncp = notcurses_stdplane(nc);
int dimy, dimx;
ncplane_dim_yx(ncp, &dimy, &dimx);
struct ncplane* ncp = notcurses_stddim_yx(nc, &dimy, &dimx);
int averr = 0;
char* pic = find_data("PurpleDrank.jpg");
ncplane_erase(ncp);

@ -137,9 +137,8 @@ wormy(worm* s, int dimy, int dimx){
static void *
worm_thread(void* vnc){
struct notcurses* nc = vnc;
struct ncplane* n = notcurses_stdplane(nc);
int dimy, dimx;
ncplane_dim_yx(n, &dimy, &dimx);
notcurses_term_dim_yx(nc, &dimy, &dimx);
int wormcount = (dimy * dimx) / 800;
worm worms[wormcount];
for(int s = 0 ; s < wormcount ; ++s){
@ -453,9 +452,9 @@ int witherworm_demo(struct notcurses* nc){
const int steps[] = { 0, 0x10040, 0x20110, 0x120, 0x12020, };
const int starts[] = { 0, 0x10101, 0x004000, 0x000040, 0x400040, };
struct ncplane* n = notcurses_stdplane(nc);
size_t i;
const size_t screens = sizeof(steps) / sizeof(*steps);
struct ncplane* n = notcurses_stdplane(nc);
ncplane_erase(n);
for(i = 0 ; i < screens ; ++i){
wchar_t key = NCKEY_INVALID;
@ -468,7 +467,7 @@ int witherworm_demo(struct notcurses* nc){
int step = steps[i];
cell_init(&c);
int y, x, maxy, maxx;
ncplane_dim_yx(n, &maxy, &maxx);
ncplane_dim_yx(n, &maxy, &maxx); // might resize
int rgb = start;
int bytes_out = 0;
int egcs_out = 0;

@ -34,8 +34,7 @@ perframecb(struct notcurses* nc, struct ncvisual* ncv __attribute__ ((unused)),
int dimx, dimy, y;
struct ncplane* n = *(struct ncplane**)vnewplane;
if(n == NULL){
struct ncplane* nstd = notcurses_stdplane(nc);
ncplane_dim_yx(nstd, &dimy, &dimx);
notcurses_term_dim_yx(nc, &dimy, &dimx);
y = dimy - sizeof(leg) / sizeof(*leg);
n = ncplane_new(nc, sizeof(leg) / sizeof(*leg), dimx, y, 0, NULL);
if(n == NULL){
@ -100,8 +99,7 @@ int xray_demo(struct notcurses* nc){
return 0;
}
int dimx, dimy;
struct ncplane* nstd = notcurses_stdplane(nc);
ncplane_dim_yx(nstd, &dimy, &dimx);
notcurses_term_dim_yx(nc, &dimy, &dimx);
struct ncplane* n = ncplane_new(nc, dimy, dimx, 0, 0, NULL);
if(n == NULL){
return -1;

Loading…
Cancel
Save