2022-08-05 14:23:39 -05:00
|
|
|
#define NK_INCLUDE_STANDARD_IO
|
2023-05-12 13:22:05 -05:00
|
|
|
|
2022-08-05 14:23:39 -05:00
|
|
|
#define NK_IMPLEMENTATION
|
|
|
|
#define NK_KEYSTATE_BASED_INPUT
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
#define STBTT_STATIC
|
|
|
|
|
2022-08-05 14:23:39 -05:00
|
|
|
#include "nuke.h"
|
2023-05-12 13:22:05 -05:00
|
|
|
|
|
|
|
#define SOKOL_GLCORE33
|
|
|
|
#include "sokol/sokol_gfx.h"
|
|
|
|
|
|
|
|
#define SOKOL_NUKLEAR_NO_SOKOL_APP
|
|
|
|
#define SOKOL_NUKLEAR_IMPL
|
|
|
|
|
|
|
|
#include "sokol/sokol_nuklear.h"
|
2022-08-05 14:23:39 -05:00
|
|
|
|
2022-12-23 13:48:29 -06:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2023-03-01 14:42:44 -06:00
|
|
|
#include "log.h"
|
2023-05-12 13:22:05 -05:00
|
|
|
#include "texture.h"
|
|
|
|
#include "window.h"
|
2022-08-05 14:23:39 -05:00
|
|
|
|
|
|
|
#define MAX_VERTEX_BUFFER 512 * 1024
|
|
|
|
#define MAX_ELEMENT_BUFFER 128 * 1024
|
|
|
|
|
|
|
|
struct nk_context *ctx;
|
2023-05-12 13:22:05 -05:00
|
|
|
//static struct nk_glfw nkglfw = {0};
|
2022-08-05 14:23:39 -05:00
|
|
|
|
2022-11-03 16:58:03 -05:00
|
|
|
void nuke_init(struct window *win) {
|
2023-05-12 13:22:05 -05:00
|
|
|
window_makecurrent(win);
|
|
|
|
|
|
|
|
snk_setup(&(snk_desc_t){
|
|
|
|
.no_default_font = false
|
|
|
|
});
|
2022-08-05 14:23:39 -05:00
|
|
|
}
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
void nuke_start() {
|
|
|
|
ctx = snk_new_frame();
|
2022-08-05 14:23:39 -05:00
|
|
|
}
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
void nuke_end() {
|
|
|
|
snk_render(1200,720);
|
2022-08-12 14:03:56 -05:00
|
|
|
}
|
|
|
|
|
2022-12-23 13:48:29 -06:00
|
|
|
int nuke_begin(const char *lbl, struct nk_rect rect, int flags) {
|
2023-05-12 13:22:05 -05:00
|
|
|
return nk_begin(ctx, lbl, rect, flags);
|
2022-12-23 13:48:29 -06:00
|
|
|
}
|
2023-01-19 13:06:32 -06:00
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
int nuke_begin_win(const char *lbl) {
|
2023-01-19 13:06:32 -06:00
|
|
|
return nk_begin(ctx, lbl, nk_rect(10, 10, 400, 600), NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE | NK_WINDOW_TITLE);
|
|
|
|
}
|
|
|
|
|
2022-12-23 13:48:29 -06:00
|
|
|
void nuke_stop() {
|
2023-05-12 13:22:05 -05:00
|
|
|
nk_end(ctx);
|
2022-12-23 13:48:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
struct nk_rect nuke_win_get_bounds() {
|
2023-05-12 13:22:05 -05:00
|
|
|
return nk_window_get_bounds(ctx);
|
2022-12-23 13:48:29 -06:00
|
|
|
}
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
void nuke_row(int height) {
|
2023-03-10 13:13:48 -06:00
|
|
|
nk_layout_row_dynamic(ctx, height, 1);
|
|
|
|
}
|
|
|
|
|
2022-12-23 13:48:29 -06:00
|
|
|
void nuke_property_float3(const char *label, float min, float *val, float max, float step, float dragstep) {
|
2023-05-12 13:22:05 -05:00
|
|
|
nk_layout_row_dynamic(ctx, 25, 1);
|
|
|
|
nk_label(ctx, label, NK_TEXT_LEFT);
|
|
|
|
nk_layout_row_dynamic(ctx, 25, 3);
|
|
|
|
nuke_property_float("#X", min, &val[0], max, step, dragstep);
|
|
|
|
nuke_property_float("#Y", min, &val[1], max, step, dragstep);
|
|
|
|
nuke_property_float("#Z", min, &val[2], max, step, dragstep);
|
2022-08-12 14:03:56 -05:00
|
|
|
}
|
|
|
|
|
2022-12-23 13:48:29 -06:00
|
|
|
void nuke_property_float2(const char *label, float min, float *val, float max, float step, float dragstep) {
|
2023-05-12 13:22:05 -05:00
|
|
|
nk_layout_row_dynamic(ctx, 25, 1);
|
|
|
|
nk_label(ctx, label, NK_TEXT_LEFT);
|
|
|
|
nk_layout_row_dynamic(ctx, 25, 2);
|
|
|
|
nuke_property_float("#X", min, &val[0], max, step, dragstep);
|
|
|
|
nuke_property_float("#Y", min, &val[1], max, step, dragstep);
|
2022-08-12 14:03:56 -05:00
|
|
|
}
|
|
|
|
|
2022-12-15 17:30:22 -06:00
|
|
|
void nuke_property_float(const char *lbl, float min, float *val, float max, float step, float dragstep) {
|
2023-05-12 13:22:05 -05:00
|
|
|
nk_property_float(ctx, lbl, min, val, max, step, dragstep);
|
2022-12-15 17:30:22 -06:00
|
|
|
}
|
|
|
|
|
2022-08-19 11:25:08 -05:00
|
|
|
int nuke_btn(const char *lbl) {
|
2023-05-12 13:22:05 -05:00
|
|
|
return nk_button_label(ctx, lbl);
|
2022-08-19 11:25:08 -05:00
|
|
|
}
|
|
|
|
|
2023-02-15 17:54:05 -06:00
|
|
|
void nuke_img(char *path) {
|
2023-05-12 13:22:05 -05:00
|
|
|
/*
|
|
|
|
struct Texture *t = texture_pullfromfile(path);
|
|
|
|
nk_layout_row_static(ctx, t->height, t->width, 1);
|
|
|
|
nk_image(ctx, nk_image_id(t->id));
|
|
|
|
*/
|
2023-02-15 17:54:05 -06:00
|
|
|
}
|
|
|
|
|
2022-08-19 11:25:08 -05:00
|
|
|
void nuke_property_int(const char *lbl, int min, int *val, int max, int step) {
|
2023-05-12 13:22:05 -05:00
|
|
|
nk_property_int(ctx, lbl, min, val, max, step, step);
|
2022-08-19 11:25:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void nuke_radio_btn(const char *lbl, int *val, int cmp) {
|
2023-05-12 13:22:05 -05:00
|
|
|
if (nk_option_label(ctx, lbl, *val == cmp)) *val = cmp;
|
2022-08-19 11:25:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void nuke_checkbox(const char *lbl, int *val) {
|
2023-05-12 13:22:05 -05:00
|
|
|
nk_checkbox_label(ctx, lbl, val);
|
2022-08-19 11:25:08 -05:00
|
|
|
}
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
void nuke_scrolltext(char *str) {
|
|
|
|
nk_edit_string_zero_terminated(ctx, NK_EDIT_MULTILINE | NK_EDIT_GOTO_END_ON_ACTIVATE, str, 1024 * 1024 * 5, NULL);
|
2023-03-17 10:25:35 -05:00
|
|
|
}
|
|
|
|
|
2022-08-17 00:01:51 -05:00
|
|
|
void nuke_nel(int cols) {
|
2023-05-12 13:22:05 -05:00
|
|
|
nk_layout_row_dynamic(ctx, 25, cols);
|
2022-08-17 00:01:51 -05:00
|
|
|
}
|
|
|
|
|
2023-03-17 10:25:35 -05:00
|
|
|
void nuke_nel_h(int cols, int h) {
|
2023-05-12 13:22:05 -05:00
|
|
|
nk_layout_row_dynamic(ctx, h, cols);
|
2023-03-17 10:25:35 -05:00
|
|
|
}
|
|
|
|
|
2022-08-17 00:01:51 -05:00
|
|
|
void nuke_label(const char *s) {
|
2023-05-12 13:22:05 -05:00
|
|
|
nk_label(ctx, s, NK_TEXT_LEFT);
|
2022-08-19 11:25:08 -05:00
|
|
|
}
|
2022-12-12 10:48:21 -06:00
|
|
|
|
|
|
|
void nuke_edit_str(char *str) {
|
2023-05-12 13:22:05 -05:00
|
|
|
nk_edit_string_zero_terminated(ctx, NK_EDIT_BOX | NK_EDIT_NO_HORIZONTAL_SCROLL, str, 130, nk_filter_ascii);
|
2022-12-23 13:48:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int nuke_push_tree_id(const char *name, int id) {
|
2023-05-12 13:22:05 -05:00
|
|
|
return nk_tree_push_id(ctx, NK_TREE_NODE, name, NK_MINIMIZED, id);
|
2022-12-23 13:48:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void nuke_tree_pop() {
|
2023-05-12 13:22:05 -05:00
|
|
|
nk_tree_pop(ctx);
|
2022-12-23 13:48:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void nuke_labelf(const char *fmt, ...) {
|
2023-05-12 13:22:05 -05:00
|
|
|
char buf[512];
|
2022-12-28 16:50:54 -06:00
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
vsnprintf(buf, 512, fmt, args);
|
|
|
|
nuke_label(buf);
|
|
|
|
va_end(args);
|
2023-02-15 17:54:05 -06:00
|
|
|
}
|