cleanup xlib text drawing

fixes #502
This commit is contained in:
Richard Gill 2022-10-03 21:11:12 +02:00
parent 492f4d9d3c
commit 6a429eca62
2 changed files with 21 additions and 31 deletions

View File

@ -385,15 +385,12 @@ nk_xsurf_stroke_curve(XSurface *surf, struct nk_vec2i p1,
}
NK_INTERN void
nk_xsurf_draw_text(XSurface *surf, short x, short y, unsigned short w, unsigned short h,
const char *text, int len, XFont *font, struct nk_color cbg, struct nk_color cfg)
nk_xsurf_draw_text(XSurface *surf, short x, short y, const char *text, int len,
XFont *font, struct nk_color cfg)
{
int tx, ty;
unsigned long bg = nk_color_from_byte(&cbg.r);
unsigned long fg = nk_color_from_byte(&cfg.r);
XSetForeground(surf->dpy, surf->gc, bg);
XFillRectangle(surf->dpy, surf->drawable, surf->gc, (int)x, (int)y, (unsigned)w, (unsigned)h);
if(!text || !font || !len) return;
tx = (int)x;
@ -939,10 +936,8 @@ nk_xlib_render(Drawable screen, struct nk_color clear)
} break;
case NK_COMMAND_TEXT: {
const struct nk_command_text *t = (const struct nk_command_text*)cmd;
nk_xsurf_draw_text(surf, t->x, t->y, t->w, t->h,
(const char*)t->string, t->length,
(XFont*)t->font->userdata.ptr,
t->background, t->foreground);
nk_xsurf_draw_text(surf, t->x, t->y, (const char*)t->string, t->length,
(XFont*)t->font->userdata.ptr, t->foreground);
} break;
case NK_COMMAND_CURVE: {
const struct nk_command_curve *q = (const struct nk_command_curve *)cmd;

View File

@ -417,8 +417,8 @@ nk_xsurf_stroke_curve(XSurface *surf, struct nk_vec2i p1,
}
NK_INTERN void
nk_xsurf_draw_text(XSurface *surf, short x, short y, unsigned short w, unsigned short h,
const char *text, int len, XFont *font, struct nk_color cbg, struct nk_color cfg)
nk_xsurf_draw_text(XSurface *surf, short x, short y, const char *text, int len,
XFont *font, struct nk_color cfg)
{
#ifdef NK_XLIB_USE_XFT
XRenderColor xrc;
@ -426,11 +426,8 @@ nk_xsurf_draw_text(XSurface *surf, short x, short y, unsigned short w, unsigned
#else
unsigned long fg = nk_color_from_byte(&cfg.r);
#endif
unsigned long bg = nk_color_from_byte(&cbg.r);
int tx, ty;
XSetForeground(surf->dpy, surf->gc, bg);
XFillRectangle(surf->dpy, surf->drawable, surf->gc, (int)x, (int)y, (unsigned)w, (unsigned)h);
if(!text || !font || !len) return;
tx = (int)x;
@ -1024,10 +1021,8 @@ nk_xlib_render(Drawable screen, struct nk_color clear)
} break;
case NK_COMMAND_TEXT: {
const struct nk_command_text *t = (const struct nk_command_text*)cmd;
nk_xsurf_draw_text(surf, t->x, t->y, t->w, t->h,
(const char*)t->string, t->length,
(XFont*)t->font->userdata.ptr,
t->background, t->foreground);
nk_xsurf_draw_text(surf, t->x, t->y, (const char*)t->string, t->length,
(XFont*)t->font->userdata.ptr, t->foreground);
} break;
case NK_COMMAND_CURVE: {
const struct nk_command_curve *q = (const struct nk_command_curve *)cmd;