rename ncplane default -> base #236

This commit is contained in:
nick black 2019-12-29 23:39:55 -05:00 committed by Nick Black
parent d5748c634d
commit 014afa348b
19 changed files with 46 additions and 45 deletions

View File

@ -387,13 +387,14 @@ API int ncplane_resize(struct ncplane* n, int keepy, int keepx, int keepleny,
// the standard plane.
API int ncplane_destroy(struct ncplane* ncp);
// Set the ncplane's default cell to this cell. If defined, it will be rendered
// Set the ncplane's base cell to this cell. If defined, it will be rendered
// anywhere that the ncplane's gcluster is 0. Erasing the ncplane does not
// reset the default cell; this function must instead be called with a zero c.
API int ncplane_set_default(struct ncplane* ncp, const cell* c);
// reset the base cell; this function must instead be called with a zero c.
API int ncplane_set_base(struct ncplane* ncp, const cell* c);
// Extract the ncplane's default cell into 'c'.
API int ncplane_default(struct ncplane* ncp, cell* c);
// Extract the ncplane's base cell into 'c'. The reference is invalidated if
// 'ncp' is destroyed.
API int ncplane_base(struct ncplane* ncp, cell* c);
// Move this plane relative to the standard plane. It is an error to attempt to
// move the standard plane.
@ -736,7 +737,7 @@ ncplane_box_sized(struct ncplane* n, const cell* ul, const cell* ur,
// Erase every cell in the ncplane, resetting all attributes to normal, all
// colors to the default color, and all cells to undrawn. All cells associated
// with this ncplane is invalidated, and must not be used after the call,
// excluding the default cell.
// excluding the base cell.
API void ncplane_erase(struct ncplane* n);
#define CELL_WIDEASIAN_MASK 0x8000000080000000ull

View File

@ -28,7 +28,7 @@ int box_demo(struct notcurses* nc){
int ytargbase = (ylen - targy) / 2;
cell c = CELL_SIMPLE_INITIALIZER(' ');
cell_set_bg_default(&c);
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
cell_release(n, &c);
ncplane_set_fg_rgb(n, 180, 40, 180);
ncplane_set_bg_default(n);

View File

@ -99,7 +99,7 @@ intro(struct notcurses* nc){
}
cell c = CELL_TRIVIAL_INITIALIZER;
cell_set_bg_rgb(&c, 0x20, 0x20, 0x20);
ncplane_set_default(ncp, &c);
ncplane_set_base(ncp, &c);
if(ncplane_cursor_move_yx(ncp, 0, 0)){
return -1;
}

View File

@ -116,7 +116,7 @@ draw_eagle(struct ncplane* n, const char* sprite){
cell bgc = CELL_TRIVIAL_INITIALIZER;
cell_set_fg_alpha(&bgc, CELL_ALPHA_TRANSPARENT);
cell_set_bg_alpha(&bgc, CELL_ALPHA_TRANSPARENT);
ncplane_set_default(n, &bgc);
ncplane_set_base(n, &bgc);
cell_release(n, &bgc);
size_t s;
int sbytes;

View File

@ -39,7 +39,7 @@ hud_standard_bg(struct ncplane* n){
cell c = CELL_SIMPLE_INITIALIZER(' ');
cell_set_bg_rgb(&c, 0xc0, 0xf0, 0xc0);
cell_set_bg_alpha(&c, CELL_ALPHA_BLEND);
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
cell_release(n, &c);
return 0;
}
@ -48,7 +48,7 @@ static int
hud_grabbed_bg(struct ncplane* n){
cell c = CELL_SIMPLE_INITIALIZER(' ');
cell_set_bg_rgb(&c, 0x40, 0x90, 0x40);
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
cell_release(n, &c);
return 0;
}
@ -133,7 +133,7 @@ int hud_schedule(const char* demoname){
return -1;
}
cell c = CELL_TRIVIAL_INITIALIZER;
ncplane_default(hud, &c);
ncplane_base(hud, &c);
ncplane_set_bg(hud, cell_get_bg(&c));
ncplane_set_bg_alpha(hud, CELL_ALPHA_BLEND);
ncplane_set_fg(hud, 0);

View File

@ -114,7 +114,7 @@ draw_luigi(struct ncplane* n, const char* sprite){
cell bgc = CELL_TRIVIAL_INITIALIZER;
cell_set_fg_alpha(&bgc, CELL_ALPHA_TRANSPARENT);
cell_set_bg_alpha(&bgc, CELL_ALPHA_TRANSPARENT);
ncplane_set_default(n, &bgc);
ncplane_set_base(n, &bgc);
cell_release(n, &bgc);
size_t s;
int sbytes;

View File

@ -38,7 +38,7 @@ legend(struct notcurses* nc, const char* msg){
cell_set_fg_rgb(&c, 0, 0, 0); // darken surrounding characters by half
cell_set_fg_alpha(&c, CELL_ALPHA_BLEND);
cell_set_bg_alpha(&c, CELL_ALPHA_TRANSPARENT); // don't touch background
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
ncplane_set_fg(n, 0xd78700);
ncplane_set_bg(n, 0);
if(ncplane_putstr_yx(n, 1, 1, msg) < 0){
@ -127,7 +127,7 @@ slidepanel(struct notcurses* nc){
// of the underlying desktop).
cell c = CELL_SIMPLE_INITIALIZER(' ');
struct timespec cur;
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
clock_gettime(CLOCK_MONOTONIC, &cur);
uint64_t deadlinens = timespec_to_ns(&cur) + DELAYSCALE * timespec_to_ns(&demodelay);
int direction = random() % 4;
@ -140,7 +140,7 @@ slidepanel(struct notcurses* nc){
ncplane_destroy(l);
cell_load_simple(n, &c, '\0');
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
clock_gettime(CLOCK_MONOTONIC, &cur);
deadlinens = timespec_to_ns(&cur) + DELAYSCALE * timespec_to_ns(&demodelay);
l = legend(nc, "default background, all opaque, no glyph");
@ -154,7 +154,7 @@ slidepanel(struct notcurses* nc){
// Next, we set our foreground transparent, allowing characters underneath to
// be seen in their natural colors. Our background remains opaque+default.
cell_set_fg_alpha(&c, CELL_ALPHA_TRANSPARENT);
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
clock_gettime(CLOCK_MONOTONIC, &cur);
deadlinens = timespec_to_ns(&cur) + DELAYSCALE * timespec_to_ns(&demodelay);
l = legend(nc, "default background, fg transparent, no glyph");
@ -169,7 +169,7 @@ slidepanel(struct notcurses* nc){
// glyphs in a blended color, with the default background color.
cell_set_fg(&c, 0x80c080);
cell_set_fg_alpha(&c, CELL_ALPHA_BLEND);
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
clock_gettime(CLOCK_MONOTONIC, &cur);
l = legend(nc, "default background, fg blended, no glyph");
deadlinens = timespec_to_ns(&cur) + DELAYSCALE * timespec_to_ns(&demodelay);
@ -184,7 +184,7 @@ slidepanel(struct notcurses* nc){
// fixed color, with the default background color.
cell_set_fg(&c, 0x80c080);
cell_set_fg_alpha(&c, CELL_ALPHA_OPAQUE);
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
clock_gettime(CLOCK_MONOTONIC, &cur);
l = legend(nc, "default background, fg colored opaque, no glyph");
deadlinens = timespec_to_ns(&cur) + DELAYSCALE * timespec_to_ns(&demodelay);
@ -201,7 +201,7 @@ slidepanel(struct notcurses* nc){
cell_set_fg_default(&c);
cell_set_fg_alpha(&c, CELL_ALPHA_TRANSPARENT);
cell_set_bg_alpha(&c, CELL_ALPHA_OPAQUE);
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
clock_gettime(CLOCK_MONOTONIC, &cur);
l = legend(nc, "default colors, fg transparent, print glyph");
deadlinens = timespec_to_ns(&cur) + DELAYSCALE * timespec_to_ns(&demodelay);
@ -216,7 +216,7 @@ slidepanel(struct notcurses* nc){
// background color from below us.
cell_set_fg_alpha(&c, CELL_ALPHA_TRANSPARENT);
cell_set_bg_alpha(&c, CELL_ALPHA_TRANSPARENT);
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
clock_gettime(CLOCK_MONOTONIC, &cur);
l = legend(nc, "all transparent, print glyph");
deadlinens = timespec_to_ns(&cur) + DELAYSCALE * timespec_to_ns(&demodelay);
@ -233,7 +233,7 @@ slidepanel(struct notcurses* nc){
cell_set_bg_alpha(&c, CELL_ALPHA_BLEND);
cell_set_fg(&c, 0x80c080);
cell_set_bg(&c, 0x204080);
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
clock_gettime(CLOCK_MONOTONIC, &cur);
l = legend(nc, "all blended, print glyph");
deadlinens = timespec_to_ns(&cur) + DELAYSCALE * timespec_to_ns(&demodelay);

View File

@ -72,7 +72,7 @@ outro_message(struct notcurses* nc, int* rows, int* cols){
}
cell bgcell = CELL_SIMPLE_INITIALIZER(' ');
channels_set_bg_rgb(&bgcell.channels, 0x58, 0x36, 0x58);
if(ncplane_set_default(non, &bgcell) < 0){
if(ncplane_set_base(non, &bgcell) < 0){
return NULL;
}
ncplane_dim_yx(non, rows, cols);

View File

@ -117,7 +117,7 @@ fill_chunk(struct ncplane* n, int idx){
cell_init(&style);
cell_set_fg_rgb(&style, r, g, b);
cell_prime(n, &style, "", 0, channels);
ncplane_set_default(n, &style);
ncplane_set_base(n, &style);
cell_release(n, &style);
return 0;
}

View File

@ -45,7 +45,7 @@ legend(struct notcurses* nc, int dimy, int dimx){
uint64_t channels = 0;
channels_set_bg_alpha(&channels, CELL_ALPHA_TRANSPARENT);
cell c = CELL_INITIALIZER(' ', 0, channels);
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
ncplane_styles_set(n, CELL_STYLE_BOLD);
ncplane_set_fg_rgb(n, 0xff, 0xff, 0xff);
if(ncplane_putstr_aligned(n, 0, NCALIGN_CENTER, "target launch") <= 0){

View File

@ -276,7 +276,7 @@ message(struct ncplane* n, int maxy, int maxx, int num, int total,
cell c = CELL_TRIVIAL_INITIALIZER;
cell_set_fg_alpha(&c, CELL_ALPHA_TRANSPARENT);
cell_set_bg_alpha(&c, CELL_ALPHA_TRANSPARENT);
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
cell_release(n, &c);
uint64_t channels = 0;
ncplane_set_fg_rgb(n, 64, 128, 240);

View File

@ -38,7 +38,7 @@ perframecb(struct notcurses* nc, struct ncvisual* ncv __attribute__ ((unused)),
cell c = CELL_SIMPLE_INITIALIZER(' ');
cell_set_fg_alpha(&c, CELL_ALPHA_TRANSPARENT);
cell_set_bg_alpha(&c, CELL_ALPHA_TRANSPARENT);
ncplane_set_default(n, &c);
ncplane_set_base(n, &c);
ncplane_set_fg_alpha(n, CELL_ALPHA_BLEND);
ncplane_set_bg_alpha(n, CELL_ALPHA_BLEND);
// fg/bg rgbs are set within loop

View File

@ -53,7 +53,7 @@ alloc_ncplane_palette(ncplane* n, planepalette* pp){
}
}
// FIXME factor this duplication out
channels = n->defcell.channels;
channels = n->basecell.channels;
pp->channels[y * pp->cols] = channels;
channels_get_fg_rgb(channels, &r, &g, &b);
if(r > pp->maxr){
@ -211,20 +211,20 @@ int ncplane_fadeout(struct ncplane* n, const struct timespec* ts, fadecb fader){
}
}
}
cell* c = &n->defcell;
cell* c = &n->basecell;
if(!cell_fg_default_p(c)){
channels_get_fg_rgb(pp.channels[pp.cols * y], &r, &g, &b);
r = r * (maxsteps - iter) / maxsteps;
g = g * (maxsteps - iter) / maxsteps;
b = b * (maxsteps - iter) / maxsteps;
cell_set_fg_rgb(&n->defcell, r, g, b);
cell_set_fg_rgb(&n->basecell, r, g, b);
}
if(!cell_bg_default_p(c)){
channels_get_bg_rgb(pp.channels[pp.cols * y], &br, &bg, &bb);
br = br * (maxsteps - iter) / maxsteps;
bg = bg * (maxsteps - iter) / maxsteps;
bb = bb * (maxsteps - iter) / maxsteps;
cell_set_bg_rgb(&n->defcell, br, bg, bb);
cell_set_bg_rgb(&n->basecell, br, bg, bb);
}
if(fader){
fader(n->nc, n);

View File

@ -61,7 +61,7 @@ typedef struct ncplane {
uint64_t channels; // works the same way as cells
uint32_t attrword; // same deal as in a cell
void* userptr; // slot for the user to stick some opaque pointer
cell defcell; // cell written anywhere that fb[i].gcluster == 0
cell basecell; // cell written anywhere that fb[i].gcluster == 0
struct notcurses* nc; // notcurses object of which we are a part
} ncplane;

View File

@ -291,7 +291,7 @@ ncplane_create(notcurses* nc, int rows, int cols, int yoff, int xoff){
p->z = nc->top;
nc->top = p;
p->nc = nc;
cell_init(&p->defcell);
cell_init(&p->basecell);
nc->stats.fbbytes += fbsize;
return p;
}
@ -925,16 +925,16 @@ int ncplane_set_bg_alpha(ncplane *n, int alpha){
return channels_set_bg_alpha(&n->channels, alpha);
}
int ncplane_set_default(ncplane* ncp, const cell* c){
int ret = cell_duplicate(ncp, &ncp->defcell, c);
int ncplane_set_base(ncplane* ncp, const cell* c){
int ret = cell_duplicate(ncp, &ncp->basecell, c);
if(ret < 0){
return -1;
}
return ret;
}
int ncplane_default(ncplane* ncp, cell* c){
return cell_duplicate(ncp, c, &ncp->defcell);
int ncplane_base(ncplane* ncp, cell* c){
return cell_duplicate(ncp, c, &ncp->basecell);
}
const char* cell_extended_gcluster(const struct ncplane* n, const cell* c){
@ -1555,11 +1555,11 @@ void ncplane_erase(ncplane* n){
// we must preserve the background, but a pure cell_duplicate() would be
// wiped out by the egcpool_dump(). do a duplication (to get the attrword
// and channels), and then reload.
char* egc = cell_egc_copy(n, &n->defcell);
char* egc = cell_egc_copy(n, &n->basecell);
memset(n->fb, 0, sizeof(*n->fb) * n->lenx * n->leny);
egcpool_dump(&n->pool);
egcpool_init(&n->pool);
cell_load(n, &n->defcell, egc);
cell_load(n, &n->basecell, egc);
free(egc);
ncplane_unlock(n);
}

View File

@ -623,7 +623,7 @@ panelreel* panelreel_create(ncplane* w, const panelreel_options* popts, int efd)
}
cell bgc = CELL_TRIVIAL_INITIALIZER;
bgc.channels = popts->bgchannel;
ncplane_set_default(pr->p, &bgc);
ncplane_set_base(pr->p, &bgc);
cell_release(pr->p, &bgc);
if(panelreel_redraw(pr)){
ncplane_destroy(pr->p);

View File

@ -160,7 +160,7 @@ dig_visible_cell(cell* c, int y, int x, ncplane* p){
// if we never loaded any content into the cell (or obliterated it by
// writing in a zero), use the plane's default cell.
if(vis->gcluster == 0){
vis = &p->defcell;
vis = &p->basecell;
}
// if we have no character in this cell, we continune to look for a
// character, but our foreground color will still be used unless it's

View File

@ -25,7 +25,7 @@ int tabletfxn(struct tablet* t, int begx, int begy, int maxx, int maxy,
ncplane_erase(p);
cell c = CELL_SIMPLE_INITIALIZER(' ');
cell_set_bg(&c, (((uintptr_t)t) % 0x1000000) + cliptop + begx + maxx);
ncplane_set_default(p, &c);
ncplane_set_base(p, &c);
cell_release(p, &c);
return tctx->getLines() > maxy - begy ? maxy - begy : tctx->getLines();
}

View File

@ -32,7 +32,7 @@ SUBCASE("SetItalic") {
cell_styles_set(&c, CELL_STYLE_ITALIC);
REQUIRE(1 == cell_load(n_, &c, "i"));
cell_set_fg_rgb(&c, 255, 255, 255);
ncplane_set_default(n_, &c);
ncplane_set_base(n_, &c);
cell_release(n_, &c);
CHECK(0 == notcurses_render(nc_));
cell_styles_off(&c, CELL_STYLE_ITALIC);
@ -45,7 +45,7 @@ SUBCASE("SetItalic") {
cell_styles_set(&c, CELL_STYLE_BOLD);
REQUIRE(1 == cell_load(n_, &c, "b"));
cell_set_fg_rgb(&c, 255, 255, 255);
ncplane_set_default(n_, &c);
ncplane_set_base(n_, &c);
cell_release(n_, &c);
CHECK(0 == notcurses_render(nc_));
cell_styles_off(&c, CELL_STYLE_BOLD);
@ -58,7 +58,7 @@ SUBCASE("SetItalic") {
cell_styles_set(&c, CELL_STYLE_UNDERLINE);
REQUIRE(1 == cell_load(n_, &c, "u"));
cell_set_fg_rgb(&c, 255, 255, 255);
ncplane_set_default(n_, &c);
ncplane_set_base(n_, &c);
cell_release(n_, &c);
CHECK(0 == notcurses_render(nc_));
cell_styles_off(&c, CELL_STYLE_UNDERLINE);