Nuklear
This is a minimal-state, immediate-mode graphical user interface toolkit written in ANSI C and licensed under public domain. It was designed as a simple embeddable user interface for application and does not have any dependencies, a default render backend or OS window/input handling but instead provides a highly modular, library-based approach, with simple input state for input and draw commands describing primitive shapes as output. So instead of providing a layered library that tries to abstract over a number of platform and render backends, it focuses only on the actual UI.
 
Loading...
Searching...
No Matches
nuklear_image.c
1#include "nuklear.h"
2#include "nuklear_internal.h"
3
4/* ===============================================================
5 *
6 * IMAGE
7 *
8 * ===============================================================*/
9NK_API nk_handle
10nk_handle_ptr(void *ptr)
11{
12 nk_handle handle = {0};
13 handle.ptr = ptr;
14 return handle;
15}
16NK_API nk_handle
17nk_handle_id(int id)
18{
19 nk_handle handle;
20 nk_zero_struct(handle);
21 handle.id = id;
22 return handle;
23}
24NK_API struct nk_image
25nk_subimage_ptr(void *ptr, nk_ushort w, nk_ushort h, struct nk_rect r)
26{
27 struct nk_image s;
28 nk_zero(&s, sizeof(s));
29 s.handle.ptr = ptr;
30 s.w = w; s.h = h;
31 s.region[0] = (nk_ushort)r.x;
32 s.region[1] = (nk_ushort)r.y;
33 s.region[2] = (nk_ushort)r.w;
34 s.region[3] = (nk_ushort)r.h;
35 return s;
36}
37NK_API struct nk_image
38nk_subimage_id(int id, nk_ushort w, nk_ushort h, struct nk_rect r)
39{
40 struct nk_image s;
41 nk_zero(&s, sizeof(s));
42 s.handle.id = id;
43 s.w = w; s.h = h;
44 s.region[0] = (nk_ushort)r.x;
45 s.region[1] = (nk_ushort)r.y;
46 s.region[2] = (nk_ushort)r.w;
47 s.region[3] = (nk_ushort)r.h;
48 return s;
49}
50NK_API struct nk_image
51nk_subimage_handle(nk_handle handle, nk_ushort w, nk_ushort h, struct nk_rect r)
52{
53 struct nk_image s;
54 nk_zero(&s, sizeof(s));
55 s.handle = handle;
56 s.w = w; s.h = h;
57 s.region[0] = (nk_ushort)r.x;
58 s.region[1] = (nk_ushort)r.y;
59 s.region[2] = (nk_ushort)r.w;
60 s.region[3] = (nk_ushort)r.h;
61 return s;
62}
63NK_API struct nk_image
64nk_image_handle(nk_handle handle)
65{
66 struct nk_image s;
67 nk_zero(&s, sizeof(s));
68 s.handle = handle;
69 s.w = 0; s.h = 0;
70 s.region[0] = 0;
71 s.region[1] = 0;
72 s.region[2] = 0;
73 s.region[3] = 0;
74 return s;
75}
76NK_API struct nk_image
77nk_image_ptr(void *ptr)
78{
79 struct nk_image s;
80 nk_zero(&s, sizeof(s));
81 NK_ASSERT(ptr);
82 s.handle.ptr = ptr;
83 s.w = 0; s.h = 0;
84 s.region[0] = 0;
85 s.region[1] = 0;
86 s.region[2] = 0;
87 s.region[3] = 0;
88 return s;
89}
90NK_API struct nk_image
91nk_image_id(int id)
92{
93 struct nk_image s;
94 nk_zero(&s, sizeof(s));
95 s.handle.id = id;
96 s.w = 0; s.h = 0;
97 s.region[0] = 0;
98 s.region[1] = 0;
99 s.region[2] = 0;
100 s.region[3] = 0;
101 return s;
102}
103NK_API nk_bool
104nk_image_is_subimage(const struct nk_image* img)
105{
106 NK_ASSERT(img);
107 return !(img->w == 0 && img->h == 0);
108}
109NK_API void
110nk_image(struct nk_context *ctx, struct nk_image img)
111{
112 struct nk_window *win;
113 struct nk_rect bounds;
114
115 NK_ASSERT(ctx);
116 NK_ASSERT(ctx->current);
117 NK_ASSERT(ctx->current->layout);
118 if (!ctx || !ctx->current || !ctx->current->layout) return;
119
120 win = ctx->current;
121 if (!nk_widget(&bounds, ctx)) return;
122 nk_draw_image(&win->buffer, bounds, &img, nk_white);
123}
124NK_API void
125nk_image_color(struct nk_context *ctx, struct nk_image img, struct nk_color col)
126{
127 struct nk_window *win;
128 struct nk_rect bounds;
129
130 NK_ASSERT(ctx);
131 NK_ASSERT(ctx->current);
132 NK_ASSERT(ctx->current->layout);
133 if (!ctx || !ctx->current || !ctx->current->layout) return;
134
135 win = ctx->current;
136 if (!nk_widget(&bounds, ctx)) return;
137 nk_draw_image(&win->buffer, bounds, &img, col);
138}
139
main API and documentation file
NK_API void nk_draw_image(struct nk_command_buffer *, struct nk_rect, const struct nk_image *, struct nk_color)
misc