From a1c7bef89406bd9efcdf56b719bb8f9fdbd4e596 Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 28 Nov 2019 15:41:51 -0500 Subject: [PATCH] sliding: draw into ncplanes #67 --- src/demo/sliding.c | 17 +++++++++++++++++ src/lib/notcurses.c | 8 ++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/demo/sliding.c b/src/demo/sliding.c index 3757c3ad8..798a16c1f 100644 --- a/src/demo/sliding.c +++ b/src/demo/sliding.c @@ -7,6 +7,19 @@ #define CHUNKS_VERT 8 #define CHUNKS_HORZ 16 +static int +fill_chunk(struct ncplane* n, int idx){ + char buf[4]; + int maxy, maxx; + ncplane_dimyx(n, &maxy, &maxx); + snprintf(buf, sizeof(buf), "%03d", idx); + ncplane_fg_rgb8(n, 255 - (idx * 4), idx * 4, 255 - (idx * 4)); + if(ncplane_putstr(n, buf) <= 0){ + return -1; + } + return 0; +} + // break whatever's on the screen into panels and shift them around like a // sliding puzzle. FIXME once we have copying, anyway. until then, just use // background colors. @@ -38,8 +51,12 @@ int sliding_puzzle_demo(struct notcurses* nc){ if(chunks[idx] == NULL){ goto done; } + fill_chunk(chunks[idx], idx); } } + if(notcurses_render(nc)){ + goto done; + } nanosleep(&demodelay, NULL); ret = 0; diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 152ddc8d6..c90864a0d 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -933,16 +933,16 @@ int cell_load(ncplane* n, cell* c, const char* gcluster){ return bytes; } -int ncplane_putstr(ncplane* n, const char* gcluster){ +int ncplane_putstr(ncplane* n, const char* gclusters){ int ret = 0; // FIXME speed up this blissfully naive solution - while(*gcluster){ + while(*gclusters){ // FIXME can we not dispense with this cell, and print directly in? cell c; memset(&c, 0, sizeof(c)); c.channels = n->channels; c.attrword = n->attrword; - int wcs = cell_load(n, &c, gcluster); + int wcs = cell_load(n, &c, gclusters); if(wcs < 0){ return -ret; } @@ -950,7 +950,7 @@ int ncplane_putstr(ncplane* n, const char* gcluster){ break; } ncplane_putc(n, &c); - gcluster += wcs; + gclusters += wcs; ret += wcs; if(ncplane_cursor_stuck(n)){ break;