From 13f9457e9808a3ab4aaf7e288b9bdd19b0f83a2f Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Wed, 26 Jul 2023 05:23:10 +0000 Subject: [PATCH] feat: Add hard-coded invisible color 254 (#94) Co-authored-by: Glen Whitney Reviewed-on: https://code.studioinfinity.org/glen/teapot-spreadsheet/pulls/94 --- doc/teapot.lyx | 22 ++++++++++++++- src/common/style.h | 1 + src/display.c | 11 +++++--- src/fteapot.fl | 68 ++++++++++++++++++++++++---------------------- 4 files changed, 64 insertions(+), 38 deletions(-) diff --git a/doc/teapot.lyx b/doc/teapot.lyx index 3d5f1bc..8d49838 100644 --- a/doc/teapot.lyx +++ b/doc/teapot.lyx @@ -4018,6 +4018,18 @@ teapot fteapot \family default set up a default palette appropriate for their respective capabilities. + Currently, the color number 254 is treated specially: when the foreground + is set to this color, the contents of the cell are not drawn into the cell + at all. + So color 254 is a hard-coded +\begin_inset Quotes eld +\end_inset + +invisible +\begin_inset Quotes erd +\end_inset + + or zero-alpha color. Hopefully, a future enhancement will allow one to display, edit, save, and restore the palette. \end_layout @@ -10467,7 +10479,15 @@ noprefix "false" \end_inset -) or making its foreground and background the same color, etc. +) or using the hard-coded +\begin_inset Quotes eld +\end_inset + +invisible +\begin_inset Quotes erd +\end_inset + + color number 254, etc. \end_layout \begin_layout Subsection diff --git a/src/common/style.h b/src/common/style.h index 9ba8dd4..3e9fef5 100644 --- a/src/common/style.h +++ b/src/common/style.h @@ -30,6 +30,7 @@ extern const char FloatFormat_Char[]; typedef unsigned char ColorNum; #define NO_COLOR_SET 0 #define MAX_MAX_COLORS UCHAR_MAX +#define INVISIBLE_COLOR (UCHAR_MAX - 1) #define COLOR_FORMAT "%hhu" typedef enum diff --git a/src/display.c b/src/display.c index bbe27cf..6f465b9 100644 --- a/src/display.c +++ b/src/display.c @@ -606,19 +606,22 @@ void redraw_sheet(Sheet *sheet) if (sc.bold) wattron(stdscr, A_BOLD); if (sc.underline) wattron(stdscr, A_UNDERLINE); short nextcp = hashcp; - if (hashcp == usecp) { + chtype blank = (chtype)' '; + if (hashcp == usecp && fg != INVISIBLE_COLOR) { (void)mvwaddstr(stdscr, (int)(height + sheet->oriy), (int)(width + sheet->orix), buf+cutoff); } else { // Alternate colors to simulate hash + chtype next_char = (chtype)buf[cutoff]; + if (fg == INVISIBLE_COLOR) next_char = blank; (void)mvwaddch(stdscr, (int)(height + sheet->oriy), - (int)(width + sheet->orix), - (chtype)buf[cutoff]); + (int)(width + sheet->orix), next_char); for (size_t ix = cutoff+1; buf[ix]; ++ix) { wcolor_set(stdscr, nextcp, NULL); if (nextcp == hashcp) nextcp = usecp; else nextcp = hashcp; - (void)waddch(stdscr, (chtype)buf[ix]); + next_char = fg == INVISIBLE_COLOR ? blank : (chtype)buf[ix]; + (void)waddch(stdscr, next_char); } } for (fill=mbslen(buf+cutoff); fillpalette))[fgcn]; - if (sc.dim) cellfg = fl_color_average(cellfg, cellbg, 0.6f); - fl_color(cellfg); - Fl_Font cellfont = FL_HELVETICA; - if (sc.bold) cellfont |= FL_BOLD; - if (sc.italic) cellfont |= FL_ITALIC; - fl_font(cellfont, fontsize); + if (fgcn != INVISIBLE_COLOR) { + Fl_Color cellfg = ((Fl_Color *)(cursheet->palette))[fgcn]; + if (sc.dim) cellfg = fl_color_average(cellfg, cellbg, 0.6f); + fl_color(cellfg); + Fl_Font cellfont = FL_HELVETICA; + if (sc.bold) cellfont |= FL_BOLD; + if (sc.italic) cellfont |= FL_ITALIC; + fl_font(cellfont, fontsize); - size_t ulen = printvalue(s, sizeof(s), 0, quote, sc.fform, + size_t ulen = printvalue(s, sizeof(s), 0, quote, sc.fform, sc.precision, cursheet, test); - ptrdiff_t len = ulen; - ptrdiff_t nlen = len; - int ww = 0, hh = 0; - fl_measure(s, ww, hh, 0); - while (ww > W-6) { - char *dc = mbspos(s+nlen, -1); - nlen = dc - s; - s[nlen] = (char)0; - ww = 0; - fl_measure(s, ww, hh, 0); + ptrdiff_t len = ulen; + ptrdiff_t nlen = len; + int ww = 0, hh = 0; + fl_measure(s, ww, hh, 0); + while (ww > W-6) { + char *dc = mbspos(s+nlen, -1); + nlen = dc - s; + s[nlen] = (char)0; + ww = 0; + fl_measure(s, ww, hh, 0); + } + if (nlen < len) { + if (nlen < 1) { s[0] = '\#'; s[1] = (char)0; } + else if (nlen < 6) for (int i = 0; s[i]; i++) s[i] = '\#'; + else { + char *ov = mbspos(s+nlen-1, -5); + if (ov < s) ov = s; + strncpy(ov, "...\#\#", sizeof(s) - nlen); + } + } + Adjust adj = sc.adjust; + fl_draw(s, xx+3, yy+3, W-6, H-6, + adj == RIGHT ? FL_ALIGN_RIGHT : + adj == LEFT ? FL_ALIGN_LEFT : FL_ALIGN_CENTER, + NULL, 0); + if (sc.underline) fl_xyline(xx, yy+H-7, xx+W); } - if (nlen < len) { - if (nlen < 1) { s[0] = '\#'; s[1] = (char)0; } - else if (nlen < 6) for (int i = 0; s[i]; i++) s[i] = '\#'; - else { - char *ov = mbspos(s+nlen-1, -5); - if (ov < s) ov = s; - strncpy(ov, "...\#\#", sizeof(s) - nlen); - } - } - Adjust adj = sc.adjust; - fl_draw(s, xx+3, yy+3, W-6, H-6, - adj == RIGHT ? FL_ALIGN_RIGHT : - adj == LEFT ? FL_ALIGN_LEFT : FL_ALIGN_CENTER, - NULL, 0); - if (sc.underline) fl_xyline(xx, yy+H-7, xx+W); fl_pop_clip(); return;