-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnuklear_console_image.h
More file actions
127 lines (101 loc) · 3.79 KB
/
nuklear_console_image.h
File metadata and controls
127 lines (101 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef NK_CONSOLE_IMAGE_H__
#define NK_CONSOLE_IMAGE_H__
typedef struct nk_console_image_data {
struct nk_image image;
struct nk_color color;
} nk_console_image_data;
#if defined(__cplusplus)
extern "C" {
#endif
NK_API nk_console* nk_console_image(nk_console* parent, struct nk_image image);
NK_API nk_console* nk_console_image_color(nk_console* parent, struct nk_image image, struct nk_color color);
NK_API struct nk_rect nk_console_image_render(nk_console* widget);
NK_API void nk_console_image_set_image(nk_console* widget, struct nk_image image);
NK_API struct nk_image nk_console_image_get_image(nk_console* widget);
NK_API void nk_console_image_set_color(nk_console* widget, struct nk_color color);
NK_API struct nk_color nk_console_image_get_color(nk_console* widget);
#if defined(__cplusplus)
}
#endif
#endif // NK_CONSOLE_IMAGE_H__
#if defined(NK_CONSOLE_IMPLEMENTATION) && !defined(NK_CONSOLE_HEADER_ONLY)
#ifndef NK_CONSOLE_IMAGE_IMPLEMENTATION_ONCE
#define NK_CONSOLE_IMAGE_IMPLEMENTATION_ONCE
#if defined(__cplusplus)
extern "C" {
#endif
NK_API void nk_console_image_set_image(nk_console* widget, struct nk_image image) {
if (widget == NULL || widget->data == NULL) {
return;
}
nk_console_image_data* data = (nk_console_image_data*)widget->data;
data->image = image;
}
NK_API struct nk_image nk_console_image_get_image(nk_console* widget) {
if (widget == NULL || widget->data == NULL) {
struct nk_image output = {0};
return output;
}
nk_console_image_data* data = (nk_console_image_data*)widget->data;
return data->image;
}
NK_API void nk_console_image_set_color(nk_console* widget, struct nk_color color) {
if (widget == NULL || widget->data == NULL) {
return;
}
nk_console_image_data* data = (nk_console_image_data*)widget->data;
data->color = color;
}
NK_API struct nk_color nk_console_image_get_color(nk_console* widget) {
if (widget == NULL || widget->data == NULL) {
struct nk_color output = {0};
return output;
}
nk_console_image_data* data = (nk_console_image_data*)widget->data;
return data->color;
}
NK_API struct nk_rect nk_console_image_render(nk_console* widget) {
nk_console_image_data* data = (nk_console_image_data*)widget->data;
if (data == NULL) {
return nk_rect(0, 0, 0, 0);
}
nk_console_layout_widget(widget);
struct nk_rect widget_bounds = nk_layout_widget_bounds(widget->ctx);
// Toggle it as disabled if needed.
if (widget->disabled ||
(widget->selectable && nk_console_get_active_widget(widget) != widget)) {
nk_widget_disable_begin(widget->ctx);
}
nk_image_color(widget->ctx, data->image, data->color);
// Release the disabled state if needed.
if (widget->disabled ||
(widget->selectable && nk_console_get_active_widget(widget) != widget)) {
nk_widget_disable_end(widget->ctx);
}
if (nk_console_is_active_widget(widget)) {
nk_console_check_up_down(widget);
nk_console_check_tooltip(widget);
}
return widget_bounds;
}
NK_API nk_console* nk_console_image(nk_console* parent, struct nk_image image) {
struct nk_color white = {255, 255, 255, 255};
return nk_console_image_color(parent, image, white);
}
NK_API
nk_console* nk_console_image_color(nk_console* parent, struct nk_image image, struct nk_color color) {
nk_console_image_data* data =
(nk_console_image_data*)NK_CONSOLE_MALLOC(nk_handle_id(0), NULL, sizeof(*data));
data->image = image;
data->color = color;
nk_console* img = nk_console_label(parent, NULL);
img->type = NK_CONSOLE_IMAGE;
img->data = (void*)data;
img->render = nk_console_image_render;
return img;
}
#if defined(__cplusplus)
}
#endif
#endif // NK_CONSOLE_IMAGE_IMPLEMENTATION_ONCE
#endif // NK_CONSOLE_IMPLEMENTATION