add a Rect to the textures for positioning them
This commit is contained in:
parent
4840f7e837
commit
2880e674ea
5 changed files with 23 additions and 8 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <X11/Xft/Xft.h>
|
#include <X11/Xft/Xft.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include "../kernel/geom.h"
|
||||||
|
|
||||||
void font_startup(void)
|
void font_startup(void)
|
||||||
{
|
{
|
||||||
|
@ -91,10 +92,16 @@ int font_max_char_width(ObFont *f)
|
||||||
return (signed) f->xftfont->max_advance_width;
|
return (signed) f->xftfont->max_advance_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void font_draw(XftDraw *d, TextureText *t, int x, int y, int w, int h)
|
void font_draw(XftDraw *d, TextureText *t, Rect *position)
|
||||||
{
|
{
|
||||||
|
int x,y,w,h;
|
||||||
XftColor c;
|
XftColor c;
|
||||||
|
|
||||||
|
x = position->x;
|
||||||
|
y = position->y;
|
||||||
|
w = position->width;
|
||||||
|
h = position->height;
|
||||||
|
|
||||||
/* accomidate for areas bigger/smaller than Xft thinks the font is tall */
|
/* accomidate for areas bigger/smaller than Xft thinks the font is tall */
|
||||||
y -= (2 * (t->font->xftfont->ascent + t->font->xftfont->descent) -
|
y -= (2 * (t->font->xftfont->ascent + t->font->xftfont->descent) -
|
||||||
(t->font->height + h) - 1) / 2;
|
(t->font->height + h) - 1) / 2;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define __font_h
|
#define __font_h
|
||||||
#include <X11/Xft/Xft.h>
|
#include <X11/Xft/Xft.h>
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
#include "../kernel/geom.h"
|
||||||
|
|
||||||
void font_startup(void);
|
void font_startup(void);
|
||||||
ObFont *font_open(char *fontstring);
|
ObFont *font_open(char *fontstring);
|
||||||
|
@ -9,5 +10,5 @@ void font_close(ObFont *f);
|
||||||
int font_measure_string(ObFont *f, char *str, int shadow, int offset);
|
int font_measure_string(ObFont *f, char *str, int shadow, int offset);
|
||||||
int font_height(ObFont *f, int shadow, int offset);
|
int font_height(ObFont *f, int shadow, int offset);
|
||||||
int font_max_char_width(ObFont *f);
|
int font_max_char_width(ObFont *f);
|
||||||
void font_draw(XftDraw *d, TextureText *t, int x, int y, int w, int h);
|
void font_draw(XftDraw *d, TextureText *t, Rect *position);
|
||||||
#endif /* __font_h */
|
#endif /* __font_h */
|
||||||
|
|
|
@ -16,14 +16,18 @@ void pixmap_mask_free(pixmap_mask *m)
|
||||||
g_free(m);
|
g_free(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mask_draw(Pixmap p, TextureMask *m, int width, int height)
|
void mask_draw(Pixmap p, TextureMask *m, Rect *position)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
if (m->mask == None) return; /* no mask given */
|
if (m->mask == None) return; /* no mask given */
|
||||||
|
|
||||||
/* set the clip region */
|
/* set the clip region */
|
||||||
x = (width - m->mask->w) / 2;
|
x = position->x + (position->width - m->mask->w) / 2;
|
||||||
y = (height - m->mask->h) / 2;
|
y = position->y + (position->height - m->mask->h) / 2;
|
||||||
|
|
||||||
|
if (x < 0) x = 0;
|
||||||
|
if (y < 0) y = 0;
|
||||||
|
|
||||||
XSetClipMask(ob_display, m->color->gc, m->mask->mask);
|
XSetClipMask(ob_display, m->color->gc, m->mask->mask);
|
||||||
XSetClipOrigin(ob_display, m->color->gc, x, y);
|
XSetClipOrigin(ob_display, m->color->gc, x, y);
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
#define __mask_h
|
#define __mask_h
|
||||||
|
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
#include "../kernel/geom.h"
|
||||||
|
|
||||||
pixmap_mask *pixmap_mask_new(int w, int h, char *data);
|
pixmap_mask *pixmap_mask_new(int w, int h, char *data);
|
||||||
void pixmap_mask_free(pixmap_mask *m);
|
void pixmap_mask_free(pixmap_mask *m);
|
||||||
void mask_draw(Pixmap p, TextureMask *m, int width, int height);
|
void mask_draw(Pixmap p, TextureMask *m, Rect *position);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -136,12 +136,14 @@ void x_paint(Window win, Appearance *l, int x, int y, int w, int h)
|
||||||
l->xftdraw = XftDrawCreate(ob_display, l->pixmap,
|
l->xftdraw = XftDrawCreate(ob_display, l->pixmap,
|
||||||
render_visual, render_colormap);
|
render_visual, render_colormap);
|
||||||
}
|
}
|
||||||
font_draw(l->xftdraw, &l->texture[i].data.text, x, y, w, h);
|
font_draw(l->xftdraw, &l->texture[i].data.text,
|
||||||
|
&l->texture[i].position);
|
||||||
break;
|
break;
|
||||||
case Bitmask:
|
case Bitmask:
|
||||||
if (l->texture[i].data.mask.color->gc == None)
|
if (l->texture[i].data.mask.color->gc == None)
|
||||||
color_allocate_gc(l->texture[i].data.mask.color);
|
color_allocate_gc(l->texture[i].data.mask.color);
|
||||||
mask_draw(l->pixmap, &l->texture[i].data.mask, w, h);
|
mask_draw(l->pixmap, &l->texture[i].data.mask,
|
||||||
|
&l->texture[i].position);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue