Blame src-nuklear/nuklear_draw.c

b53a5c
#include "nuklear.h"
b53a5c
#include "nuklear_internal.h"
b53a5c
b53a5c
/* ==============================================================
b53a5c
 *
b53a5c
 *                          DRAW
b53a5c
 *
b53a5c
 * ===============================================================*/
b53a5c
NK_LIB void
b53a5c
nk_command_buffer_init(struct nk_command_buffer *cb,
b53a5c
    struct nk_buffer *b, enum nk_command_clipping clip)
b53a5c
{
b53a5c
    NK_ASSERT(cb);
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!cb || !b) return;
b53a5c
    cb->base = b;
b53a5c
    cb->use_clipping = (int)clip;
b53a5c
    cb->begin = b->allocated;
b53a5c
    cb->end = b->allocated;
b53a5c
    cb->last = b->allocated;
b53a5c
}
b53a5c
NK_LIB void
b53a5c
nk_command_buffer_reset(struct nk_command_buffer *b)
b53a5c
{
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b) return;
b53a5c
    b->begin = 0;
b53a5c
    b->end = 0;
b53a5c
    b->last = 0;
b53a5c
    b->clip = nk_null_rect;
b53a5c
#ifdef NK_INCLUDE_COMMAND_USERDATA
b53a5c
    b->userdata.ptr = 0;
b53a5c
#endif
b53a5c
}
b53a5c
NK_LIB void*
b53a5c
nk_command_buffer_push(struct nk_command_buffer* b,
b53a5c
    enum nk_command_type t, nk_size size)
b53a5c
{
b53a5c
    NK_STORAGE const nk_size align = NK_ALIGNOF(struct nk_command);
b53a5c
    struct nk_command *cmd;
b53a5c
    nk_size alignment;
b53a5c
    void *unaligned;
b53a5c
    void *memory;
b53a5c
b53a5c
    NK_ASSERT(b);
b53a5c
    NK_ASSERT(b->base);
b53a5c
    if (!b) return 0;
b53a5c
    cmd = (struct nk_command*)nk_buffer_alloc(b->base,NK_BUFFER_FRONT,size,align);
b53a5c
    if (!cmd) return 0;
b53a5c
b53a5c
    /* make sure the offset to the next command is aligned */
b53a5c
    b->last = (nk_size)((nk_byte*)cmd - (nk_byte*)b->base->memory.ptr);
b53a5c
    unaligned = (nk_byte*)cmd + size;
b53a5c
    memory = NK_ALIGN_PTR(unaligned, align);
b53a5c
    alignment = (nk_size)((nk_byte*)memory - (nk_byte*)unaligned);
b53a5c
#ifdef NK_ZERO_COMMAND_MEMORY
b53a5c
    NK_MEMSET(cmd, 0, size + alignment);
b53a5c
#endif
b53a5c
b53a5c
    cmd->type = t;
b53a5c
    cmd->next = b->base->allocated + alignment;
b53a5c
#ifdef NK_INCLUDE_COMMAND_USERDATA
b53a5c
    cmd->userdata = b->userdata;
b53a5c
#endif
b53a5c
    b->end = cmd->next;
b53a5c
    return cmd;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_push_scissor(struct nk_command_buffer *b, struct nk_rect r)
b53a5c
{
b53a5c
    struct nk_command_scissor *cmd;
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b) return;
b53a5c
b53a5c
    b->clip.x = r.x;
b53a5c
    b->clip.y = r.y;
b53a5c
    b->clip.w = r.w;
b53a5c
    b->clip.h = r.h;
b53a5c
    cmd = (struct nk_command_scissor*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_SCISSOR, sizeof(*cmd));
b53a5c
b53a5c
    if (!cmd) return;
b53a5c
    cmd->x = (short)r.x;
b53a5c
    cmd->y = (short)r.y;
b53a5c
    cmd->w = (unsigned short)NK_MAX(0, r.w);
b53a5c
    cmd->h = (unsigned short)NK_MAX(0, r.h);
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_stroke_line(struct nk_command_buffer *b, float x0, float y0,
b53a5c
    float x1, float y1, float line_thickness, struct nk_color c)
b53a5c
{
b53a5c
    struct nk_command_line *cmd;
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b || line_thickness <= 0) return;
b53a5c
    cmd = (struct nk_command_line*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_LINE, sizeof(*cmd));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->line_thickness = (unsigned short)line_thickness;
b53a5c
    cmd->begin.x = (short)x0;
b53a5c
    cmd->begin.y = (short)y0;
b53a5c
    cmd->end.x = (short)x1;
b53a5c
    cmd->end.y = (short)y1;
b53a5c
    cmd->color = c;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_stroke_curve(struct nk_command_buffer *b, float ax, float ay,
b53a5c
    float ctrl0x, float ctrl0y, float ctrl1x, float ctrl1y,
b53a5c
    float bx, float by, float line_thickness, struct nk_color col)
b53a5c
{
b53a5c
    struct nk_command_curve *cmd;
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b || col.a == 0 || line_thickness <= 0) return;
b53a5c
b53a5c
    cmd = (struct nk_command_curve*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_CURVE, sizeof(*cmd));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->line_thickness = (unsigned short)line_thickness;
b53a5c
    cmd->begin.x = (short)ax;
b53a5c
    cmd->begin.y = (short)ay;
b53a5c
    cmd->ctrl[0].x = (short)ctrl0x;
b53a5c
    cmd->ctrl[0].y = (short)ctrl0y;
b53a5c
    cmd->ctrl[1].x = (short)ctrl1x;
b53a5c
    cmd->ctrl[1].y = (short)ctrl1y;
b53a5c
    cmd->end.x = (short)bx;
b53a5c
    cmd->end.y = (short)by;
b53a5c
    cmd->color = col;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_stroke_rect(struct nk_command_buffer *b, struct nk_rect rect,
b53a5c
    float rounding, float line_thickness, struct nk_color c)
b53a5c
{
b53a5c
    struct nk_command_rect *cmd;
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b || c.a == 0 || rect.w == 0 || rect.h == 0 || line_thickness <= 0) return;
b53a5c
    if (b->use_clipping) {
b53a5c
        const struct nk_rect *clip = &b->clip;
b53a5c
        if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h,
b53a5c
            clip->x, clip->y, clip->w, clip->h)) return;
b53a5c
    }
b53a5c
    cmd = (struct nk_command_rect*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_RECT, sizeof(*cmd));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->rounding = (unsigned short)rounding;
b53a5c
    cmd->line_thickness = (unsigned short)line_thickness;
b53a5c
    cmd->x = (short)rect.x;
b53a5c
    cmd->y = (short)rect.y;
b53a5c
    cmd->w = (unsigned short)NK_MAX(0, rect.w);
b53a5c
    cmd->h = (unsigned short)NK_MAX(0, rect.h);
b53a5c
    cmd->color = c;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_fill_rect(struct nk_command_buffer *b, struct nk_rect rect,
b53a5c
    float rounding, struct nk_color c)
b53a5c
{
b53a5c
    struct nk_command_rect_filled *cmd;
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b || c.a == 0 || rect.w == 0 || rect.h == 0) return;
b53a5c
    if (b->use_clipping) {
b53a5c
        const struct nk_rect *clip = &b->clip;
b53a5c
        if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h,
b53a5c
            clip->x, clip->y, clip->w, clip->h)) return;
b53a5c
    }
b53a5c
b53a5c
    cmd = (struct nk_command_rect_filled*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_RECT_FILLED, sizeof(*cmd));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->rounding = (unsigned short)rounding;
b53a5c
    cmd->x = (short)rect.x;
b53a5c
    cmd->y = (short)rect.y;
b53a5c
    cmd->w = (unsigned short)NK_MAX(0, rect.w);
b53a5c
    cmd->h = (unsigned short)NK_MAX(0, rect.h);
b53a5c
    cmd->color = c;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_fill_rect_multi_color(struct nk_command_buffer *b, struct nk_rect rect,
b53a5c
    struct nk_color left, struct nk_color top, struct nk_color right,
b53a5c
    struct nk_color bottom)
b53a5c
{
b53a5c
    struct nk_command_rect_multi_color *cmd;
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b || rect.w == 0 || rect.h == 0) return;
b53a5c
    if (b->use_clipping) {
b53a5c
        const struct nk_rect *clip = &b->clip;
b53a5c
        if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h,
b53a5c
            clip->x, clip->y, clip->w, clip->h)) return;
b53a5c
    }
b53a5c
b53a5c
    cmd = (struct nk_command_rect_multi_color*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_RECT_MULTI_COLOR, sizeof(*cmd));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->x = (short)rect.x;
b53a5c
    cmd->y = (short)rect.y;
b53a5c
    cmd->w = (unsigned short)NK_MAX(0, rect.w);
b53a5c
    cmd->h = (unsigned short)NK_MAX(0, rect.h);
b53a5c
    cmd->left = left;
b53a5c
    cmd->top = top;
b53a5c
    cmd->right = right;
b53a5c
    cmd->bottom = bottom;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_stroke_circle(struct nk_command_buffer *b, struct nk_rect r,
b53a5c
    float line_thickness, struct nk_color c)
b53a5c
{
b53a5c
    struct nk_command_circle *cmd;
b53a5c
    if (!b || r.w == 0 || r.h == 0 || line_thickness <= 0) return;
b53a5c
    if (b->use_clipping) {
b53a5c
        const struct nk_rect *clip = &b->clip;
b53a5c
        if (!NK_INTERSECT(r.x, r.y, r.w, r.h, clip->x, clip->y, clip->w, clip->h))
b53a5c
            return;
b53a5c
    }
b53a5c
b53a5c
    cmd = (struct nk_command_circle*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_CIRCLE, sizeof(*cmd));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->line_thickness = (unsigned short)line_thickness;
b53a5c
    cmd->x = (short)r.x;
b53a5c
    cmd->y = (short)r.y;
b53a5c
    cmd->w = (unsigned short)NK_MAX(r.w, 0);
b53a5c
    cmd->h = (unsigned short)NK_MAX(r.h, 0);
b53a5c
    cmd->color = c;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_fill_circle(struct nk_command_buffer *b, struct nk_rect r, struct nk_color c)
b53a5c
{
b53a5c
    struct nk_command_circle_filled *cmd;
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b || c.a == 0 || r.w == 0 || r.h == 0) return;
b53a5c
    if (b->use_clipping) {
b53a5c
        const struct nk_rect *clip = &b->clip;
b53a5c
        if (!NK_INTERSECT(r.x, r.y, r.w, r.h, clip->x, clip->y, clip->w, clip->h))
b53a5c
            return;
b53a5c
    }
b53a5c
b53a5c
    cmd = (struct nk_command_circle_filled*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_CIRCLE_FILLED, sizeof(*cmd));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->x = (short)r.x;
b53a5c
    cmd->y = (short)r.y;
b53a5c
    cmd->w = (unsigned short)NK_MAX(r.w, 0);
b53a5c
    cmd->h = (unsigned short)NK_MAX(r.h, 0);
b53a5c
    cmd->color = c;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_stroke_arc(struct nk_command_buffer *b, float cx, float cy, float radius,
b53a5c
    float a_min, float a_max, float line_thickness, struct nk_color c)
b53a5c
{
b53a5c
    struct nk_command_arc *cmd;
b53a5c
    if (!b || c.a == 0 || line_thickness <= 0) return;
b53a5c
    cmd = (struct nk_command_arc*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_ARC, sizeof(*cmd));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->line_thickness = (unsigned short)line_thickness;
b53a5c
    cmd->cx = (short)cx;
b53a5c
    cmd->cy = (short)cy;
b53a5c
    cmd->r = (unsigned short)radius;
b53a5c
    cmd->a[0] = a_min;
b53a5c
    cmd->a[1] = a_max;
b53a5c
    cmd->color = c;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_fill_arc(struct nk_command_buffer *b, float cx, float cy, float radius,
b53a5c
    float a_min, float a_max, struct nk_color c)
b53a5c
{
b53a5c
    struct nk_command_arc_filled *cmd;
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b || c.a == 0) return;
b53a5c
    cmd = (struct nk_command_arc_filled*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_ARC_FILLED, sizeof(*cmd));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->cx = (short)cx;
b53a5c
    cmd->cy = (short)cy;
b53a5c
    cmd->r = (unsigned short)radius;
b53a5c
    cmd->a[0] = a_min;
b53a5c
    cmd->a[1] = a_max;
b53a5c
    cmd->color = c;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_stroke_triangle(struct nk_command_buffer *b, float x0, float y0, float x1,
b53a5c
    float y1, float x2, float y2, float line_thickness, struct nk_color c)
b53a5c
{
b53a5c
    struct nk_command_triangle *cmd;
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b || c.a == 0 || line_thickness <= 0) return;
b53a5c
    if (b->use_clipping) {
b53a5c
        const struct nk_rect *clip = &b->clip;
b53a5c
        if (!NK_INBOX(x0, y0, clip->x, clip->y, clip->w, clip->h) &&
b53a5c
            !NK_INBOX(x1, y1, clip->x, clip->y, clip->w, clip->h) &&
b53a5c
            !NK_INBOX(x2, y2, clip->x, clip->y, clip->w, clip->h))
b53a5c
            return;
b53a5c
    }
b53a5c
b53a5c
    cmd = (struct nk_command_triangle*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_TRIANGLE, sizeof(*cmd));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->line_thickness = (unsigned short)line_thickness;
b53a5c
    cmd->a.x = (short)x0;
b53a5c
    cmd->a.y = (short)y0;
b53a5c
    cmd->b.x = (short)x1;
b53a5c
    cmd->b.y = (short)y1;
b53a5c
    cmd->c.x = (short)x2;
b53a5c
    cmd->c.y = (short)y2;
b53a5c
    cmd->color = c;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_fill_triangle(struct nk_command_buffer *b, float x0, float y0, float x1,
b53a5c
    float y1, float x2, float y2, struct nk_color c)
b53a5c
{
b53a5c
    struct nk_command_triangle_filled *cmd;
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b || c.a == 0) return;
b53a5c
    if (!b) return;
b53a5c
    if (b->use_clipping) {
b53a5c
        const struct nk_rect *clip = &b->clip;
b53a5c
        if (!NK_INBOX(x0, y0, clip->x, clip->y, clip->w, clip->h) &&
b53a5c
            !NK_INBOX(x1, y1, clip->x, clip->y, clip->w, clip->h) &&
b53a5c
            !NK_INBOX(x2, y2, clip->x, clip->y, clip->w, clip->h))
b53a5c
            return;
b53a5c
    }
b53a5c
b53a5c
    cmd = (struct nk_command_triangle_filled*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_TRIANGLE_FILLED, sizeof(*cmd));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->a.x = (short)x0;
b53a5c
    cmd->a.y = (short)y0;
b53a5c
    cmd->b.x = (short)x1;
b53a5c
    cmd->b.y = (short)y1;
b53a5c
    cmd->c.x = (short)x2;
b53a5c
    cmd->c.y = (short)y2;
b53a5c
    cmd->color = c;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_stroke_polygon(struct nk_command_buffer *b,  float *points, int point_count,
b53a5c
    float line_thickness, struct nk_color col)
b53a5c
{
b53a5c
    int i;
b53a5c
    nk_size size = 0;
b53a5c
    struct nk_command_polygon *cmd;
b53a5c
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b || col.a == 0 || line_thickness <= 0) return;
b53a5c
    size = sizeof(*cmd) + sizeof(short) * 2 * (nk_size)point_count;
b53a5c
    cmd = (struct nk_command_polygon*) nk_command_buffer_push(b, NK_COMMAND_POLYGON, size);
b53a5c
    if (!cmd) return;
b53a5c
    cmd->color = col;
b53a5c
    cmd->line_thickness = (unsigned short)line_thickness;
b53a5c
    cmd->point_count = (unsigned short)point_count;
b53a5c
    for (i = 0; i < point_count; ++i) {
b53a5c
        cmd->points[i].x = (short)points[i*2];
b53a5c
        cmd->points[i].y = (short)points[i*2+1];
b53a5c
    }
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_fill_polygon(struct nk_command_buffer *b, float *points, int point_count,
b53a5c
    struct nk_color col)
b53a5c
{
b53a5c
    int i;
b53a5c
    nk_size size = 0;
b53a5c
    struct nk_command_polygon_filled *cmd;
b53a5c
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b || col.a == 0) return;
b53a5c
    size = sizeof(*cmd) + sizeof(short) * 2 * (nk_size)point_count;
b53a5c
    cmd = (struct nk_command_polygon_filled*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_POLYGON_FILLED, size);
b53a5c
    if (!cmd) return;
b53a5c
    cmd->color = col;
b53a5c
    cmd->point_count = (unsigned short)point_count;
b53a5c
    for (i = 0; i < point_count; ++i) {
b53a5c
        cmd->points[i].x = (short)points[i*2+0];
b53a5c
        cmd->points[i].y = (short)points[i*2+1];
b53a5c
    }
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_stroke_polyline(struct nk_command_buffer *b, float *points, int point_count,
b53a5c
    float line_thickness, struct nk_color col)
b53a5c
{
b53a5c
    int i;
b53a5c
    nk_size size = 0;
b53a5c
    struct nk_command_polyline *cmd;
b53a5c
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b || col.a == 0 || line_thickness <= 0) return;
b53a5c
    size = sizeof(*cmd) + sizeof(short) * 2 * (nk_size)point_count;
b53a5c
    cmd = (struct nk_command_polyline*) nk_command_buffer_push(b, NK_COMMAND_POLYLINE, size);
b53a5c
    if (!cmd) return;
b53a5c
    cmd->color = col;
b53a5c
    cmd->point_count = (unsigned short)point_count;
b53a5c
    cmd->line_thickness = (unsigned short)line_thickness;
b53a5c
    for (i = 0; i < point_count; ++i) {
b53a5c
        cmd->points[i].x = (short)points[i*2];
b53a5c
        cmd->points[i].y = (short)points[i*2+1];
b53a5c
    }
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_draw_image(struct nk_command_buffer *b, struct nk_rect r,
b53a5c
    const struct nk_image *img, struct nk_color col)
b53a5c
{
b53a5c
    struct nk_command_image *cmd;
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b) return;
b53a5c
    if (b->use_clipping) {
b53a5c
        const struct nk_rect *c = &b->clip;
b53a5c
        if (c->w == 0 || c->h == 0 || !NK_INTERSECT(r.x, r.y, r.w, r.h, c->x, c->y, c->w, c->h))
b53a5c
            return;
b53a5c
    }
b53a5c
b53a5c
    cmd = (struct nk_command_image*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_IMAGE, sizeof(*cmd));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->x = (short)r.x;
b53a5c
    cmd->y = (short)r.y;
b53a5c
    cmd->w = (unsigned short)NK_MAX(0, r.w);
b53a5c
    cmd->h = (unsigned short)NK_MAX(0, r.h);
b53a5c
    cmd->img = *img;
b53a5c
    cmd->col = col;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_draw_nine_slice(struct nk_command_buffer *b, struct nk_rect r,
b53a5c
    const struct nk_nine_slice *slc, struct nk_color col)
b53a5c
{
b53a5c
    struct nk_image img;
b53a5c
    const struct nk_image *slcimg = (const struct nk_image*)slc;
b53a5c
    nk_ushort rgnX, rgnY, rgnW, rgnH;
b53a5c
    rgnX = slcimg->region[0];
b53a5c
    rgnY = slcimg->region[1];
b53a5c
    rgnW = slcimg->region[2];
b53a5c
    rgnH = slcimg->region[3];
b53a5c
b53a5c
    /* top-left */
b53a5c
    img.handle = slcimg->handle;
b53a5c
    img.w = slcimg->w;
b53a5c
    img.h = slcimg->h;
b53a5c
    img.region[0] = rgnX;
b53a5c
    img.region[1] = rgnY;
b53a5c
    img.region[2] = slc->l;
b53a5c
    img.region[3] = slc->t;
b53a5c
b53a5c
    nk_draw_image(b,
b53a5c
        nk_rect(r.x, r.y, (float)slc->l, (float)slc->t),
b53a5c
        &img, col);
b53a5c
b53a5c
#define IMG_RGN(x, y, w, h) img.region[0] = (nk_ushort)(x); img.region[1] = (nk_ushort)(y); img.region[2] = (nk_ushort)(w); img.region[3] = (nk_ushort)(h);
b53a5c
b53a5c
    /* top-center */
b53a5c
    IMG_RGN(rgnX + slc->l, rgnY, rgnW - slc->l - slc->r, slc->t);
b53a5c
    nk_draw_image(b,
b53a5c
        nk_rect(r.x + (float)slc->l, r.y, (float)(r.w - slc->l - slc->r), (float)slc->t),
b53a5c
        &img, col);
b53a5c
b53a5c
    /* top-right */
b53a5c
    IMG_RGN(rgnX + rgnW - slc->r, rgnY, slc->r, slc->t);
b53a5c
    nk_draw_image(b,
b53a5c
        nk_rect(r.x + r.w - (float)slc->r, r.y, (float)slc->r, (float)slc->t),
b53a5c
        &img, col);
b53a5c
b53a5c
    /* center-left */
b53a5c
    IMG_RGN(rgnX, rgnY + slc->t, slc->l, rgnH - slc->t - slc->b);
b53a5c
    nk_draw_image(b,
b53a5c
        nk_rect(r.x, r.y + (float)slc->t, (float)slc->l, (float)(r.h - slc->t - slc->b)),
b53a5c
        &img, col);
b53a5c
b53a5c
    /* center */
b53a5c
    IMG_RGN(rgnX + slc->l, rgnY + slc->t, rgnW - slc->l - slc->r, rgnH - slc->t - slc->b);
b53a5c
    nk_draw_image(b,
b53a5c
        nk_rect(r.x + (float)slc->l, r.y + (float)slc->t, (float)(r.w - slc->l - slc->r), (float)(r.h - slc->t - slc->b)),
b53a5c
        &img, col);
b53a5c
b53a5c
    /* center-right */
b53a5c
    IMG_RGN(rgnX + rgnW - slc->r, rgnY + slc->t, slc->r, rgnH - slc->t - slc->b);
b53a5c
    nk_draw_image(b,
b53a5c
        nk_rect(r.x + r.w - (float)slc->r, r.y + (float)slc->t, (float)slc->r, (float)(r.h - slc->t - slc->b)),
b53a5c
        &img, col);
b53a5c
b53a5c
    /* bottom-left */
b53a5c
    IMG_RGN(rgnX, rgnY + rgnH - slc->b, slc->l, slc->b);
b53a5c
    nk_draw_image(b,
b53a5c
        nk_rect(r.x, r.y + r.h - (float)slc->b, (float)slc->l, (float)slc->b),
b53a5c
        &img, col);
b53a5c
b53a5c
    /* bottom-center */
b53a5c
    IMG_RGN(rgnX + slc->l, rgnY + rgnH - slc->b, rgnW - slc->l - slc->r, slc->b);
b53a5c
    nk_draw_image(b,
b53a5c
        nk_rect(r.x + (float)slc->l, r.y + r.h - (float)slc->b, (float)(r.w - slc->l - slc->r), (float)slc->b),
b53a5c
        &img, col);
b53a5c
b53a5c
    /* bottom-right */
b53a5c
    IMG_RGN(rgnX + rgnW - slc->r, rgnY + rgnH - slc->b, slc->r, slc->b);
b53a5c
    nk_draw_image(b,
b53a5c
        nk_rect(r.x + r.w - (float)slc->r, r.y + r.h - (float)slc->b, (float)slc->r, (float)slc->b),
b53a5c
        &img, col);
b53a5c
b53a5c
#undef IMG_RGN
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_push_custom(struct nk_command_buffer *b, struct nk_rect r,
b53a5c
    nk_command_custom_callback cb, nk_handle usr)
b53a5c
{
b53a5c
    struct nk_command_custom *cmd;
b53a5c
    NK_ASSERT(b);
b53a5c
    if (!b) return;
b53a5c
    if (b->use_clipping) {
b53a5c
        const struct nk_rect *c = &b->clip;
b53a5c
        if (c->w == 0 || c->h == 0 || !NK_INTERSECT(r.x, r.y, r.w, r.h, c->x, c->y, c->w, c->h))
b53a5c
            return;
b53a5c
    }
b53a5c
b53a5c
    cmd = (struct nk_command_custom*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_CUSTOM, sizeof(*cmd));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->x = (short)r.x;
b53a5c
    cmd->y = (short)r.y;
b53a5c
    cmd->w = (unsigned short)NK_MAX(0, r.w);
b53a5c
    cmd->h = (unsigned short)NK_MAX(0, r.h);
b53a5c
    cmd->callback_data = usr;
b53a5c
    cmd->callback = cb;
b53a5c
}
b53a5c
NK_API void
b53a5c
nk_draw_text(struct nk_command_buffer *b, struct nk_rect r,
b53a5c
    const char *string, int length, const struct nk_user_font *font,
b53a5c
    struct nk_color bg, struct nk_color fg)
b53a5c
{
b53a5c
    float text_width = 0;
b53a5c
    struct nk_command_text *cmd;
b53a5c
b53a5c
    NK_ASSERT(b);
b53a5c
    NK_ASSERT(font);
b53a5c
    if (!b || !string || !length || (bg.a == 0 && fg.a == 0)) return;
b53a5c
    if (b->use_clipping) {
b53a5c
        const struct nk_rect *c = &b->clip;
b53a5c
        if (c->w == 0 || c->h == 0 || !NK_INTERSECT(r.x, r.y, r.w, r.h, c->x, c->y, c->w, c->h))
b53a5c
            return;
b53a5c
    }
b53a5c
b53a5c
    /* make sure text fits inside bounds */
b53a5c
    text_width = font->width(font->userdata, font->height, string, length);
b53a5c
    if (text_width > r.w){
b53a5c
        int glyphs = 0;
b53a5c
        float txt_width = (float)text_width;
b53a5c
        length = nk_text_clamp(font, string, length, r.w, &glyphs, &txt_width, 0,0);
b53a5c
    }
b53a5c
b53a5c
    if (!length) return;
b53a5c
    cmd = (struct nk_command_text*)
b53a5c
        nk_command_buffer_push(b, NK_COMMAND_TEXT, sizeof(*cmd) + (nk_size)(length + 1));
b53a5c
    if (!cmd) return;
b53a5c
    cmd->x = (short)r.x;
b53a5c
    cmd->y = (short)r.y;
b53a5c
    cmd->w = (unsigned short)r.w;
b53a5c
    cmd->h = (unsigned short)r.h;
b53a5c
    cmd->background = bg;
b53a5c
    cmd->foreground = fg;
b53a5c
    cmd->font = font;
b53a5c
    cmd->length = length;
b53a5c
    cmd->height = font->height;
b53a5c
    NK_MEMCPY(cmd->string, string, (nk_size)length);
b53a5c
    cmd->string[length] = '\0';
b53a5c
}
b53a5c