dwm-meillo

diff draw.c @ 34:cd30cce52b78

added logo+description
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 09:32:22 +0200
parents e90449e03167
children 989178822938
line diff
     1.1 --- a/draw.c	Thu Jul 13 01:55:54 2006 +0200
     1.2 +++ b/draw.c	Thu Jul 13 09:32:22 2006 +0200
     1.3 @@ -11,39 +11,39 @@
     1.4  #include "wm.h"
     1.5  
     1.6  static void
     1.7 -drawborder(Brush *b)
     1.8 +drawborder(void)
     1.9  {
    1.10  	XPoint points[5];
    1.11 -	XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter);
    1.12 -	XSetForeground(dpy, b->gc, b->border);
    1.13 -	points[0].x = b->x;
    1.14 -	points[0].y = b->y;
    1.15 -	points[1].x = b->w - 1;
    1.16 +	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
    1.17 +	XSetForeground(dpy, dc.gc, dc.border);
    1.18 +	points[0].x = dc.x;
    1.19 +	points[0].y = dc.y;
    1.20 +	points[1].x = dc.w - 1;
    1.21  	points[1].y = 0;
    1.22  	points[2].x = 0;
    1.23 -	points[2].y = b->h - 1;
    1.24 -	points[3].x = -(b->w - 1);
    1.25 +	points[2].y = dc.h - 1;
    1.26 +	points[3].x = -(dc.w - 1);
    1.27  	points[3].y = 0;
    1.28  	points[4].x = 0;
    1.29 -	points[4].y = -(b->h - 1);
    1.30 -	XDrawLines(dpy, b->drawable, b->gc, points, 5, CoordModePrevious);
    1.31 +	points[4].y = -(dc.h - 1);
    1.32 +	XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
    1.33  }
    1.34  
    1.35  void
    1.36 -draw(Brush *b, Bool border, const char *text)
    1.37 +draw(Bool border, const char *text)
    1.38  {
    1.39  	int x, y, w, h;
    1.40  	unsigned int len;
    1.41  	static char buf[256];
    1.42  	XGCValues gcv;
    1.43 -	XRectangle r = { b->x, b->y, b->w, b->h };
    1.44 +	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
    1.45  
    1.46 -	XSetForeground(dpy, b->gc, b->bg);
    1.47 -	XFillRectangles(dpy, b->drawable, b->gc, &r, 1);
    1.48 +	XSetForeground(dpy, dc.gc, dc.bg);
    1.49 +	XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
    1.50  
    1.51  	w = 0;
    1.52  	if(border)
    1.53 -		drawborder(b);
    1.54 +		drawborder();
    1.55  
    1.56  	if(!text)
    1.57  		return;
    1.58 @@ -54,33 +54,33 @@
    1.59  	memcpy(buf, text, len);
    1.60  	buf[len] = 0;
    1.61  
    1.62 -	h = b->font.ascent + b->font.descent;
    1.63 -	y = b->y + (b->h / 2) - (h / 2) + b->font.ascent;
    1.64 -	x = b->x + (h / 2);
    1.65 +	h = dc.font.ascent + dc.font.descent;
    1.66 +	y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
    1.67 +	x = dc.x + (h / 2);
    1.68  
    1.69  	/* shorten text if necessary */
    1.70 -	while(len && (w = textnw(&b->font, buf, len)) > b->w - h)
    1.71 +	while(len && (w = textnw(&dc.font, buf, len)) > dc.w - h)
    1.72  		buf[--len] = 0;
    1.73  
    1.74 -	if(w > b->w)
    1.75 +	if(w > dc.w)
    1.76  		return; /* too long */
    1.77  
    1.78 -	gcv.foreground = b->fg;
    1.79 -	gcv.background = b->bg;
    1.80 -	if(b->font.set) {
    1.81 -		XChangeGC(dpy, b->gc, GCForeground | GCBackground, &gcv);
    1.82 -		XmbDrawImageString(dpy, b->drawable, b->font.set, b->gc,
    1.83 +	gcv.foreground = dc.fg;
    1.84 +	gcv.background = dc.bg;
    1.85 +	if(dc.font.set) {
    1.86 +		XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
    1.87 +		XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc,
    1.88  				x, y, buf, len);
    1.89  	}
    1.90  	else {
    1.91 -		gcv.font = b->font.xfont->fid;
    1.92 -		XChangeGC(dpy, b->gc, GCForeground | GCBackground | GCFont, &gcv);
    1.93 -		XDrawImageString(dpy, b->drawable, b->gc, x, y, buf, len);
    1.94 +		gcv.font = dc.font.xfont->fid;
    1.95 +		XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv);
    1.96 +		XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len);
    1.97  	}
    1.98  }
    1.99  
   1.100  static unsigned long
   1.101 -xloadcolors(Colormap cmap, const char *colstr)
   1.102 +xinitcolors(Colormap cmap, const char *colstr)
   1.103  {
   1.104  	XColor color;
   1.105  	XAllocNamedColor(dpy, cmap, colstr, &color, &color);
   1.106 @@ -88,13 +88,12 @@
   1.107  }
   1.108  
   1.109  void
   1.110 -loadcolors(int scr, Brush *b,
   1.111 -		const char *bg, const char *fg, const char *border)
   1.112 +initcolors(const char *bg, const char *fg, const char *border)
   1.113  {
   1.114 -	Colormap cmap = DefaultColormap(dpy, scr);
   1.115 -	b->bg = xloadcolors(cmap, bg);
   1.116 -	b->fg = xloadcolors(cmap, fg);
   1.117 -	b->border = xloadcolors(cmap, border);
   1.118 +	Colormap cmap = DefaultColormap(dpy, screen);
   1.119 +	dc.bg = xinitcolors(cmap, bg);
   1.120 +	dc.fg = xinitcolors(cmap, fg);
   1.121 +	dc.border = xinitcolors(cmap, border);
   1.122  }
   1.123  
   1.124  unsigned int
   1.125 @@ -121,7 +120,7 @@
   1.126  }
   1.127  
   1.128  void
   1.129 -loadfont(Fnt *font, const char *fontstr)
   1.130 +initfont(Fnt *font, const char *fontstr)
   1.131  {
   1.132  	char **missing, *def;
   1.133  	int i, n;
   1.134 @@ -164,7 +163,7 @@
   1.135  		if (!font->xfont)
   1.136  			font->xfont = XLoadQueryFont(dpy, "fixed");
   1.137  		if (!font->xfont)
   1.138 -			error("error, cannot load 'fixed' font\n");
   1.139 +			error("error, cannot init 'fixed' font\n");
   1.140  		font->ascent = font->xfont->ascent;
   1.141  		font->descent = font->xfont->descent;
   1.142  	}