mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
cell: implement fg/bgdefault bits
This commit is contained in:
parent
d400c79870
commit
27e90d9204
@ -4,6 +4,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -227,6 +228,13 @@ int notcurses_palette_size(const struct notcurses* nc);
|
||||
|
||||
// Working with cells
|
||||
|
||||
#define CELL_TRIVIAL_INITIALIZER { .gcluster = '\0', .attrword = 0, .channels = 0, }
|
||||
|
||||
static inline void
|
||||
cell_init(cell* c){
|
||||
memset(c, 0, sizeof(*c));
|
||||
}
|
||||
|
||||
// Breaks the UTF-8 string in 'gcluster' down, setting up the cell 'c'.
|
||||
int cell_load(struct ncplane* n, cell* c, const char* gcluster);
|
||||
|
||||
@ -281,11 +289,15 @@ cell_rgb_blue(uint32_t rgb){
|
||||
return (rgb & 0xffull);
|
||||
}
|
||||
|
||||
#define CELL_FGDEFAULT_MASK 0x4000000000000000ull
|
||||
#define CELL_BGDEFAULT_MASK 0x0000000040000000ull
|
||||
|
||||
static inline void
|
||||
cell_rgb_set_fg(uint64_t* channels, unsigned r, unsigned g, unsigned b){
|
||||
uint64_t rgb = (r & 0xffull) << 48u;
|
||||
rgb |= (g & 0xffull) << 40u;
|
||||
rgb |= (b & 0xffull) << 32u;
|
||||
rgb |= CELL_FGDEFAULT_MASK;
|
||||
*channels = (*channels & ~0x00ffffff00000000ull) | rgb;
|
||||
}
|
||||
|
||||
@ -294,6 +306,7 @@ cell_rgb_set_bg(uint64_t* channels, unsigned r, unsigned g, unsigned b){
|
||||
uint64_t rgb = (r & 0xffull) << 16u;
|
||||
rgb |= (g & 0xffull) << 8u;
|
||||
rgb |= (b & 0xffull);
|
||||
rgb |= CELL_BGDEFAULT_MASK;
|
||||
*channels = (*channels & ~0x0000000000ffffffull) | rgb;
|
||||
}
|
||||
|
||||
@ -321,6 +334,16 @@ cell_get_bg(const cell* c, unsigned* r, unsigned* g, unsigned* b){
|
||||
*b = cell_rgb_blue(cell_bg_rgb(c->channels));
|
||||
}
|
||||
|
||||
static inline bool
|
||||
cell_fg_default_p(const cell* c){
|
||||
return !(c->channels & CELL_FGDEFAULT_MASK);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
cell_bg_default_p(const cell* c){
|
||||
return !(c->channels & CELL_BGDEFAULT_MASK);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
@ -587,6 +587,9 @@ int notcurses_render(notcurses* nc){
|
||||
// FIXME z-culling
|
||||
const cell* c = &nc->stdscr->fb[fbcellidx(nc->stdscr, y, x)];
|
||||
cell_get_fg(c, &r, &g, &b);
|
||||
if(cell_fg_default_p(c)){
|
||||
r = 255; g = 255; b = 255; // FIXME
|
||||
}
|
||||
cell_get_bg(c, &br, &bg, &bb);
|
||||
if(r != pr || g != pg || b != pb || br != pbr || bg != pbg || bb != pbb ||
|
||||
(x == 0 && y == 0)){
|
||||
|
Loading…
x
Reference in New Issue
Block a user