From: Brendan Hansen Date: Wed, 12 Jan 2022 03:51:36 +0000 (-0600) Subject: added 'code' background X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=0ca09b5a3ccf54b1e0d5f851459def90d841bb9e;p=sent.git added 'code' background --- diff --git a/drw.c b/drw.c index c1582e7..7f9ac5d 100644 --- a/drw.c +++ b/drw.c @@ -225,9 +225,15 @@ drw_setscheme(Drw *drw, Clr *scm) void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) { + int col = ColFg; + if (!drw || !drw->scheme) return; - XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel); + + if (invert == 1) col = ColBg; + if (invert == 2) col = ColAccent; + + XSetForeground(drw->dpy, drw->gc, drw->scheme[col].pixel); if (filled) XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); else @@ -258,8 +264,8 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp if (!render) { w = ~w; } else { - XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); - XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); + XSetForeground(drw->dpy, drw->gc, drw->scheme[invert == 1 ? ColFg : ColBg].pixel); + // XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); d = XftDrawCreate(drw->dpy, drw->drawable, DefaultVisual(drw->dpy, drw->screen), DefaultColormap(drw->dpy, drw->screen)); @@ -308,7 +314,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp if (render) { ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent; - XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg], + XftDrawStringUtf8(d, &drw->scheme[invert == 1 ? ColBg : ColFg], usedfont->xfont, x, ty, (XftChar8 *)buf, len); } x += ew; diff --git a/drw.h b/drw.h index 4c67419..f894bf3 100644 --- a/drw.h +++ b/drw.h @@ -12,7 +12,7 @@ typedef struct Fnt { struct Fnt *next; } Fnt; -enum { ColFg, ColBg }; /* Clr scheme index */ +enum { ColFg, ColAccent, ColBg }; /* Clr scheme index */ typedef XftColor Clr; typedef struct { diff --git a/sent.c b/sent.c index 4728dd3..ece7674 100644 --- a/sent.c +++ b/sent.c @@ -53,7 +53,7 @@ typedef struct { typedef struct { unsigned int linecount; char **lines; - int *invert; + int *colors; Image *img; char *embed; int imagesplit; @@ -414,7 +414,7 @@ load(FILE *fp) static size_t size = 0; size_t blen, maxlines; char buf[BUFSIZ], *p; - int inverted; + int colorset; Slide *s; /* read each line from fp and add it to the item list */ @@ -442,9 +442,11 @@ load(FILE *fp) continue; blen = strlen(buf); - inverted = 0; - if (buf[0] == '$') { - inverted = 1; + switch (buf[0]) { + case '$': colorset = 1; goto shiftbuf; + case '%': colorset = 2; goto shiftbuf; + default: colorset = 0; break; + shiftbuf: blen -= 1; memmove(buf, buf + 1, blen); buf[blen] = '\0'; @@ -455,11 +457,11 @@ load(FILE *fp) maxlines = 2 * s->linecount + 1; if (!(s->lines = realloc(s->lines, maxlines * sizeof(s->lines[0])))) die("sent: Unable to reallocate %u bytes:", maxlines * sizeof(s->lines[0])); - if (!(s->invert = realloc(s->invert, maxlines * sizeof(s->invert[0])))) - die("sent: Unable to reallocate %u bytes:", maxlines * sizeof(s->invert[0])); + if (!(s->colors = realloc(s->colors, maxlines * sizeof(s->colors[0])))) + die("sent: Unable to reallocate %u bytes:", maxlines * sizeof(s->colors[0])); } - s->invert[s->linecount] = inverted; + s->colors[s->linecount] = colorset; if (!(s->lines[s->linecount] = strdup(buf))) die("sent: Unable to strdup:"); @@ -551,15 +553,17 @@ xdraw() if (!im) { drw_rect(d, 0, 0, xw.w, xw.h, 1, 1); for (i = 0; i < slides[idx].linecount; i++) { - if (slides[idx].invert[i]) { + if (slides[idx].colors[i]) { drw_rect(d, 0, - (xw.h - height) / 2 + i * linespacing * d->fonts->h, + (xw.h - height) / 2 + (i * linespacing - 0.125f) * d->fonts->h, xw.w, - floor(d->fonts->h * (((i < slides[idx].linecount - 1) && slides[idx].invert[i + 1] != 0) ? linespacing : 1) + 0.5), - 1, 0); + // floor(d->fonts->h * (((i < slides[idx].linecount - 1) && slides[idx].colors[i + 1] != 0) ? linespacing : 1) + 0.5), + d->fonts->h * (linespacing + 0.0625f), + 1, slides[idx].colors[i] == 2 ? 2 : 0); } - + } + for (i = 0; i < slides[idx].linecount; i++) { drw_text(d, (xw.w - width) / 2, (xw.h - height) / 2 + i * linespacing * d->fonts->h, @@ -567,7 +571,7 @@ xdraw() d->fonts->h, 0, slides[idx].lines[i], - slides[idx].invert[i]); + slides[idx].colors[i] == 1); } if (idx != 0 && progressheight != 0) { drw_rect(d, @@ -629,9 +633,9 @@ xinit() if (!(d = drw_create(xw.dpy, xw.scr, xw.win, xw.w, xw.h))) die("sent: Unable to create drawing context"); if (use_inverted_colors) { - sc = drw_scm_create(d, inverted_colors, 2); + sc = drw_scm_create(d, inverted_colors, 3); } else { - sc = drw_scm_create(d, colors, 2); + sc = drw_scm_create(d, colors, 3); } drw_setscheme(d, sc); XSetWindowBackground(xw.dpy, xw.win, sc[ColBg].pixel); @@ -757,10 +761,13 @@ main(int argc, char *argv[]) fontfallbacks[0] = EARGF(usage()); break; case 'c': - colors[0] = EARGF(usage()); + colors[ColFg] = EARGF(usage()); break; + case 'a': + colors[ColAccent] = EARGF(usage()); + break; case 'b': - colors[1] = EARGF(usage()); + colors[ColBg] = EARGF(usage()); break; default: usage();