boxdemo: finally do something worth doing

pull/353/head
nick black 4 years ago committed by Nick Black
parent 865241ee7c
commit 7120d428e8

@ -2,9 +2,37 @@
#include <unistd.h>
#include "demo.h"
static int
reload_corners(struct ncplane* n, cell* ul, cell* ur, cell* ll, cell* lr){
int dimy, dimx;
ncplane_dim_yx(n, &dimy, &dimx);
cell c = CELL_TRIVIAL_INITIALIZER;
if(ncplane_at_yx(n, 1, dimx - 1, &c) < 0){
cell_release(n, &c);
return -1;
}
ul->channels = c.channels;
if(ncplane_at_yx(n, dimy - 1, dimx - 1, &c) < 0){
cell_release(n, &c);
return -1;
}
ur->channels = c.channels;
if(ncplane_at_yx(n, dimy - 1, 0, &c) < 0){
cell_release(n, &c);
return -1;
}
lr->channels = c.channels;
if(ncplane_at_yx(n, 1, 0, &c) < 0){
cell_release(n, &c);
return -1;
}
ll->channels = c.channels;
cell_release(n, &c);
return 0;
}
int box_demo(struct notcurses* nc){
struct timespec iterdelay;
timespec_div(&demodelay, 256, &iterdelay);
struct ncplane* n = notcurses_stdplane(nc);
ncplane_erase(n);
cell ul = CELL_TRIVIAL_INITIALIZER, ll = CELL_TRIVIAL_INITIALIZER;
@ -13,10 +41,6 @@ int box_demo(struct notcurses* nc){
if(cells_double_box(n, 0, 0, &ul, &ur, &ll, &lr, &hl, &vl)){
return -1;
}
struct timespec start, now;
clock_gettime(CLOCK_MONOTONIC, &start);
int zbonus = 40;
int zbonusdelta = 20;
int ylen, xlen;
ncplane_dim_yx(n, &ylen, &xlen);
// target grid is 7x7
@ -50,35 +74,61 @@ int box_demo(struct notcurses* nc){
if(ncplane_putstr_aligned(n, ytargbase++, NCALIGN_CENTER, "┗━━┻━━┛") < 0){
return -1;
}
for(int idx = 0 ; idx < 256 ; ++idx){
int y = 1, x = 0;
if(cell_set_fg_rgb(&ul, 0xff, 0, 0)){
return -1;
}
if(cell_set_bg_rgb(&ul, 20, 40, 20)){
return -1;
}
if(cell_set_fg_rgb(&ur, 0, 0xff, 0)){
return -1;
}
if(cell_set_bg_rgb(&ur, 20, 40, 20)){
return -1;
}
if(cell_set_fg_rgb(&ll, 0, 0, 0xff)){
return -1;
}
if(cell_set_bg_rgb(&ll, 20, 40, 20)){
return -1;
}
if(cell_set_fg_rgb(&lr, 0xff, 0xff, 0xff)){
return -1;
}
if(cell_set_bg_rgb(&lr, 20, 40, 20)){
return -1;
}
int y = 1, x = 0;
ncplane_dim_yx(n, &ylen, &xlen);
--ylen;
while(ylen - y >= targy && xlen - x >= targx){
if(ncplane_cursor_move_yx(n, y, x)){
return -1;
}
if(ncplane_box_sized(n, &ul, &ur, &ll, &lr, &hl, &vl, ylen, xlen,
NCBOXGRAD_LEFT | NCBOXGRAD_BOTTOM |
NCBOXGRAD_RIGHT | NCBOXGRAD_TOP)){
return -1;
}
ylen -= 2;
xlen -= 2;
++y;
++x;
}
DEMO_RENDER(nc);
int iters = 50;
struct timespec iterdelay;
ns_to_timespec(timespec_to_ns(&demodelay) * 3 / iters, &iterdelay);
nanosleep(&iterdelay, NULL);
while(iters--){
if(reload_corners(n, &ul, &ur, &ll, &lr)){
return -1;
}
y = 1;
x = 0;
ncplane_dim_yx(n, &ylen, &xlen);
--ylen;
while(ylen - y >= targy && xlen - x >= targx){
if(cell_set_fg_rgb(&ul, idx, 255 - (y * 2), 255 - idx)){
return -1;
}
if(cell_set_bg_rgb(&ul, 20, zbonus, 20)){
return -1;
}
if(cell_set_fg_rgb(&ur, idx / 2, zbonus, (255 - idx) / 2)){
return -1;
}
if(cell_set_bg_rgb(&ur, 20, zbonus, 20)){
return -1;
}
if(cell_set_fg_rgb(&ll, idx / 2, zbonus, (255 - idx) / 2)){
return -1;
}
if(cell_set_bg_rgb(&ll, 20, zbonus, 20)){
return -1;
}
if(cell_set_fg_rgb(&lr, 255 - idx, 255 - (y * 2), zbonus)){
return -1;
}
if(cell_set_bg_rgb(&lr, 20, zbonus, 20)){
return -1;
}
if(ncplane_cursor_move_yx(n, y, x)){
return -1;
}
@ -94,11 +144,6 @@ int box_demo(struct notcurses* nc){
}
DEMO_RENDER(nc);
nanosleep(&iterdelay, NULL);
clock_gettime(CLOCK_MONOTONIC, &now);
if((zbonus += zbonusdelta > 255) || zbonus < 0){
zbonusdelta = -zbonusdelta;
zbonus += zbonusdelta;
}
}
cell_release(n, &ul);
cell_release(n, &ur);

@ -446,7 +446,6 @@ int main(int argc, char** argv){
if(menu_create(nc) == NULL){
goto err;
}
fprintf(stderr, "START THEM DEMOS [%s]\n", spec);
if(ext_demos(nc, spec, ignore_failures) == NULL){
goto err;
}

Loading…
Cancel
Save