shuffle: color and label pieces #67

This commit is contained in:
nick black 2019-11-28 16:19:08 -05:00
parent e81377cf05
commit ad183a6322
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 40 additions and 9 deletions

View File

@ -13,10 +13,39 @@ fill_chunk(struct ncplane* n, int idx){
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){
cell ul = CELL_TRIVIAL_INITIALIZER, ur = CELL_TRIVIAL_INITIALIZER;
cell ll = CELL_TRIVIAL_INITIALIZER, lr = CELL_TRIVIAL_INITIALIZER;
cell hl = CELL_TRIVIAL_INITIALIZER, vl = CELL_TRIVIAL_INITIALIZER;
if(ncplane_rounded_box_cells(n, &ul, &ur, &ll, &lr, &hl, &vl)){
return -1;
}
int r = 255 - (idx * 3);
int g = idx * 3;
int b = 255 - (idx * 3);
cell_set_fg(&ul, r, g, b);
cell_set_fg(&ur, r, g, b);
cell_set_fg(&ll, r, g, b);
cell_set_fg(&lr, r, g, b);
cell_set_fg(&hl, r, g, b);
cell_set_fg(&vl, r, g, b);
if(ncplane_box(n, &ul, &ur, &ll, &lr, &hl, &vl, maxy - 1, maxx - 1)){
return -1;
}
if(maxx >= 5 && maxy >= 3){
if(ncplane_cursor_move_yx(n, (maxy - 1) / 2, (maxx - 3) / 2)){
return -1;
}
ncplane_fg_rgb8(n, 224, 224, 224);
if(ncplane_putstr(n, buf) <= 0){
return -1;
}
}
cell_release(n, &ul);
cell_release(n, &ur);
cell_release(n, &ll);
cell_release(n, &lr);
cell_release(n, &hl);
cell_release(n, &vl);
return 0;
}
@ -28,7 +57,8 @@ int sliding_puzzle_demo(struct notcurses* nc){
int maxx, maxy;
int chunky, chunkx;
notcurses_term_dimyx(nc, &maxy, &maxx);
if(maxy < CHUNKS_VERT || maxx < CHUNKS_HORZ){
// want at least 2x2 for each sliding chunk
if(maxy < CHUNKS_VERT * 2 || maxx < CHUNKS_HORZ * 2){
fprintf(stderr, "Terminal too small, need at least %dx%d\n",
CHUNKS_HORZ, CHUNKS_VERT);
return -1;

View File

@ -783,7 +783,7 @@ term_setstyles(const notcurses* nc, FILE* out, uint32_t* curattr, const cell* c)
// find the topmost cell for this coordinate
static const cell*
visible_cell(const notcurses* nc, int y, int x){
visible_cell(const notcurses* nc, int y, int x, const ncplane** retp){
const ncplane* p = nc->top;
while(p){
// where in the plane this coordinate would be, based off absy/absx. the
@ -794,6 +794,7 @@ visible_cell(const notcurses* nc, int y, int x){
poffx = x - p->absx;
if(poffy < p->leny && poffy >= 0){
if(poffx < p->lenx && poffx >= 0){
*retp = p;
return &p->fb[fbcellidx(p, poffy, poffx)];
}
}
@ -822,10 +823,10 @@ int notcurses_render(notcurses* nc){
// FIXME previous line could have ended halfway through multicol. what happens?
for(x = 0 ; x < nc->stdscr->lenx ; ++x){
unsigned r, g, b, br, bg, bb;
const cell* c = visible_cell(nc, y, x);
if(c == NULL){ // very bad :(
continue;
}
const ncplane* p;
const cell* c = visible_cell(nc, y, x, &p);
assert(c);
assert(p);
// we allow these to be set distinctly, but terminfo only supports using
// them both via the 'op' capability. unless we want to generate the 'op'
// escapes ourselves, if either is set to default, we first send op, and
@ -844,7 +845,7 @@ int notcurses_render(notcurses* nc){
term_setstyles(nc, out, &curattr, c);
// FIXME what to do if we're at the last cell, and it's wide?
// fprintf(stderr, "[%02d/%02d] %p ", y, x, c);
term_putc(out, nc->stdscr, c);
term_putc(out, p, c);
if(cell_double_wide_p(c)){
++x;
}