Alien-Xmake

 view release on metacpan or  search on metacpan

eg/nuklear/nuklear_xlib.h  view on Meta::CPAN

    struct nk_image img, struct nk_color col)
{
    XImageWithAlpha *aimage = img.handle.ptr;

    NK_UNUSED(col);

    if (aimage){
        if (aimage->clipMask){
            XSetClipMask(surf->dpy, surf->gc, aimage->clipMask);
            XSetClipOrigin(surf->dpy, surf->gc, x, y);
        }
        XPutImage(surf->dpy, surf->drawable, surf->gc, aimage->ximage, 0, 0, x, y, w, h);
        XSetClipMask(surf->dpy, surf->gc, None);
    }
}

void
nk_xsurf_image_free(struct nk_image* image)
{
    XSurface *surf = xlib.surf;
    XImageWithAlpha *aimage = image->handle.ptr;
    if (!aimage) return;
    XDestroyImage(aimage->ximage);
    XFreePixmap(surf->dpy, aimage->clipMask);
    XFreeGC(surf->dpy, aimage->clipMaskGC);
    free(aimage);
}


NK_INTERN void
nk_xsurf_clear(XSurface *surf, unsigned long color)
{
    XSetForeground(surf->dpy, surf->gc, color);
    XFillRectangle(surf->dpy, surf->drawable, surf->gc, 0, 0, surf->w, surf->h);
}

NK_INTERN void
nk_xsurf_blit(Drawable target, XSurface *surf, unsigned int w, unsigned int h)
{
    XCopyArea(surf->dpy, surf->drawable, target, surf->gc, 0, 0, w, h, 0, 0);
}

NK_INTERN void
nk_xsurf_del(XSurface *surf)
{
#ifdef NK_XLIB_USE_XFT
    XftDrawDestroy(surf->ftdraw);
#endif
    XFreePixmap(surf->dpy, surf->drawable);
    XFreeGC(surf->dpy, surf->gc);
    free(surf);
}

NK_API XFont*
nk_xfont_create(Display *dpy, const char *name)
{
#ifdef NK_XLIB_USE_XFT
    XFont *font = (XFont*)calloc(1, sizeof(XFont));
    font->ft = XftFontOpenName(dpy, XDefaultScreen(dpy), name);
    if (!font->ft) {
        fprintf(stderr, "missing font: %s\n", name);
        return font;
    }
    font->ascent = font->ft->ascent;
    font->descent = font->ft->descent;
    font->height = font->ft->height;
#else
    int n;
    char *def, **missing;
    XFont *font = (XFont*)calloc(1, sizeof(XFont));
    font->set = XCreateFontSet(dpy, name, &missing, &n, &def);
    if(missing) {
        while(n--)
            fprintf(stderr, "missing fontset: %s\n", missing[n]);
        XFreeStringList(missing);
    }
    if(font->set) {
        XFontStruct **xfonts;
        char **font_names;
        XExtentsOfFontSet(font->set);
        n = XFontsOfFontSet(font->set, &xfonts, &font_names);
        while(n--) {
            font->ascent = NK_MAX(font->ascent, (*xfonts)->ascent);
            font->descent = NK_MAX(font->descent,(*xfonts)->descent);
            xfonts++;
        }
    } else {
        if(!(font->xfont = XLoadQueryFont(dpy, name))
        && !(font->xfont = XLoadQueryFont(dpy, "fixed"))) {
            free(font);
            return 0;
        }
        font->ascent = font->xfont->ascent;
        font->descent = font->xfont->descent;
    }
    font->height = font->ascent + font->descent;
#endif
    return font;
}

NK_INTERN float
nk_xfont_get_text_width(nk_handle handle, float height, const char *text, int len)
{
    XFont *font = (XFont*)handle.ptr;

#ifdef NK_XLIB_USE_XFT
    XGlyphInfo g;

    NK_UNUSED(height);

    if(!font || !text)
        return 0;

    XftTextExtentsUtf8(xlib.dpy, font->ft, (FcChar8*)text, len, &g);
    return g.xOff;
#else
    XRectangle r;

    NK_UNUSED(height);

    if(!font || !text)
        return 0;

    if(font->set) {
        XmbTextExtents(font->set, (const char*)text, len, NULL, &r);
        return (float)r.width;
    } else{
        int w = XTextWidth(font->xfont, (const char*)text, len);
        return (float)w;
    }
#endif
}

NK_API void



( run in 0.636 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )