diff options
| author | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-10 19:46:24 +0200 |
|---|---|---|
| committer | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-10 19:46:24 +0200 |
| commit | 39677ec76616fe4165ef92afb14db2bef2488e30 (patch) | |
| tree | 7ea1c021042b7d7da53660aa127af37847273a91 /draw.c | |
| parent | added new stuff (diff) | |
| download | dwm-39677ec76616fe4165ef92afb14db2bef2488e30.tar.gz dwm-39677ec76616fe4165ef92afb14db2bef2488e30.zip | |
several new changes, made gridmenu working
Diffstat (limited to '')
| -rw-r--r-- | draw.c | 41 |
1 files changed, 21 insertions, 20 deletions
| @@ -14,7 +14,7 @@ drawborder(Display *dpy, Brush *b) | |||
| 14 | { | 14 | { |
| 15 | XPoint points[5]; | 15 | XPoint points[5]; |
| 16 | XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter); | 16 | XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter); |
| 17 | XSetForeground(dpy, b->gc, b->color.border); | 17 | XSetForeground(dpy, b->gc, b->border); |
| 18 | points[0].x = b->rect.x; | 18 | points[0].x = b->rect.x; |
| 19 | points[0].y = b->rect.y; | 19 | points[0].y = b->rect.y; |
| 20 | points[1].x = b->rect.width - 1; | 20 | points[1].x = b->rect.width - 1; |
| @@ -29,54 +29,54 @@ drawborder(Display *dpy, Brush *b) | |||
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | void | 31 | void |
| 32 | draw(Display *dpy, Brush *b) | 32 | draw(Display *dpy, Brush *b, Bool border, const char *text) |
| 33 | { | 33 | { |
| 34 | unsigned int x, y, w, h, len; | 34 | unsigned int x, y, w, h, len; |
| 35 | static char buf[256]; | 35 | static char buf[256]; |
| 36 | XGCValues gcv; | 36 | XGCValues gcv; |
| 37 | 37 | ||
| 38 | XSetForeground(dpy, b->gc, b->color.bg); | 38 | XSetForeground(dpy, b->gc, b->bg); |
| 39 | XFillRectangles(dpy, b->drawable, b->gc, &b->rect, 1); | 39 | XFillRectangles(dpy, b->drawable, b->gc, &b->rect, 1); |
| 40 | 40 | ||
| 41 | if(b->border) | 41 | if(border) |
| 42 | drawborder(dpy, b); | 42 | drawborder(dpy, b); |
| 43 | 43 | ||
| 44 | if(!b->text) | 44 | if(!text) |
| 45 | return; | 45 | return; |
| 46 | 46 | ||
| 47 | len = strlen(b->text); | 47 | len = strlen(text); |
| 48 | if(len >= sizeof(buf)) | 48 | if(len >= sizeof(buf)) |
| 49 | len = sizeof(buf) - 1; | 49 | len = sizeof(buf) - 1; |
| 50 | memcpy(buf, b->text, len); | 50 | memcpy(buf, text, len); |
| 51 | buf[len] = 0; | 51 | buf[len] = 0; |
| 52 | 52 | ||
| 53 | h = b->font->ascent + b->font->descent; | 53 | h = b->font.ascent + b->font.descent; |
| 54 | y = b->rect.y + (b->rect.height / 2) - (h / 2) + b->font->ascent; | 54 | y = b->rect.y + (b->rect.height / 2) - (h / 2) + b->font.ascent; |
| 55 | x = b->rect.x + (h / 2); | 55 | x = b->rect.x + (h / 2); |
| 56 | 56 | ||
| 57 | /* shorten text if necessary */ | 57 | /* shorten text if necessary */ |
| 58 | while(len && (w = textwidth_l(b->font, buf, len)) > b->rect.width - h) | 58 | while(len && (w = textwidth_l(&b->font, buf, len)) > b->rect.width - h) |
| 59 | buf[--len] = 0; | 59 | buf[--len] = 0; |
| 60 | 60 | ||
| 61 | if(w > b->rect.width) | 61 | if(w > b->rect.width) |
| 62 | return; /* too long */ | 62 | return; /* too long */ |
| 63 | 63 | ||
| 64 | gcv.foreground = b->color.fg; | 64 | gcv.foreground = b->fg; |
| 65 | gcv.background = b->color.bg; | 65 | gcv.background = b->bg; |
| 66 | if(b->font->set) { | 66 | if(b->font.set) { |
| 67 | XChangeGC(dpy, b->gc, GCForeground | GCBackground, &gcv); | 67 | XChangeGC(dpy, b->gc, GCForeground | GCBackground, &gcv); |
| 68 | XmbDrawImageString(dpy, b->drawable, b->font->set, b->gc, | 68 | XmbDrawImageString(dpy, b->drawable, b->font.set, b->gc, |
| 69 | x, y, buf, len); | 69 | x, y, buf, len); |
| 70 | } | 70 | } |
| 71 | else { | 71 | else { |
| 72 | gcv.font = b->font->xfont->fid; | 72 | gcv.font = b->font.xfont->fid; |
| 73 | XChangeGC(dpy, b->gc, GCForeground | GCBackground | GCFont, &gcv); | 73 | XChangeGC(dpy, b->gc, GCForeground | GCBackground | GCFont, &gcv); |
| 74 | XDrawImageString(dpy, b->drawable, b->gc, x, y, buf, len); | 74 | XDrawImageString(dpy, b->drawable, b->gc, x, y, buf, len); |
| 75 | } | 75 | } |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | static unsigned long | 78 | static unsigned long |
| 79 | xloadcolor(Display *dpy, Colormap cmap, const char *colstr) | 79 | xloadcolors(Display *dpy, Colormap cmap, const char *colstr) |
| 80 | { | 80 | { |
| 81 | XColor color; | 81 | XColor color; |
| 82 | XAllocNamedColor(dpy, cmap, colstr, &color, &color); | 82 | XAllocNamedColor(dpy, cmap, colstr, &color, &color); |
| @@ -84,13 +84,13 @@ xloadcolor(Display *dpy, Colormap cmap, const char *colstr) | |||
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | void | 86 | void |
| 87 | loadcolor(Display *dpy, int screen, Color *c, | 87 | loadcolors(Display *dpy, int screen, Brush *b, |
| 88 | const char *bg, const char *fg, const char *border) | 88 | const char *bg, const char *fg, const char *border) |
| 89 | { | 89 | { |
| 90 | Colormap cmap = DefaultColormap(dpy, screen); | 90 | Colormap cmap = DefaultColormap(dpy, screen); |
| 91 | c->bg = xloadcolor(dpy, cmap, bg); | 91 | b->bg = xloadcolors(dpy, cmap, bg); |
| 92 | c->fg = xloadcolor(dpy, cmap, fg); | 92 | b->fg = xloadcolors(dpy, cmap, fg); |
| 93 | c->border = xloadcolor(dpy, cmap, border); | 93 | b->border = xloadcolors(dpy, cmap, border); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | unsigned int | 96 | unsigned int |
| @@ -160,4 +160,5 @@ loadfont(Display *dpy, Fnt *font, const char *fontstr) | |||
| 160 | font->ascent = font->xfont->ascent; | 160 | font->ascent = font->xfont->ascent; |
| 161 | font->descent = font->xfont->descent; | 161 | font->descent = font->xfont->descent; |
| 162 | } | 162 | } |
| 163 | font->height = font->ascent + font->descent; | ||
| 163 | } | 164 | } |
