removed obsolete stuff from liblitz

This commit is contained in:
Anselm R. Garbe 2006-06-20 15:47:08 +02:00
parent 03ea172fa4
commit 4f833eb4e4
4 changed files with 60 additions and 198 deletions

View File

@ -40,7 +40,7 @@ static unsigned int curroff = 0;
static unsigned int cmdw = 0;
static unsigned int twidth = 0;
static unsigned int cwidth = 0;
static BlitzDraw draw = { 0 };
static BlitzWidget *draw = nil;
static const int seek = 30; /* 30px */
static void draw_menu(void);
@ -71,7 +71,7 @@ update_offsets()
return;
for(i = curroff; i < item.size; i++) {
tw = blitz_textwidth(&draw.font, item.data[i]);
tw = blitz_textwidth(draw->font, item.data[i]);
if(tw > irect.width / 3)
tw = irect.width / 3;
w += tw + irect.height;
@ -82,7 +82,7 @@ update_offsets()
w = cmdw + 2 * seek;
for(i = curroff; i > 0; i--) {
tw = blitz_textwidth(&draw.font, item.data[i]);
tw = blitz_textwidth(draw->font, item.data[i]);
if(tw > irect.width / 3)
tw = irect.width / 3;
w += tw + irect.height;
@ -129,69 +129,67 @@ draw_menu()
{
unsigned int i, offx = 0;
draw.align = WEST;
draw->align = WEST;
draw.rect = irect;
draw.rect.x = 0;
draw.rect.y = 0;
draw.color = normcolor;
draw.data = nil;
blitz_drawlabel(&draw);
draw->rect = irect;
draw->rect.x = 0;
draw->rect.y = 0;
draw->color = normcolor;
draw->text = nil;
draw->draw(draw);
/* print command */
if(!title || text[0]) {
draw.data = text;
draw.color = normcolor;
draw->text = text;
draw->color = normcolor;
cmdw = cwidth;
if(cmdw && item.size)
draw.rect.width = cmdw;
blitz_drawlabel(&draw);
draw->rect.width = cmdw;
draw->draw(draw);
}
else {
cmdw = twidth;
draw.data = title;
draw.color = selcolor;
draw.rect.width = cmdw;
blitz_drawlabel(&draw);
blitz_drawborder(&draw);
draw->text = title;
draw->color = selcolor;
draw->rect.width = cmdw;
draw->draw(draw);
}
offx += draw.rect.width;
offx += draw->rect.width;
draw.align = CENTER;
draw->align = CENTER;
if(item.size) {
draw.color = normcolor;
draw.data = prevoff < curroff ? "<" : nil;
draw.rect.x = offx;
draw.rect.width = seek;
offx += draw.rect.width;
blitz_drawlabel(&draw);
draw->color = normcolor;
draw->text = prevoff < curroff ? "<" : nil;
draw->rect.x = offx;
draw->rect.width = seek;
offx += draw->rect.width;
draw->draw(draw);
/* determine maximum items */
for(i = curroff; i < nextoff; i++) {
draw.data = item.data[i];
draw.rect.x = offx;
draw.rect.width = blitz_textwidth(&draw.font, draw.data);
if(draw.rect.width > irect.width / 3)
draw.rect.width = irect.width / 3;
draw.rect.width += irect.height;
draw->text = item.data[i];
draw->rect.x = offx;
draw->rect.width = blitz_textwidth(draw->font, draw->text);
if(draw->rect.width > irect.width / 3)
draw->rect.width = irect.width / 3;
draw->rect.width += irect.height;
if(sel == i) {
draw.color = selcolor;
blitz_drawlabel(&draw);
blitz_drawborder(&draw);
draw->color = selcolor;
draw->draw(draw);
} else {
draw.color = normcolor;
blitz_drawlabel(&draw);
draw->color = normcolor;
draw->draw(draw);
}
offx += draw.rect.width;
offx += draw->rect.width;
}
draw.color = normcolor;
draw.data = item.size > nextoff ? ">" : nil;
draw.rect.x = irect.width - seek;
draw.rect.width = seek;
blitz_drawlabel(&draw);
draw->color = normcolor;
draw->text = item.size > nextoff ? ">" : nil;
draw->rect.x = irect.width - seek;
draw->rect.width = seek;
draw->draw(draw);
}
XCopyArea(dpy, draw.drawable, win, draw.gc, 0, 0, irect.width,
XCopyArea(dpy, draw->drawable, win, draw->gc, 0, 0, irect.width,
irect.height, 0, 0);
XSync(dpy, False);
}
@ -346,6 +344,9 @@ main(int argc, char *argv[])
int i;
XSetWindowAttributes wa;
char *maxname, *p;
BlitzFont font;
GC gc;
Drawable pmap;
XEvent ev;
/* command line args */
@ -387,10 +388,11 @@ main(int argc, char *argv[])
/* set font and colors */
blitz_x11_init(dpy);
draw.font.fontstr = getenv("WMII_FONT");
if (!draw.font.fontstr)
draw.font.fontstr = strdup(BLITZ_FONT);
blitz_loadfont(&draw.font);
font.fontstr = getenv("WMII_FONT");
if (!font.fontstr)
font.fontstr = strdup(BLITZ_FONT);
blitz_loadfont(&font);
if((p = getenv("WMII_NORMCOLORS")))
cext_strlcpy(normcolor.colstr, p, sizeof(normcolor.colstr));
@ -410,7 +412,7 @@ main(int argc, char *argv[])
| SubstructureRedirectMask | SubstructureNotifyMask;
irect.width = DisplayWidth(dpy, screen);
irect.height = draw.font.ascent + draw.font.descent + 4;
irect.height = font.ascent + font.descent + 4;
irect.y = DisplayHeight(dpy, screen) - irect.height;
irect.x = 0;
@ -422,19 +424,20 @@ main(int argc, char *argv[])
XSync(dpy, False);
/* pixmap */
draw.gc = XCreateGC(dpy, win, 0, 0);
draw.drawable = XCreatePixmap(dpy, win, irect.width, irect.height,
gc = XCreateGC(dpy, win, 0, 0);
pmap = XCreatePixmap(dpy, win, irect.width, irect.height,
DefaultDepth(dpy, screen));
XSync(dpy, False);
draw = blitz_create_input(pmap, gc, &font);
if(maxname)
cwidth = blitz_textwidth(&draw.font, maxname) + irect.height;
cwidth = blitz_textwidth(draw->font, maxname) + irect.height;
if(cwidth > irect.width / 3)
cwidth = irect.width / 3;
if(title) {
twidth = blitz_textwidth(&draw.font, title) + irect.height;
twidth = blitz_textwidth(draw->font, title) + irect.height;
if(twidth > irect.width / 3)
twidth = irect.width / 3;
}
@ -466,8 +469,8 @@ main(int argc, char *argv[])
}
XUngrabKeyboard(dpy, CurrentTime);
XFreePixmap(dpy, draw.drawable);
XFreeGC(dpy, draw.gc);
XFreePixmap(dpy, pmap);
XFreeGC(dpy, gc);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);

View File

@ -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 input.c label.c tile.c
SRC = blitz.c color.c font.c input.c tile.c
OBJ = ${SRC:.c=.o}
all: liblitz.a

View File

@ -61,19 +61,6 @@ struct BlitzWidget {
void (*draw)(BlitzWidget *);
};
/* obsolete, will be replaced soon */
typedef struct {
BlitzAlign align;
Drawable drawable;
GC gc;
BlitzColor color;
BlitzFont font;
XRectangle rect; /* relative rect */
XRectangle *notch; /* relative notch rect */
char *data;
} BlitzDraw;
/***/
Blitz __blitz;
/* blitz.c */
@ -83,10 +70,6 @@ Bool blitz_x11_event(XEvent *ev);
/* color.c */
int blitz_loadcolor(BlitzColor *c);
/* label.c */
void blitz_drawlabel(BlitzDraw *d);
void blitz_drawborder(BlitzDraw *d);
/* input.c */
BlitzWidget *blitz_create_input(Drawable drawable, GC gc, BlitzFont *font);
void blitz_draw_input(BlitzWidget *i);

View File

@ -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);
}