mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
shuffle: color and label pieces #67
This commit is contained in:
parent
e81377cf05
commit
ad183a6322
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user