mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 09:09:03 -04:00
yield: transparent background for label
This commit is contained in:
parent
97a92cbbd7
commit
c023ccf4d6
@ -36,10 +36,10 @@ int intro(struct notcurses* nc){
|
||||
struct ncplane* ncp = notcurses_stddim_yx(nc, &rows, &cols);
|
||||
uint32_t ccul, ccur, ccll, cclr;
|
||||
ccul = ccur = ccll = cclr = 0;
|
||||
channel_set_rgb8(&ccul, 0, 0xd0, 0);
|
||||
channel_set_rgb8(&ccur, 0xff, 0, 0);
|
||||
channel_set_rgb8(&ccll, 0x88, 0, 0xcc);
|
||||
channel_set_rgb8(&cclr, 0, 0, 0);
|
||||
channel_set_rgb8(&ccul, 0, 0xff, 0xff);
|
||||
channel_set_rgb8(&ccur, 0xff, 0xff, 0);
|
||||
channel_set_rgb8(&ccll, 0xff, 0, 0);
|
||||
channel_set_rgb8(&cclr, 0, 0, 0xff);
|
||||
// we use full block rather+fg than space+bg to conflict less with the menu
|
||||
ncplane_home(ncp);
|
||||
if(ncplane_highgradient_sized(ncp, ccul, ccur, ccll, cclr, rows, cols) <= 0){
|
||||
|
@ -23,9 +23,9 @@ int yield_demo(struct notcurses* nc){
|
||||
}
|
||||
|
||||
DEMO_RENDER(nc);
|
||||
demo_nanosleep(nc, &demodelay);
|
||||
|
||||
ncplane_erase(std);
|
||||
struct timespec delay;
|
||||
timespec_div(&demodelay, 2, &delay);
|
||||
demo_nanosleep(nc, &delay);
|
||||
|
||||
int vy, vx, vscaley, vscalex;
|
||||
vopts.scaling = NCSCALE_NONE;
|
||||
@ -39,6 +39,24 @@ int yield_demo(struct notcurses* nc){
|
||||
const int MAXITER = 512;
|
||||
timespec_div(&demodelay, MAXITER, &scaled);
|
||||
long tfilled = 0;
|
||||
|
||||
struct ncplane_options labopts = {
|
||||
.y = 3,
|
||||
.x = NCALIGN_CENTER,
|
||||
.rows = 1,
|
||||
.cols = 12,
|
||||
.flags = NCPLANE_OPTION_HORALIGNED,
|
||||
};
|
||||
struct ncplane* label = ncplane_create(std, &labopts);
|
||||
if(label == NULL){
|
||||
ncvisual_destroy(wmv);
|
||||
return -1;
|
||||
}
|
||||
ncplane_set_bg_alpha(label, CELL_ALPHA_TRANSPARENT);
|
||||
ncplane_set_fg_rgb8(label, 0, 0, 0);
|
||||
ncplane_set_styles(label, NCSTYLE_BOLD);
|
||||
ncplane_printf_aligned(label, 0, NCALIGN_CENTER, "Yield: %3.1f%%", ((double)tfilled * 100) / threshold_painted);
|
||||
|
||||
int iters = 0;
|
||||
while(tfilled < threshold_painted && iters < MAXITER){
|
||||
//fprintf(stderr, "%d/%d x %d/%d tfilled: %ld thresh: %ld total: %ld\n", vy, vx, vscaley, vscalex, tfilled, threshold_painted, total);
|
||||
@ -73,18 +91,15 @@ int yield_demo(struct notcurses* nc){
|
||||
ncvisual_destroy(wmv);
|
||||
return -1;
|
||||
}
|
||||
ncplane_set_bg_rgb8(std, 0x10, 0x10, 0x10);
|
||||
ncplane_set_fg_rgb8(std, 0xf0, 0x20, 0x20);
|
||||
ncplane_set_styles(std, NCSTYLE_BOLD);
|
||||
if(tfilled > threshold_painted){
|
||||
tfilled = threshold_painted; // don't allow printing of 100.1% etc
|
||||
}
|
||||
ncplane_printf_aligned(std, 3, NCALIGN_CENTER, "Yield: %3.1f%%", ((double)tfilled * 100) / threshold_painted);
|
||||
ncplane_set_styles(std, NCSTYLE_NONE);
|
||||
ncplane_printf_aligned(label, 0, NCALIGN_CENTER, "Yield: %3.1f%%", ((double)tfilled * 100) / threshold_painted);
|
||||
DEMO_RENDER(nc);
|
||||
demo_nanosleep(nc, &scaled);
|
||||
++iters;
|
||||
}
|
||||
ncplane_destroy(label);
|
||||
ncvisual_destroy(wmv);
|
||||
ncplane_erase(std);
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user