mirror of https://github.com/0intro/wmii
added brush.c (sorry I missed it)
This commit is contained in:
parent
8ad66e8f67
commit
36b738b2ca
|
@ -47,6 +47,8 @@ struct BlitzFont {
|
|||
XFontSet set;
|
||||
int ascent;
|
||||
int descent;
|
||||
int rbearing;
|
||||
int lbearing;
|
||||
char *fontstr;
|
||||
};
|
||||
|
||||
|
@ -61,11 +63,19 @@ struct BlitzBrush {
|
|||
};
|
||||
|
||||
struct BlitzInput {
|
||||
Blitz *blitz;
|
||||
char *text;
|
||||
char *selstart;
|
||||
char *selend;
|
||||
char *cursor;
|
||||
unsigned int size;
|
||||
BlitzBrush bg;
|
||||
Drawable drawable;
|
||||
GC gc;
|
||||
BlitzColor sel;
|
||||
BlitzColor norm;
|
||||
BlitzFont *font;
|
||||
XRectangle rect; /* relative rect */
|
||||
};
|
||||
|
||||
/* color.c */
|
||||
|
@ -73,7 +83,7 @@ int blitz_loadcolor(Blitz *blitz, BlitzColor *c);
|
|||
|
||||
/* brush.c */
|
||||
void blitz_draw_label(BlitzBrush *b, char *text);
|
||||
void blitz_draw_input(BlitzBrush *b, BlitzInput *input);
|
||||
void blitz_draw_input(BlitzInput *i);
|
||||
void blitz_draw_tile(BlitzBrush *b);
|
||||
|
||||
/* font.c */
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <cext.h>
|
||||
#include "blitz.h"
|
||||
|
||||
static void
|
||||
xdrawbg(Display *dpy, Drawable drawable, GC gc, XRectangle rect, BlitzColor c)
|
||||
{
|
||||
XPoint points[5];
|
||||
XSetForeground(dpy, gc, c.bg);
|
||||
XFillRectangles(dpy, drawable, gc, &rect, 1);
|
||||
XSetLineAttributes(dpy, gc, 1, LineSolid, CapButt, JoinMiter);
|
||||
XSetForeground(dpy, gc, c.border);
|
||||
points[0].x = rect.x;
|
||||
points[0].y = rect.y;
|
||||
points[1].x = rect.width - 1;
|
||||
points[1].y = 0;
|
||||
points[2].x = 0;
|
||||
points[2].y = rect.height - 1;
|
||||
points[3].x = -(rect.width - 1);
|
||||
points[3].y = 0;
|
||||
points[4].x = 0;
|
||||
points[4].y = -(rect.height - 1);
|
||||
XDrawLines(dpy, drawable, gc, points, 5, CoordModePrevious);
|
||||
}
|
||||
|
||||
void
|
||||
blitz_draw_tile(BlitzBrush *b)
|
||||
{
|
||||
xdrawbg(b->blitz->display, b->drawable, b->gc, b->rect, b->color);
|
||||
}
|
||||
|
||||
void
|
||||
blitz_draw_label(BlitzBrush *b, char *text)
|
||||
{
|
||||
unsigned int x, y, w, h, shortened, len;
|
||||
static char buf[2048];
|
||||
XGCValues gcv;
|
||||
|
||||
blitz_draw_tile(b);
|
||||
|
||||
if (!text)
|
||||
return;
|
||||
|
||||
x = y = shortened = 0;
|
||||
w = h = 1;
|
||||
cext_strlcpy(buf, text, sizeof(buf));
|
||||
len = strlen(buf);
|
||||
gcv.foreground = b->color.fg;
|
||||
gcv.background = b->color.bg;
|
||||
if(b->font->set)
|
||||
XChangeGC(b->blitz->display, b->gc, GCForeground | GCBackground, &gcv);
|
||||
else {
|
||||
gcv.font = b->font->xfont->fid;
|
||||
XChangeGC(b->blitz->display, b->gc, GCForeground | GCBackground | GCFont, &gcv);
|
||||
}
|
||||
|
||||
h = b->font->ascent + b->font->descent;
|
||||
y = b->rect.y + b->rect.height / 2 - h / 2 + b->font->ascent;
|
||||
|
||||
/* shorten text if necessary */
|
||||
while (len && (w = blitz_textwidth(b->font, buf)) > b->rect.width) {
|
||||
buf[len - 1] = 0;
|
||||
len--;
|
||||
shortened = 1;
|
||||
}
|
||||
|
||||
if (w > b->rect.width)
|
||||
return;
|
||||
|
||||
/* mark shortened info in the string */
|
||||
if (shortened) {
|
||||
if (len > 3)
|
||||
buf[len - 3] = '.';
|
||||
if (len > 2)
|
||||
buf[len - 2] = '.';
|
||||
if (len > 1)
|
||||
buf[len - 1] = '.';
|
||||
}
|
||||
switch (b->align) {
|
||||
case EAST:
|
||||
x = b->rect.x + b->rect.width - (h / 2 + w);
|
||||
break;
|
||||
case CENTER:
|
||||
x = b->rect.x + (b->rect.width - w) / 2;
|
||||
break;
|
||||
default:
|
||||
x = b->rect.x + h / 2;
|
||||
break;
|
||||
}
|
||||
if(b->font->set)
|
||||
XmbDrawString(b->blitz->display, b->drawable, b->font->set, b->gc,
|
||||
x, y, buf, len);
|
||||
else
|
||||
XDrawString(b->blitz->display, b->drawable, b->gc, x, y, buf, len);
|
||||
}
|
||||
|
||||
void
|
||||
blitz_draw_input(BlitzInput *i)
|
||||
{
|
||||
xdrawbg(i->blitz->display, i->drawable, i->gc, i->rect, i->norm);
|
||||
|
||||
if (!i)
|
||||
return;
|
||||
}
|
|
@ -56,6 +56,10 @@ blitz_loadfont(Blitz *blitz, BlitzFont *font)
|
|||
font->ascent = (*xfonts)->ascent;
|
||||
if(font->descent < (*xfonts)->descent)
|
||||
font->descent = (*xfonts)->descent;
|
||||
if(font->rbearing < (*xfonts)->max_bounds.rbearing)
|
||||
font->rbearing = (*xfonts)->max_bounds.rbearing;
|
||||
if(font->lbearing < (*xfonts)->min_bounds.lbearing)
|
||||
font->lbearing = (*xfonts)->min_bounds.lbearing;
|
||||
xfonts++;
|
||||
}
|
||||
}
|
||||
|
@ -74,5 +78,7 @@ blitz_loadfont(Blitz *blitz, BlitzFont *font)
|
|||
}
|
||||
font->ascent = font->xfont->ascent;
|
||||
font->descent = font->xfont->descent;
|
||||
font->rbearing = font->xfont->max_bounds.rbearing;
|
||||
font->lbearing = font->xfont->min_bounds.lbearing;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue