2#include "nuklear_internal.h"
15 nk_style_default(ctx);
17 if (font) ctx->style.font = font;
18#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
19 nk_draw_list_init(&ctx->draw_list);
22#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
27 alloc.userdata.ptr = 0;
28 alloc.alloc = nk_malloc;
29 alloc.free = nk_mfree;
30 return nk_init(ctx, &alloc, font);
34nk_init_fixed(
struct nk_context *ctx,
void *memory, nk_size size,
38 if (!memory)
return 0;
40 nk_buffer_init_fixed(&ctx->memory, memory, size);
41 ctx->use_pool = nk_false;
50 if (!cmds || !pool)
return 0;
54 if (pool->
type == NK_BUFFER_FIXED) {
56 nk_pool_init_fixed(&ctx->pool, pool->
memory.ptr, pool->
memory.size);
60 nk_pool_init(&ctx->pool, alloc, NK_POOL_DEFAULT_CAPACITY);
62 ctx->use_pool = nk_true;
72 nk_buffer_init(&ctx->memory, alloc, NK_DEFAULT_COMMAND_BUFFER_SIZE);
73 nk_pool_init(&ctx->pool, alloc, NK_POOL_DEFAULT_CAPACITY);
74 ctx->use_pool = nk_true;
77#ifdef NK_INCLUDE_COMMAND_USERDATA
82 ctx->userdata = handle;
84 ctx->current->buffer.userdata = handle;
88nk_set_display_size(
struct nk_context *ctx,
float width,
float height)
92 if (width < 0) width = 0;
93 if (height < 0) height = 0;
104 if (bounds.w < 0) bounds.w = 0;
105 if (bounds.h < 0) bounds.h = 0;
113 nk_buffer_free(&ctx->memory);
115 nk_pool_free(&ctx->pool);
117 nk_zero(&ctx->input,
sizeof(ctx->input));
118 nk_zero(&ctx->style,
sizeof(ctx->style));
119 nk_zero(&ctx->memory,
sizeof(ctx->memory));
139 nk_buffer_clear(&ctx->memory);
140 else nk_buffer_reset(&ctx->memory, NK_BUFFER_FRONT);
143 ctx->memory.
calls = 0;
144 ctx->last_widget_state = 0;
145 ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_ARROW];
152 if ((iter->flags & NK_WINDOW_MINIMIZED) &&
153 !(iter->flags & NK_WINDOW_CLOSED) &&
154 iter->seq == ctx->seq) {
159 if (((iter->flags & NK_WINDOW_HIDDEN) ||
160 (iter->flags & NK_WINDOW_CLOSED)) &&
161 iter == ctx->active) {
162 ctx->active = iter->prev;
163 ctx->end = iter->prev;
167 ctx->active->flags &= ~(unsigned)NK_WINDOW_ROM;
170 if (iter->popup.win && iter->popup.win->seq != ctx->seq) {
171 nk_free_window(ctx, iter->popup.win);
175 {
struct nk_table *n, *it = iter->tables;
178 if (it->seq != ctx->seq) {
179 nk_remove_table(iter, it);
181 nk_free_table(ctx, it);
182 if (it == iter->tables)
187 if (iter->seq != ctx->seq || iter->flags & NK_WINDOW_CLOSED) {
189 nk_remove_window(ctx, iter);
190 nk_free_window(ctx, iter);
192 }
else iter = iter->next;
201 if (!ctx || !buffer)
return;
203 buffer->end = buffer->begin;
204 buffer->last = buffer->begin;
205 buffer->clip = nk_null_rect;
212 nk_start_buffer(ctx, &win->buffer);
220 if (!ctx || !win)
return;
223 buf = &win->popup.buf;
224 buf->begin = win->buffer.end;
225 buf->end = win->buffer.end;
226 buf->parent = win->buffer.last;
227 buf->last = buf->begin;
228 buf->active = nk_true;
236 if (!ctx || !win)
return;
238 buf = &win->popup.buf;
239 buf->last = win->buffer.last;
240 buf->end = win->buffer.end;
247 if (!ctx || !buffer)
return;
259 if (!ctx || !win)
return;
260 nk_finish_buffer(ctx, &win->buffer);
261 if (!win->popup.buf.active)
return;
263 buf = &win->popup.buf;
264 memory = ctx->memory.
memory.ptr;
265 parent_last = nk_ptr_add(
struct nk_command, memory, buf->parent);
266 parent_last->next = buf->end;
276 if (!ctx->style.cursor_active)
277 ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_ARROW];
278 if (ctx->style.cursor_active && !ctx->input.mouse.grabbed && ctx->style.cursor_visible) {
280 const struct nk_cursor *cursor = ctx->style.cursor_active;
281 nk_command_buffer_init(&ctx->
overlay, &ctx->memory, NK_CLIPPING_OFF);
282 nk_start_buffer(ctx, &ctx->
overlay);
284 mouse_bounds.x = ctx->input.mouse.pos.x - cursor->offset.x;
285 mouse_bounds.y = ctx->input.mouse.pos.y - cursor->offset.y;
286 mouse_bounds.w = cursor->size.x;
287 mouse_bounds.h = cursor->size.y;
289 nk_draw_image(&ctx->
overlay, mouse_bounds, &cursor->img, nk_white);
290 nk_finish_buffer(ctx, &ctx->
overlay);
294 buffer = (nk_byte*)ctx->memory.
memory.ptr;
297 if (it->buffer.last == it->buffer.begin || (it->flags & NK_WINDOW_HIDDEN)||
301 cmd = nk_ptr_add(
struct nk_command, buffer, it->buffer.last);
302 while (next && ((next->buffer.last == next->buffer.begin) ||
303 (next->flags & NK_WINDOW_HIDDEN) || next->seq != ctx->seq))
306 if (next) cmd->next = next->buffer.begin;
314 if (!it->popup.buf.active)
317 buf = &it->popup.buf;
318 cmd->next = buf->begin;
319 cmd = nk_ptr_add(
struct nk_command, buffer, buf->last);
320 buf->active = nk_false;
326 cmd->next = ctx->
overlay.begin;
337 if (!ctx->count)
return 0;
339 buffer = (nk_byte*)ctx->memory.
memory.ptr;
342 ctx->
build = nk_true;
345 while (iter && ((iter->buffer.begin == iter->buffer.end) ||
346 (iter->flags & NK_WINDOW_HIDDEN) || iter->seq != ctx->seq))
349 return nk_ptr_add_const(
struct nk_command, buffer, iter->buffer.begin);
358 if (!ctx || !cmd || !ctx->count)
return 0;
359 if (cmd->next >= ctx->memory.
allocated)
return 0;
360 buffer = (nk_byte*)ctx->memory.
memory.ptr;
361 next = nk_ptr_add_const(
struct nk_command, buffer, cmd->next);
struct nk_allocator pool
!< buffer marker to free a buffer to a certain offset
struct nk_memory memory
!< memory management type
enum nk_allocation_type type
!< allocator callback for dynamic buffers
nk_size allocated
!< growing factor for dynamic memory management
nk_size calls
!< totally consumed memory given that enough memory is present
command base and header of every command inside the buffer
struct nk_rect display_bounds
surface nuklear is drawn into, in widget/mouse space.
struct nk_command_buffer overlay
draw buffer used for overlay drawing operation like cursor