Cleaned up custom draw commands to better fit

Had to change some small things to make everything work for a
general case instead of vertex draw list only. Furthermore I
don't want a custom widget inside nuklear so I removed it.
Feel free to add it back into your own version.
This commit is contained in:
vurtun 2017-02-25 22:50:37 +01:00
parent 4c25cd34f5
commit e5c1cf9d70

View File

@ -1773,9 +1773,6 @@ NK_API void nk_textedit_redo(struct nk_text_edit*);
update and draw your widget. The reason for seperating is to only draw and
update what is actually neccessary which is crucial for performance.
*/
typedef void (*nk_command_custom_callback)(struct nk_draw_list *list, short x, short y, unsigned short w, unsigned short h, nk_handle callback_data);
enum nk_command_type {
NK_COMMAND_NOP,
NK_COMMAND_SCISSOR,
@ -1795,7 +1792,7 @@ enum nk_command_type {
NK_COMMAND_POLYLINE,
NK_COMMAND_TEXT,
NK_COMMAND_IMAGE,
NK_COMMAND_CUSTOM
NK_COMMAND_CUSTOM
};
/* command base and header of every command inside the buffer */
@ -1937,12 +1934,14 @@ struct nk_command_image {
struct nk_color col;
};
typedef void (*nk_command_custom_callback)(void *canvas, short x,short y,
unsigned short w, unsigned short h, nk_handle callback_data);
struct nk_command_custom {
struct nk_command header;
short x, y;
struct nk_command header;
short x, y;
unsigned short w, h;
nk_handle callback_data;
nk_command_custom_callback callback;
nk_handle callback_data;
nk_command_custom_callback callback;
};
struct nk_command_text {
@ -1989,10 +1988,10 @@ NK_API void nk_fill_triangle(struct nk_command_buffer*, float x0, float y0, floa
NK_API void nk_fill_polygon(struct nk_command_buffer*, float*, int point_count, struct nk_color);
/* misc */
NK_API void nk_push_scissor(struct nk_command_buffer*, struct nk_rect);
NK_API void nk_draw_image(struct nk_command_buffer*, struct nk_rect, const struct nk_image*, struct nk_color);
NK_API void nk_draw_custom(struct nk_command_buffer*, struct nk_rect, nk_command_custom_callback callback, nk_handle callback_data);
NK_API void nk_draw_text(struct nk_command_buffer*, struct nk_rect, const char *text, int len, const struct nk_user_font*, struct nk_color, struct nk_color);
NK_API void nk_push_scissor(struct nk_command_buffer*, struct nk_rect);
NK_API void nk_push_custom(struct nk_command_buffer*, struct nk_rect, nk_command_custom_callback, nk_handle usr);
NK_API const struct nk_command* nk__next(struct nk_context*, const struct nk_command*);
NK_API const struct nk_command* nk__begin(struct nk_context*);
@ -6509,13 +6508,13 @@ nk_draw_image(struct nk_command_buffer *b, struct nk_rect r,
}
NK_API void
nk_draw_custom(struct nk_command_buffer *b, struct nk_rect r,
nk_command_custom_callback callback, nk_handle callback_data)
nk_push_custom(struct nk_command_buffer *b, struct nk_rect r,
nk_command_custom_callback cb, nk_handle usr)
{
struct nk_command_custom *cmd;
NK_ASSERT(b);
if (!b) return;
if (b->use_clipping) {
if (b->use_clipping) {
const struct nk_rect *c = &b->clip;
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))
return;
@ -6524,12 +6523,12 @@ nk_draw_custom(struct nk_command_buffer *b, struct nk_rect r,
cmd = (struct nk_command_custom*)
nk_command_buffer_push(b, NK_COMMAND_CUSTOM, sizeof(*cmd));
if (!cmd) return;
cmd->x = (short)r.x;
cmd->x = (short)r.x;
cmd->y = (short)r.y;
cmd->w = (unsigned short)NK_MAX(0, r.w);
cmd->h = (unsigned short)NK_MAX(0, r.h);
cmd->callback_data = callback_data;
cmd->callback = callback;
cmd->callback_data = usr;
cmd->callback = cb;
}
NK_API void
@ -7859,7 +7858,7 @@ nk_convert(struct nk_context *ctx, struct nk_buffer *cmds,
const struct nk_command_image *i = (const struct nk_command_image*)cmd;
nk_draw_list_add_image(&ctx->draw_list, i->img, nk_rect(i->x, i->y, i->w, i->h), i->col);
} break;
case NK_COMMAND_CUSTOM: {
case NK_COMMAND_CUSTOM: {
const struct nk_command_custom *c = (const struct nk_command_custom*)cmd;
c->callback(&ctx->draw_list, c->x, c->y, c->w, c->h, c->callback_data);
} break;
@ -19203,22 +19202,6 @@ nk_image(struct nk_context *ctx, struct nk_image img)
nk_draw_image(&win->buffer, bounds, &img, nk_white);
}
NK_API void
nk_custom(struct nk_context *ctx, nk_command_custom_callback callback, nk_handle callback_data)
{
struct nk_window *win;
struct nk_rect bounds;
NK_ASSERT(ctx);
NK_ASSERT(ctx->current);
NK_ASSERT(ctx->current->layout);
if (!ctx || !ctx->current || !ctx->current->layout) return;
win = ctx->current;
if (!nk_widget(&bounds, ctx)) return;
nk_draw_custom(&win->buffer, bounds, callback, callback_data);
}
/*----------------------------------------------------------------
*
* BUTTON