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 @@
include ../config.mk
-SRC = cleanupdraw.c setupdraw.c drawtext.c eprint.c getcolor.c initfont.c \
-textnw.c textw.c
+SRC = cleanupdraw.c drawsquare.c drawtext.c eprint.c getcolor.c initfont.c \
+setupdraw.c textnw.c textw.c
OBJ = ${SRC:.c=.o}
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 @@
#include <X11/Xlib.h>
/* enums */
-enum { ColFG, ColBG, ColLast };
+enum { ColBorder, ColFG, ColBG, ColLast };
/* typedefs */
typedef struct {
@@ -21,7 +21,8 @@ typedef struct {
/* forward declarations */
void cleanupdraw(DC *dc);
-void drawtext(DC *dc, const char *text, unsigned long col[ColLast]);
+void drawsquare(DC *dc, Bool filled, unsigned long col[ColLast], Bool invert);
+void drawtext(DC *dc, const char *text, unsigned long col[ColLast], Bool invert);
void eprint(const char *fmt, ...);
unsigned long getcolor(DC *dc, const char *colstr);
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 @@
+/* See LICENSE file for copyright and license details. */
+#include <X11/Xlib.h>
+#include "draw.h"
+
+void
+drawsquare(DC *dc, Bool filled, unsigned long col[ColLast], Bool invert) {
+ int n;
+ XRectangle r = { dc->x, dc->y, dc->w, dc->h };
+
+ XSetForeground(dc->dpy, dc->gc, col[invert ? ColBG : ColFG]);
+ n = ((dc->font.ascent + dc->font.descent + 2) / 4) + (filled ? 1 : 0);
+ r.width = r.height = n;
+ r.x = dc->x + 1;
+ r.y = dc->y + 1;
+ if(filled)
+ XFillRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1);
+ else
+ XDrawRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1);
+}
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 @@
#define MIN(a, b) ((a) < (b) ? (a) : (b))
void
-drawtext(DC *dc, const char *text, unsigned long col[ColLast]) {
+drawtext(DC *dc, const char *text, unsigned long col[ColLast], Bool invert) {
char buf[256];
int i, x, y, h, len, olen;
XRectangle r = { dc->x, dc->y, dc->w, dc->h };
- XSetForeground(dc->dpy, dc->gc, col[ColBG]);
+ XSetForeground(dc->dpy, dc->gc, col[invert ? ColFG : ColBG]);
XFillRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1);
if(!text)
return;
@@ -26,7 +26,7 @@ drawtext(DC *dc, const char *text, unsigned long col[ColLast]) {
memcpy(buf, text, len);
if(len < olen)
for(i = len; i && i > len - 3; buf[--i] = '.');
- XSetForeground(dc->dpy, dc->gc, col[ColFG]);
+ XSetForeground(dc->dpy, dc->gc, col[invert ? ColBG : ColFG]);
if(dc->font.set)
XmbDrawString(dc->dpy, dc->drawable, dc->font.set, dc->gc, x, y, buf, len);
else