diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 7fac3410f..3293761db 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -137,6 +137,9 @@ mbswidth(const char* mbs){ (((((uint64_t)(fr) << 16u) + ((uint64_t)(fg) << 8u) + (uint64_t)(fb)) << 32ull) + \ (((br) << 16u) + ((bg) << 8u) + (bb)) + CELL_BGDEFAULT_MASK + CELL_FGDEFAULT_MASK) +#define CHANNEL_RGB_INITIALIZER(r, g, b) \ + (((uint32_t)r << 16u) + ((uint32_t)g << 8u) + (b) + CELL_BGDEFAULT_MASK) + // These lowest-level functions manipulate a 64-bit channel encoding directly. // Users will typically manipulate ncplane and cell channels through those APIs, // rather than calling these directly. diff --git a/src/poc/gradients.c b/src/poc/gradients.c new file mode 100644 index 000000000..329ab59bb --- /dev/null +++ b/src/poc/gradients.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include + +// gradient of 'A's changing color and background changing in reverse +static int +gradientA(struct notcurses* nc){ + int dimy, dimx; + struct ncplane* stdn = notcurses_stddim_yx(nc, &dimy, &dimx); + uint64_t ul = CHANNELS_RGB_INITIALIZER(0, 0, 0, 0xff, 0xff, 0xff); + uint64_t ur = CHANNELS_RGB_INITIALIZER(0, 0xff, 0xff, 0xff, 0, 0); + uint64_t ll = CHANNELS_RGB_INITIALIZER(0xff, 0, 0, 0, 0xff, 0xff); + uint64_t lr = CHANNELS_RGB_INITIALIZER(0xff, 0xff, 0xff, 0, 0, 0); + if(ncplane_gradient(stdn, "A", NCSTYLE_NONE, ul, ur, ll, lr, dimy - 1, dimx - 1) <= 0){ + return -1; + } + if(notcurses_render(nc)){ + return -1; + } + sleep(3); + return 0; +} + +static int +gradStriations(struct notcurses* nc){ + int dimy, dimx; + struct ncplane* stdn = notcurses_stddim_yx(nc, &dimy, &dimx); + uint64_t ul = CHANNELS_RGB_INITIALIZER(0, 0, 0, 0xff, 0xff, 0xff); + uint64_t ur = CHANNELS_RGB_INITIALIZER(0, 0xff, 0xff, 0xff, 0, 0); + uint64_t ll = CHANNELS_RGB_INITIALIZER(0xff, 0, 0, 0, 0xff, 0xff); + uint64_t lr = CHANNELS_RGB_INITIALIZER(0xff, 0xff, 0xff, 0, 0, 0); + if(ncplane_gradient(stdn, "▀", NCSTYLE_NONE, ul, ur, ll, lr, dimy - 1, dimx - 1) <= 0){ + return -1; + } + if(notcurses_render(nc)){ + return -1; + } + sleep(3); + return 0; +} + +// gradient of 'A's changing color and background changing in reverse +static int +gradHigh(struct notcurses* nc){ + int dimy, dimx; + struct ncplane* stdn = notcurses_stddim_yx(nc, &dimy, &dimx); + uint64_t ul = CHANNEL_RGB_INITIALIZER(0, 0, 0); + uint64_t ur = CHANNEL_RGB_INITIALIZER(0, 0xff, 0xff); + uint64_t ll = CHANNEL_RGB_INITIALIZER(0xff, 0, 0); + uint64_t lr = CHANNEL_RGB_INITIALIZER(0xff, 0xff, 0xff); + if(ncplane_highgradient(stdn, ul, ur, ll, lr, dimy - 1, dimx - 1) <= 0){ + return -1; + } + if(notcurses_render(nc)){ + return -1; + } + sleep(3); + return 0; +} + +int main(void){ + if(setlocale(LC_ALL, "") == NULL){ + return EXIT_FAILURE; + } + struct notcurses_options opts = { + .flags = NCOPTION_INHIBIT_SETLOCALE, + }; + struct notcurses* nc = notcurses_init(&opts, NULL); + if(nc == NULL){ + return EXIT_FAILURE; + } + // no short-circuiting, intentional | + int ret = gradientA(nc) | gradStriations(nc) | gradHigh(nc); + if(notcurses_stop(nc) || ret){ + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +}