dwm-meillo

diff draw.c @ 3:e969f3575b7a

several new changes, made gridmenu working
author Anselm R. Garbe <garbeam@wmii.de>
date Mon, 10 Jul 2006 19:46:24 +0200
parents a79188fe4a40
children e5018cae273f
line diff
     1.1 --- a/draw.c	Mon Jul 10 18:35:39 2006 +0200
     1.2 +++ b/draw.c	Mon Jul 10 19:46:24 2006 +0200
     1.3 @@ -14,7 +14,7 @@
     1.4  {
     1.5  	XPoint points[5];
     1.6  	XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter);
     1.7 -	XSetForeground(dpy, b->gc, b->color.border);
     1.8 +	XSetForeground(dpy, b->gc, b->border);
     1.9  	points[0].x = b->rect.x;
    1.10  	points[0].y = b->rect.y;
    1.11  	points[1].x = b->rect.width - 1;
    1.12 @@ -29,54 +29,54 @@
    1.13  }
    1.14  
    1.15  void
    1.16 -draw(Display *dpy, Brush *b)
    1.17 +draw(Display *dpy, Brush *b, Bool border, const char *text)
    1.18  {
    1.19  	unsigned int x, y, w, h, len;
    1.20  	static char buf[256];
    1.21  	XGCValues gcv;
    1.22  
    1.23 -	XSetForeground(dpy, b->gc, b->color.bg);
    1.24 +	XSetForeground(dpy, b->gc, b->bg);
    1.25  	XFillRectangles(dpy, b->drawable, b->gc, &b->rect, 1);
    1.26  
    1.27 -	if(b->border)
    1.28 +	if(border)
    1.29  		drawborder(dpy, b);
    1.30  
    1.31 -	if(!b->text)
    1.32 +	if(!text)
    1.33  		return;
    1.34  
    1.35 -	len = strlen(b->text);
    1.36 +	len = strlen(text);
    1.37  	if(len >= sizeof(buf))
    1.38  		len = sizeof(buf) - 1;
    1.39 -	memcpy(buf, b->text, len);
    1.40 +	memcpy(buf, text, len);
    1.41  	buf[len] = 0;
    1.42  
    1.43 -	h = b->font->ascent + b->font->descent;
    1.44 -	y = b->rect.y + (b->rect.height / 2) - (h / 2) + b->font->ascent;
    1.45 +	h = b->font.ascent + b->font.descent;
    1.46 +	y = b->rect.y + (b->rect.height / 2) - (h / 2) + b->font.ascent;
    1.47  	x = b->rect.x + (h / 2);
    1.48  
    1.49  	/* shorten text if necessary */
    1.50 -	while(len && (w = textwidth_l(b->font, buf, len)) > b->rect.width - h)
    1.51 +	while(len && (w = textwidth_l(&b->font, buf, len)) > b->rect.width - h)
    1.52  		buf[--len] = 0;
    1.53  
    1.54  	if(w > b->rect.width)
    1.55  		return; /* too long */
    1.56  
    1.57 -	gcv.foreground = b->color.fg;
    1.58 -	gcv.background = b->color.bg;
    1.59 -	if(b->font->set) {
    1.60 +	gcv.foreground = b->fg;
    1.61 +	gcv.background = b->bg;
    1.62 +	if(b->font.set) {
    1.63  		XChangeGC(dpy, b->gc, GCForeground | GCBackground, &gcv);
    1.64 -		XmbDrawImageString(dpy, b->drawable, b->font->set, b->gc,
    1.65 +		XmbDrawImageString(dpy, b->drawable, b->font.set, b->gc,
    1.66  				x, y, buf, len);
    1.67  	}
    1.68  	else {
    1.69 -		gcv.font = b->font->xfont->fid;
    1.70 +		gcv.font = b->font.xfont->fid;
    1.71  		XChangeGC(dpy, b->gc, GCForeground | GCBackground | GCFont, &gcv);
    1.72  		XDrawImageString(dpy, b->drawable, b->gc, x, y, buf, len);
    1.73  	}
    1.74  }
    1.75  
    1.76  static unsigned long
    1.77 -xloadcolor(Display *dpy, Colormap cmap, const char *colstr)
    1.78 +xloadcolors(Display *dpy, Colormap cmap, const char *colstr)
    1.79  {
    1.80  	XColor color;
    1.81  	XAllocNamedColor(dpy, cmap, colstr, &color, &color);
    1.82 @@ -84,13 +84,13 @@
    1.83  }
    1.84  
    1.85  void
    1.86 -loadcolor(Display *dpy, int screen, Color *c,
    1.87 +loadcolors(Display *dpy, int screen, Brush *b,
    1.88  		const char *bg, const char *fg, const char *border)
    1.89  {
    1.90  	Colormap cmap = DefaultColormap(dpy, screen);
    1.91 -	c->bg = xloadcolor(dpy, cmap, bg);
    1.92 -	c->fg = xloadcolor(dpy, cmap, fg);
    1.93 -	c->border = xloadcolor(dpy, cmap, border);
    1.94 +	b->bg = xloadcolors(dpy, cmap, bg);
    1.95 +	b->fg = xloadcolors(dpy, cmap, fg);
    1.96 +	b->border = xloadcolors(dpy, cmap, border);
    1.97  }
    1.98  
    1.99  unsigned int
   1.100 @@ -160,4 +160,5 @@
   1.101  		font->ascent = font->xfont->ascent;
   1.102  		font->descent = font->xfont->descent;
   1.103  	}
   1.104 +	font->height = font->ascent + font->descent;
   1.105  }