2 #include "nuklear_internal.h" 
   11     struct nk_buffer *b, 
enum nk_command_clipping clip)
 
   15     if (!cb || !b) 
return;
 
   17     cb->use_clipping = (int)clip;
 
   30     b->clip = nk_null_rect;
 
   31 #ifdef NK_INCLUDE_COMMAND_USERDATA 
   37     enum nk_command_type t, nk_size size)
 
   39     NK_STORAGE 
const nk_size align = NK_ALIGNOF(
struct nk_command);
 
   48     cmd = (
struct nk_command*)nk_buffer_alloc(b->base,NK_BUFFER_FRONT,size,align);
 
   52     b->last = (nk_size)((nk_byte*)cmd - (nk_byte*)b->base->
memory.ptr);
 
   53     unaligned = (nk_byte*)cmd + size;
 
   54     memory = NK_ALIGN_PTR(unaligned, align);
 
   55     alignment = (nk_size)((nk_byte*)memory - (nk_byte*)unaligned);
 
   56 #ifdef NK_ZERO_COMMAND_MEMORY 
   57     NK_MEMSET(cmd, 0, size + alignment);
 
   61     cmd->next = b->base->
allocated + alignment;
 
   62 #ifdef NK_INCLUDE_COMMAND_USERDATA 
   63     cmd->userdata = b->userdata;
 
   80         nk_command_buffer_push(b, NK_COMMAND_SCISSOR, 
sizeof(*cmd));
 
   85     cmd->w = (
unsigned short)NK_MAX(0, r.w);
 
   86     cmd->h = (
unsigned short)NK_MAX(0, r.h);
 
   90     float x1, 
float y1, 
float line_thickness, 
struct nk_color c)
 
   94     if (!b || line_thickness <= 0) 
return;
 
   96         nk_command_buffer_push(b, NK_COMMAND_LINE, 
sizeof(*cmd));
 
   98     cmd->line_thickness = (
unsigned short)line_thickness;
 
   99     cmd->begin.x = (short)x0;
 
  100     cmd->begin.y = (short)y0;
 
  101     cmd->end.x = (short)x1;
 
  102     cmd->end.y = (short)y1;
 
  107     float ctrl0x, 
float ctrl0y, 
float ctrl1x, 
float ctrl1y,
 
  108     float bx, 
float by, 
float line_thickness, 
struct nk_color col)
 
  112     if (!b || col.a == 0 || line_thickness <= 0) 
return;
 
  115         nk_command_buffer_push(b, NK_COMMAND_CURVE, 
sizeof(*cmd));
 
  117     cmd->line_thickness = (
unsigned short)line_thickness;
 
  118     cmd->begin.x = (short)ax;
 
  119     cmd->begin.y = (short)ay;
 
  120     cmd->ctrl[0].x = (short)ctrl0x;
 
  121     cmd->ctrl[0].y = (short)ctrl0y;
 
  122     cmd->ctrl[1].x = (short)ctrl1x;
 
  123     cmd->ctrl[1].y = (short)ctrl1y;
 
  124     cmd->end.x = (short)bx;
 
  125     cmd->end.y = (short)by;
 
  130     float rounding, 
float line_thickness, 
struct nk_color c)
 
  134     if (!b || c.a == 0 || rect.w == 0 || rect.h == 0 || line_thickness <= 0) 
return;
 
  135     if (b->use_clipping) {
 
  136         const struct nk_rect *clip = &b->clip;
 
  137         if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h,
 
  138             clip->x, clip->y, clip->w, clip->h)) 
return;
 
  141         nk_command_buffer_push(b, NK_COMMAND_RECT, 
sizeof(*cmd));
 
  143     cmd->rounding = (
unsigned short)rounding;
 
  144     cmd->line_thickness = (
unsigned short)line_thickness;
 
  145     cmd->x = (short)rect.x;
 
  146     cmd->y = (
short)rect.y;
 
  147     cmd->w = (
unsigned short)NK_MAX(0, rect.w);
 
  148     cmd->h = (
unsigned short)NK_MAX(0, rect.h);
 
  157     if (!b || c.a == 0 || rect.w == 0 || rect.h == 0) 
return;
 
  158     if (b->use_clipping) {
 
  159         const struct nk_rect *clip = &b->clip;
 
  160         if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h,
 
  161             clip->x, clip->y, clip->w, clip->h)) 
return;
 
  165         nk_command_buffer_push(b, NK_COMMAND_RECT_FILLED, 
sizeof(*cmd));
 
  167     cmd->rounding = (
unsigned short)rounding;
 
  168     cmd->x = (short)rect.x;
 
  169     cmd->y = (
short)rect.y;
 
  170     cmd->w = (
unsigned short)NK_MAX(0, rect.w);
 
  171     cmd->h = (
unsigned short)NK_MAX(0, rect.h);
 
  181     if (!b || rect.w == 0 || rect.h == 0) 
return;
 
  182     if (b->use_clipping) {
 
  183         const struct nk_rect *clip = &b->clip;
 
  184         if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h,
 
  185             clip->x, clip->y, clip->w, clip->h)) 
return;
 
  189         nk_command_buffer_push(b, NK_COMMAND_RECT_MULTI_COLOR, 
sizeof(*cmd));
 
  191     cmd->x = (short)rect.x;
 
  192     cmd->y = (
short)rect.y;
 
  193     cmd->w = (
unsigned short)NK_MAX(0, rect.w);
 
  194     cmd->h = (
unsigned short)NK_MAX(0, rect.h);
 
  198     cmd->bottom = bottom;
 
  202     float line_thickness, 
struct nk_color c)
 
  205     if (!b || r.w == 0 || r.h == 0 || line_thickness <= 0) 
return;
 
  206     if (b->use_clipping) {
 
  207         const struct nk_rect *clip = &b->clip;
 
  208         if (!NK_INTERSECT(r.x, r.y, r.w, r.h, clip->x, clip->y, clip->w, clip->h))
 
  213         nk_command_buffer_push(b, NK_COMMAND_CIRCLE, 
sizeof(*cmd));
 
  215     cmd->line_thickness = (
unsigned short)line_thickness;
 
  218     cmd->w = (
unsigned short)NK_MAX(r.w, 0);
 
  219     cmd->h = (
unsigned short)NK_MAX(r.h, 0);
 
  227     if (!b || c.a == 0 || r.w == 0 || r.h == 0) 
return;
 
  228     if (b->use_clipping) {
 
  229         const struct nk_rect *clip = &b->clip;
 
  230         if (!NK_INTERSECT(r.x, r.y, r.w, r.h, clip->x, clip->y, clip->w, clip->h))
 
  235         nk_command_buffer_push(b, NK_COMMAND_CIRCLE_FILLED, 
sizeof(*cmd));
 
  239     cmd->w = (
unsigned short)NK_MAX(r.w, 0);
 
  240     cmd->h = (
unsigned short)NK_MAX(r.h, 0);
 
  245     float a_min, 
float a_max, 
float line_thickness, 
struct nk_color c)
 
  248     if (!b || c.a == 0 || line_thickness <= 0) 
return;
 
  250         nk_command_buffer_push(b, NK_COMMAND_ARC, 
sizeof(*cmd));
 
  252     cmd->line_thickness = (
unsigned short)line_thickness;
 
  255     cmd->r = (
unsigned short)radius;
 
  262     float a_min, 
float a_max, 
struct nk_color c)
 
  266     if (!b || c.a == 0) 
return;
 
  268         nk_command_buffer_push(b, NK_COMMAND_ARC_FILLED, 
sizeof(*cmd));
 
  272     cmd->r = (
unsigned short)radius;
 
  279     float y1, 
float x2, 
float y2, 
float line_thickness, 
struct nk_color c)
 
  283     if (!b || c.a == 0 || line_thickness <= 0) 
return;
 
  284     if (b->use_clipping) {
 
  285         const struct nk_rect *clip = &b->clip;
 
  286         if (!NK_INBOX(x0, y0, clip->x, clip->y, clip->w, clip->h) &&
 
  287             !NK_INBOX(x1, y1, clip->x, clip->y, clip->w, clip->h) &&
 
  288             !NK_INBOX(x2, y2, clip->x, clip->y, clip->w, clip->h))
 
  293         nk_command_buffer_push(b, NK_COMMAND_TRIANGLE, 
sizeof(*cmd));
 
  295     cmd->line_thickness = (
unsigned short)line_thickness;
 
  296     cmd->a.x = (short)x0;
 
  297     cmd->a.y = (short)y0;
 
  298     cmd->b.x = (short)x1;
 
  299     cmd->b.y = (short)y1;
 
  300     cmd->c.x = (short)x2;
 
  301     cmd->c.y = (short)y2;
 
  306     float y1, 
float x2, 
float y2, 
struct nk_color c)
 
  310     if (!b || c.a == 0) 
return;
 
  312     if (b->use_clipping) {
 
  313         const struct nk_rect *clip = &b->clip;
 
  314         if (!NK_INBOX(x0, y0, clip->x, clip->y, clip->w, clip->h) &&
 
  315             !NK_INBOX(x1, y1, clip->x, clip->y, clip->w, clip->h) &&
 
  316             !NK_INBOX(x2, y2, clip->x, clip->y, clip->w, clip->h))
 
  321         nk_command_buffer_push(b, NK_COMMAND_TRIANGLE_FILLED, 
sizeof(*cmd));
 
  323     cmd->a.x = (short)x0;
 
  324     cmd->a.y = (short)y0;
 
  325     cmd->b.x = (short)x1;
 
  326     cmd->b.y = (short)y1;
 
  327     cmd->c.x = (short)x2;
 
  328     cmd->c.y = (short)y2;
 
  332 nk_stroke_polygon(
struct nk_command_buffer *b, 
const float *points, 
int point_count,
 
  333     float line_thickness, 
struct nk_color col)
 
  340     if (!b || col.a == 0 || line_thickness <= 0) 
return;
 
  341     size = 
sizeof(*cmd) + 
sizeof(short) * 2 * (nk_size)point_count;
 
  342     cmd = (
struct nk_command_polygon*) nk_command_buffer_push(b, NK_COMMAND_POLYGON, size);
 
  345     cmd->line_thickness = (
unsigned short)line_thickness;
 
  346     cmd->point_count = (
unsigned short)point_count;
 
  347     for (i = 0; i < point_count; ++i) {
 
  348         cmd->points[i].x = (short)points[i*2];
 
  349         cmd->points[i].y = (short)points[i*2+1];
 
  353 nk_fill_polygon(
struct nk_command_buffer *b, 
const float *points, 
int point_count,
 
  361     if (!b || col.a == 0) 
return;
 
  362     size = 
sizeof(*cmd) + 
sizeof(short) * 2 * (nk_size)point_count;
 
  364         nk_command_buffer_push(b, NK_COMMAND_POLYGON_FILLED, size);
 
  367     cmd->point_count = (
unsigned short)point_count;
 
  368     for (i = 0; i < point_count; ++i) {
 
  369         cmd->points[i].x = (short)points[i*2+0];
 
  370         cmd->points[i].y = (short)points[i*2+1];
 
  374 nk_stroke_polyline(
struct nk_command_buffer *b, 
const float *points, 
int point_count,
 
  375     float line_thickness, 
struct nk_color col)
 
  382     if (!b || col.a == 0 || line_thickness <= 0) 
return;
 
  383     size = 
sizeof(*cmd) + 
sizeof(short) * 2 * (nk_size)point_count;
 
  387     cmd->point_count = (
unsigned short)point_count;
 
  388     cmd->line_thickness = (
unsigned short)line_thickness;
 
  389     for (i = 0; i < point_count; ++i) {
 
  390         cmd->points[i].x = (short)points[i*2];
 
  391         cmd->points[i].y = (short)points[i*2+1];
 
  401     if (b->use_clipping) {
 
  402         const struct nk_rect *c = &b->clip;
 
  403         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))
 
  408         nk_command_buffer_push(b, NK_COMMAND_IMAGE, 
sizeof(*cmd));
 
  412     cmd->w = (
unsigned short)NK_MAX(0, r.w);
 
  413     cmd->h = (
unsigned short)NK_MAX(0, r.h);
 
  423     nk_ushort rgnX, rgnY, rgnW, rgnH;
 
  424     rgnX = slcimg->region[0];
 
  425     rgnY = slcimg->region[1];
 
  426     rgnW = slcimg->region[2];
 
  427     rgnH = slcimg->region[3];
 
  430     img.handle = slcimg->handle;
 
  433     img.region[0] = rgnX;
 
  434     img.region[1] = rgnY;
 
  435     img.region[2] = slc->l;
 
  436     img.region[3] = slc->t;
 
  439         nk_rect(r.x, r.y, (
float)slc->l, (
float)slc->t),
 
  442 #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); 
  445     IMG_RGN(rgnX + slc->l, rgnY, rgnW - slc->l - slc->r, slc->t);
 
  447         nk_rect(r.x + (
float)slc->l, r.y, (
float)(r.w - slc->l - slc->r), (
float)slc->t),
 
  451     IMG_RGN(rgnX + rgnW - slc->r, rgnY, slc->r, slc->t);
 
  453         nk_rect(r.x + r.w - (
float)slc->r, r.y, (
float)slc->r, (
float)slc->t),
 
  457     IMG_RGN(rgnX, rgnY + slc->t, slc->l, rgnH - slc->t - slc->b);
 
  459         nk_rect(r.x, r.y + (
float)slc->t, (
float)slc->l, (
float)(r.h - slc->t - slc->b)),
 
  463     IMG_RGN(rgnX + slc->l, rgnY + slc->t, rgnW - slc->l - slc->r, rgnH - slc->t - slc->b);
 
  465         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)),
 
  469     IMG_RGN(rgnX + rgnW - slc->r, rgnY + slc->t, slc->r, rgnH - slc->t - slc->b);
 
  471         nk_rect(r.x + r.w - (
float)slc->r, r.y + (
float)slc->t, (
float)slc->r, (
float)(r.h - slc->t - slc->b)),
 
  475     IMG_RGN(rgnX, rgnY + rgnH - slc->b, slc->l, slc->b);
 
  477         nk_rect(r.x, r.y + r.h - (
float)slc->b, (
float)slc->l, (
float)slc->b),
 
  481     IMG_RGN(rgnX + slc->l, rgnY + rgnH - slc->b, rgnW - slc->l - slc->r, slc->b);
 
  483         nk_rect(r.x + (
float)slc->l, r.y + r.h - (
float)slc->b, (
float)(r.w - slc->l - slc->r), (
float)slc->b),
 
  487     IMG_RGN(rgnX + rgnW - slc->r, rgnY + rgnH - slc->b, slc->r, slc->b);
 
  489         nk_rect(r.x + r.w - (
float)slc->r, r.y + r.h - (
float)slc->b, (
float)slc->r, (
float)slc->b),
 
  496     nk_command_custom_callback cb, 
nk_handle usr)
 
  501     if (b->use_clipping) {
 
  502         const struct nk_rect *c = &b->clip;
 
  503         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))
 
  508         nk_command_buffer_push(b, NK_COMMAND_CUSTOM, 
sizeof(*cmd));
 
  512     cmd->w = (
unsigned short)NK_MAX(0, r.w);
 
  513     cmd->h = (
unsigned short)NK_MAX(0, r.h);
 
  514     cmd->callback_data = usr;
 
  519     const char *
string, 
int length, 
const struct nk_user_font *font,
 
  522     float text_width = 0;
 
  527     if (!b || !
string || !length || (bg.a == 0 && fg.a == 0)) 
return;
 
  528     if (b->use_clipping) {
 
  529         const struct nk_rect *c = &b->clip;
 
  530         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))
 
  535     text_width = font->
width(font->userdata, font->
height, 
string, length);
 
  536     if (text_width > r.w){
 
  538         float txt_width = (float)text_width;
 
  539         length = nk_text_clamp(font, 
string, length, r.w, &glyphs, &txt_width, 0,0);
 
  544         nk_command_buffer_push(b, NK_COMMAND_TEXT, 
sizeof(*cmd) + (nk_size)(length + 1));
 
  548     cmd->w = (
unsigned short)r.w;
 
  549     cmd->h = (
unsigned short)r.h;
 
  550     cmd->background = bg;
 
  551     cmd->foreground = fg;
 
  553     cmd->length = length;
 
  554     cmd->height = font->
height;
 
  555     NK_MEMCPY(cmd->string, 
string, (nk_size)length);
 
  556     cmd->string[length] = 
'\0';
 
main API and documentation file
 
NK_API void nk_draw_image(struct nk_command_buffer *, struct nk_rect, const struct nk_image *, struct nk_color)
misc
 
NK_API void nk_stroke_line(struct nk_command_buffer *b, float x0, float y0, float x1, float y1, float line_thickness, struct nk_color)
shape outlines
 
NK_API void nk_fill_rect(struct nk_command_buffer *, struct nk_rect, float rounding, struct nk_color)
filled shades
 
struct nk_memory memory
!< memory management type
 
nk_size allocated
!< growing factor for dynamic memory management
 
command base and header of every command inside the buffer
 
nk_text_width_f width
!< max height of the font
 
float height
!< user provided font handle