aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor Lane Smith <cls@lubutu.com>2010-06-28 06:09:34 +0100
committerConnor Lane Smith <cls@lubutu.com>2010-06-28 06:09:34 +0100
commit18dcf738967a45208e880b72ce273afdd93ee6c7 (patch)
tree750ef101f905125871cd63e6734cbbae25f4cb44
parent9f3b0c6ea843340b87a045ea0afd2d1b33425eee (diff)
extended libdraw
-rw-r--r--dinput.c8
-rw-r--r--dmenu.c18
-rw-r--r--draw/Makefile4
-rw-r--r--draw/draw.h5
-rw-r--r--draw/drawsquare.c19
-rw-r--r--draw/drawtext.c6
6 files changed, 40 insertions, 20 deletions
diff --git a/dinput.c b/dinput.c
index 228780c..0bf2679 100644
--- a/dinput.c
+++ b/dinput.c
@@ -72,15 +72,15 @@ drawinput(void)
72 dc.y = 0; 72 dc.y = 0;
73 dc.w = mw; 73 dc.w = mw;
74 dc.h = mh; 74 dc.h = mh;
75 drawtext(&dc, NULL, normcol); 75 drawtext(&dc, NULL, normcol, False);
76 /* print prompt? */ 76 /* print prompt? */
77 if(prompt) { 77 if(prompt) {
78 dc.w = promptw; 78 dc.w = promptw;
79 drawtext(&dc, prompt, selcol); 79 drawtext(&dc, prompt, selcol, False);
80 dc.x += dc.w; 80 dc.x += dc.w;
81 } 81 }
82 dc.w = mw - dc.x; 82 dc.w = mw - dc.x;
83 drawtext(&dc, *text ? text : NULL, normcol); 83 drawtext(&dc, *text ? text : NULL, normcol, False);
84 drawcursor(); 84 drawcursor();
85 XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); 85 XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
86 XFlush(dpy); 86 XFlush(dpy);
@@ -233,7 +233,7 @@ run(void) {
233 233
234 /* main event loop */ 234 /* main event loop */
235 while(running && !XNextEvent(dpy, &ev)) 235 while(running && !XNextEvent(dpy, &ev))
236 switch (ev.type) { 236 switch(ev.type) {
237 case KeyPress: 237 case KeyPress:
238 kpress(&ev.xkey); 238 kpress(&ev.xkey);
239 break; 239 break;
diff --git a/dmenu.c b/dmenu.c
index 8c0ea41..8059f29 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -161,18 +161,18 @@ drawmenu(void) {
161 dc.y = 0; 161 dc.y = 0;
162 dc.w = mw; 162 dc.w = mw;
163 dc.h = mh; 163 dc.h = mh;
164 drawtext(&dc, NULL, normcol); 164 drawtext(&dc, NULL, normcol, False);
165 /* print prompt? */ 165 /* print prompt? */
166 if(prompt) { 166 if(prompt) {
167 dc.w = promptw; 167 dc.w = promptw;
168 drawtext(&dc, prompt, selcol); 168 drawtext(&dc, prompt, selcol, False);
169 dc.x += dc.w; 169 dc.x += dc.w;
170 } 170 }
171 dc.w = mw - dc.x; 171 dc.w = mw - dc.x;
172 /* print command */ 172 /* print command */
173 if(cmdw && item && lines == 0) 173 if(cmdw && item && lines == 0)
174 dc.w = cmdw; 174 dc.w = cmdw;
175 drawtext(&dc, *text ? text : NULL, normcol); 175 drawtext(&dc, *text ? text : NULL, normcol, False);
176 if(curr) { 176 if(curr) {
177 if(lines > 0) 177 if(lines > 0)
178 drawmenuv(); 178 drawmenuv();
@@ -189,16 +189,16 @@ drawmenuh(void) {
189 189
190 dc.x += cmdw; 190 dc.x += cmdw;
191 dc.w = spaceitem; 191 dc.w = spaceitem;
192 drawtext(&dc, curr->left ? "<" : NULL, normcol); 192 drawtext(&dc, curr->left ? "<" : NULL, normcol, False);
193 dc.x += dc.w; 193 dc.x += dc.w;
194 for(i = curr; i != next; i = i->right) { 194 for(i = curr; i != next; i = i->right) {
195 dc.w = MIN(textw(&dc, i->text), mw / 3); 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 dc.x += dc.w; 197 dc.x += dc.w;
198 } 198 }
199 dc.w = spaceitem; 199 dc.w = spaceitem;
200 dc.x = mw - dc.w; 200 dc.x = mw - dc.w;
201 drawtext(&dc, next ? ">" : NULL, normcol); 201 drawtext(&dc, next ? ">" : NULL, normcol, False);
202} 202}
203 203
204void 204void
@@ -209,11 +209,11 @@ drawmenuv(void) {
209 dc.h = dc.font.height + 2; 209 dc.h = dc.font.height + 2;
210 dc.y = dc.h; 210 dc.y = dc.h;
211 for(i = curr; i != next; i = i->right) { 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 dc.y += dc.h; 213 dc.y += dc.h;
214 } 214 }
215 dc.h = mh - dc.y; 215 dc.h = mh - dc.y;
216 drawtext(&dc, NULL, normcol); 216 drawtext(&dc, NULL, normcol, False);
217} 217}
218 218
219Bool 219Bool
@@ -456,7 +456,7 @@ run(void) {
456 456
457 /* main event loop */ 457 /* main event loop */
458 while(running && !XNextEvent(dpy, &ev)) 458 while(running && !XNextEvent(dpy, &ev))
459 switch (ev.type) { 459 switch(ev.type) {
460 case KeyPress: 460 case KeyPress:
461 kpress(&ev.xkey); 461 kpress(&ev.xkey);
462 break; 462 break;
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