diff options
Diffstat (limited to 'draw')
| -rw-r--r-- | draw/Makefile | 4 | ||||
| -rw-r--r-- | draw/draw.h | 5 | ||||
| -rw-r--r-- | draw/drawsquare.c | 19 | ||||
| -rw-r--r-- | draw/drawtext.c | 6 |
4 files changed, 27 insertions, 7 deletions
diff --git a/draw/Makefile b/draw/Makefile index 1f72b61..4b39490 100644 --- a/draw/Makefile +++ b/draw/Makefile | |||
| @@ -3,8 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | include ../config.mk | 4 | include ../config.mk |
| 5 | 5 | ||
| 6 | SRC = cleanupdraw.c setupdraw.c drawtext.c eprint.c getcolor.c initfont.c \ | 6 | SRC = cleanupdraw.c drawsquare.c drawtext.c eprint.c getcolor.c initfont.c \ |
| 7 | textnw.c textw.c | 7 | setupdraw.c textnw.c textw.c |
| 8 | OBJ = ${SRC:.c=.o} | 8 | OBJ = ${SRC:.c=.o} |
| 9 | 9 | ||
| 10 | all: libdraw.a | 10 | all: libdraw.a |
diff --git a/draw/draw.h b/draw/draw.h index 4646a18..f282392 100644 --- a/draw/draw.h +++ b/draw/draw.h | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | #include <X11/Xlib.h> | 2 | #include <X11/Xlib.h> |
| 3 | 3 | ||
| 4 | /* enums */ | 4 | /* enums */ |
| 5 | enum { ColFG, ColBG, ColLast }; | 5 | enum { ColBorder, ColFG, ColBG, ColLast }; |
| 6 | 6 | ||
| 7 | /* typedefs */ | 7 | /* typedefs */ |
| 8 | typedef struct { | 8 | typedef struct { |
| @@ -21,7 +21,8 @@ typedef struct { | |||
| 21 | 21 | ||
| 22 | /* forward declarations */ | 22 | /* forward declarations */ |
| 23 | void cleanupdraw(DC *dc); | 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 | void eprint(const char *fmt, ...); | 26 | void eprint(const char *fmt, ...); |
| 26 | unsigned long getcolor(DC *dc, const char *colstr); | 27 | unsigned long getcolor(DC *dc, const char *colstr); |
| 27 | void initfont(DC *dc, const char *fontstr); | 28 | void initfont(DC *dc, const char *fontstr); |
diff --git a/draw/drawsquare.c b/draw/drawsquare.c new file mode 100644 index 0000000..8899043 --- /dev/null +++ b/draw/drawsquare.c | |||
| @@ -0,0 +1,19 @@ | |||
| 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 | } | ||
diff --git a/draw/drawtext.c b/draw/drawtext.c index cf7b015..d347b36 100644 --- a/draw/drawtext.c +++ b/draw/drawtext.c | |||
| @@ -6,12 +6,12 @@ | |||
| 6 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | 6 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 7 | 7 | ||
| 8 | void | 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 | char buf[256]; | 10 | char buf[256]; |
| 11 | int i, x, y, h, len, olen; | 11 | int i, x, y, h, len, olen; |
| 12 | XRectangle r = { dc->x, dc->y, dc->w, dc->h }; | 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 | XFillRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1); | 15 | XFillRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1); |
| 16 | if(!text) | 16 | if(!text) |
| 17 | return; | 17 | return; |
| @@ -26,7 +26,7 @@ drawtext(DC *dc, const char *text, unsigned long col[ColLast]) { | |||
| 26 | memcpy(buf, text, len); | 26 | memcpy(buf, text, len); |
| 27 | if(len < olen) | 27 | if(len < olen) |
| 28 | for(i = len; i && i > len - 3; buf[--i] = '.'); | 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 | if(dc->font.set) | 30 | if(dc->font.set) |
| 31 | XmbDrawString(dc->dpy, dc->drawable, dc->font.set, dc->gc, x, y, buf, len); | 31 | XmbDrawString(dc->dpy, dc->drawable, dc->font.set, dc->gc, x, y, buf, len); |
| 32 | else | 32 | else |
