added 'code' background
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 12 Jan 2022 03:51:36 +0000 (21:51 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 12 Jan 2022 03:51:36 +0000 (21:51 -0600)
drw.c
drw.h
sent.c

diff --git a/drw.c b/drw.c
index c1582e746cc57b7a475c1de3fcc53507cdb50b37..7f9ac5dc48aed409cdd54d5315d885e169eb6cc4 100644 (file)
--- 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 4c67419a98dd6d87e0b15e6f14094f24aa44c143..f894bf35aaf96fe336da9df43bf96896007df738 100644 (file)
--- 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 4728dd39d316299134a7d441be30fef5db61bbc7..ece76740a3877321ae76c39b4298fd6597586bd3 100644 (file)
--- 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();