wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit d7fea5865fafe49ac811dd4a8a265eead168f3b4
parent ac473e4ebd1ba1cb190196d56df47725efab6892
Author: Anselm R. Garbe <garbeam@wmii.de>
Date:   Tue, 13 Jun 2006 15:57:00 +0200

s/draw.c/label.c/


Diffstat:
liblitz/Makefile | 2+-
liblitz/blitz.h | 8++++----
liblitz/draw.c | 124-------------------------------------------------------------------------------
liblitz/label.c | 124+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 129 insertions(+), 129 deletions(-)

diff --git a/liblitz/Makefile b/liblitz/Makefile @@ -6,7 +6,7 @@ include ../config.mk CFLAGS += -I../libixp -I../libcext LDFLAGS += -L../libixp -lixp -L../libcext -lcext -SRC = blitz.c color.c font.c draw.c window.c +SRC = blitz.c color.c font.c label.c window.c OBJ = ${SRC:.c=.o} all: liblitz.a diff --git a/liblitz/blitz.h b/liblitz/blitz.h @@ -95,7 +95,10 @@ Blitz __blitz; /* blitz.c */ void blitz_x11_init(Display *dpy); -/* draw.c */ +/* color.c */ +int blitz_loadcolor(BlitzColor *c, char *colstr); + +/* label.c */ void blitz_drawlabel(BlitzDraw *d); void blitz_drawborder(BlitzDraw *d); @@ -103,9 +106,6 @@ void blitz_drawborder(BlitzDraw *d); unsigned int blitz_textwidth(BlitzFont *font, char *text); void blitz_loadfont(BlitzFont *font, char *fontstr); -/* color.c */ -int blitz_loadcolor(BlitzColor *c, char *colstr); - /* window.c */ BlitzWin *blitz_create_win(unsigned long mask, int x, int y, int w, int h); diff --git a/liblitz/draw.c b/liblitz/draw.c @@ -1,124 +0,0 @@ -/* - * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> - * See LICENSE file for license details. - */ - -#include <stdio.h> -#include <string.h> -#include <cext.h> - -#include "blitz.h" - -static void -xdrawbg(BlitzDraw *d) -{ - XRectangle rect[4]; - XSetForeground(__blitz.display, d->gc, d->color.bg); - if (!d->notch) { - XFillRectangles(__blitz.display, d->drawable, d->gc, &d->rect, 1); - return; - } - rect[0] = d->rect; - rect[0].height = d->notch->y; - rect[1] = d->rect; - rect[1].y = d->notch->y; - rect[1].width = d->notch->x; - rect[1].height = d->notch->height; - rect[2].x = d->notch->x + d->notch->width; - rect[2].y = d->notch->y; - rect[2].width = d->rect.width - (d->notch->x + d->notch->width); - rect[2].height = d->notch->height; - rect[3] = d->rect; - rect[3].y = d->notch->y + d->notch->height; - rect[3].height = d->rect.height - (d->notch->y + d->notch->height); - XFillRectangles(__blitz.display, d->drawable, d->gc, rect, 4); -} - -void -blitz_drawborder(BlitzDraw *d) -{ - XPoint points[5]; - - XSetLineAttributes(__blitz.display, d->gc, 1, LineSolid, CapButt, JoinMiter); - XSetForeground(__blitz.display, d->gc, d->color.border); - points[0].x = d->rect.x; - points[0].y = d->rect.y; - points[1].x = d->rect.width - 1; - points[1].y = 0; - points[2].x = 0; - points[2].y = d->rect.height - 1; - points[3].x = -(d->rect.width - 1); - points[3].y = 0; - points[4].x = 0; - points[4].y = -(d->rect.height - 1); - XDrawLines(__blitz.display, d->drawable, d->gc, points, 5, CoordModePrevious); -} - -static void -xdrawtext(BlitzDraw *d) -{ - unsigned int x = 0, y = 0, w = 1, h = 1, shortened = 0; - unsigned int len = 0; - static char text[2048]; - XGCValues gcv; - - if (!d->data) - return; - - len = strlen(d->data); - cext_strlcpy(text, d->data, sizeof(text)); - gcv.foreground = d->color.fg; - gcv.background = d->color.bg; - if(d->font.set) - XChangeGC(__blitz.display, d->gc, GCForeground | GCBackground, &gcv); - else { - gcv.font = d->font.xfont->fid; - XChangeGC(__blitz.display, d->gc, GCForeground | GCBackground | GCFont, &gcv); - } - - h = d->font.ascent + d->font.descent; - y = d->rect.y + d->rect.height / 2 - h / 2 + d->font.ascent; - - /* shorten text if necessary */ - while (len && (w = blitz_textwidth(&d->font, text)) > d->rect.width) { - text[len - 1] = 0; - len--; - shortened = 1; - } - - if (w > d->rect.width) - return; - - /* mark shortened info in the string */ - if (shortened) { - if (len > 3) - text[len - 3] = '.'; - if (len > 2) - text[len - 2] = '.'; - if (len > 1) - text[len - 1] = '.'; - } - switch (d->align) { - case EAST: - x = d->rect.x + d->rect.width - (h / 2 + w); - break; - case CENTER: - x = d->rect.x + (d->rect.width - w) / 2; - break; - default: - x = d->rect.x + h / 2; - break; - } - if(d->font.set) - XmbDrawString(__blitz.display, d->drawable, d->font.set, d->gc, x, y, text, len); - else - XDrawString(__blitz.display, d->drawable, d->gc, x, y, text, len); -} - -void -blitz_drawlabel(BlitzDraw * d) -{ - xdrawbg(d); - if (d->data) - xdrawtext(d); -} diff --git a/liblitz/label.c b/liblitz/label.c @@ -0,0 +1,124 @@ +/* + * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> + * See LICENSE file for license details. + */ + +#include <stdio.h> +#include <string.h> +#include <cext.h> + +#include "blitz.h" + +static void +xdrawbg(BlitzDraw *d) +{ + XRectangle rect[4]; + XSetForeground(__blitz.display, d->gc, d->color.bg); + if (!d->notch) { + XFillRectangles(__blitz.display, d->drawable, d->gc, &d->rect, 1); + return; + } + rect[0] = d->rect; + rect[0].height = d->notch->y; + rect[1] = d->rect; + rect[1].y = d->notch->y; + rect[1].width = d->notch->x; + rect[1].height = d->notch->height; + rect[2].x = d->notch->x + d->notch->width; + rect[2].y = d->notch->y; + rect[2].width = d->rect.width - (d->notch->x + d->notch->width); + rect[2].height = d->notch->height; + rect[3] = d->rect; + rect[3].y = d->notch->y + d->notch->height; + rect[3].height = d->rect.height - (d->notch->y + d->notch->height); + XFillRectangles(__blitz.display, d->drawable, d->gc, rect, 4); +} + +void +blitz_drawborder(BlitzDraw *d) +{ + XPoint points[5]; + + XSetLineAttributes(__blitz.display, d->gc, 1, LineSolid, CapButt, JoinMiter); + XSetForeground(__blitz.display, d->gc, d->color.border); + points[0].x = d->rect.x; + points[0].y = d->rect.y; + points[1].x = d->rect.width - 1; + points[1].y = 0; + points[2].x = 0; + points[2].y = d->rect.height - 1; + points[3].x = -(d->rect.width - 1); + points[3].y = 0; + points[4].x = 0; + points[4].y = -(d->rect.height - 1); + XDrawLines(__blitz.display, d->drawable, d->gc, points, 5, CoordModePrevious); +} + +static void +xdrawtext(BlitzDraw *d) +{ + unsigned int x = 0, y = 0, w = 1, h = 1, shortened = 0; + unsigned int len = 0; + static char text[2048]; + XGCValues gcv; + + if (!d->data) + return; + + len = strlen(d->data); + cext_strlcpy(text, d->data, sizeof(text)); + gcv.foreground = d->color.fg; + gcv.background = d->color.bg; + if(d->font.set) + XChangeGC(__blitz.display, d->gc, GCForeground | GCBackground, &gcv); + else { + gcv.font = d->font.xfont->fid; + XChangeGC(__blitz.display, d->gc, GCForeground | GCBackground | GCFont, &gcv); + } + + h = d->font.ascent + d->font.descent; + y = d->rect.y + d->rect.height / 2 - h / 2 + d->font.ascent; + + /* shorten text if necessary */ + while (len && (w = blitz_textwidth(&d->font, text)) > d->rect.width) { + text[len - 1] = 0; + len--; + shortened = 1; + } + + if (w > d->rect.width) + return; + + /* mark shortened info in the string */ + if (shortened) { + if (len > 3) + text[len - 3] = '.'; + if (len > 2) + text[len - 2] = '.'; + if (len > 1) + text[len - 1] = '.'; + } + switch (d->align) { + case EAST: + x = d->rect.x + d->rect.width - (h / 2 + w); + break; + case CENTER: + x = d->rect.x + (d->rect.width - w) / 2; + break; + default: + x = d->rect.x + h / 2; + break; + } + if(d->font.set) + XmbDrawString(__blitz.display, d->drawable, d->font.set, d->gc, x, y, text, len); + else + XDrawString(__blitz.display, d->drawable, d->gc, x, y, text, len); +} + +void +blitz_drawlabel(BlitzDraw * d) +{ + xdrawbg(d); + if (d->data) + xdrawtext(d); +}