diff --git a/src/demo/normal.c b/src/demo/normal.c index 9519b3d50..3048d3b5a 100644 --- a/src/demo/normal.c +++ b/src/demo/normal.c @@ -24,7 +24,7 @@ mandelbrot(int y, int x, int dy, int dx){ static int mcell(uint32_t* c, int y, int x, int dy, int dx){ int iter = mandelbrot(y, x, dy, dx); - *c = ((255 - iter) << 24u) + ((255 - iter) << 16u) + ((255 - iter) << 8u); + *c = (0xff << 24u) + ((255 - iter) << 16u) + ((255 - iter) << 8u) + (255 - iter); return 0; } @@ -36,13 +36,9 @@ offset(uint32_t* rgba, int y, int x, int dx){ // make a pixel array out from the center, blitting it as we go int normal_demo(struct notcurses* nc){ int dy, dx; - // we can't resize (and thus can't rotate) the standard plane, so dup it - struct ncplane* n = ncplane_dup(notcurses_stddim_yx(nc, &dy, &dx), NULL); - if(n == NULL){ - return -1; - } - ncplane_erase(n); - struct ncvisual* ncv = NULL; + struct ncplane* nstd = notcurses_stddim_yx(nc, &dy, &dx); + ncplane_erase(nstd); + struct ncplane* n = NULL; dy *= VSCALE; // double-block trick means both 2x resolution and even linecount yay uint32_t* rgba = malloc(sizeof(*rgba) * dy * dx); if(!rgba){ @@ -67,37 +63,39 @@ int normal_demo(struct notcurses* nc){ goto err; } } - if(ncblit_rgba(n, 0, 0, dx * sizeof(*rgba), rgba, 0, 0, dy, dx) < 0){ + if(ncblit_rgba(nstd, 0, 0, dx * sizeof(*rgba), rgba, 0, 0, dy, dx) < 0){ goto err; } DEMO_RENDER(nc); } free(rgba); rgba = NULL; - ncv = ncvisual_from_plane(n, 0, 0, -1, -1); - if(!ncv){ - goto err; - } - ncplane_erase(n); struct timespec scaled; - timespec_div(&demodelay, 16, &scaled); - for(int i = 1 ; i < 16 ; ++i){ + timespec_div(&demodelay, 4, &scaled); + // we can't resize (and thus can't rotate) the standard plane, so dup it + n = ncplane_dup(nstd, NULL); + if(n == NULL){ + return -1; + } + for(int i = 0 ; i < 16 ; ++i){ demo_nanosleep(nc, &scaled); - if(ncvisual_rotate(ncv, M_PI / 2)){ + if(ncplane_rotate_cw(n)){ goto err; } - if(ncvisual_render(ncv, 0, 0, -1, -1) <= 0){ + DEMO_RENDER(nc); + } + for(int i = 0 ; i < 16 ; ++i){ + demo_nanosleep(nc, &scaled); + if(ncplane_rotate_ccw(n)){ goto err; } DEMO_RENDER(nc); } - ncvisual_destroy(ncv); ncplane_destroy(n); return 0; err: free(rgba); - ncvisual_destroy(ncv); ncplane_destroy(n); return -1; } diff --git a/src/lib/fill.c b/src/lib/fill.c index b2709275d..23a7ead0a 100644 --- a/src/lib/fill.c +++ b/src/lib/fill.c @@ -504,7 +504,9 @@ static int rotate_merge(ncplane* n, ncplane* newp){ int dimy, dimx; ncplane_dim_yx(newp, &dimy, &dimx); +fprintf(stderr, "NEWPlen: %d/%d\n", dimy, dimx); int ret = ncplane_resize(n, 0, 0, 0, 0, 0, 0, dimy, dimx); +fprintf(stderr, "nlen: %d/%d\n", ncplane_dim_y(n), ncplane_dim_x(n)); if(ret == 0){ for(int y = 0 ; y < dimy ; ++y){ for(int x = 0 ; x < dimx ; ++x){ @@ -526,6 +528,8 @@ int ncplane_rotate_cw(ncplane* n){ } int dimy, dimx; ncplane_dim_yx(n, &dimy, &dimx); + int centy, centx; + ncplane_center_abs(n, ¢y, ¢x); // the topmost row consists of the leftmost two columns. the rightmost column // of the topmost row consists of the top half of the top two leftmost cells. // the penultimate column of the topmost row consists of the bottom half of @@ -545,6 +549,11 @@ int ncplane_rotate_cw(ncplane* n){ } int ret = rotate_merge(n, newp); ret |= ncplane_destroy(newp); + int cent2y, cent2x; + int absy, absx; + ncplane_center_abs(n, ¢2y, ¢2x); + ncplane_yx(n, &absy, &absx); + ncplane_move_yx(n, absy + centy - cent2y, absx + centx - cent2x); return ret; } @@ -555,6 +564,8 @@ int ncplane_rotate_ccw(ncplane* n){ } int dimy, dimx, targdimy, targdimx; ncplane_dim_yx(n, &dimy, &dimx); + int centy, centx; + ncplane_center_abs(n, ¢y, ¢x); ncplane_dim_yx(newp, &targdimy, &targdimx); int x = dimx - 2, y; // Each row of the target plane is taken from a column of the source plane. @@ -572,6 +583,11 @@ int ncplane_rotate_ccw(ncplane* n){ } int ret = rotate_merge(n, newp); ret |= ncplane_destroy(newp); + int cent2y, cent2x; + int absy, absx; + ncplane_center_abs(n, ¢2y, ¢2x); + ncplane_yx(n, &absy, &absx); + ncplane_move_yx(n, absy + centy - cent2y, absx + centx - cent2x); return ret; }