extended libdraw
18dcf738
6 file(s) · +40 −20
| 72 | 72 | dc.y = 0; |
|
| 73 | 73 | dc.w = mw; |
|
| 74 | 74 | dc.h = mh; |
|
| 75 | - | drawtext(&dc, NULL, normcol); |
|
| 75 | + | drawtext(&dc, NULL, normcol, False); |
|
| 76 | 76 | /* print prompt? */ |
|
| 77 | 77 | if(prompt) { |
|
| 78 | 78 | dc.w = promptw; |
|
| 79 | - | drawtext(&dc, prompt, selcol); |
|
| 79 | + | drawtext(&dc, prompt, selcol, False); |
|
| 80 | 80 | dc.x += dc.w; |
|
| 81 | 81 | } |
|
| 82 | 82 | dc.w = mw - dc.x; |
|
| 83 | - | drawtext(&dc, *text ? text : NULL, normcol); |
|
| 83 | + | drawtext(&dc, *text ? text : NULL, normcol, False); |
|
| 84 | 84 | drawcursor(); |
|
| 85 | 85 | XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); |
|
| 86 | 86 | XFlush(dpy); |
|
| 233 | 233 | ||
| 234 | 234 | /* main event loop */ |
|
| 235 | 235 | while(running && !XNextEvent(dpy, &ev)) |
|
| 236 | - | switch (ev.type) { |
|
| 236 | + | switch(ev.type) { |
|
| 237 | 237 | case KeyPress: |
|
| 238 | 238 | kpress(&ev.xkey); |
|
| 239 | 239 | break; |
|
| 161 | 161 | dc.y = 0; |
|
| 162 | 162 | dc.w = mw; |
|
| 163 | 163 | dc.h = mh; |
|
| 164 | - | drawtext(&dc, NULL, normcol); |
|
| 164 | + | drawtext(&dc, NULL, normcol, False); |
|
| 165 | 165 | /* print prompt? */ |
|
| 166 | 166 | if(prompt) { |
|
| 167 | 167 | dc.w = promptw; |
|
| 168 | - | drawtext(&dc, prompt, selcol); |
|
| 168 | + | drawtext(&dc, prompt, selcol, False); |
|
| 169 | 169 | dc.x += dc.w; |
|
| 170 | 170 | } |
|
| 171 | 171 | dc.w = mw - dc.x; |
|
| 172 | 172 | /* print command */ |
|
| 173 | 173 | if(cmdw && item && lines == 0) |
|
| 174 | 174 | dc.w = cmdw; |
|
| 175 | - | drawtext(&dc, *text ? text : NULL, normcol); |
|
| 175 | + | drawtext(&dc, *text ? text : NULL, normcol, False); |
|
| 176 | 176 | if(curr) { |
|
| 177 | 177 | if(lines > 0) |
|
| 178 | 178 | drawmenuv(); |
|
| 189 | 189 | ||
| 190 | 190 | dc.x += cmdw; |
|
| 191 | 191 | dc.w = spaceitem; |
|
| 192 | - | drawtext(&dc, curr->left ? "<" : NULL, normcol); |
|
| 192 | + | drawtext(&dc, curr->left ? "<" : NULL, normcol, False); |
|
| 193 | 193 | dc.x += dc.w; |
|
| 194 | 194 | for(i = curr; i != next; i = i->right) { |
|
| 195 | 195 | dc.w = MIN(textw(&dc, i->text), mw / 3); |
|
| 196 | - | drawtext(&dc, i->text, (sel == i) ? selcol : normcol); |
|
| 196 | + | drawtext(&dc, i->text, (sel == i) ? selcol : normcol, False); |
|
| 197 | 197 | dc.x += dc.w; |
|
| 198 | 198 | } |
|
| 199 | 199 | dc.w = spaceitem; |
|
| 200 | 200 | dc.x = mw - dc.w; |
|
| 201 | - | drawtext(&dc, next ? ">" : NULL, normcol); |
|
| 201 | + | drawtext(&dc, next ? ">" : NULL, normcol, False); |
|
| 202 | 202 | } |
|
| 203 | 203 | ||
| 204 | 204 | void |
|
| 209 | 209 | dc.h = dc.font.height + 2; |
|
| 210 | 210 | dc.y = dc.h; |
|
| 211 | 211 | for(i = curr; i != next; i = i->right) { |
|
| 212 | - | drawtext(&dc, i->text, (sel == i) ? selcol : normcol); |
|
| 212 | + | drawtext(&dc, i->text, (sel == i) ? selcol : normcol, False); |
|
| 213 | 213 | dc.y += dc.h; |
|
| 214 | 214 | } |
|
| 215 | 215 | dc.h = mh - dc.y; |
|
| 216 | - | drawtext(&dc, NULL, normcol); |
|
| 216 | + | drawtext(&dc, NULL, normcol, False); |
|
| 217 | 217 | } |
|
| 218 | 218 | ||
| 219 | 219 | Bool |
|
| 456 | 456 | ||
| 457 | 457 | /* main event loop */ |
|
| 458 | 458 | while(running && !XNextEvent(dpy, &ev)) |
|
| 459 | - | switch (ev.type) { |
|
| 459 | + | switch(ev.type) { |
|
| 460 | 460 | case KeyPress: |
|
| 461 | 461 | kpress(&ev.xkey); |
|
| 462 | 462 | break; |
|
| 3 | 3 | ||
| 4 | 4 | include ../config.mk |
|
| 5 | 5 | ||
| 6 | - | SRC = cleanupdraw.c setupdraw.c drawtext.c eprint.c getcolor.c initfont.c \ |
|
| 7 | - | textnw.c textw.c |
|
| 6 | + | SRC = cleanupdraw.c drawsquare.c drawtext.c eprint.c getcolor.c initfont.c \ |
|
| 7 | + | setupdraw.c textnw.c textw.c |
|
| 8 | 8 | OBJ = ${SRC:.c=.o} |
|
| 9 | 9 | ||
| 10 | 10 | all: libdraw.a |
| 2 | 2 | #include <X11/Xlib.h> |
|
| 3 | 3 | ||
| 4 | 4 | /* enums */ |
|
| 5 | - | enum { ColFG, ColBG, ColLast }; |
|
| 5 | + | enum { ColBorder, ColFG, ColBG, ColLast }; |
|
| 6 | 6 | ||
| 7 | 7 | /* typedefs */ |
|
| 8 | 8 | typedef struct { |
|
| 21 | 21 | ||
| 22 | 22 | /* forward declarations */ |
|
| 23 | 23 | void cleanupdraw(DC *dc); |
|
| 24 | - | void drawtext(DC *dc, const char *text, unsigned long col[ColLast]); |
|
| 24 | + | void drawsquare(DC *dc, Bool filled, unsigned long col[ColLast], Bool invert); |
|
| 25 | + | void drawtext(DC *dc, const char *text, unsigned long col[ColLast], Bool invert); |
|
| 25 | 26 | void eprint(const char *fmt, ...); |
|
| 26 | 27 | unsigned long getcolor(DC *dc, const char *colstr); |
|
| 27 | 28 | void initfont(DC *dc, const char *fontstr); |
|
| 1 | + | /* See LICENSE file for copyright and license details. */ |
|
| 2 | + | #include <X11/Xlib.h> |
|
| 3 | + | #include "draw.h" |
|
| 4 | + | ||
| 5 | + | void |
|
| 6 | + | drawsquare(DC *dc, Bool filled, unsigned long col[ColLast], Bool invert) { |
|
| 7 | + | int n; |
|
| 8 | + | XRectangle r = { dc->x, dc->y, dc->w, dc->h }; |
|
| 9 | + | ||
| 10 | + | XSetForeground(dc->dpy, dc->gc, col[invert ? ColBG : ColFG]); |
|
| 11 | + | n = ((dc->font.ascent + dc->font.descent + 2) / 4) + (filled ? 1 : 0); |
|
| 12 | + | r.width = r.height = n; |
|
| 13 | + | r.x = dc->x + 1; |
|
| 14 | + | r.y = dc->y + 1; |
|
| 15 | + | if(filled) |
|
| 16 | + | XFillRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1); |
|
| 17 | + | else |
|
| 18 | + | XDrawRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1); |
|
| 19 | + | } |
| 6 | 6 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
|
| 7 | 7 | ||
| 8 | 8 | void |
|
| 9 | - | drawtext(DC *dc, const char *text, unsigned long col[ColLast]) { |
|
| 9 | + | drawtext(DC *dc, const char *text, unsigned long col[ColLast], Bool invert) { |
|
| 10 | 10 | char buf[256]; |
|
| 11 | 11 | int i, x, y, h, len, olen; |
|
| 12 | 12 | XRectangle r = { dc->x, dc->y, dc->w, dc->h }; |
|
| 13 | 13 | ||
| 14 | - | XSetForeground(dc->dpy, dc->gc, col[ColBG]); |
|
| 14 | + | XSetForeground(dc->dpy, dc->gc, col[invert ? ColFG : ColBG]); |
|
| 15 | 15 | XFillRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1); |
|
| 16 | 16 | if(!text) |
|
| 17 | 17 | return; |
|
| 26 | 26 | memcpy(buf, text, len); |
|
| 27 | 27 | if(len < olen) |
|
| 28 | 28 | for(i = len; i && i > len - 3; buf[--i] = '.'); |
|
| 29 | - | XSetForeground(dc->dpy, dc->gc, col[ColFG]); |
|
| 29 | + | XSetForeground(dc->dpy, dc->gc, col[invert ? ColBG : ColFG]); |
|
| 30 | 30 | if(dc->font.set) |
|
| 31 | 31 | XmbDrawString(dc->dpy, dc->drawable, dc->font.set, dc->gc, x, y, buf, len); |
|
| 32 | 32 | else |
|