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 nk_color_fv(&col.r, color);
440 if (aliasing == NK_ANTI_ALIASING_ON) {
442 const float AA_SIZE = 1.0f;
443 NK_STORAGE
const nk_size pnt_align = NK_ALIGNOF(
struct nk_vec2);
444 NK_STORAGE
const nk_size pnt_size =
sizeof(
struct nk_vec2);
448 nk_size vertex_offset;
449 nk_size index = list->vertex_count;
451 const nk_size idx_count = (thick_line) ? (count * 18) : (count * 12);
452 const nk_size vtx_count = (thick_line) ? (points_count * 4): (points_count *3);
454 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
455 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
458 struct nk_vec2 *normals, *temp;
459 if (!vtx || !ids)
return;
462 vertex_offset = (nk_size)((nk_byte*)vtx - (nk_byte*)list->vertices->memory.ptr);
463 nk_buffer_mark(list->vertices, NK_BUFFER_FRONT);
464 size = pnt_size * ((thick_line) ? 5 : 3) * points_count;
465 normals = (
struct nk_vec2*) nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT, size, pnt_align);
466 if (!normals)
return;
467 temp = normals + points_count;
470 vtx = (
void*)((nk_byte*)list->vertices->memory.ptr + vertex_offset);
473 for (i1 = 0; i1 < count; ++i1) {
474 const nk_size i2 = ((i1 + 1) == points_count) ? 0 : (i1 + 1);
475 struct nk_vec2 diff = nk_vec2_sub(points[i2], points[i1]);
479 len = nk_vec2_len_sqr(diff);
481 len = NK_INV_SQRT(len);
484 diff = nk_vec2_muls(diff, len);
485 normals[i1].x = diff.y;
486 normals[i1].y = -diff.x;
490 normals[points_count-1] = normals[points_count-2];
496 temp[0] = nk_vec2_add(points[0], nk_vec2_muls(normals[0], AA_SIZE));
497 temp[1] = nk_vec2_sub(points[0], nk_vec2_muls(normals[0], AA_SIZE));
498 d = nk_vec2_muls(normals[points_count-1], AA_SIZE);
499 temp[(points_count-1) * 2 + 0] = nk_vec2_add(points[points_count-1], d);
500 temp[(points_count-1) * 2 + 1] = nk_vec2_sub(points[points_count-1], d);
505 for (i1 = 0; i1 < count; i1++) {
508 nk_size i2 = ((i1 + 1) == points_count) ? 0 : (i1 + 1);
509 nk_size idx2 = ((i1+1) == points_count) ? index: (idx1 + 3);
512 dm = nk_vec2_muls(nk_vec2_add(normals[i1], normals[i2]), 0.5f);
513 dmr2 = dm.x * dm.x + dm.y* dm.y;
514 if (dmr2 > 0.000001f) {
515 float scale = 1.0f/dmr2;
516 scale = NK_MIN(100.0f, scale);
517 dm = nk_vec2_muls(dm, scale);
520 dm = nk_vec2_muls(dm, AA_SIZE);
521 temp[i2*2+0] = nk_vec2_add(points[i2], dm);
522 temp[i2*2+1] = nk_vec2_sub(points[i2], dm);
524 ids[0] = (nk_draw_index)(idx2 + 0); ids[1] = (nk_draw_index)(idx1+0);
525 ids[2] = (nk_draw_index)(idx1 + 2); ids[3] = (nk_draw_index)(idx1+2);
526 ids[4] = (nk_draw_index)(idx2 + 2); ids[5] = (nk_draw_index)(idx2+0);
527 ids[6] = (nk_draw_index)(idx2 + 1); ids[7] = (nk_draw_index)(idx1+1);
528 ids[8] = (nk_draw_index)(idx1 + 0); ids[9] = (nk_draw_index)(idx1+0);
529 ids[10]= (nk_draw_index)(idx2 + 0); ids[11]= (nk_draw_index)(idx2+1);
535 for (i = 0; i < points_count; ++i) {
536 const struct nk_vec2 uv = list->config.tex_null.uv;
537 vtx = nk_draw_vertex(vtx, &list->config, points[i], uv, col);
538 vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+0], uv, col_trans);
539 vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+1], uv, col_trans);
543 const float half_inner_thickness = (thickness - AA_SIZE) * 0.5f;
545 struct nk_vec2 d1 = nk_vec2_muls(normals[0], half_inner_thickness + AA_SIZE);
546 struct nk_vec2 d2 = nk_vec2_muls(normals[0], half_inner_thickness);
548 temp[0] = nk_vec2_add(points[0], d1);
549 temp[1] = nk_vec2_add(points[0], d2);
550 temp[2] = nk_vec2_sub(points[0], d2);
551 temp[3] = nk_vec2_sub(points[0], d1);
553 d1 = nk_vec2_muls(normals[points_count-1], half_inner_thickness + AA_SIZE);
554 d2 = nk_vec2_muls(normals[points_count-1], half_inner_thickness);
556 temp[(points_count-1)*4+0] = nk_vec2_add(points[points_count-1], d1);
557 temp[(points_count-1)*4+1] = nk_vec2_add(points[points_count-1], d2);
558 temp[(points_count-1)*4+2] = nk_vec2_sub(points[points_count-1], d2);
559 temp[(points_count-1)*4+3] = nk_vec2_sub(points[points_count-1], d1);
564 for (i1 = 0; i1 < count; ++i1) {
566 const nk_size i2 = ((i1+1) == points_count) ? 0: (i1 + 1);
567 nk_size idx2 = ((i1+1) == points_count) ? index: (idx1 + 4);
570 struct nk_vec2 dm = nk_vec2_muls(nk_vec2_add(normals[i1], normals[i2]), 0.5f);
571 float dmr2 = dm.x * dm.x + dm.y* dm.y;
572 if (dmr2 > 0.000001f) {
573 float scale = 1.0f/dmr2;
574 scale = NK_MIN(100.0f, scale);
575 dm = nk_vec2_muls(dm, scale);
578 dm_out = nk_vec2_muls(dm, ((half_inner_thickness) + AA_SIZE));
579 dm_in = nk_vec2_muls(dm, half_inner_thickness);
580 temp[i2*4+0] = nk_vec2_add(points[i2], dm_out);
581 temp[i2*4+1] = nk_vec2_add(points[i2], dm_in);
582 temp[i2*4+2] = nk_vec2_sub(points[i2], dm_in);
583 temp[i2*4+3] = nk_vec2_sub(points[i2], dm_out);
586 ids[0] = (nk_draw_index)(idx2 + 1); ids[1] = (nk_draw_index)(idx1+1);
587 ids[2] = (nk_draw_index)(idx1 + 2); ids[3] = (nk_draw_index)(idx1+2);
588 ids[4] = (nk_draw_index)(idx2 + 2); ids[5] = (nk_draw_index)(idx2+1);
589 ids[6] = (nk_draw_index)(idx2 + 1); ids[7] = (nk_draw_index)(idx1+1);
590 ids[8] = (nk_draw_index)(idx1 + 0); ids[9] = (nk_draw_index)(idx1+0);
591 ids[10]= (nk_draw_index)(idx2 + 0); ids[11] = (nk_draw_index)(idx2+1);
592 ids[12]= (nk_draw_index)(idx2 + 2); ids[13] = (nk_draw_index)(idx1+2);
593 ids[14]= (nk_draw_index)(idx1 + 3); ids[15] = (nk_draw_index)(idx1+3);
594 ids[16]= (nk_draw_index)(idx2 + 3); ids[17] = (nk_draw_index)(idx2+2);
600 for (i = 0; i < points_count; ++i) {
601 const struct nk_vec2 uv = list->config.tex_null.uv;
602 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+0], uv, col_trans);
603 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+1], uv, col);
604 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+2], uv, col);
605 vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+3], uv, col_trans);
609 nk_buffer_reset(list->vertices, NK_BUFFER_FRONT);
613 nk_size idx = list->vertex_count;
614 const nk_size idx_count = count * 6;
615 const nk_size vtx_count = count * 4;
616 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
617 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
618 if (!vtx || !ids)
return;
620 for (i1 = 0; i1 < count; ++i1) {
622 const struct nk_vec2 uv = list->config.tex_null.uv;
623 const nk_size i2 = ((i1+1) == points_count) ? 0 : i1 + 1;
624 const struct nk_vec2 p1 = points[i1];
625 const struct nk_vec2 p2 = points[i2];
626 struct nk_vec2 diff = nk_vec2_sub(p2, p1);
630 len = nk_vec2_len_sqr(diff);
632 len = NK_INV_SQRT(len);
634 diff = nk_vec2_muls(diff, len);
637 dx = diff.x * (thickness * 0.5f);
638 dy = diff.y * (thickness * 0.5f);
640 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p1.x + dy, p1.y - dx), uv, col);
641 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(p2.x + dy, p2.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(p1.x - dy, p1.y + dx), uv, col);
645 ids[0] = (nk_draw_index)(idx+0); ids[1] = (nk_draw_index)(idx+1);
646 ids[2] = (nk_draw_index)(idx+2); ids[3] = (nk_draw_index)(idx+0);
647 ids[4] = (nk_draw_index)(idx+2); ids[5] = (nk_draw_index)(idx+3);
655nk_draw_list_fill_poly_convex(
struct nk_draw_list *list,
656 const struct nk_vec2 *points,
const unsigned int points_count,
657 struct nk_color color,
enum nk_anti_aliasing aliasing)
662 NK_STORAGE
const nk_size pnt_align = NK_ALIGNOF(
struct nk_vec2);
663 NK_STORAGE
const nk_size pnt_size =
sizeof(
struct nk_vec2);
665 if (!list || points_count < 3)
return;
667#ifdef NK_INCLUDE_COMMAND_USERDATA
668 nk_draw_list_push_userdata(list, list->userdata);
671 color.a = (nk_byte)((
float)color.a * list->config.global_alpha);
672 nk_color_fv(&col.r, color);
676 if (aliasing == NK_ANTI_ALIASING_ON) {
681 const float AA_SIZE = 1.0f;
682 nk_size vertex_offset = 0;
683 nk_size index = list->vertex_count;
685 const nk_size idx_count = (points_count-2)*3 + points_count*6;
686 const nk_size vtx_count = (points_count*2);
688 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
689 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
693 unsigned int vtx_inner_idx = (
unsigned int)(index + 0);
694 unsigned int vtx_outer_idx = (
unsigned int)(index + 1);
695 if (!vtx || !ids)
return;
698 vertex_offset = (nk_size)((nk_byte*)vtx - (nk_byte*)list->vertices->memory.ptr);
699 nk_buffer_mark(list->vertices, NK_BUFFER_FRONT);
700 size = pnt_size * points_count;
701 normals = (
struct nk_vec2*) nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT, size, pnt_align);
702 if (!normals)
return;
703 vtx = (
void*)((nk_byte*)list->vertices->memory.ptr + vertex_offset);
706 for (i = 2; i < points_count; i++) {
707 ids[0] = (nk_draw_index)(vtx_inner_idx);
708 ids[1] = (nk_draw_index)(vtx_inner_idx + ((i-1) << 1));
709 ids[2] = (nk_draw_index)(vtx_inner_idx + (i << 1));
714 for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) {
715 struct nk_vec2 p0 = points[i0];
716 struct nk_vec2 p1 = points[i1];
717 struct nk_vec2 diff = nk_vec2_sub(p1, p0);
720 float len = nk_vec2_len_sqr(diff);
722 len = NK_INV_SQRT(len);
724 diff = nk_vec2_muls(diff, len);
726 normals[i0].x = diff.y;
727 normals[i0].y = -diff.x;
731 for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) {
732 const struct nk_vec2 uv = list->config.tex_null.uv;
733 struct nk_vec2 n0 = normals[i0];
734 struct nk_vec2 n1 = normals[i1];
735 struct nk_vec2 dm = nk_vec2_muls(nk_vec2_add(n0, n1), 0.5f);
736 float dmr2 = dm.x*dm.x + dm.y*dm.y;
737 if (dmr2 > 0.000001f) {
738 float scale = 1.0f / dmr2;
739 scale = NK_MIN(scale, 100.0f);
740 dm = nk_vec2_muls(dm, scale);
742 dm = nk_vec2_muls(dm, AA_SIZE * 0.5f);
745 vtx = nk_draw_vertex(vtx, &list->config, nk_vec2_sub(points[i1], dm), uv, col);
746 vtx = nk_draw_vertex(vtx, &list->config, nk_vec2_add(points[i1], dm), uv, col_trans);
749 ids[0] = (nk_draw_index)(vtx_inner_idx+(i1<<1));
750 ids[1] = (nk_draw_index)(vtx_inner_idx+(i0<<1));
751 ids[2] = (nk_draw_index)(vtx_outer_idx+(i0<<1));
752 ids[3] = (nk_draw_index)(vtx_outer_idx+(i0<<1));
753 ids[4] = (nk_draw_index)(vtx_outer_idx+(i1<<1));
754 ids[5] = (nk_draw_index)(vtx_inner_idx+(i1<<1));
758 nk_buffer_reset(list->vertices, NK_BUFFER_FRONT);
761 nk_size index = list->vertex_count;
762 const nk_size idx_count = (points_count-2)*3;
763 const nk_size vtx_count = points_count;
764 void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
765 nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
767 if (!vtx || !ids)
return;
768 for (i = 0; i < vtx_count; ++i)
769 vtx = nk_draw_vertex(vtx, &list->config, points[i], list->config.tex_null.uv, col);
770 for (i = 2; i < points_count; ++i) {
771 ids[0] = (nk_draw_index)index;
772 ids[1] = (nk_draw_index)(index+ i - 1);
773 ids[2] = (nk_draw_index)(index+i);
779nk_draw_list_path_clear(
struct nk_draw_list *list)
783 nk_buffer_reset(list->buffer, NK_BUFFER_FRONT);
784 list->path_count = 0;
785 list->path_offset = 0;
788nk_draw_list_path_line_to(
struct nk_draw_list *list,
struct nk_vec2 pos)
791 struct nk_draw_command *cmd = 0;
794 if (!list->cmd_count)
795 nk_draw_list_add_clip(list, nk_null_rect);
797 cmd = nk_draw_list_command_last(list);
798 if (cmd && cmd->texture.ptr != list->config.tex_null.texture.ptr)
799 nk_draw_list_push_image(list, list->config.tex_null.texture);
801 points = nk_draw_list_alloc_path(list, 1);
806nk_draw_list_path_arc_to_fast(
struct nk_draw_list *list,
struct nk_vec2 center,
807 float radius,
int a_min,
int a_max)
812 if (a_min <= a_max) {
813 for (a = a_min; a <= a_max; a++) {
814 const struct nk_vec2 c = list->circle_vtx[(nk_size)a % NK_LEN(list->circle_vtx)];
815 const float x = center.x + c.x * radius;
816 const float y = center.y + c.y * radius;
817 nk_draw_list_path_line_to(list,
nk_vec2(x, y));
822nk_draw_list_path_arc_to(
struct nk_draw_list *list,
struct nk_vec2 center,
823 float radius,
float a_min,
float a_max,
unsigned int segments)
828 if (radius == 0.0f)
return;
848 {
const float d_angle = (a_max - a_min) / (
float)segments;
849 const float sin_d = (float)NK_SIN(d_angle);
850 const float cos_d = (float)NK_COS(d_angle);
852 float cx = (float)NK_COS(a_min) * radius;
853 float cy = (float)NK_SIN(a_min) * radius;
854 for(i = 0; i <= segments; ++i) {
855 float new_cx, new_cy;
856 const float x = center.x + cx;
857 const float y = center.y + cy;
858 nk_draw_list_path_line_to(list,
nk_vec2(x, y));
860 new_cx = cx * cos_d - cy * sin_d;
861 new_cy = cy * cos_d + cx * sin_d;
867nk_draw_list_path_rect_to(
struct nk_draw_list *list,
struct nk_vec2 a,
868 struct nk_vec2 b,
float rounding)
874 r = NK_MIN(r, ((b.x-a.x) < 0) ? -(b.x-a.x): (b.x-a.x));
875 r = NK_MIN(r, ((b.y-a.y) < 0) ? -(b.y-a.y): (b.y-a.y));
878 nk_draw_list_path_line_to(list, a);
879 nk_draw_list_path_line_to(list,
nk_vec2(b.x,a.y));
880 nk_draw_list_path_line_to(list, b);
881 nk_draw_list_path_line_to(list,
nk_vec2(a.x,b.y));
883 nk_draw_list_path_arc_to_fast(list,
nk_vec2(a.x + r, a.y + r), r, 6, 9);
884 nk_draw_list_path_arc_to_fast(list,
nk_vec2(b.x - r, a.y + r), r, 9, 12);
885 nk_draw_list_path_arc_to_fast(list,
nk_vec2(b.x - r, b.y - r), r, 0, 3);
886 nk_draw_list_path_arc_to_fast(list,
nk_vec2(a.x + r, b.y - r), r, 3, 6);
890nk_draw_list_path_curve_to(
struct nk_draw_list *list,
struct nk_vec2 p2,
898 NK_ASSERT(list->path_count);
899 if (!list || !list->path_count)
return;
900 num_segments = NK_MAX(num_segments, 1);
902 p1 = nk_draw_list_path_last(list);
903 t_step = 1.0f/(float)num_segments;
904 for (i_step = 1; i_step <= num_segments; ++i_step) {
905 float t = t_step * (float)i_step;
911 float x = w1 * p1.x + w2 * p2.x + w3 * p3.x + w4 * p4.x;
912 float y = w1 * p1.y + w2 * p2.y + w3 * p3.y + w4 * p4.y;
913 nk_draw_list_path_line_to(list,
nk_vec2(x,y));
917nk_draw_list_path_fill(
struct nk_draw_list *list,
struct nk_color color)
922 points = (
struct nk_vec2*)nk_buffer_memory(list->buffer);
923 nk_draw_list_fill_poly_convex(list, points, list->path_count, color, list->config.shape_AA);
924 nk_draw_list_path_clear(list);
927nk_draw_list_path_stroke(
struct nk_draw_list *list,
struct nk_color color,
928 enum nk_draw_list_stroke closed,
float thickness)
933 points = (
struct nk_vec2*)nk_buffer_memory(list->buffer);
934 nk_draw_list_stroke_poly_line(list, points, list->path_count, color,
935 closed, thickness, list->config.line_AA);
936 nk_draw_list_path_clear(list);
939nk_draw_list_stroke_line(
struct nk_draw_list *list,
struct nk_vec2 a,
943 if (!list || !col.a)
return;
944 if (list->line_AA == NK_ANTI_ALIASING_ON) {
945 nk_draw_list_path_line_to(list, a);
946 nk_draw_list_path_line_to(list, b);
948 nk_draw_list_path_line_to(list, nk_vec2_sub(a,
nk_vec2(0.5f,0.5f)));
949 nk_draw_list_path_line_to(list, nk_vec2_sub(b,
nk_vec2(0.5f,0.5f)));
951 nk_draw_list_path_stroke(list, col, NK_STROKE_OPEN, thickness);
954nk_draw_list_fill_rect(
struct nk_draw_list *list,
struct nk_rect rect,
955 struct nk_color col,
float rounding)
958 if (!list || !col.a)
return;
960 if (list->line_AA == NK_ANTI_ALIASING_ON) {
961 nk_draw_list_path_rect_to(list,
nk_vec2(rect.x, rect.y),
962 nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding);
964 nk_draw_list_path_rect_to(list,
nk_vec2(rect.x-0.5f, rect.y-0.5f),
965 nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding);
966 } nk_draw_list_path_fill(list, col);
969nk_draw_list_stroke_rect(
struct nk_draw_list *list,
struct nk_rect rect,
970 struct nk_color col,
float rounding,
float thickness)
973 if (!list || !col.a)
return;
974 if (list->line_AA == NK_ANTI_ALIASING_ON) {
975 nk_draw_list_path_rect_to(list,
nk_vec2(rect.x, rect.y),
976 nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding);
978 nk_draw_list_path_rect_to(list,
nk_vec2(rect.x-0.5f, rect.y-0.5f),
979 nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding);
980 } nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness);
983nk_draw_list_fill_rect_multi_color(
struct nk_draw_list *list,
struct nk_rect rect,
993 nk_color_fv(&col_left.r, left);
994 nk_color_fv(&col_right.r, right);
995 nk_color_fv(&col_top.r, top);
996 nk_color_fv(&col_bottom.r, bottom);
1001 nk_draw_list_push_image(list, list->config.tex_null.texture);
1002 index = (nk_draw_index)list->vertex_count;
1003 vtx = nk_draw_list_alloc_vertices(list, 4);
1004 idx = nk_draw_list_alloc_elements(list, 6);
1005 if (!vtx || !idx)
return;
1007 idx[0] = (nk_draw_index)(index+0); idx[1] = (nk_draw_index)(index+1);
1008 idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0);
1009 idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3);
1011 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.x, rect.y), list->config.tex_null.uv, col_left);
1012 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.x + rect.w, rect.y), list->config.tex_null.uv, col_top);
1013 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.x + rect.w, rect.y + rect.h), list->config.tex_null.uv, col_right);
1014 vtx = nk_draw_vertex(vtx, &list->config,
nk_vec2(rect.x, rect.y + rect.h), list->config.tex_null.uv, col_bottom);
1017nk_draw_list_fill_triangle(
struct nk_draw_list *list,
struct nk_vec2 a,
1021 if (!list || !col.a)
return;
1022 nk_draw_list_path_line_to(list, a);
1023 nk_draw_list_path_line_to(list, b);
1024 nk_draw_list_path_line_to(list, c);
1025 nk_draw_list_path_fill(list, col);
1028nk_draw_list_stroke_triangle(
struct nk_draw_list *list,
struct nk_vec2 a,
1032 if (!list || !col.a)
return;
1033 nk_draw_list_path_line_to(list, a);
1034 nk_draw_list_path_line_to(list, b);
1035 nk_draw_list_path_line_to(list, c);
1036 nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness);
1039nk_draw_list_fill_circle(
struct nk_draw_list *list,
struct nk_vec2 center,
1040 float radius,
struct nk_color col,
unsigned int segs)
1044 if (!list || !col.a)
return;
1045 a_max = NK_PI * 2.0f * ((float)segs - 1.0f) / (
float)segs;
1046 nk_draw_list_path_arc_to(list, center, radius, 0.0f, a_max, segs);
1047 nk_draw_list_path_fill(list, col);
1050nk_draw_list_stroke_circle(
struct nk_draw_list *list,
struct nk_vec2 center,
1051 float radius,
struct nk_color col,
unsigned int segs,
float thickness)
1055 if (!list || !col.a)
return;
1056 a_max = NK_PI * 2.0f * ((float)segs - 1.0f) / (
float)segs;
1057 nk_draw_list_path_arc_to(list, center, radius, 0.0f, a_max, segs);
1058 nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness);
1061nk_draw_list_stroke_curve(
struct nk_draw_list *list,
struct nk_vec2 p0,
1063 struct nk_color col,
unsigned int segments,
float thickness)
1066 if (!list || !col.a)
return;
1067 nk_draw_list_path_line_to(list, p0);
1068 nk_draw_list_path_curve_to(list, cp0, cp1, p1, segments);
1069 nk_draw_list_path_stroke(list, col, NK_STROKE_OPEN, thickness);
1072nk_draw_list_push_rect_uv(
struct nk_draw_list *list,
struct nk_vec2 a,
1084 nk_draw_index index;
1088 nk_color_fv(&col.r, color);
1094 index = (nk_draw_index)list->vertex_count;
1095 vtx = nk_draw_list_alloc_vertices(list, 4);
1096 idx = nk_draw_list_alloc_elements(list, 6);
1097 if (!vtx || !idx)
return;
1099 idx[0] = (nk_draw_index)(index+0); idx[1] = (nk_draw_index)(index+1);
1100 idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0);
1101 idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3);
1103 vtx = nk_draw_vertex(vtx, &list->config, a, uva, col);
1104 vtx = nk_draw_vertex(vtx, &list->config, b, uvb, col);
1105 vtx = nk_draw_vertex(vtx, &list->config, c, uvc, col);
1106 vtx = nk_draw_vertex(vtx, &list->config, d, uvd, col);
1109nk_draw_list_add_image(
struct nk_draw_list *list,
struct nk_image texture,
1115 nk_draw_list_push_image(list, texture.handle);
1116 if (nk_image_is_subimage(&texture)) {
1119 uv[0].x = (float)texture.region[0]/(
float)texture.w;
1120 uv[0].y = (float)texture.region[1]/(
float)texture.h;
1121 uv[1].x = (float)(texture.region[0] + texture.region[2])/(float)texture.w;
1122 uv[1].y = (float)(texture.region[1] + texture.region[3])/(float)texture.h;
1123 nk_draw_list_push_rect_uv(list,
nk_vec2(rect.x, rect.y),
1124 nk_vec2(rect.x + rect.w, rect.y + rect.h), uv[0], uv[1], color);
1125 }
else nk_draw_list_push_rect_uv(list,
nk_vec2(rect.x, rect.y),
1126 nk_vec2(rect.x + rect.w, rect.y + rect.h),
1130nk_draw_list_add_text(
struct nk_draw_list *list,
const struct nk_user_font *font,
1131 struct nk_rect rect,
const char *text,
int len,
float font_height,
1136 nk_rune unicode = 0;
1139 int next_glyph_len = 0;
1140 struct nk_user_font_glyph g;
1143 if (!list || !len || !text)
return;
1144 if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h,
1145 list->clip_rect.x, list->clip_rect.y, list->clip_rect.w, list->clip_rect.h))
return;
1147 nk_draw_list_push_image(list, font->texture);
1149 glyph_len = nk_utf_decode(text, &unicode, len);
1150 if (!glyph_len)
return;
1153 fg.a = (nk_byte)((
float)fg.a * list->config.global_alpha);
1154 while (text_len < len && glyph_len) {
1155 float gx, gy, gh, gw;
1156 float char_width = 0;
1157 if (unicode == NK_UTF_INVALID)
break;
1160 next_glyph_len = nk_utf_decode(text + text_len + glyph_len, &next, (
int)len - text_len);
1161 font->query(font->userdata, font_height, &g, unicode,
1162 (next == NK_UTF_INVALID) ?
'\0' : next);
1165 gx = x + g.offset.x;
1166 gy = rect.y + g.offset.y;
1167 gw = g.width; gh = g.height;
1168 char_width = g.xadvance;
1169 nk_draw_list_push_rect_uv(list,
nk_vec2(gx,gy),
nk_vec2(gx + gw, gy+ gh),
1170 g.uv[0], g.uv[1], fg);
1173 text_len += glyph_len;
1175 glyph_len = next_glyph_len;
1184 nk_flags res = NK_CONVERT_SUCCESS;
1188 NK_ASSERT(vertices);
1189 NK_ASSERT(elements);
1193 if (!ctx || !cmds || !vertices || !elements || !config || !config->
vertex_layout)
1194 return NK_CONVERT_INVALID_PARAM;
1196 nk_draw_list_setup(&ctx->draw_list, config, cmds, vertices, elements,
1198 nk_foreach(cmd, ctx)
1200#ifdef NK_INCLUDE_COMMAND_USERDATA
1201 ctx->draw_list.userdata = cmd->userdata;
1203 switch (cmd->type) {
1204 case NK_COMMAND_NOP:
break;
1205 case NK_COMMAND_SCISSOR: {
1207 nk_draw_list_add_clip(&ctx->draw_list,
nk_rect(s->x, s->y, s->w, s->h));
1209 case NK_COMMAND_LINE: {
1211 nk_draw_list_stroke_line(&ctx->draw_list,
nk_vec2(l->begin.x, l->begin.y),
1212 nk_vec2(l->end.x, l->end.y), l->color, l->line_thickness);
1214 case NK_COMMAND_CURVE: {
1216 nk_draw_list_stroke_curve(&ctx->draw_list,
nk_vec2(q->begin.x, q->begin.y),
1218 q->ctrl[1].y),
nk_vec2(q->end.x, q->end.y), q->color,
1221 case NK_COMMAND_RECT: {
1223 nk_draw_list_stroke_rect(&ctx->draw_list,
nk_rect(r->x, r->y, r->w, r->h),
1224 r->color, (
float)r->rounding, r->line_thickness);
1226 case NK_COMMAND_RECT_FILLED: {
1228 nk_draw_list_fill_rect(&ctx->draw_list,
nk_rect(r->x, r->y, r->w, r->h),
1229 r->color, (
float)r->rounding);
1231 case NK_COMMAND_RECT_MULTI_COLOR: {
1233 nk_draw_list_fill_rect_multi_color(&ctx->draw_list,
nk_rect(r->x, r->y, r->w, r->h),
1234 r->left, r->top, r->right, r->bottom);
1236 case NK_COMMAND_CIRCLE: {
1238 nk_draw_list_stroke_circle(&ctx->draw_list,
nk_vec2((
float)c->x + (
float)c->w/2,
1239 (
float)c->y + (
float)c->h/2), (
float)c->w/2, c->color,
1242 case NK_COMMAND_CIRCLE_FILLED: {
1244 nk_draw_list_fill_circle(&ctx->draw_list,
nk_vec2((
float)c->x + (
float)c->w/2,
1245 (
float)c->y + (
float)c->h/2), (
float)c->w/2, c->color,
1248 case NK_COMMAND_ARC: {
1250 nk_draw_list_path_line_to(&ctx->draw_list,
nk_vec2(c->cx, c->cy));
1251 nk_draw_list_path_arc_to(&ctx->draw_list,
nk_vec2(c->cx, c->cy), c->r,
1253 nk_draw_list_path_stroke(&ctx->draw_list, c->color, NK_STROKE_CLOSED, c->line_thickness);
1255 case NK_COMMAND_ARC_FILLED: {
1257 nk_draw_list_path_line_to(&ctx->draw_list,
nk_vec2(c->cx, c->cy));
1258 nk_draw_list_path_arc_to(&ctx->draw_list,
nk_vec2(c->cx, c->cy), c->r,
1260 nk_draw_list_path_fill(&ctx->draw_list, c->color);
1262 case NK_COMMAND_TRIANGLE: {
1264 nk_draw_list_stroke_triangle(&ctx->draw_list,
nk_vec2(t->a.x, t->a.y),
1268 case NK_COMMAND_TRIANGLE_FILLED: {
1270 nk_draw_list_fill_triangle(&ctx->draw_list,
nk_vec2(t->a.x, t->a.y),
1273 case NK_COMMAND_POLYGON: {
1276 for (i = 0; i < p->point_count; ++i) {
1277 struct nk_vec2 pnt =
nk_vec2((
float)p->points[i].x, (
float)p->points[i].y);
1278 nk_draw_list_path_line_to(&ctx->draw_list, pnt);
1280 nk_draw_list_path_stroke(&ctx->draw_list, p->color, NK_STROKE_CLOSED, p->line_thickness);
1282 case NK_COMMAND_POLYGON_FILLED: {
1285 for (i = 0; i < p->point_count; ++i) {
1286 struct nk_vec2 pnt =
nk_vec2((
float)p->points[i].x, (
float)p->points[i].y);
1287 nk_draw_list_path_line_to(&ctx->draw_list, pnt);
1289 nk_draw_list_path_fill(&ctx->draw_list, p->color);
1291 case NK_COMMAND_POLYLINE: {
1294 for (i = 0; i < p->point_count; ++i) {
1295 struct nk_vec2 pnt =
nk_vec2((
float)p->points[i].x, (
float)p->points[i].y);
1296 nk_draw_list_path_line_to(&ctx->draw_list, pnt);
1298 nk_draw_list_path_stroke(&ctx->draw_list, p->color, NK_STROKE_OPEN, p->line_thickness);
1300 case NK_COMMAND_TEXT: {
1302 nk_draw_list_add_text(&ctx->draw_list, t->font,
nk_rect(t->x, t->y, t->w, t->h),
1303 t->string, t->length, t->height, t->foreground);
1305 case NK_COMMAND_IMAGE: {
1307 nk_draw_list_add_image(&ctx->draw_list, i->img,
nk_rect(i->x, i->y, i->w, i->h), i->col);
1309 case NK_COMMAND_CUSTOM: {
1311 c->callback(&ctx->draw_list, c->x, c->y, c->w, c->h, c->callback_data);
1317 res |= (vertices->
needed > vertices->
allocated) ? NK_CONVERT_VERTEX_BUFFER_FULL: 0;
1318 res |= (elements->
needed > elements->
allocated) ? NK_CONVERT_ELEMENT_BUFFER_FULL: 0;
1321NK_API
const struct nk_draw_command*
1325 return nk__draw_list_begin(&ctx->draw_list, buffer);
1327NK_API
const struct nk_draw_command*
1330 return nk__draw_list_end(&ctx->draw_list, buffer);
1332NK_API
const struct nk_draw_command*
1333nk__draw_next(
const struct nk_draw_command *cmd,
1336 return nk__draw_list_next(cmd, buffer, &ctx->draw_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