From 906df9879dd760d157312fb3c92e5b569ccab41a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Thu, 7 Apr 2022 12:17:26 +0900 Subject: [PATCH 1/3] introduce tiling window background, fix nk_image_is_subimage() --- nuklear.h | 37 +++++++++++++++++++++++++++++-------- src/CHANGELOG | 2 ++ src/nuklear.h | 4 +++- src/nuklear_image.c | 3 ++- src/nuklear_panel.c | 8 ++++---- src/nuklear_style.c | 2 +- src/nuklear_vertex.c | 18 +++++++++++++++++- 7 files changed, 58 insertions(+), 16 deletions(-) diff --git a/nuklear.h b/nuklear.h index 9a33488dc..fd087f017 100644 --- a/nuklear.h +++ b/nuklear.h @@ -4840,6 +4840,7 @@ NK_API void nk_draw_list_fill_poly_convex(struct nk_draw_list*, const struct nk_ /* misc */ NK_API void nk_draw_list_add_image(struct nk_draw_list*, struct nk_image texture, struct nk_rect rect, struct nk_color); +NK_API void nk_draw_list_add_image_tiled(struct nk_draw_list*, struct nk_image texture, struct nk_rect rect, struct nk_color); NK_API void nk_draw_list_add_text(struct nk_draw_list*, const struct nk_user_font*, struct nk_rect, const char *text, int len, float font_height, struct nk_color); #ifdef NK_INCLUDE_COMMAND_USERDATA NK_API void nk_draw_list_push_userdata(struct nk_draw_list*, nk_handle userdata); @@ -5226,7 +5227,7 @@ struct nk_style_window_header { struct nk_style_window { struct nk_style_window_header header; - struct nk_style_item fixed_background; + struct nk_style_item image; struct nk_color background; struct nk_color border_color; @@ -5246,6 +5247,7 @@ struct nk_style_window { float tooltip_border; float popup_border; float min_row_height_padding; + NK_BOOL tiled_background; float rounding; struct nk_vec2 spacing; @@ -10508,6 +10510,19 @@ nk_draw_list_add_image(struct nk_draw_list *list, struct nk_image texture, nk_vec2(0.0f, 0.0f), nk_vec2(1.0f, 1.0f),color); } NK_API void +nk_draw_list_add_image_tiled(struct nk_draw_list *list, struct nk_image texture, + struct nk_rect rect, struct nk_color color) +{ + NK_ASSERT(list); + if (!list) return; + /* push new command with given texture */ + nk_draw_list_push_image(list, texture.handle); + /* No support for tiled subimages, texture.region is ignored */ + nk_draw_list_push_rect_uv(list, nk_vec2(rect.x, rect.y), + nk_vec2(rect.x + rect.w, rect.y + rect.h), nk_vec2(0.0f, 0.0f), + nk_vec2(rect.w/(float)texture.w, rect.h/(float)texture.h), color); +} +NK_API void nk_draw_list_add_text(struct nk_draw_list *list, const struct nk_user_font *font, struct nk_rect rect, const char *text, int len, float font_height, struct nk_color fg) @@ -10685,7 +10700,10 @@ nk_convert(struct nk_context *ctx, struct nk_buffer *cmds, } break; case NK_COMMAND_IMAGE: { 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); + if(ctx->style.window.tiled_background) + nk_draw_list_add_image_tiled(&ctx->draw_list, i->img, nk_rect(i->x, i->y, i->w, i->h), i->col); + else + 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: { const struct nk_command_custom *c = (const struct nk_command_custom*)cmd; @@ -18654,7 +18672,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) /* window */ win->background = table[NK_COLOR_WINDOW]; - win->fixed_background = nk_style_item_color(table[NK_COLOR_WINDOW]); + win->image = nk_style_item_color(table[NK_COLOR_WINDOW]); win->border_color = table[NK_COLOR_BORDER]; win->popup_border_color = table[NK_COLOR_BORDER]; win->combo_border_color = table[NK_COLOR_BORDER]; @@ -19697,15 +19715,15 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan body.y = (win->bounds.y + layout->header_height); body.h = (win->bounds.h - layout->header_height); - switch(style->window.fixed_background.type) { + switch(style->window.image.type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, body, &style->window.fixed_background.data.image, nk_white); + nk_draw_image(out, body, &style->window.image.data.image, nk_white); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, body, &style->window.fixed_background.data.slice, nk_white); + nk_draw_nine_slice(out, body, &style->window.image.data.slice, nk_white); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, body, 0, style->window.fixed_background.data.color); + nk_fill_rect(out, body, 0, style->window.image.data.color); break; } } @@ -23542,7 +23560,8 @@ NK_API nk_bool nk_image_is_subimage(const struct nk_image* img) { NK_ASSERT(img); - return !(img->w == 0 && img->h == 0); + return !(img->region[0] == 0 && img->region[1] == 0 && + img->region[2] == 0 && img->region[3] == 0); } NK_API void nk_image(struct nk_context *ctx, struct nk_image img) @@ -29629,6 +29648,8 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/04/07 (5.0.0) - tiling window backgrounds, nk_style_window.fixed_background +/// renamed to nk_style_window.image /// - 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS /// - 2021/12/22 (4.9.5) - Revert layout bounds not accounting for padding due to regressions /// - 2021/12/22 (4.9.4) - Fix checking hovering when window is minimized diff --git a/src/CHANGELOG b/src/CHANGELOG index 4be9f0479..8abb2babc 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,6 +7,8 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2022/04/07 (5.0.0) - tiling window backgrounds, nk_style_window.fixed_background +/// renamed to nk_style_window.image /// - 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS /// - 2021/12/22 (4.9.5) - Revert layout bounds not accounting for padding due to regressions /// - 2021/12/22 (4.9.4) - Fix checking hovering when window is minimized diff --git a/src/nuklear.h b/src/nuklear.h index b97c95c08..6b7e916f8 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -4619,6 +4619,7 @@ NK_API void nk_draw_list_fill_poly_convex(struct nk_draw_list*, const struct nk_ /* misc */ NK_API void nk_draw_list_add_image(struct nk_draw_list*, struct nk_image texture, struct nk_rect rect, struct nk_color); +NK_API void nk_draw_list_add_image_tiled(struct nk_draw_list*, struct nk_image texture, struct nk_rect rect, struct nk_color); NK_API void nk_draw_list_add_text(struct nk_draw_list*, const struct nk_user_font*, struct nk_rect, const char *text, int len, float font_height, struct nk_color); #ifdef NK_INCLUDE_COMMAND_USERDATA NK_API void nk_draw_list_push_userdata(struct nk_draw_list*, nk_handle userdata); @@ -5005,7 +5006,7 @@ struct nk_style_window_header { struct nk_style_window { struct nk_style_window_header header; - struct nk_style_item fixed_background; + struct nk_style_item image; struct nk_color background; struct nk_color border_color; @@ -5025,6 +5026,7 @@ struct nk_style_window { float tooltip_border; float popup_border; float min_row_height_padding; + NK_BOOL tiled_background; float rounding; struct nk_vec2 spacing; diff --git a/src/nuklear_image.c b/src/nuklear_image.c index 526714419..541e411a6 100644 --- a/src/nuklear_image.c +++ b/src/nuklear_image.c @@ -104,7 +104,8 @@ NK_API nk_bool nk_image_is_subimage(const struct nk_image* img) { NK_ASSERT(img); - return !(img->w == 0 && img->h == 0); + return !(img->region[0] == 0 && img->region[1] == 0 && + img->region[2] == 0 && img->region[3] == 0); } NK_API void nk_image(struct nk_context *ctx, struct nk_image img) diff --git a/src/nuklear_panel.c b/src/nuklear_panel.c index f170d7ccc..77dc13207 100644 --- a/src/nuklear_panel.c +++ b/src/nuklear_panel.c @@ -301,15 +301,15 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan body.y = (win->bounds.y + layout->header_height); body.h = (win->bounds.h - layout->header_height); - switch(style->window.fixed_background.type) { + switch(style->window.image.type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, body, &style->window.fixed_background.data.image, nk_white); + nk_draw_image(out, body, &style->window.image.data.image, nk_white); break; case NK_STYLE_ITEM_NINE_SLICE: - nk_draw_nine_slice(out, body, &style->window.fixed_background.data.slice, nk_white); + nk_draw_nine_slice(out, body, &style->window.image.data.slice, nk_white); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, body, 0, style->window.fixed_background.data.color); + nk_fill_rect(out, body, 0, style->window.image.data.color); break; } } diff --git a/src/nuklear_style.c b/src/nuklear_style.c index 0e0851e0a..42d5d826c 100644 --- a/src/nuklear_style.c +++ b/src/nuklear_style.c @@ -598,7 +598,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) /* window */ win->background = table[NK_COLOR_WINDOW]; - win->fixed_background = nk_style_item_color(table[NK_COLOR_WINDOW]); + win->image = nk_style_item_color(table[NK_COLOR_WINDOW]); win->border_color = table[NK_COLOR_BORDER]; win->popup_border_color = table[NK_COLOR_BORDER]; win->combo_border_color = table[NK_COLOR_BORDER]; diff --git a/src/nuklear_vertex.c b/src/nuklear_vertex.c index b98eb1ed1..077225c42 100644 --- a/src/nuklear_vertex.c +++ b/src/nuklear_vertex.c @@ -1126,6 +1126,19 @@ nk_draw_list_add_image(struct nk_draw_list *list, struct nk_image texture, nk_vec2(0.0f, 0.0f), nk_vec2(1.0f, 1.0f),color); } NK_API void +nk_draw_list_add_image_tiled(struct nk_draw_list *list, struct nk_image texture, + struct nk_rect rect, struct nk_color color) +{ + NK_ASSERT(list); + if (!list) return; + /* push new command with given texture */ + nk_draw_list_push_image(list, texture.handle); + /* No support for tiled subimages, texture.region is ignored */ + nk_draw_list_push_rect_uv(list, nk_vec2(rect.x, rect.y), + nk_vec2(rect.x + rect.w, rect.y + rect.h), nk_vec2(0.0f, 0.0f), + nk_vec2(rect.w/(float)texture.w, rect.h/(float)texture.h), color); +} +NK_API void nk_draw_list_add_text(struct nk_draw_list *list, const struct nk_user_font *font, struct nk_rect rect, const char *text, int len, float font_height, struct nk_color fg) @@ -1303,7 +1316,10 @@ nk_convert(struct nk_context *ctx, struct nk_buffer *cmds, } break; case NK_COMMAND_IMAGE: { 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); + if(ctx->style.window.tiled_background) + nk_draw_list_add_image_tiled(&ctx->draw_list, i->img, nk_rect(i->x, i->y, i->w, i->h), i->col); + else + 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: { const struct nk_command_custom *c = (const struct nk_command_custom*)cmd; From 94de2a50076a9de2b9bd5329506c6a1b128ad27f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Thu, 7 Apr 2022 12:31:54 +0900 Subject: [PATCH 2/3] Fix demo files breaking due to the API change --- demo/common/canvas.c | 6 +++--- example/canvas.c | 6 +++--- example/extended.c | 6 +++--- example/skinning.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/demo/common/canvas.c b/demo/common/canvas.c index 6c50bcbd4..1d96a90d2 100644 --- a/demo/common/canvas.c +++ b/demo/common/canvas.c @@ -13,12 +13,12 @@ canvas_begin(struct nk_context *ctx, struct nk_canvas *canvas, nk_flags flags, /* save style properties which will be overwritten */ canvas->panel_padding = ctx->style.window.padding; canvas->item_spacing = ctx->style.window.spacing; - canvas->window_background = ctx->style.window.fixed_background; + canvas->window_background = ctx->style.window.image; /* use the complete window space and set background */ ctx->style.window.spacing = nk_vec2(0,0); ctx->style.window.padding = nk_vec2(0,0); - ctx->style.window.fixed_background = nk_style_item_color(background_color); + ctx->style.window.image = nk_style_item_color(background_color); /* create/update window and set position + size */ if (!nk_begin(ctx, "Canvas", nk_rect(x, y, width, height), NK_WINDOW_NO_SCROLLBAR|flags)) @@ -42,7 +42,7 @@ canvas_end(struct nk_context *ctx, struct nk_canvas *canvas) nk_end(ctx); ctx->style.window.spacing = canvas->panel_padding; ctx->style.window.padding = canvas->item_spacing; - ctx->style.window.fixed_background = canvas->window_background; + ctx->style.window.image = canvas->window_background; } static void diff --git a/example/canvas.c b/example/canvas.c index 5f651cc84..5d12c28cc 100644 --- a/example/canvas.c +++ b/example/canvas.c @@ -364,12 +364,12 @@ canvas_begin(struct nk_context *ctx, struct nk_canvas *canvas, nk_flags flags, /* save style properties which will be overwritten */ canvas->panel_padding = ctx->style.window.padding; canvas->item_spacing = ctx->style.window.spacing; - canvas->window_background = ctx->style.window.fixed_background; + canvas->window_background = ctx->style.window.image; /* use the complete window space and set background */ ctx->style.window.spacing = nk_vec2(0,0); ctx->style.window.padding = nk_vec2(0,0); - ctx->style.window.fixed_background = nk_style_item_color(background_color); + ctx->style.window.image = nk_style_item_color(background_color); /* create/update window and set position + size */ flags = flags & ~NK_WINDOW_DYNAMIC; @@ -390,7 +390,7 @@ canvas_end(struct nk_context *ctx, struct nk_canvas *canvas) nk_end(ctx); ctx->style.window.spacing = canvas->panel_padding; ctx->style.window.padding = canvas->item_spacing; - ctx->style.window.fixed_background = canvas->window_background; + ctx->style.window.image = canvas->window_background; } int main(int argc, char *argv[]) diff --git a/example/extended.c b/example/extended.c index f1ae3c129..fd4c05e94 100644 --- a/example/extended.c +++ b/example/extended.c @@ -84,8 +84,8 @@ ui_piemenu(struct nk_context *ctx, struct nk_vec2 pos, float radius, /* pie menu popup */ struct nk_color border = ctx->style.window.border_color; - struct nk_style_item background = ctx->style.window.fixed_background; - ctx->style.window.fixed_background = nk_style_item_hide(); + struct nk_style_item background = ctx->style.window.image; + ctx->style.window.image = nk_style_item_hide(); ctx->style.window.border_color = nk_rgba(0,0,0,0); total_space = nk_window_get_content_region(ctx); @@ -167,7 +167,7 @@ ui_piemenu(struct nk_context *ctx, struct nk_vec2 pos, float radius, ctx->style.window.padding = nk_vec2(8,8); nk_popup_end(ctx); - ctx->style.window.fixed_background = background; + ctx->style.window.image = background; ctx->style.window.border_color = border; return ret; } diff --git a/example/skinning.c b/example/skinning.c index 54f71e454..5995faeb4 100644 --- a/example/skinning.c +++ b/example/skinning.c @@ -415,7 +415,7 @@ int main(int argc, char *argv[]) /* window */ ctx.style.window.background = nk_rgb(204,204,204); - ctx.style.window.fixed_background = nk_style_item_image(media.window); + ctx.style.window.image = nk_style_item_image(media.window); ctx.style.window.border_color = nk_rgb(67,67,67); ctx.style.window.combo_border_color = nk_rgb(67,67,67); ctx.style.window.contextual_border_color = nk_rgb(67,67,67); From 2648cd52c7eae979523e60d03e6bad07ab213472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wladislav=20=E3=83=B4=E3=83=A9=E3=83=89=20Artsimovich?= Date: Thu, 14 Apr 2022 11:16:17 +0900 Subject: [PATCH 3/3] Introduced draw cmd type NK_COMMAND_IMAGE_TILED to distinguish modes --- nuklear.h | 41 +++++++++++++++++++++++++++++++++++------ src/nuklear.h | 2 ++ src/nuklear_draw.c | 23 +++++++++++++++++++++++ src/nuklear_panel.c | 5 ++++- src/nuklear_vertex.c | 11 ++++++----- 5 files changed, 70 insertions(+), 12 deletions(-) diff --git a/nuklear.h b/nuklear.h index fd087f017..e9f24bb9e 100644 --- a/nuklear.h +++ b/nuklear.h @@ -4439,6 +4439,7 @@ enum nk_command_type { NK_COMMAND_POLYLINE, NK_COMMAND_TEXT, NK_COMMAND_IMAGE, + NK_COMMAND_IMAGE_TILED, NK_COMMAND_CUSTOM }; @@ -4636,6 +4637,7 @@ NK_API void nk_fill_polygon(struct nk_command_buffer*, float*, int point_count, /* misc */ 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_image_tiled(struct nk_command_buffer*, struct nk_rect, const struct nk_image*, struct nk_color); NK_API void nk_draw_nine_slice(struct nk_command_buffer*, struct nk_rect, const struct nk_nine_slice*, struct nk_color); 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); @@ -9240,6 +9242,29 @@ nk_draw_image(struct nk_command_buffer *b, struct nk_rect r, cmd->col = col; } NK_API void +nk_draw_image_tiled(struct nk_command_buffer *b, struct nk_rect r, + const struct nk_image *img, struct nk_color col) +{ + struct nk_command_image *cmd; + NK_ASSERT(b); + if (!b) return; + 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; + } + + cmd = (struct nk_command_image*) + nk_command_buffer_push(b, NK_COMMAND_IMAGE_TILED, sizeof(*cmd)); + if (!cmd) return; + 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->img = *img; + cmd->col = col; +} +NK_API void nk_draw_nine_slice(struct nk_command_buffer *b, struct nk_rect r, const struct nk_nine_slice *slc, struct nk_color col) { @@ -10700,11 +10725,12 @@ nk_convert(struct nk_context *ctx, struct nk_buffer *cmds, } break; case NK_COMMAND_IMAGE: { const struct nk_command_image *i = (const struct nk_command_image*)cmd; - if(ctx->style.window.tiled_background) - nk_draw_list_add_image_tiled(&ctx->draw_list, i->img, nk_rect(i->x, i->y, i->w, i->h), i->col); - else - nk_draw_list_add_image(&ctx->draw_list, i->img, nk_rect(i->x, i->y, i->w, i->h), i->col); - } break; + 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_IMAGE_TILED: { + const struct nk_command_image *i = (const struct nk_command_image*)cmd; + nk_draw_list_add_image_tiled(&ctx->draw_list, i->img, nk_rect(i->x, i->y, i->w, i->h), i->col); + } break; 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); @@ -19717,7 +19743,10 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan switch(style->window.image.type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, body, &style->window.image.data.image, nk_white); + if(ctx->style.window.tiled_background) + nk_draw_image_tiled(out, body, &style->window.image.data.image, nk_white); + else + nk_draw_image(out, body, &style->window.image.data.image, nk_white); break; case NK_STYLE_ITEM_NINE_SLICE: nk_draw_nine_slice(out, body, &style->window.image.data.slice, nk_white); diff --git a/src/nuklear.h b/src/nuklear.h index 6b7e916f8..aacb77b42 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -4218,6 +4218,7 @@ enum nk_command_type { NK_COMMAND_POLYLINE, NK_COMMAND_TEXT, NK_COMMAND_IMAGE, + NK_COMMAND_IMAGE_TILED, NK_COMMAND_CUSTOM }; @@ -4415,6 +4416,7 @@ NK_API void nk_fill_polygon(struct nk_command_buffer*, float*, int point_count, /* misc */ 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_image_tiled(struct nk_command_buffer*, struct nk_rect, const struct nk_image*, struct nk_color); NK_API void nk_draw_nine_slice(struct nk_command_buffer*, struct nk_rect, const struct nk_nine_slice*, struct nk_color); 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); diff --git a/src/nuklear_draw.c b/src/nuklear_draw.c index efdf9c59b..be9e62f00 100644 --- a/src/nuklear_draw.c +++ b/src/nuklear_draw.c @@ -415,6 +415,29 @@ nk_draw_image(struct nk_command_buffer *b, struct nk_rect r, cmd->col = col; } NK_API void +nk_draw_image_tiled(struct nk_command_buffer *b, struct nk_rect r, + const struct nk_image *img, struct nk_color col) +{ + struct nk_command_image *cmd; + NK_ASSERT(b); + if (!b) return; + 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; + } + + cmd = (struct nk_command_image*) + nk_command_buffer_push(b, NK_COMMAND_IMAGE_TILED, sizeof(*cmd)); + if (!cmd) return; + 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->img = *img; + cmd->col = col; +} +NK_API void nk_draw_nine_slice(struct nk_command_buffer *b, struct nk_rect r, const struct nk_nine_slice *slc, struct nk_color col) { diff --git a/src/nuklear_panel.c b/src/nuklear_panel.c index 77dc13207..92d70fdc7 100644 --- a/src/nuklear_panel.c +++ b/src/nuklear_panel.c @@ -303,7 +303,10 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan switch(style->window.image.type) { case NK_STYLE_ITEM_IMAGE: - nk_draw_image(out, body, &style->window.image.data.image, nk_white); + if(ctx->style.window.tiled_background) + nk_draw_image_tiled(out, body, &style->window.image.data.image, nk_white); + else + nk_draw_image(out, body, &style->window.image.data.image, nk_white); break; case NK_STYLE_ITEM_NINE_SLICE: nk_draw_nine_slice(out, body, &style->window.image.data.slice, nk_white); diff --git a/src/nuklear_vertex.c b/src/nuklear_vertex.c index 077225c42..5b718cd40 100644 --- a/src/nuklear_vertex.c +++ b/src/nuklear_vertex.c @@ -1316,11 +1316,12 @@ nk_convert(struct nk_context *ctx, struct nk_buffer *cmds, } break; case NK_COMMAND_IMAGE: { const struct nk_command_image *i = (const struct nk_command_image*)cmd; - if(ctx->style.window.tiled_background) - nk_draw_list_add_image_tiled(&ctx->draw_list, i->img, nk_rect(i->x, i->y, i->w, i->h), i->col); - else - nk_draw_list_add_image(&ctx->draw_list, i->img, nk_rect(i->x, i->y, i->w, i->h), i->col); - } break; + 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_IMAGE_TILED: { + const struct nk_command_image *i = (const struct nk_command_image*)cmd; + nk_draw_list_add_image_tiled(&ctx->draw_list, i->img, nk_rect(i->x, i->y, i->w, i->h), i->col); + } break; 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);