2 * draw.c - draw functions
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 extern Client
*clients
, *sel
, *stack
; /* global client list and stack */
31 drawtext(Display
*disp
, DC drawcontext
, Drawable drawable
, const char *text
, unsigned long col
[ColLast
])
36 XRectangle r
= { drawcontext
.x
, drawcontext
.y
, drawcontext
.w
, drawcontext
.h
};
38 XSetForeground(disp
, drawcontext
.gc
, col
[ColBG
]);
39 XFillRectangles(disp
, drawable
, drawcontext
.gc
, &r
, 1);
43 olen
= len
= a_strlen(text
);
44 if(len
>= sizeof(buf
))
45 len
= sizeof(buf
) - 1;
46 memcpy(buf
, text
, len
);
48 h
= drawcontext
.font
.ascent
+ drawcontext
.font
.descent
;
49 y
= drawcontext
.y
+ (drawcontext
.h
/ 2) - (h
/ 2) + drawcontext
.font
.ascent
;
50 x
= drawcontext
.x
+ (h
/ 2);
51 /* shorten text if necessary */
52 while(len
&& (w
= textnw(drawcontext
.font
.set
, drawcontext
.font
.xfont
, buf
, len
)) > drawcontext
.w
- h
)
55 return; /* too long */
65 XSetForeground(disp
, drawcontext
.gc
, col
[ColFG
]);
66 if(drawcontext
.font
.set
)
67 XmbDrawString(disp
, drawable
, drawcontext
.font
.set
, drawcontext
.gc
, x
, y
, buf
, len
);
69 XDrawString(disp
, drawable
, drawcontext
.gc
, x
, y
, buf
, len
);
73 drawsquare(Display
*disp
, DC drawcontext
, Drawable drawable
, Bool filled
, unsigned long col
)
77 XRectangle r
= { drawcontext
.x
, drawcontext
.y
, drawcontext
.w
, drawcontext
.h
};
80 XChangeGC(disp
, drawcontext
.gc
, GCForeground
, &gcv
);
81 x
= (drawcontext
.font
.ascent
+ drawcontext
.font
.descent
+ 2) / 4;
82 r
.x
= drawcontext
.x
+ 1;
83 r
.y
= drawcontext
.y
+ 1;
84 r
.width
= r
.height
= x
;
87 r
.width
++; r
.height
++;
88 XFillRectangles(disp
, drawable
, drawcontext
.gc
, &r
, 1);
91 XDrawRectangles(disp
, drawable
, drawcontext
.gc
, &r
, 1);
95 textnw(XFontSet set
, XFontStruct
*xfont
, const char *text
, int len
)
101 XmbTextExtents(set
, text
, len
, NULL
, &r
);
104 return XTextWidth(xfont
, text
, len
);