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);
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;
92 nk_buffer_free(&ctx->memory);
94 nk_pool_free(&ctx->pool);
96 nk_zero(&ctx->input,
sizeof(ctx->input));
97 nk_zero(&ctx->style,
sizeof(ctx->style));
98 nk_zero(&ctx->memory,
sizeof(ctx->memory));
118 nk_buffer_clear(&ctx->memory);
119 else nk_buffer_reset(&ctx->memory, NK_BUFFER_FRONT);
122 ctx->memory.
calls = 0;
123 ctx->last_widget_state = 0;
124 ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_ARROW];
133 iter->seq == ctx->seq) {
140 iter == ctx->active) {
141 ctx->active = iter->prev;
142 ctx->end = iter->prev;
149 if (iter->popup.win && iter->popup.win->seq != ctx->seq) {
150 nk_free_window(ctx, iter->popup.win);
154 {
struct nk_table *n, *it = iter->tables;
157 if (it->seq != ctx->seq) {
158 nk_remove_table(iter, it);
160 nk_free_table(ctx, it);
161 if (it == iter->tables)
168 nk_remove_window(ctx, iter);
169 nk_free_window(ctx, iter);
171 }
else iter = iter->next;
180 if (!ctx || !buffer)
return;
182 buffer->end = buffer->begin;
183 buffer->last = buffer->begin;
184 buffer->clip = nk_null_rect;
191 nk_start_buffer(ctx, &win->buffer);
199 if (!ctx || !win)
return;
202 buf = &win->popup.buf;
203 buf->begin = win->buffer.end;
204 buf->end = win->buffer.end;
205 buf->parent = win->buffer.last;
206 buf->last = buf->begin;
207 buf->active = nk_true;
215 if (!ctx || !win)
return;
217 buf = &win->popup.buf;
218 buf->last = win->buffer.last;
219 buf->end = win->buffer.end;
226 if (!ctx || !buffer)
return;
238 if (!ctx || !win)
return;
239 nk_finish_buffer(ctx, &win->buffer);
240 if (!win->popup.buf.active)
return;
242 buf = &win->popup.buf;
243 memory = ctx->memory.
memory.ptr;
244 parent_last = nk_ptr_add(
struct nk_command, memory, buf->parent);
245 parent_last->next = buf->end;
255 if (!ctx->style.cursor_active)
256 ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_ARROW];
257 if (ctx->style.cursor_active && !ctx->input.mouse.grabbed && ctx->style.cursor_visible) {
259 const struct nk_cursor *cursor = ctx->style.cursor_active;
260 nk_command_buffer_init(&ctx->
overlay, &ctx->memory, NK_CLIPPING_OFF);
261 nk_start_buffer(ctx, &ctx->
overlay);
263 mouse_bounds.x = ctx->input.mouse.pos.x - cursor->offset.x;
264 mouse_bounds.y = ctx->input.mouse.pos.y - cursor->offset.y;
265 mouse_bounds.w = cursor->size.x;
266 mouse_bounds.h = cursor->size.y;
269 nk_finish_buffer(ctx, &ctx->
overlay);
273 buffer = (nk_byte*)ctx->memory.
memory.ptr;
280 cmd = nk_ptr_add(
struct nk_command, buffer, it->buffer.last);
281 while (next && ((next->buffer.last == next->buffer.begin) ||
285 if (next) cmd->next = next->buffer.begin;
293 if (!it->popup.buf.active)
296 buf = &it->popup.buf;
297 cmd->next = buf->begin;
298 cmd = nk_ptr_add(
struct nk_command, buffer, buf->last);
299 buf->active = nk_false;
305 cmd->next = ctx->
overlay.begin;
316 if (!ctx->count)
return 0;
318 buffer = (nk_byte*)ctx->memory.
memory.ptr;
321 ctx->
build = nk_true;
324 while (iter && ((iter->buffer.begin == iter->buffer.end) ||
328 return nk_ptr_add_const(
struct nk_command, buffer, iter->buffer.begin);
337 if (!ctx || !cmd || !ctx->count)
return 0;
338 if (cmd->next >= ctx->memory.
allocated)
return 0;
339 buffer = (nk_byte*)ctx->memory.
memory.ptr;
340 next = nk_ptr_add_const(
struct nk_command, buffer, cmd->next);
main API and documentation file
NK_API void nk_free(struct nk_context *)
Frees all memory allocated by nuklear; Not needed if context was initialized with nk_init_fixed.
NK_API nk_bool nk_init_fixed(struct nk_context *, void *memory, nk_size size, const struct nk_user_font *)
@ NK_WINDOW_CLOSED
Directly closes and frees the window at the end of the frame.
@ NK_WINDOW_MINIMIZED
marks the window as minimized
@ NK_WINDOW_HIDDEN
Hides window and stops any window interaction and drawing.
@ NK_WINDOW_ROM
sets window widgets into a read only mode and does not allow input changes
NK_API void nk_draw_image(struct nk_command_buffer *, struct nk_rect, const struct nk_image *, struct nk_color)
misc
NK_API nk_bool nk_init_custom(struct nk_context *, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font *)
Initializes a nk_context struct from two different either fixed or growing buffers.
NK_API const struct nk_command * nk__begin(struct nk_context *)
Returns a draw command list iterator to iterate all draw commands accumulated over one frame.
NK_API nk_bool nk_init(struct nk_context *, const struct nk_allocator *, const struct nk_user_font *)
NK_API const struct nk_command * nk__next(struct nk_context *, const struct nk_command *)
Returns draw command pointer pointing to the next command inside the draw command list.
NK_API void nk_clear(struct nk_context *)
Resets the context state at the end of the frame.
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_command_buffer overlay
draw buffer used for overlay drawing operation like cursor