aboutsummaryrefslogtreecommitdiff
path: root/draw
diff options
context:
space:
mode:
Diffstat (limited to 'draw')
-rw-r--r--draw/Makefile4
-rw-r--r--draw/draw.h5
-rw-r--r--draw/drawsquare.c19
-rw-r--r--draw/drawtext.c6
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
4include ../config.mk 4include ../config.mk
5 5
6SRC = cleanupdraw.c setupdraw.c drawtext.c eprint.c getcolor.c initfont.c \ 6SRC = cleanupdraw.c drawsquare.c drawtext.c eprint.c getcolor.c initfont.c \
7textnw.c textw.c 7setupdraw.c textnw.c textw.c
8OBJ = ${SRC:.c=.o} 8OBJ = ${SRC:.c=.o}
9 9
10all: libdraw.a 10all: 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 */
5enum { ColFG, ColBG, ColLast }; 5enum { ColBorder, ColFG, ColBG, ColLast };
6 6
7/* typedefs */ 7/* typedefs */
8typedef struct { 8typedef struct {
@@ -21,7 +21,8 @@ typedef struct {
21 21
22/* forward declarations */ 22/* forward declarations */
23void cleanupdraw(DC *dc); 23void cleanupdraw(DC *dc);
24void drawtext(DC *dc, const char *text, unsigned long col[ColLast]); 24void drawsquare(DC *dc, Bool filled, unsigned long col[ColLast], Bool invert);
25void drawtext(DC *dc, const char *text, unsigned long col[ColLast], Bool invert);
25void eprint(const char *fmt, ...); 26void eprint(const char *fmt, ...);
26unsigned long getcolor(DC *dc, const char *colstr); 27unsigned long getcolor(DC *dc, const char *colstr);
27void initfont(DC *dc, const char *fontstr); 28void 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
5void
6drawsquare(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
8void 8void
9drawtext(DC *dc, const char *text, unsigned long col[ColLast]) { 9drawtext(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