nuklear input fixed

This commit is contained in:
John Alanbrook 2023-08-23 04:19:09 +00:00
parent 3f2ae7ff82
commit 54e247433f
4 changed files with 49 additions and 0 deletions

View file

@ -2,6 +2,7 @@
#include "ffi.h"
#include "font.h"
#include "nuke.h"
#include "log.h"
#include "script.h"
#include "stb_ds.h"
@ -120,6 +121,8 @@ void rm_downkey(int key) {
}
static void cursor_pos_cb(GLFWwindow *w, double xpos, double ypos) {
nuke_input_cursor(xpos, ypos);
mouse_delta.x = xpos - mouse_pos.x;
mouse_delta.y = ypos - mouse_pos.y;
@ -149,9 +152,13 @@ static void pawn_call_keydown(int key) {
static void scroll_cb(GLFWwindow *w, double xoffset, double yoffset) {
mouseWheelY = yoffset;
mouseWheelX = xoffset;
nuke_input_scroll(xoffset, yoffset);
}
static void mb_cb(GLFWwindow *w, int button, int action, int mods) {
nuke_input_button(button, mouse_pos.x, mouse_pos.y, action == GLFW_PRESS);
JSValue argv[3];
argv[0] = jsinput;
switch (action) {
@ -181,6 +188,8 @@ void set_mouse_mode(int mousemode) {
}
void char_cb(GLFWwindow *w, unsigned int codepoint) {
nuke_input_char(codepoint);
static char out[2] = {0};
static JSValue argv[2];

View file

@ -33,12 +33,42 @@ void nuke_init(struct window *win) {
snk_setup(&(snk_desc_t){
.no_default_font = false
});
ctx = snk_new_frame();
}
void nuke_start() {
ctx = snk_new_frame();
}
void nuke_input_cursor(int x, int y)
{
nk_input_motion(ctx, x, y);
}
void nuke_input_key(int key, int down)
{
nk_input_key(ctx, key, down);
}
void nuke_input_button(int btn, int x, int y, int down)
{
nk_input_button(ctx, btn, x, y, down);
}
void nuke_input_scroll(float x, float y)
{
nk_input_scroll(ctx, nk_vec2(x, y));
}
void nuke_input_char(char c)
{
nk_input_char(ctx, c);
}
void nuke_input_begin() { nk_input_begin(ctx); }
void nuke_input_end() { nk_input_end(ctx); }
void nuke_end() {
snk_render(1200,720);
}

View file

@ -27,6 +27,14 @@ void nuke_property_float(const char *lbl, float min, float *val, float max, floa
void nuke_property_float2(const char *label, float min, float *val, float max, float step, float dragstep);
void nuke_property_float3(const char *label, float min, float *val, float max, float step, float dragstep);
void nuke_input_begin();
void nuke_input_end();
void nuke_input_cursor(int x, int y);
void nuke_input_key(int key, int down);
void nuke_input_button(int btn, int x, int y, int down);
void nuke_input_scroll(float x, float y);
void nuke_input_char(char c);
void nuke_property_int(const char *lbl, int min, int *val, int max, int step);
void nuke_radio_btn(const char *lbl, int *val, int cmp);
void nuke_checkbox(const char *lbl, int *val);

View file

@ -231,11 +231,13 @@ int main(int argc, char **args) {
deltaT = elapsed;
lastTick = glfwGetTime();
//double wait = fmax(0, renderMS - elapsed);
nuke_input_begin();
if (sim_playing())
input_poll(fmax(0, renderMS-elapsed));
else
input_poll(1000);
window_all_handle_events();
nuke_input_end();
framems[framei++] = elapsed;
if (framei == FPSBUF) framei = 0;