sliding: draw into ncplanes #67

This commit is contained in:
nick black 2019-11-28 15:41:51 -05:00 committed by Nick Black
parent 222c532c77
commit a1c7bef894
2 changed files with 21 additions and 4 deletions

View File

@ -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;

View File

@ -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;