extended libdraw

master
Connor Lane Smith 15 years ago
parent 9f3b0c6ea8
commit 18dcf73896
  1. 8
      dinput.c
  2. 18
      dmenu.c
  3. 4
      draw/Makefile
  4. 5
      draw/draw.h
  5. 19
      draw/drawsquare.c
  6. 6
      draw/drawtext.c

@ -72,15 +72,15 @@ drawinput(void)
dc.y = 0; dc.y = 0;
dc.w = mw; dc.w = mw;
dc.h = mh; dc.h = mh;
drawtext(&dc, NULL, normcol); drawtext(&dc, NULL, normcol, False);
/* print prompt? */ /* print prompt? */
if(prompt) { if(prompt) {
dc.w = promptw; dc.w = promptw;
drawtext(&dc, prompt, selcol); drawtext(&dc, prompt, selcol, False);
dc.x += dc.w; dc.x += dc.w;
} }
dc.w = mw - dc.x; dc.w = mw - dc.x;
drawtext(&dc, *text ? text : NULL, normcol); drawtext(&dc, *text ? text : NULL, normcol, False);
drawcursor(); drawcursor();
XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
XFlush(dpy); XFlush(dpy);
@ -233,7 +233,7 @@ run(void) {
/* main event loop */ /* main event loop */
while(running && !XNextEvent(dpy, &ev)) while(running && !XNextEvent(dpy, &ev))
switch (ev.type) { switch(ev.type) {
case KeyPress: case KeyPress:
kpress(&ev.xkey); kpress(&ev.xkey);
break; break;

@ -161,18 +161,18 @@ drawmenu(void) {
dc.y = 0; dc.y = 0;
dc.w = mw; dc.w = mw;
dc.h = mh; dc.h = mh;
drawtext(&dc, NULL, normcol); drawtext(&dc, NULL, normcol, False);
/* print prompt? */ /* print prompt? */
if(prompt) { if(prompt) {
dc.w = promptw; dc.w = promptw;
drawtext(&dc, prompt, selcol); drawtext(&dc, prompt, selcol, False);
dc.x += dc.w; dc.x += dc.w;
} }
dc.w = mw - dc.x; dc.w = mw - dc.x;
/* print command */ /* print command */
if(cmdw && item && lines == 0) if(cmdw && item && lines == 0)
dc.w = cmdw; dc.w = cmdw;
drawtext(&dc, *text ? text : NULL, normcol); drawtext(&dc, *text ? text : NULL, normcol, False);
if(curr) { if(curr) {
if(lines > 0) if(lines > 0)
drawmenuv(); drawmenuv();
@ -189,16 +189,16 @@ drawmenuh(void) {
dc.x += cmdw; dc.x += cmdw;
dc.w = spaceitem; dc.w = spaceitem;
drawtext(&dc, curr->left ? "<" : NULL, normcol); drawtext(&dc, curr->left ? "<" : NULL, normcol, False);
dc.x += dc.w; dc.x += dc.w;
for(i = curr; i != next; i = i->right) { for(i = curr; i != next; i = i->right) {
dc.w = MIN(textw(&dc, i->text), mw / 3); dc.w = MIN(textw(&dc, i->text), mw / 3);
drawtext(&dc, i->text, (sel == i) ? selcol : normcol); drawtext(&dc, i->text, (sel == i) ? selcol : normcol, False);
dc.x += dc.w; dc.x += dc.w;
} }
dc.w = spaceitem; dc.w = spaceitem;
dc.x = mw - dc.w; dc.x = mw - dc.w;
drawtext(&dc, next ? ">" : NULL, normcol); drawtext(&dc, next ? ">" : NULL, normcol, False);
} }
void void
@ -209,11 +209,11 @@ drawmenuv(void) {
dc.h = dc.font.height + 2; dc.h = dc.font.height + 2;
dc.y = dc.h; dc.y = dc.h;
for(i = curr; i != next; i = i->right) { for(i = curr; i != next; i = i->right) {
drawtext(&dc, i->text, (sel == i) ? selcol : normcol); drawtext(&dc, i->text, (sel == i) ? selcol : normcol, False);
dc.y += dc.h; dc.y += dc.h;
} }
dc.h = mh - dc.y; dc.h = mh - dc.y;
drawtext(&dc, NULL, normcol); drawtext(&dc, NULL, normcol, False);
} }
Bool Bool
@ -456,7 +456,7 @@ run(void) {
/* main event loop */ /* main event loop */
while(running && !XNextEvent(dpy, &ev)) while(running && !XNextEvent(dpy, &ev))
switch (ev.type) { switch(ev.type) {
case KeyPress: case KeyPress:
kpress(&ev.xkey); kpress(&ev.xkey);
break; break;

@ -3,8 +3,8 @@
include ../config.mk include ../config.mk
SRC = cleanupdraw.c setupdraw.c drawtext.c eprint.c getcolor.c initfont.c \ SRC = cleanupdraw.c drawsquare.c drawtext.c eprint.c getcolor.c initfont.c \
textnw.c textw.c setupdraw.c textnw.c textw.c
OBJ = ${SRC:.c=.o} OBJ = ${SRC:.c=.o}
all: libdraw.a all: libdraw.a

@ -2,7 +2,7 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
/* enums */ /* enums */
enum { ColFG, ColBG, ColLast }; enum { ColBorder, ColFG, ColBG, ColLast };
/* typedefs */ /* typedefs */
typedef struct { typedef struct {
@ -21,7 +21,8 @@ typedef struct {
/* forward declarations */ /* forward declarations */
void cleanupdraw(DC *dc); 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, ...); void eprint(const char *fmt, ...);
unsigned long getcolor(DC *dc, const char *colstr); unsigned long getcolor(DC *dc, const char *colstr);
void initfont(DC *dc, const char *fontstr); void initfont(DC *dc, const char *fontstr);

@ -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);
}

@ -6,12 +6,12 @@
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
void 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]; char buf[256];
int i, x, y, h, len, olen; int i, x, y, h, len, olen;
XRectangle r = { dc->x, dc->y, dc->w, dc->h }; 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); XFillRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1);
if(!text) if(!text)
return; return;
@ -26,7 +26,7 @@ drawtext(DC *dc, const char *text, unsigned long col[ColLast]) {
memcpy(buf, text, len); memcpy(buf, text, len);
if(len < olen) if(len < olen)
for(i = len; i && i > len - 3; buf[--i] = '.'); 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) if(dc->font.set)
XmbDrawString(dc->dpy, dc->drawable, dc->font.set, dc->gc, x, y, buf, len); XmbDrawString(dc->dpy, dc->drawable, dc->font.set, dc->gc, x, y, buf, len);
else else

Loading…
Cancel
Save