prosperon/source/engine/thirdparty/Nuklear/src/nuklear_image.c

140 lines
3.1 KiB
C
Raw Normal View History

2022-06-21 12:48:19 -05:00
#include "nuklear.h"
#include "nuklear_internal.h"
/* ===============================================================
*
* IMAGE
*
* ===============================================================*/
NK_API nk_handle
nk_handle_ptr(void *ptr)
{
nk_handle handle = {0};
handle.ptr = ptr;
return handle;
}
NK_API nk_handle
nk_handle_id(int id)
{
nk_handle handle;
nk_zero_struct(handle);
handle.id = id;
return handle;
}
NK_API struct nk_image
nk_subimage_ptr(void *ptr, nk_ushort w, nk_ushort h, struct nk_rect r)
{
struct nk_image s;
nk_zero(&s, sizeof(s));
s.handle.ptr = ptr;
s.w = w; s.h = h;
s.region[0] = (nk_ushort)r.x;
s.region[1] = (nk_ushort)r.y;
s.region[2] = (nk_ushort)r.w;
s.region[3] = (nk_ushort)r.h;
return s;
}
NK_API struct nk_image
nk_subimage_id(int id, nk_ushort w, nk_ushort h, struct nk_rect r)
{
struct nk_image s;
nk_zero(&s, sizeof(s));
s.handle.id = id;
s.w = w; s.h = h;
s.region[0] = (nk_ushort)r.x;
s.region[1] = (nk_ushort)r.y;
s.region[2] = (nk_ushort)r.w;
s.region[3] = (nk_ushort)r.h;
return s;
}
NK_API struct nk_image
nk_subimage_handle(nk_handle handle, nk_ushort w, nk_ushort h, struct nk_rect r)
{
struct nk_image s;
nk_zero(&s, sizeof(s));
s.handle = handle;
s.w = w; s.h = h;
s.region[0] = (nk_ushort)r.x;
s.region[1] = (nk_ushort)r.y;
s.region[2] = (nk_ushort)r.w;
s.region[3] = (nk_ushort)r.h;
return s;
}
NK_API struct nk_image
nk_image_handle(nk_handle handle)
{
struct nk_image s;
nk_zero(&s, sizeof(s));
s.handle = handle;
s.w = 0; s.h = 0;
s.region[0] = 0;
s.region[1] = 0;
s.region[2] = 0;
s.region[3] = 0;
return s;
}
NK_API struct nk_image
nk_image_ptr(void *ptr)
{
struct nk_image s;
nk_zero(&s, sizeof(s));
NK_ASSERT(ptr);
s.handle.ptr = ptr;
s.w = 0; s.h = 0;
s.region[0] = 0;
s.region[1] = 0;
s.region[2] = 0;
s.region[3] = 0;
return s;
}
NK_API struct nk_image
nk_image_id(int id)
{
struct nk_image s;
nk_zero(&s, sizeof(s));
s.handle.id = id;
s.w = 0; s.h = 0;
s.region[0] = 0;
s.region[1] = 0;
s.region[2] = 0;
s.region[3] = 0;
return s;
}
NK_API nk_bool
nk_image_is_subimage(const struct nk_image* img)
{
NK_ASSERT(img);
return !(img->w == 0 && img->h == 0);
}
NK_API void
nk_image(struct nk_context *ctx, struct nk_image img)
{
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_image(&win->buffer, bounds, &img, nk_white);
}
NK_API void
nk_image_color(struct nk_context *ctx, struct nk_image img, struct nk_color col)
{
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_image(&win->buffer, bounds, &img, col);
}