2#include "nuklear_internal.h"
9#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
11nk_draw_list_init(
struct nk_draw_list *list)
16 nk_zero(list,
sizeof(*list));
17 for (i = 0; i < NK_LEN(list->circle_vtx); ++i) {
18 const float a = ((float)i / (
float)NK_LEN(list->circle_vtx)) * 2 * NK_PI;
19 list->circle_vtx[i].x = (float)NK_COS(a);
20 list->circle_vtx[i].y = (float)NK_SIN(a);
24nk_draw_list_setup(
struct nk_draw_list *canvas,
const struct nk_convert_config *config,
26 enum nk_anti_aliasing line_aa,
enum nk_anti_aliasing shape_aa)
33 if (!canvas || !config || !cmds || !vertices || !elements)
36 canvas->buffer = cmds;
37 canvas->config = *config;
38 canvas->elements = elements;
39 canvas->vertices = vertices;
40 canvas->line_AA = line_aa;
41 canvas->shape_AA = shape_aa;
42 canvas->clip_rect = nk_null_rect;
44 canvas->cmd_offset = 0;
45 canvas->element_count = 0;
46 canvas->vertex_count = 0;
47 canvas->cmd_offset = 0;
48 canvas->cmd_count = 0;
49 canvas->path_count = 0;
51NK_API
const struct nk_draw_command*
52nk__draw_list_begin(
const struct nk_draw_list *canvas,
const struct nk_buffer *buffer)
56 const struct nk_draw_command *cmd;
59 if (!buffer || !buffer->
size || !canvas->cmd_count)
62 memory = (nk_byte*)buffer->
memory.ptr;
63 offset = buffer->
memory.size - canvas->cmd_offset;
64 cmd = nk_ptr_add(
const struct nk_draw_command, memory, offset);
67NK_API
const struct nk_draw_command*
68nk__draw_list_end(
const struct nk_draw_list *canvas,
const struct nk_buffer *buffer)
73 const struct nk_draw_command *end;
77 if (!buffer || !canvas)
80 memory = (nk_byte*)buffer->
memory.ptr;
81 size = buffer->
memory.size;
82 offset = size - canvas->cmd_offset;
83 end = nk_ptr_add(
const struct nk_draw_command, memory, offset);
84 end -= (canvas->cmd_count-1);
87NK_API
const struct nk_draw_command*
88nk__draw_list_next(
const struct nk_draw_command *cmd,
89 const struct nk_buffer *buffer,
const struct nk_draw_list *canvas)
91 const struct nk_draw_command *end;
94 if (!cmd || !buffer || !canvas)
97 end = nk__draw_list_end(canvas, buffer);
98 if (cmd <= end)
return 0;
102nk_draw_list_alloc_path(
struct nk_draw_list *list,
int count)
105 NK_STORAGE
const nk_size point_align = NK_ALIGNOF(
struct nk_vec2);
106 NK_STORAGE
const nk_size point_size =
sizeof(
struct nk_vec2);
108 nk_buffer_alloc(list->buffer, NK_BUFFER_FRONT,
109 point_size * (nk_size)count, point_align);
111 if (!points)
return 0;
112 if (!list->path_offset) {
113 void *memory = nk_buffer_memory(list->buffer);
114 list->path_offset = (
unsigned int)((nk_byte*)points - (nk_byte*)memory);
116 list->path_count += (
unsigned int)count;
120nk_draw_list_path_last(struct nk_draw_list *list)
124 NK_ASSERT(list->path_count);
125 memory = nk_buffer_memory(list->buffer);
126 point = nk_ptr_add(
struct nk_vec2, memory, list->path_offset);
127 point += (list->path_count-1);
130NK_INTERN
struct nk_draw_command*
131nk_draw_list_push_command(
struct nk_draw_list *list,
struct nk_rect clip,
134 NK_STORAGE
const nk_size cmd_align = NK_ALIGNOF(
struct nk_draw_command);
135 NK_STORAGE
const nk_size cmd_size =
sizeof(
struct nk_draw_command);
136 struct nk_draw_command *cmd;
139 cmd = (
struct nk_draw_command*)
140 nk_buffer_alloc(list->buffer, NK_BUFFER_BACK, cmd_size, cmd_align);
143 if (!list->cmd_count) {
144 nk_byte *memory = (nk_byte*)nk_buffer_memory(list->buffer);
145 nk_size total = nk_buffer_total(list->buffer);
146 memory = nk_ptr_add(nk_byte, memory, total);
147 list->cmd_offset = (nk_size)(memory - (nk_byte*)cmd);
151 cmd->clip_rect = clip;
152 cmd->texture = texture;
153#ifdef NK_INCLUDE_COMMAND_USERDATA
154 cmd->userdata = list->userdata;
158 list->clip_rect = clip;
161NK_INTERN
struct nk_draw_command*
162nk_draw_list_command_last(
struct nk_draw_list *list)
166 struct nk_draw_command *cmd;
167 NK_ASSERT(list->cmd_count);
169 memory = nk_buffer_memory(list->buffer);
170 size = nk_buffer_total(list->buffer);
171 cmd = nk_ptr_add(
struct nk_draw_command, memory, size - list->cmd_offset);
172 return (cmd - (list->cmd_count-1));
175nk_draw_list_add_clip(
struct nk_draw_list *list,
struct nk_rect rect)
179 if (!list->cmd_count) {
180 nk_draw_list_push_command(list, rect, list->config.tex_null.texture);
182 struct nk_draw_command *prev = nk_draw_list_command_last(list);
183 if (prev->elem_count == 0)
184 prev->clip_rect = rect;
185 nk_draw_list_push_command(list, rect, prev->texture);
189nk_draw_list_push_image(
struct nk_draw_list *list,
nk_handle texture)
193 if (!list->cmd_count) {
194 nk_draw_list_push_command(list, nk_null_rect, texture);
196 struct nk_draw_command *prev = nk_draw_list_command_last(list);
197 if (prev->elem_count == 0) {
198 prev->texture = texture;
199 #ifdef NK_INCLUDE_COMMAND_USERDATA
200 prev->userdata = list->userdata;
202 }
else if (prev->texture.id != texture.id
203 #ifdef NK_INCLUDE_COMMAND_USERDATA
204 || prev->userdata.id != list->userdata.id
207 nk_draw_list_push_command(list, prev->clip_rect, texture);
211#ifdef NK_INCLUDE_COMMAND_USERDATA
213nk_draw_list_push_userdata(
struct nk_draw_list *list,
nk_handle userdata)
215 list->userdata = userdata;
219nk_draw_list_alloc_vertices(
struct nk_draw_list *list, nk_size count)
224 vtx = nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT,
225 list->config.vertex_size*count, list->config.vertex_alignment);
227 list->vertex_count += (
unsigned int)count;
238 if(
sizeof(nk_draw_index)==2) NK_ASSERT((list->vertex_count < NK_USHORT_MAX &&
239 "To many vertices for 16-bit vertex indices. Please read comment above on how to solve this problem"));
242NK_INTERN nk_draw_index*
243nk_draw_list_alloc_elements(
struct nk_draw_list *list, nk_size count)
246 struct nk_draw_command *cmd;
247 NK_STORAGE
const nk_size elem_align = NK_ALIGNOF(nk_draw_index);
248 NK_STORAGE
const nk_size elem_size =
sizeof(nk_draw_index);
252 ids = (nk_draw_index*)
253 nk_buffer_alloc(list->elements, NK_BUFFER_FRONT, elem_size*count, elem_align);
255 cmd = nk_draw_list_command_last(list);
256 list->element_count += (
unsigned int)count;
257 cmd->elem_count += (
unsigned int)count;
261nk_draw_vertex_layout_element_is_end_of_layout(
262 const struct nk_draw_vertex_layout_element *element)
264 return (element->attribute == NK_VERTEX_ATTRIBUTE_COUNT ||
265 element->format == NK_FORMAT_COUNT);
268nk_draw_vertex_color(
void *attr,
const float *vals,
269 enum nk_draw_vertex_layout_format format)
273 NK_ASSERT(format >= NK_FORMAT_COLOR_BEGIN);
274 NK_ASSERT(format <= NK_FORMAT_COLOR_END);
275 if (format < NK_FORMAT_COLOR_BEGIN || format > NK_FORMAT_COLOR_END)
return;
277 val[0] = NK_SATURATE(vals[0]);
278 val[1] = NK_SATURATE(vals[1]);
279 val[2] = NK_SATURATE(vals[2]);
280 val[3] = NK_SATURATE(vals[3]);
283 default: NK_ASSERT(0 &&
"Invalid vertex layout color format");
break;
284 case NK_FORMAT_R8G8B8A8:
285 case NK_FORMAT_R8G8B8: {
286 struct nk_color col = nk_rgba_fv(val);
287 NK_MEMCPY(attr, &col.r,
sizeof(col));
289 case NK_FORMAT_B8G8R8A8: {
290 struct nk_color col = nk_rgba_fv(val);
291 struct nk_color bgra = nk_rgba(col.b, col.g, col.r, col.a);
292 NK_MEMCPY(attr, &bgra,
sizeof(bgra));
294 case NK_FORMAT_R16G15B16: {
296 col[0] = (nk_ushort)(val[0]*(
float)NK_USHORT_MAX);
297 col[1] = (nk_ushort)(val[1]*(
float)NK_USHORT_MAX);
298 col[2] = (nk_ushort)(val[2]*(
float)NK_USHORT_MAX);
299 NK_MEMCPY(attr, col,
sizeof(col));
301 case NK_FORMAT_R16G15B16A16: {
303 col[0] = (nk_ushort)(val[0]*(
float)NK_USHORT_MAX);
304 col[1] = (nk_ushort)(val[1]*(
float)NK_USHORT_MAX);
305 col[2] = (nk_ushort)(val[2]*(
float)NK_USHORT_MAX);
306 col[3] = (nk_ushort)(val[3]*(
float)NK_USHORT_MAX);
307 NK_MEMCPY(attr, col,
sizeof(col));
309 case NK_FORMAT_R32G32B32: {
311 col[0] = (nk_uint)(val[0]*(
float)NK_UINT_MAX);
312 col[1] = (nk_uint)(val[1]*(
float)NK_UINT_MAX);
313 col[2] = (nk_uint)(val[2]*(
float)NK_UINT_MAX);
314 NK_MEMCPY(attr, col,
sizeof(col));
316 case NK_FORMAT_R32G32B32A32: {
318 col[0] = (nk_uint)(val[0]*(
float)NK_UINT_MAX);
319 col[1] = (nk_uint)(val[1]*(
float)NK_UINT_MAX);
320 col[2] = (nk_uint)(val[2]*(
float)NK_UINT_MAX);
321 col[3] = (nk_uint)(val[3]*(
float)NK_UINT_MAX);
322 NK_MEMCPY(attr, col,
sizeof(col));
324 case NK_FORMAT_R32G32B32A32_FLOAT:
325 NK_MEMCPY(attr, val,
sizeof(
float)*4);
327 case NK_FORMAT_R32G32B32A32_DOUBLE: {
329 col[0] = (double)val[0];
330 col[1] = (double)val[1];
331 col[2] = (double)val[2];
332 col[3] = (double)val[3];
333 NK_MEMCPY(attr, col,
sizeof(col));
335 case NK_FORMAT_RGB32:
336 case NK_FORMAT_RGBA32: {
337 struct nk_color col = nk_rgba_fv(val);
338 nk_uint color = nk_color_u32(col);
339 NK_MEMCPY(attr, &color,
sizeof(color));
343nk_draw_vertex_element(
void *dst,
const float *values,
int value_count,
344 enum nk_draw_vertex_layout_format format)
347 void *attribute = dst;
349 NK_ASSERT(format < NK_FORMAT_COLOR_BEGIN);
350 if (format >= NK_FORMAT_COLOR_BEGIN && format <= NK_FORMAT_COLOR_END)
return;
351 for (value_index = 0; value_index < value_count; ++value_index) {
353 default: NK_ASSERT(0 &&
"invalid vertex layout format");
break;
354 case NK_FORMAT_SCHAR: {
355 char value = (char)NK_CLAMP((
float)NK_SCHAR_MIN, values[value_index], (float)NK_SCHAR_MAX);
356 NK_MEMCPY(attribute, &value,
sizeof(value));
357 attribute = (
void*)((
char*)attribute +
sizeof(char));
359 case NK_FORMAT_SSHORT: {
360 nk_short value = (nk_short)NK_CLAMP((
float)NK_SSHORT_MIN, values[value_index], (float)NK_SSHORT_MAX);
361 NK_MEMCPY(attribute, &value,
sizeof(value));
362 attribute = (
void*)((
char*)attribute +
sizeof(value));
364 case NK_FORMAT_SINT: {
365 nk_int value = (nk_int)NK_CLAMP((
float)NK_SINT_MIN, values[value_index], (float)NK_SINT_MAX);
366 NK_MEMCPY(attribute, &value,
sizeof(value));
367 attribute = (
void*)((
char*)attribute +
sizeof(nk_int));
369 case NK_FORMAT_UCHAR: {
370 unsigned char value = (
unsigned char)NK_CLAMP((
float)NK_UCHAR_MIN, values[value_index], (float)NK_UCHAR_MAX);
371 NK_MEMCPY(attribute, &value,
sizeof(value));
372 attribute = (
void*)((
char*)attribute +
sizeof(
unsigned char));
374 case NK_FORMAT_USHORT: {
375 nk_ushort value = (nk_ushort)NK_CLAMP((
float)NK_USHORT_MIN, values[value_index], (float)NK_USHORT_MAX);
376 NK_MEMCPY(attribute, &value,
sizeof(value));
377 attribute = (
void*)((
char*)attribute +
sizeof(value));
379 case NK_FORMAT_UINT: {
380 nk_uint value = (nk_uint)NK_CLAMP((
float)NK_UINT_MIN, values[value_index], (float)NK_UINT_MAX);
381 NK_MEMCPY(attribute, &value,
sizeof(value));
382 attribute = (
void*)((
char*)attribute +
sizeof(nk_uint));
384 case NK_FORMAT_FLOAT:
385 NK_MEMCPY(attribute, &values[value_index],
sizeof(values[value_index]));
386 attribute = (
void*)((
char*)attribute +
sizeof(float));
388 case NK_FORMAT_DOUBLE: {
389 double value = (double)values[value_index];
390 NK_MEMCPY(attribute, &value,
sizeof(value));
391 attribute = (
void*)((
char*)attribute +
sizeof(double));
400 void *result = (
void*)((
char*)dst + config->
vertex_size);
401 const struct nk_draw_vertex_layout_element *elem_iter = config->
vertex_layout;
402 while (!nk_draw_vertex_layout_element_is_end_of_layout(elem_iter)) {
403 void *address = (
void*)((
char*)dst + elem_iter->offset);
404 switch (elem_iter->attribute) {
405 case NK_VERTEX_ATTRIBUTE_COUNT:
406 default: NK_ASSERT(0 &&
"wrong element attribute");
break;
407 case NK_VERTEX_POSITION: nk_draw_vertex_element(address, &pos.x, 2, elem_iter->format);
break;
408 case NK_VERTEX_TEXCOORD: nk_draw_vertex_element(address, &uv.x, 2, elem_iter->format);
break;
409 case NK_VERTEX_COLOR: nk_draw_vertex_color(address, &color.r, elem_iter->format);
break;
416nk_draw_list_stroke_poly_line(
struct nk_draw_list *list,
const struct nk_vec2 *points,
417 const unsigned int points_count,
struct nk_color color,
enum nk_draw_list_stroke closed,
418 float thickness,
enum nk_anti_aliasing aliasing)
425 if (!list || points_count < 2)
return;
427 color.a = (nk_byte)((
float)color.a * list->config.global_alpha);
428 count = points_count;
429 if (!closed) count = points_count-1;
430 thick_line = thickness > 1.0f;
432#ifdef NK_INCLUDE_COMMAND_USERDATA
433 nk_draw_list_push_userdata(list, list->userdata);
436 color.a = (nk_byte)((
float)color.a * list->config.global_alpha);
437 nk_color_fv(&col.r, color);
441 if (aliasing == NK_ANTI_ALIASING_ON) {
443 const float AA_SIZE = 1.0f;
444 NK_STORAGE
const nk_size pnt_align = NK_ALIGNOF(
struct nk_vec2);
445 NK_STORAGE
const nk_size pnt_size =
sizeof(
struct nk_vec2);
449 nk_size vertex_offset;
450 nk_size index = list->vertex_count;
452 const nk_size idx_count = (thick_line) ? (count * 18) : (count * 12);
453 const nk_size vtx_count = (thick_line) ? (points_count * 4): (points_count *3);
455 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
456 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
459 struct nk_vec2 *normals, *temp;
460 if (!vtx || !ids)
return;
463 vertex_offset = (nk_size)((nk_byte*)vtx - (nk_byte*)list->vertices->memory.ptr);
464 nk_buffer_mark(list->vertices, NK_BUFFER_FRONT);
465 size = pnt_size * ((thick_line) ? 5 : 3) * points_count;
466 normals = (
struct nk_vec2*) nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT, size, pnt_align);
467 if (!normals)
return;
468 temp = normals + points_count;
471 vtx = (
void*)((nk_byte*)list->vertices->memory.ptr + vertex_offset);
474 for (i1 = 0; i1 < count; ++i1) {
475 const nk_size i2 = ((i1 + 1) == points_count) ? 0 : (i1 + 1);
476 struct nk_vec2 diff = nk_vec2_sub(points[i2], points[i1]);
480 len = nk_vec2_len_sqr(diff);
482 len = NK_INV_SQRT(len);
485 diff = nk_vec2_muls(diff, len);
486 normals[i1].x = diff.y;
487 normals[i1].y = -diff.x;
491 normals[points_count-1] = normals[points_count-2];
497 temp[0] = nk_vec2_add(points[0], nk_vec2_muls(normals[0], AA_SIZE));
498 temp[1] = nk_vec2_sub(points[0], nk_vec2_muls(normals[0], AA_SIZE));
499 d = nk_vec2_muls(normals[points_count-1], AA_SIZE);
500 temp[(points_count-1) * 2 + 0] = nk_vec2_add(points[points_count-1], d);
501 temp[(points_count-1) * 2 + 1] = nk_vec2_sub(points[points_count-1], d);
506 for (i1 = 0; i1 < count; i1++) {
509 nk_size i2 = ((i1 + 1) == points_count) ? 0 : (i1 + 1);
510 nk_size idx2 = ((i1+1) == points_count) ? index: (idx1 + 3);
513 dm = nk_vec2_muls(nk_vec2_add(normals[i1], normals[i2]), 0.5f);
514 dmr2 = dm.x * dm.x + dm.y* dm.y;
515 if (dmr2 > 0.000001f) {
516 float scale = 1.0f/dmr2;
517 scale = NK_MIN(100.0f, scale);
518 dm = nk_vec2_muls(dm, scale);
521 dm = nk_vec2_muls(dm, AA_SIZE);
522 temp[i2*2+0] = nk_vec2_add(points[i2], dm);
523 temp[i2*2+1] = nk_vec2_sub(points[i2], dm);
525 ids[0] = (nk_draw_index)(idx2 + 0); ids[1] = (nk_draw_index)(idx1+0);
526 ids[2] = (nk_draw_index)(idx1 + 2); ids[3] = (nk_draw_index)(idx1+2);
527 ids[4] = (nk_draw_index)(idx2 + 2); ids[5] = (nk_draw_index)(idx2+0);
528 ids[6] = (nk_draw_index)(idx2 + 1); ids[7] = (nk_draw_index)(idx1+1);
529 ids[8] = (nk_draw_index)(idx1 + 0); ids[9] = (nk_draw_index)(idx1+0);
530 ids[10]= (nk_draw_index)(idx2 + 0); ids[11]= (nk_draw_index)(idx2+1);
536 for (i = 0; i < points_count; ++i) {
537 const struct nk_vec2 uv = list->config.tex_null.uv;
538 vtx = nk_draw_vertex(vtx, &list->config, points[i], uv, col);
539 vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+0], uv, col_trans);
540 vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+1], uv, col_trans);
544 const float half_inner_thickness = (thickness - AA_SIZE) * 0.5f;
546 struct nk_vec2 d1 = nk_vec2_muls(normals[0], half_inner_thickness + AA_SIZE);
547 struct nk_vec2 d2 = nk_vec2_muls(normals[0], half_inner_thickness);
549 temp[0] = nk_vec2_add(points[0], d1);
550 temp[1] = nk_vec2_add(points[0], d2);
551 temp[2] = nk_vec2_sub(points[0], d2);
552 temp[3] = nk_vec2_sub(points[0], d1);
554 d1 = nk_vec2_muls(normals[points_count-1], half_inner_thickness + AA_SIZE);
555 d2 = nk_vec2_muls(normals[points_count-1], half_inner_thickness);
557 temp[(points_count-1)*4+0] = nk_vec2_add(points[points_count-1], d1);
558 temp[(points_count-1)*4+1] = nk_vec2_add(points[points_count-1], d2);
559 temp[(points_count-1)*4+2] = nk_vec2_sub(points[points_count-1], d2);
560 temp[(points_count-1)*4+3] = nk_vec2_sub(points[points_count-1], d1);
565 for (i1 = 0; i1 < count; ++i1) {
567 const nk_size i2 = ((i1+1) == points_count) ? 0: (i1 + 1);
568 nk_size idx2 = ((i1+1) == points_count) ? index: (idx1 + 4);
571 struct nk_vec2 dm = nk_vec2_muls(nk_vec2_add(normals[i1], normals[i2]), 0.5f);
572 float dmr2 = dm.x * dm.x + dm.y* dm.y;
573 if (dmr2 > 0.000001f) {
574 float scale = 1.0f/dmr2;
575 scale = NK_MIN(100.0f, scale);
576 dm = nk_vec2_muls(dm, scale);
579 dm_out = nk_vec2_muls(dm, ((half_inner_thickness) + AA_SIZE));
580 dm_in = nk_vec2_muls(dm, half_inner_thickness);
581 temp[i2*4+0] = nk_vec2_add(points[i2], dm_out);
582 temp[i2*4+1] = nk_vec2_add(points[i2], dm_in);
583 temp[i2*4+2] = nk_vec2_sub(points[i2], dm_in);
584 temp[i2*4+3] = nk_vec2_sub(points[i2], dm_out);
587 ids[0] = (nk_draw_index)(idx2 + 1); ids[1] = (nk_draw_index)(idx1+1);
588 ids[2] = (nk_draw_index)(idx1 + 2); ids[3] = (nk_draw_index)(idx1+2);
589 ids[4] = (nk_draw_index)(idx2 + 2); ids[5] = (nk_draw_index)(idx2+1);
590 ids[6] = (nk_draw_index)(idx2 + 1); ids[7] = (nk_draw_index)(idx1+1);
591 ids[8] = (nk_draw_index)(idx1 + 0); ids[9] = (nk_draw_index)(idx1+0);
592 ids[10]= (nk_draw_index)(idx2 + 0); ids[11] = (nk_draw_index)(idx2+1);
593 ids[12]= (nk_draw_index)(idx2 + 2); ids[13] = (nk_draw_index)(idx1+2);
594 ids[14]= (nk_draw_index)(idx1 + 3); ids[15] = (nk_draw_index)(idx1+3);
595 ids[16]= (nk_draw_index)(idx2 + 3); ids[17] = (nk_draw_index)(idx2+2);
601 for (i = 0; i < points_count; ++i) {
602 const struct nk_vec2 uv = list->config.tex_null.uv;
603 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+0], uv, col_trans);
604 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+1], uv, col);
605 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+2], uv, col);
606 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+3], uv, col_trans);
610 nk_buffer_reset(list->vertices, NK_BUFFER_FRONT);
614 nk_size idx = list->vertex_count;
615 const nk_size idx_count = count * 6;
616 const nk_size vtx_count = count * 4;
617 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
618 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
619 if (!vtx || !ids)
return;
621 for (i1 = 0; i1 < count; ++i1) {
623 const struct nk_vec2 uv = list->config.tex_null.uv;
624 const nk_size i2 = ((i1+1) == points_count) ? 0 : i1 + 1;
625 const struct nk_vec2 p1 = points[i1];
626 const struct nk_vec2 p2 = points[i2];
627 struct nk_vec2 diff = nk_vec2_sub(p2, p1);
631 len = nk_vec2_len_sqr(diff);
633 len = NK_INV_SQRT(len);
635 diff = nk_vec2_muls(diff, len);
638 dx = diff.x * (thickness * 0.5f);
639 dy = diff.y * (thickness * 0.5f);
641 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p1.x + dy, p1.y - dx), uv, col);
642 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p2.x + dy, p2.y - dx), uv, col);
643 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p2.x - dy, p2.y + dx), uv, col);
644 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p1.x - dy, p1.y + dx), uv, col);
646 ids[0] = (nk_draw_index)(idx+0); ids[1] = (nk_draw_index)(idx+1);
647 ids[2] = (nk_draw_index)(idx+2); ids[3] = (nk_draw_index)(idx+0);
648 ids[4] = (nk_draw_index)(idx+2); ids[5] = (nk_draw_index)(idx+3);
656nk_draw_list_fill_poly_convex(
struct nk_draw_list *list,
657 const struct nk_vec2 *points,
const unsigned int points_count,
658 struct nk_color color,
enum nk_anti_aliasing aliasing)
663 NK_STORAGE
const nk_size pnt_align = NK_ALIGNOF(
struct nk_vec2);
664 NK_STORAGE
const nk_size pnt_size =
sizeof(
struct nk_vec2);
666 if (!list || points_count < 3)
return;
668#ifdef NK_INCLUDE_COMMAND_USERDATA
669 nk_draw_list_push_userdata(list, list->userdata);
672 color.a = (nk_byte)((
float)color.a * list->config.global_alpha);
673 nk_color_fv(&col.r, color);
677 if (aliasing == NK_ANTI_ALIASING_ON) {
682 const float AA_SIZE = 1.0f;
683 nk_size vertex_offset = 0;
684 nk_size index = list->vertex_count;
686 const nk_size idx_count = (points_count-2)*3 + points_count*6;
687 const nk_size vtx_count = (points_count*2);
689 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
690 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
694 unsigned int vtx_inner_idx = (
unsigned int)(index + 0);
695 unsigned int vtx_outer_idx = (
unsigned int)(index + 1);
696 if (!vtx || !ids)
return;
699 vertex_offset = (nk_size)((nk_byte*)vtx - (nk_byte*)list->vertices->memory.ptr);
700 nk_buffer_mark(list->vertices, NK_BUFFER_FRONT);
701 size = pnt_size * points_count;
702 normals = (
struct nk_vec2*) nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT, size, pnt_align);
703 if (!normals)
return;
704 vtx = (
void*)((nk_byte*)list->vertices->memory.ptr + vertex_offset);
707 for (i = 2; i < points_count; i++) {
708 ids[0] = (nk_draw_index)(vtx_inner_idx);
709 ids[1] = (nk_draw_index)(vtx_inner_idx + ((i-1) << 1));
710 ids[2] = (nk_draw_index)(vtx_inner_idx + (i << 1));
715 for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) {
716 struct nk_vec2 p0 = points[i0];
717 struct nk_vec2 p1 = points[i1];
718 struct nk_vec2 diff = nk_vec2_sub(p1, p0);
721 float len = nk_vec2_len_sqr(diff);
723 len = NK_INV_SQRT(len);
725 diff = nk_vec2_muls(diff, len);
727 normals[i0].x = diff.y;
728 normals[i0].y = -diff.x;
732 for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) {
733 const struct nk_vec2 uv = list->config.tex_null.uv;
734 struct nk_vec2 n0 = normals[i0];
735 struct nk_vec2 n1 = normals[i1];
736 struct nk_vec2 dm = nk_vec2_muls(nk_vec2_add(n0, n1), 0.5f);
737 float dmr2 = dm.x*dm.x + dm.y*dm.y;
738 if (dmr2 > 0.000001f) {
739 float scale = 1.0f / dmr2;
740 scale = NK_MIN(scale, 100.0f);
741 dm = nk_vec2_muls(dm, scale);
743 dm = nk_vec2_muls(dm, AA_SIZE * 0.5f);
746 vtx = nk_draw_vertex(vtx, &list->config, nk_vec2_sub(points[i1], dm), uv, col);
747 vtx = nk_draw_vertex(vtx, &list->config, nk_vec2_add(points[i1], dm), uv, col_trans);
750 ids[0] = (nk_draw_index)(vtx_inner_idx+(i1<<1));
751 ids[1] = (nk_draw_index)(vtx_inner_idx+(i0<<1));
752 ids[2] = (nk_draw_index)(vtx_outer_idx+(i0<<1));
753 ids[3] = (nk_draw_index)(vtx_outer_idx+(i0<<1));
754 ids[4] = (nk_draw_index)(vtx_outer_idx+(i1<<1));
755 ids[5] = (nk_draw_index)(vtx_inner_idx+(i1<<1));
759 nk_buffer_reset(list->vertices, NK_BUFFER_FRONT);
762 nk_size index = list->vertex_count;
763 const nk_size idx_count = (points_count-2)*3;
764 const nk_size vtx_count = points_count;
765 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
766 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
768 if (!vtx || !ids)
return;
769 for (i = 0; i < vtx_count; ++i)
770 vtx = nk_draw_vertex(vtx, &list->config, points[i], list->config.tex_null.uv, col);
771 for (i = 2; i < points_count; ++i) {
772 ids[0] = (nk_draw_index)index;
773 ids[1] = (nk_draw_index)(index+ i - 1);
774 ids[2] = (nk_draw_index)(index+i);
780nk_draw_list_path_clear(
struct nk_draw_list *list)
784 nk_buffer_reset(list->buffer, NK_BUFFER_FRONT);
785 list->path_count = 0;
786 list->path_offset = 0;
789nk_draw_list_path_line_to(
struct nk_draw_list *list,
struct nk_vec2 pos)
792 struct nk_draw_command *cmd = 0;
795 if (!list->cmd_count)
796 nk_draw_list_add_clip(list, nk_null_rect);
798 cmd = nk_draw_list_command_last(list);
799 if (cmd && cmd->texture.ptr != list->config.tex_null.texture.ptr)
800 nk_draw_list_push_image(list, list->config.tex_null.texture);
802 points = nk_draw_list_alloc_path(list, 1);
807nk_draw_list_path_arc_to_fast(
struct nk_draw_list *list,
struct nk_vec2 center,
808 float radius,
int a_min,
int a_max)
813 if (a_min <= a_max) {
814 for (a = a_min; a <= a_max; a++) {
815 const struct nk_vec2 c = list->circle_vtx[(nk_size)a % NK_LEN(list->circle_vtx)];
816 const float x = center.x + c.x * radius;
817 const float y = center.y + c.y * radius;
818 nk_draw_list_path_line_to(list,
nk_vec2(x, y));
823nk_draw_list_path_arc_to(
struct nk_draw_list *list,
struct nk_vec2 center,
824 float radius,
float a_min,
float a_max,
unsigned int segments)
829 if (radius == 0.0f)
return;
849 {
const float d_angle = (a_max - a_min) / (
float)segments;
850 const float sin_d = (float)NK_SIN(d_angle);
851 const float cos_d = (float)NK_COS(d_angle);
853 float cx = (float)NK_COS(a_min) * radius;
854 float cy = (float)NK_SIN(a_min) * radius;
855 for(i = 0; i <= segments; ++i) {
856 float new_cx, new_cy;
857 const float x = center.x + cx;
858 const float y = center.y + cy;
859 nk_draw_list_path_line_to(list,
nk_vec2(x, y));
861 new_cx = cx * cos_d - cy * sin_d;
862 new_cy = cy * cos_d + cx * sin_d;
868nk_draw_list_path_rect_to(
struct nk_draw_list *list,
struct nk_vec2 a,
869 struct nk_vec2 b,
float rounding)
875 r = NK_MIN(r, ((b.x-a.x) < 0) ? -(b.x-a.x): (b.x-a.x));
876 r = NK_MIN(r, ((b.y-a.y) < 0) ? -(b.y-a.y): (b.y-a.y));
879 nk_draw_list_path_line_to(list, a);
880 nk_draw_list_path_line_to(list,
nk_vec2(b.x,a.y));
881 nk_draw_list_path_line_to(list, b);
882 nk_draw_list_path_line_to(list,
nk_vec2(a.x,b.y));
884 nk_draw_list_path_arc_to_fast(list,
nk_vec2(a.x + r, a.y + r), r, 6, 9);
885 nk_draw_list_path_arc_to_fast(list,
nk_vec2(b.x - r, a.y + r), r, 9, 12);
886 nk_draw_list_path_arc_to_fast(list,
nk_vec2(b.x - r, b.y - r), r, 0, 3);
887 nk_draw_list_path_arc_to_fast(list,
nk_vec2(a.x + r, b.y - r), r, 3, 6);
891nk_draw_list_path_curve_to(
struct nk_draw_list *list,
struct nk_vec2 p2,
899 NK_ASSERT(list->path_count);
900 if (!list || !list->path_count)
return;
901 num_segments = NK_MAX(num_segments, 1);
903 p1 = nk_draw_list_path_last(list);
904 t_step = 1.0f/(float)num_segments;
905 for (i_step = 1; i_step <= num_segments; ++i_step) {
906 float t = t_step * (float)i_step;
912 float x = w1 * p1.x + w2 * p2.x + w3 * p3.x + w4 * p4.x;
913 float y = w1 * p1.y + w2 * p2.y + w3 * p3.y + w4 * p4.y;
914 nk_draw_list_path_line_to(list,
nk_vec2(x,y));
918nk_draw_list_path_fill(
struct nk_draw_list *list,
struct nk_color color)
923 points = (
struct nk_vec2*)nk_buffer_memory(list->buffer);
924 nk_draw_list_fill_poly_convex(list, points, list->path_count, color, list->config.shape_AA);
925 nk_draw_list_path_clear(list);
928nk_draw_list_path_stroke(
struct nk_draw_list *list,
struct nk_color color,
929 enum nk_draw_list_stroke closed,
float thickness)
934 points = (
struct nk_vec2*)nk_buffer_memory(list->buffer);
935 nk_draw_list_stroke_poly_line(list, points, list->path_count, color,
936 closed, thickness, list->config.line_AA);
937 nk_draw_list_path_clear(list);
940nk_draw_list_stroke_line(
struct nk_draw_list *list,
struct nk_vec2 a,
944 if (!list || !col.a)
return;
945 if (list->line_AA == NK_ANTI_ALIASING_ON) {
946 nk_draw_list_path_line_to(list, a);
947 nk_draw_list_path_line_to(list, b);
949 nk_draw_list_path_line_to(list, nk_vec2_sub(a,
nk_vec2(0.5f,0.5f)));
950 nk_draw_list_path_line_to(list, nk_vec2_sub(b,
nk_vec2(0.5f,0.5f)));
952 nk_draw_list_path_stroke(list, col, NK_STROKE_OPEN, thickness);
955nk_draw_list_fill_rect(
struct nk_draw_list *list,
struct nk_rect rect,
956 struct nk_color col,
float rounding)
959 if (!list || !col.a)
return;
961 if (list->line_AA == NK_ANTI_ALIASING_ON) {
962 nk_draw_list_path_rect_to(list,
nk_vec2(rect.x, rect.y),
963 nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding);
965 nk_draw_list_path_rect_to(list,
nk_vec2(rect.x-0.5f, rect.y-0.5f),
966 nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding);
967 } nk_draw_list_path_fill(list, col);
970nk_draw_list_stroke_rect(
struct nk_draw_list *list,
struct nk_rect rect,
971 struct nk_color col,
float rounding,
float thickness)
974 if (!list || !col.a)
return;
975 if (list->line_AA == NK_ANTI_ALIASING_ON) {
976 nk_draw_list_path_rect_to(list,
nk_vec2(rect.x, rect.y),
977 nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding);
979 nk_draw_list_path_rect_to(list,
nk_vec2(rect.x-0.5f, rect.y-0.5f),
980 nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding);
981 } nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness);
984nk_draw_list_fill_rect_multi_color(
struct nk_draw_list *list,
struct nk_rect rect,
994 nk_color_fv(&col_left.r, left);
995 nk_color_fv(&col_right.r, right);
996 nk_color_fv(&col_top.r, top);
997 nk_color_fv(&col_bottom.r, bottom);
1002 nk_draw_list_push_image(list, list->config.tex_null.texture);
1003 index = (nk_draw_index)list->vertex_count;
1004 vtx = nk_draw_list_alloc_vertices(list, 4);
1005 idx = nk_draw_list_alloc_elements(list, 6);
1006 if (!vtx || !idx)
return;
1008 idx[0] = (nk_draw_index)(index+0); idx[1] = (nk_draw_index)(index+1);
1009 idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0);
1010 idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3);
1012 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.x, rect.y), list->config.tex_null.uv, col_left);
1013 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.x + rect.w, rect.y), list->config.tex_null.uv, col_top);
1014 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.x + rect.w, rect.y + rect.h), list->config.tex_null.uv, col_right);
1015 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.x, rect.y + rect.h), list->config.tex_null.uv, col_bottom);
1018nk_draw_list_fill_triangle(
struct nk_draw_list *list,
struct nk_vec2 a,
1022 if (!list || !col.a)
return;
1023 nk_draw_list_path_line_to(list, a);
1024 nk_draw_list_path_line_to(list, b);
1025 nk_draw_list_path_line_to(list, c);
1026 nk_draw_list_path_fill(list, col);
1029nk_draw_list_stroke_triangle(
struct nk_draw_list *list,
struct nk_vec2 a,
1033 if (!list || !col.a)
return;
1034 nk_draw_list_path_line_to(list, a);
1035 nk_draw_list_path_line_to(list, b);
1036 nk_draw_list_path_line_to(list, c);
1037 nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness);
1040nk_draw_list_fill_circle(
struct nk_draw_list *list,
struct nk_vec2 center,
1041 float radius,
struct nk_color col,
unsigned int segs)
1045 if (!list || !col.a)
return;
1046 a_max = NK_PI * 2.0f * ((float)segs - 1.0f) / (float)segs;
1047 nk_draw_list_path_arc_to(list, center, radius, 0.0f, a_max, segs);
1048 nk_draw_list_path_fill(list, col);
1051nk_draw_list_stroke_circle(
struct nk_draw_list *list,
struct nk_vec2 center,
1052 float radius,
struct nk_color col,
unsigned int segs,
float thickness)
1056 if (!list || !col.a)
return;
1057 a_max = NK_PI * 2.0f * ((float)segs - 1.0f) / (float)segs;
1058 nk_draw_list_path_arc_to(list, center, radius, 0.0f, a_max, segs);
1059 nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness);
1062nk_draw_list_stroke_curve(
struct nk_draw_list *list,
struct nk_vec2 p0,
1064 struct nk_color col,
unsigned int segments,
float thickness)
1067 if (!list || !col.a)
return;
1068 nk_draw_list_path_line_to(list, p0);
1069 nk_draw_list_path_curve_to(list, cp0, cp1, p1, segments);
1070 nk_draw_list_path_stroke(list, col, NK_STROKE_OPEN, thickness);
1073nk_draw_list_push_rect_uv(
struct nk_draw_list *list,
struct nk_vec2 a,
1085 nk_draw_index index;
1089 nk_color_fv(&col.r, color);
1095 index = (nk_draw_index)list->vertex_count;
1096 vtx = nk_draw_list_alloc_vertices(list, 4);
1097 idx = nk_draw_list_alloc_elements(list, 6);
1098 if (!vtx || !idx)
return;
1100 idx[0] = (nk_draw_index)(index+0); idx[1] = (nk_draw_index)(index+1);
1101 idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0);
1102 idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3);
1104 vtx = nk_draw_vertex(vtx, &list->config, a, uva, col);
1105 vtx = nk_draw_vertex(vtx, &list->config, b, uvb, col);
1106 vtx = nk_draw_vertex(vtx, &list->config, c, uvc, col);
1107 vtx = nk_draw_vertex(vtx, &list->config, d, uvd, col);
1110nk_draw_list_add_image(
struct nk_draw_list *list,
struct nk_image texture,
1116 nk_draw_list_push_image(list, texture.handle);
1117 if (nk_image_is_subimage(&texture)) {
1120 uv[0].x = (float)texture.region[0]/(
float)texture.w;
1121 uv[0].y = (float)texture.region[1]/(
float)texture.h;
1122 uv[1].x = (float)(texture.region[0] + texture.region[2])/(float)texture.w;
1123 uv[1].y = (float)(texture.region[1] + texture.region[3])/(float)texture.h;
1124 nk_draw_list_push_rect_uv(list,
nk_vec2(rect.x, rect.y),
1125 nk_vec2(rect.x + rect.w, rect.y + rect.h), uv[0], uv[1], color);
1126 }
else nk_draw_list_push_rect_uv(list,
nk_vec2(rect.x, rect.y),
1127 nk_vec2(rect.x + rect.w, rect.y + rect.h),
1131nk_draw_list_add_text(
struct nk_draw_list *list,
const struct nk_user_font *font,
1132 struct nk_rect rect,
const char *text,
int len,
float font_height,
1137 nk_rune unicode = 0;
1140 int next_glyph_len = 0;
1141 struct nk_user_font_glyph g;
1144 if (!list || !len || !text)
return;
1145 if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h,
1146 list->clip_rect.x, list->clip_rect.y, list->clip_rect.w, list->clip_rect.h))
return;
1148 nk_draw_list_push_image(list, font->texture);
1150 glyph_len = nk_utf_decode(text, &unicode, len);
1151 if (!glyph_len)
return;
1154 fg.a = (nk_byte)((
float)fg.a * list->config.global_alpha);
1155 while (text_len < len && glyph_len) {
1156 float gx, gy, gh, gw;
1157 float char_width = 0;
1161 next_glyph_len = nk_utf_decode(text + text_len + glyph_len, &next, (
int)len - text_len);
1162 font->query(font->userdata, font_height, &g, unicode,
1166 gx = x + g.offset.x;
1167 gy = rect.y + g.offset.y;
1168 gw = g.width; gh = g.height;
1169 char_width = g.xadvance;
1170 nk_draw_list_push_rect_uv(list,
nk_vec2(gx,gy),
nk_vec2(gx + gw, gy+ gh),
1171 g.uv[0], g.uv[1], fg);
1174 text_len += glyph_len;
1176 glyph_len = next_glyph_len;
1185 nk_flags res = NK_CONVERT_SUCCESS;
1189 NK_ASSERT(vertices);
1190 NK_ASSERT(elements);
1194 if (!ctx || !cmds || !vertices || !elements || !config || !config->
vertex_layout)
1195 return NK_CONVERT_INVALID_PARAM;
1197 nk_draw_list_setup(&ctx->draw_list, config, cmds, vertices, elements,
1201#ifdef NK_INCLUDE_COMMAND_USERDATA
1202 ctx->draw_list.userdata = cmd->userdata;
1204 switch (cmd->type) {
1205 case NK_COMMAND_NOP:
break;
1206 case NK_COMMAND_SCISSOR: {
1208 nk_draw_list_add_clip(&ctx->draw_list,
nk_rect(s->x, s->y, s->w, s->h));
1210 case NK_COMMAND_LINE: {
1212 nk_draw_list_stroke_line(&ctx->draw_list,
nk_vec2(l->begin.x, l->begin.y),
1213 nk_vec2(l->end.x, l->end.y), l->color, l->line_thickness);
1215 case NK_COMMAND_CURVE: {
1217 nk_draw_list_stroke_curve(&ctx->draw_list,
nk_vec2(q->begin.x, q->begin.y),
1219 q->ctrl[1].y),
nk_vec2(q->end.x, q->end.y), q->color,
1222 case NK_COMMAND_RECT: {
1224 nk_draw_list_stroke_rect(&ctx->draw_list,
nk_rect(r->x, r->y, r->w, r->h),
1225 r->color, (
float)r->rounding, r->line_thickness);
1227 case NK_COMMAND_RECT_FILLED: {
1229 nk_draw_list_fill_rect(&ctx->draw_list,
nk_rect(r->x, r->y, r->w, r->h),
1230 r->color, (
float)r->rounding);
1232 case NK_COMMAND_RECT_MULTI_COLOR: {
1234 nk_draw_list_fill_rect_multi_color(&ctx->draw_list,
nk_rect(r->x, r->y, r->w, r->h),
1235 r->left, r->top, r->right, r->bottom);
1237 case NK_COMMAND_CIRCLE: {
1239 nk_draw_list_stroke_circle(&ctx->draw_list,
nk_vec2((
float)c->x + (
float)c->w/2,
1240 (
float)c->y + (
float)c->h/2), (
float)c->w/2, c->color,
1243 case NK_COMMAND_CIRCLE_FILLED: {
1245 nk_draw_list_fill_circle(&ctx->draw_list,
nk_vec2((
float)c->x + (
float)c->w/2,
1246 (
float)c->y + (
float)c->h/2), (
float)c->w/2, c->color,
1249 case NK_COMMAND_ARC: {
1251 nk_draw_list_path_line_to(&ctx->draw_list,
nk_vec2(c->cx, c->cy));
1252 nk_draw_list_path_arc_to(&ctx->draw_list,
nk_vec2(c->cx, c->cy), c->r,
1254 nk_draw_list_path_stroke(&ctx->draw_list, c->color, NK_STROKE_CLOSED, c->line_thickness);
1256 case NK_COMMAND_ARC_FILLED: {
1258 nk_draw_list_path_line_to(&ctx->draw_list,
nk_vec2(c->cx, c->cy));
1259 nk_draw_list_path_arc_to(&ctx->draw_list,
nk_vec2(c->cx, c->cy), c->r,
1261 nk_draw_list_path_fill(&ctx->draw_list, c->color);
1263 case NK_COMMAND_TRIANGLE: {
1265 nk_draw_list_stroke_triangle(&ctx->draw_list,
nk_vec2(t->a.x, t->a.y),
1269 case NK_COMMAND_TRIANGLE_FILLED: {
1271 nk_draw_list_fill_triangle(&ctx->draw_list,
nk_vec2(t->a.x, t->a.y),
1274 case NK_COMMAND_POLYGON: {
1277 for (i = 0; i < p->point_count; ++i) {
1278 struct nk_vec2 pnt =
nk_vec2((
float)p->points[i].x, (
float)p->points[i].y);
1279 nk_draw_list_path_line_to(&ctx->draw_list, pnt);
1281 nk_draw_list_path_stroke(&ctx->draw_list, p->color, NK_STROKE_CLOSED, p->line_thickness);
1283 case NK_COMMAND_POLYGON_FILLED: {
1286 for (i = 0; i < p->point_count; ++i) {
1287 struct nk_vec2 pnt =
nk_vec2((
float)p->points[i].x, (
float)p->points[i].y);
1288 nk_draw_list_path_line_to(&ctx->draw_list, pnt);
1290 nk_draw_list_path_fill(&ctx->draw_list, p->color);
1292 case NK_COMMAND_POLYLINE: {
1295 for (i = 0; i < p->point_count; ++i) {
1296 struct nk_vec2 pnt =
nk_vec2((
float)p->points[i].x, (
float)p->points[i].y);
1297 nk_draw_list_path_line_to(&ctx->draw_list, pnt);
1299 nk_draw_list_path_stroke(&ctx->draw_list, p->color, NK_STROKE_OPEN, p->line_thickness);
1301 case NK_COMMAND_TEXT: {
1303 nk_draw_list_add_text(&ctx->draw_list, t->font,
nk_rect(t->x, t->y, t->w, t->h),
1304 t->string, t->length, t->height, t->foreground);
1306 case NK_COMMAND_IMAGE: {
1308 nk_draw_list_add_image(&ctx->draw_list, i->img,
nk_rect(i->x, i->y, i->w, i->h), i->col);
1310 case NK_COMMAND_CUSTOM: {
1312 c->callback(&ctx->draw_list, c->x, c->y, c->w, c->h, c->callback_data);
1318 res |= (vertices->
needed > vertices->
allocated) ? NK_CONVERT_VERTEX_BUFFER_FULL: 0;
1319 res |= (elements->
needed > elements->
allocated) ? NK_CONVERT_ELEMENT_BUFFER_FULL: 0;
1322NK_API
const struct nk_draw_command*
1326 return nk__draw_list_begin(&ctx->draw_list, buffer);
1328NK_API
const struct nk_draw_command*
1331 return nk__draw_list_end(&ctx->draw_list, buffer);
1333NK_API
const struct nk_draw_command*
1334nk__draw_next(
const struct nk_draw_command *cmd,
1337 return nk__draw_list_next(cmd, buffer, &ctx->draw_list);
main API and documentation file
#define NK_UTF_INVALID
internal invalid utf8 rune
#define nk_foreach(c, ctx)
Iterates over each draw command inside the context draw command list.
struct nk_memory memory
!< memory management type
nk_size needed
!< total amount of memory allocated
nk_size size
!< number of allocation calls
nk_size allocated
!< growing factor for dynamic memory management
command base and header of every command inside the buffer
enum nk_anti_aliasing shape_AA
!< line anti-aliasing flag can be turned off if you are tight on memory
enum nk_anti_aliasing line_AA
!< global alpha value
nk_size vertex_size
!< describes the vertex output format and packing
const struct nk_draw_vertex_layout_element * vertex_layout
!< handle to texture with a white pixel for shape drawing
unsigned arc_segment_count
!< number of segments used for circles: default to 22
unsigned circle_segment_count
!< shape anti-aliasing flag can be turned off if you are tight on memory
unsigned curve_segment_count
!< number of segments used for arcs: default to 22