|
@@ -281,6 +281,7 @@ NK_API void nk_glfw3_device_create(
|
|
uint32_t framebuffer_width, uint32_t framebuffer_height);
|
|
uint32_t framebuffer_width, uint32_t framebuffer_height);
|
|
|
|
|
|
NK_API void nk_glfw3_char_callback(GLFWwindow *win, unsigned int codepoint);
|
|
NK_API void nk_glfw3_char_callback(GLFWwindow *win, unsigned int codepoint);
|
|
|
|
+NK_API void nk_glfw3_key_callback(GLFWwindow *win, int key, int scancode, int action, int mods);
|
|
NK_API void nk_gflw3_scroll_callback(GLFWwindow *win, double xoff, double yoff);
|
|
NK_API void nk_gflw3_scroll_callback(GLFWwindow *win, double xoff, double yoff);
|
|
NK_API void nk_glfw3_mouse_button_callback(GLFWwindow *win, int button,
|
|
NK_API void nk_glfw3_mouse_button_callback(GLFWwindow *win, int button,
|
|
int action, int mods);
|
|
int action, int mods);
|
|
@@ -372,7 +373,9 @@ static struct nk_glfw {
|
|
struct nk_glfw_device vulkan;
|
|
struct nk_glfw_device vulkan;
|
|
struct nk_context ctx;
|
|
struct nk_context ctx;
|
|
struct nk_font_atlas atlas;
|
|
struct nk_font_atlas atlas;
|
|
|
|
+ struct nk_vec2 fb_scale;
|
|
unsigned int text[NK_GLFW_TEXT_MAX];
|
|
unsigned int text[NK_GLFW_TEXT_MAX];
|
|
|
|
+ nk_char key_events[NK_KEY_MAX];
|
|
int text_len;
|
|
int text_len;
|
|
struct nk_vec2 scroll;
|
|
struct nk_vec2 scroll;
|
|
double last_button_click;
|
|
double last_button_click;
|
|
@@ -1251,12 +1254,18 @@ NK_API void nk_glfw3_new_frame(void) {
|
|
double x, y;
|
|
double x, y;
|
|
struct nk_context *ctx = &glfw.ctx;
|
|
struct nk_context *ctx = &glfw.ctx;
|
|
struct GLFWwindow *win = glfw.win;
|
|
struct GLFWwindow *win = glfw.win;
|
|
|
|
+ nk_char* k_state = glfw.key_events;
|
|
|
|
|
|
/* update the timer */
|
|
/* update the timer */
|
|
float delta_time_now = (float)glfwGetTime();
|
|
float delta_time_now = (float)glfwGetTime();
|
|
glfw.ctx.delta_time_seconds = delta_time_now - glfw.delta_time_seconds_last;
|
|
glfw.ctx.delta_time_seconds = delta_time_now - glfw.delta_time_seconds_last;
|
|
glfw.delta_time_seconds_last = delta_time_now;
|
|
glfw.delta_time_seconds_last = delta_time_now;
|
|
|
|
|
|
|
|
+ glfwGetWindowSize(win, &glfw.width, &glfw.height);
|
|
|
|
+ glfwGetFramebufferSize(win, &glfw.display_width, &glfw.display_height);
|
|
|
|
+ glfw.fb_scale.x = (float)glfw.display_width/(float)glfw.width;
|
|
|
|
+ glfw.fb_scale.y = (float)glfw.display_height/(float)glfw.height;
|
|
|
|
+
|
|
nk_input_begin(ctx);
|
|
nk_input_begin(ctx);
|
|
for (i = 0; i < glfw.text_len; ++i)
|
|
for (i = 0; i < glfw.text_len; ++i)
|
|
nk_input_unicode(ctx, glfw.text[i]);
|
|
nk_input_unicode(ctx, glfw.text[i]);
|
|
@@ -1269,61 +1278,39 @@ NK_API void nk_glfw3_new_frame(void) {
|
|
glfwSetInputMode(glfw.win, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
|
glfwSetInputMode(glfw.win, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- nk_input_key(ctx, NK_KEY_DEL,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_DELETE) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_ENTER,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_ENTER) == GLFW_PRESS ||
|
|
|
|
- glfwGetKey(win, GLFW_KEY_KP_ENTER) == GLFW_PRESS);
|
|
|
|
-
|
|
|
|
- nk_input_key(ctx, NK_KEY_TAB, glfwGetKey(win, GLFW_KEY_TAB) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_BACKSPACE,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_BACKSPACE) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_UP, glfwGetKey(win, GLFW_KEY_UP) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_DOWN,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_DOWN) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_TEXT_START,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_HOME) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_TEXT_END,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_END) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_SCROLL_START,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_HOME) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_SCROLL_END,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_END) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_SCROLL_DOWN,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_PAGE_DOWN) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_SCROLL_UP,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_PAGE_UP) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_SHIFT,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS ||
|
|
|
|
- glfwGetKey(win, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS);
|
|
|
|
|
|
+ if (k_state[NK_KEY_DEL] >= 0) nk_input_key(ctx, NK_KEY_DEL, k_state[NK_KEY_DEL]);
|
|
|
|
+ if (k_state[NK_KEY_ENTER] >= 0) nk_input_key(ctx, NK_KEY_ENTER, k_state[NK_KEY_ENTER]);
|
|
|
|
+
|
|
|
|
+ if (k_state[NK_KEY_TAB] >= 0) nk_input_key(ctx, NK_KEY_TAB, k_state[NK_KEY_TAB]);
|
|
|
|
+ if (k_state[NK_KEY_BACKSPACE] >= 0) nk_input_key(ctx, NK_KEY_BACKSPACE, k_state[NK_KEY_BACKSPACE]);
|
|
|
|
+ if (k_state[NK_KEY_UP] >= 0) nk_input_key(ctx, NK_KEY_UP, k_state[NK_KEY_UP]);
|
|
|
|
+ if (k_state[NK_KEY_DOWN] >= 0) nk_input_key(ctx, NK_KEY_DOWN, k_state[NK_KEY_DOWN]);
|
|
|
|
+ if (k_state[NK_KEY_SCROLL_UP] >= 0) nk_input_key(ctx, NK_KEY_SCROLL_UP, k_state[NK_KEY_SCROLL_UP]);
|
|
|
|
+ if (k_state[NK_KEY_SCROLL_DOWN] >= 0) nk_input_key(ctx, NK_KEY_SCROLL_DOWN, k_state[NK_KEY_SCROLL_DOWN]);
|
|
|
|
+
|
|
|
|
+ nk_input_key(ctx, NK_KEY_TEXT_START, glfwGetKey(win, GLFW_KEY_HOME) == GLFW_PRESS);
|
|
|
|
+ nk_input_key(ctx, NK_KEY_TEXT_END, glfwGetKey(win, GLFW_KEY_END) == GLFW_PRESS);
|
|
|
|
+ nk_input_key(ctx, NK_KEY_SCROLL_START, glfwGetKey(win, GLFW_KEY_HOME) == GLFW_PRESS);
|
|
|
|
+ nk_input_key(ctx, NK_KEY_SCROLL_END, glfwGetKey(win, GLFW_KEY_END) == GLFW_PRESS);
|
|
|
|
+ nk_input_key(ctx, NK_KEY_SHIFT, glfwGetKey(win, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS||
|
|
|
|
+ glfwGetKey(win, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS);
|
|
|
|
|
|
if (glfwGetKey(win, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS ||
|
|
if (glfwGetKey(win, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS ||
|
|
glfwGetKey(win, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS) {
|
|
glfwGetKey(win, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS) {
|
|
- nk_input_key(ctx, NK_KEY_COPY,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_C) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_PASTE,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_V) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_CUT,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_X) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_TEXT_UNDO,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_Z) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_TEXT_REDO,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_R) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_TEXT_WORD_LEFT,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_LEFT) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_TEXT_WORD_RIGHT,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_RIGHT) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_TEXT_LINE_START,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_B) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_TEXT_LINE_END,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_E) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_TEXT_SELECT_ALL,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_A) == GLFW_PRESS);
|
|
|
|
|
|
+ /* Note these are physical keys and won't respect any layouts/key mapping */
|
|
|
|
+ if (k_state[NK_KEY_COPY] >= 0) nk_input_key(ctx, NK_KEY_COPY, k_state[NK_KEY_COPY]);
|
|
|
|
+ if (k_state[NK_KEY_PASTE] >= 0) nk_input_key(ctx, NK_KEY_PASTE, k_state[NK_KEY_PASTE]);
|
|
|
|
+ if (k_state[NK_KEY_CUT] >= 0) nk_input_key(ctx, NK_KEY_CUT, k_state[NK_KEY_CUT]);
|
|
|
|
+ if (k_state[NK_KEY_TEXT_UNDO] >= 0) nk_input_key(ctx, NK_KEY_TEXT_UNDO, k_state[NK_KEY_TEXT_UNDO]);
|
|
|
|
+ if (k_state[NK_KEY_TEXT_REDO] >= 0) nk_input_key(ctx, NK_KEY_TEXT_REDO, k_state[NK_KEY_TEXT_REDO]);
|
|
|
|
+ if (k_state[NK_KEY_TEXT_LINE_START] >= 0) nk_input_key(ctx, NK_KEY_TEXT_LINE_START, k_state[NK_KEY_TEXT_LINE_START]);
|
|
|
|
+ if (k_state[NK_KEY_TEXT_LINE_END] >= 0) nk_input_key(ctx, NK_KEY_TEXT_LINE_END, k_state[NK_KEY_TEXT_LINE_END]);
|
|
|
|
+ if (k_state[NK_KEY_TEXT_SELECT_ALL] >= 0) nk_input_key(ctx, NK_KEY_TEXT_SELECT_ALL, k_state[NK_KEY_TEXT_SELECT_ALL]);
|
|
|
|
+ if (k_state[NK_KEY_LEFT] >= 0) nk_input_key(ctx, NK_KEY_TEXT_WORD_LEFT, k_state[NK_KEY_LEFT]);
|
|
|
|
+ if (k_state[NK_KEY_RIGHT] >= 0) nk_input_key(ctx, NK_KEY_TEXT_WORD_RIGHT, k_state[NK_KEY_RIGHT]);
|
|
} else {
|
|
} else {
|
|
- nk_input_key(ctx, NK_KEY_LEFT,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_LEFT) == GLFW_PRESS);
|
|
|
|
- nk_input_key(ctx, NK_KEY_RIGHT,
|
|
|
|
- glfwGetKey(win, GLFW_KEY_RIGHT) == GLFW_PRESS);
|
|
|
|
|
|
+ if (k_state[NK_KEY_LEFT] >= 0) nk_input_key(ctx, NK_KEY_LEFT, k_state[NK_KEY_LEFT]);
|
|
|
|
+ if (k_state[NK_KEY_RIGHT] >= 0) nk_input_key(ctx, NK_KEY_RIGHT, k_state[NK_KEY_RIGHT]);
|
|
nk_input_key(ctx, NK_KEY_COPY, 0);
|
|
nk_input_key(ctx, NK_KEY_COPY, 0);
|
|
nk_input_key(ctx, NK_KEY_PASTE, 0);
|
|
nk_input_key(ctx, NK_KEY_PASTE, 0);
|
|
nk_input_key(ctx, NK_KEY_CUT, 0);
|
|
nk_input_key(ctx, NK_KEY_CUT, 0);
|
|
@@ -1352,6 +1339,10 @@ NK_API void nk_glfw3_new_frame(void) {
|
|
(int)glfw.double_click_pos.y, glfw.is_double_click_down);
|
|
(int)glfw.double_click_pos.y, glfw.is_double_click_down);
|
|
nk_input_scroll(ctx, glfw.scroll);
|
|
nk_input_scroll(ctx, glfw.scroll);
|
|
nk_input_end(&glfw.ctx);
|
|
nk_input_end(&glfw.ctx);
|
|
|
|
+
|
|
|
|
+ /* clear after nk_input_end (-1 since we're doing up/down boolean) */
|
|
|
|
+ memset(glfw.key_events, -1, sizeof(glfw.key_events));
|
|
|
|
+
|
|
glfw.text_len = 0;
|
|
glfw.text_len = 0;
|
|
glfw.scroll = nk_vec2(0, 0);
|
|
glfw.scroll = nk_vec2(0, 0);
|
|
}
|
|
}
|
|
@@ -1520,10 +1511,10 @@ VkSemaphore nk_glfw3_render(VkQueue graphics_queue, uint32_t buffer_index,
|
|
if (!cmd->elem_count)
|
|
if (!cmd->elem_count)
|
|
continue;
|
|
continue;
|
|
|
|
|
|
- scissor.offset.x = (int32_t)(NK_MAX(cmd->clip_rect.x, 0.f));
|
|
|
|
- scissor.offset.y = (int32_t)(NK_MAX(cmd->clip_rect.y, 0.f));
|
|
|
|
- scissor.extent.width = (uint32_t)(cmd->clip_rect.w);
|
|
|
|
- scissor.extent.height = (uint32_t)(cmd->clip_rect.h);
|
|
|
|
|
|
+ scissor.offset.x = (int32_t)(NK_MAX(cmd->clip_rect.x, 0.f) * glfw.fb_scale.x);
|
|
|
|
+ scissor.offset.y = (int32_t)(NK_MAX(cmd->clip_rect.y, 0.f) * glfw.fb_scale.y);
|
|
|
|
+ scissor.extent.width = (uint32_t)(cmd->clip_rect.w * glfw.fb_scale.x);
|
|
|
|
+ scissor.extent.height = (uint32_t)(cmd->clip_rect.h * glfw.fb_scale.y);
|
|
vkCmdSetScissor(command_buffer, 0, 1, &scissor);
|
|
vkCmdSetScissor(command_buffer, 0, 1, &scissor);
|
|
vkCmdDrawIndexed(command_buffer, cmd->elem_count, 1, index_offset,
|
|
vkCmdDrawIndexed(command_buffer, cmd->elem_count, 1, index_offset,
|
|
0, 0);
|
|
0, 0);
|
|
@@ -1566,6 +1557,56 @@ NK_API void nk_glfw3_char_callback(GLFWwindow *win, unsigned int codepoint) {
|
|
glfw.text[glfw.text_len++] = codepoint;
|
|
glfw.text[glfw.text_len++] = codepoint;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+NK_API void
|
|
|
|
+nk_glfw3_key_callback(GLFWwindow *win, int key, int scancode, int action, int mods)
|
|
|
|
+{
|
|
|
|
+ /*
|
|
|
|
+ * convert GLFW_REPEAT to down (technically GLFW_RELEASE, GLFW_PRESS, GLFW_REPEAT are
|
|
|
|
+ * already 0, 1, 2 but just to be clearer)
|
|
|
|
+ */
|
|
|
|
+ nk_char a = (action == GLFW_RELEASE) ? nk_false : nk_true;
|
|
|
|
+
|
|
|
|
+ NK_UNUSED(win);
|
|
|
|
+ NK_UNUSED(scancode);
|
|
|
|
+ NK_UNUSED(mods);
|
|
|
|
+
|
|
|
|
+ switch (key) {
|
|
|
|
+ case GLFW_KEY_DELETE: glfw.key_events[NK_KEY_DEL] = a; break;
|
|
|
|
+ case GLFW_KEY_TAB: glfw.key_events[NK_KEY_TAB] = a; break;
|
|
|
|
+ case GLFW_KEY_BACKSPACE: glfw.key_events[NK_KEY_BACKSPACE] = a; break;
|
|
|
|
+ case GLFW_KEY_UP: glfw.key_events[NK_KEY_UP] = a; break;
|
|
|
|
+ case GLFW_KEY_DOWN: glfw.key_events[NK_KEY_DOWN] = a; break;
|
|
|
|
+ case GLFW_KEY_LEFT: glfw.key_events[NK_KEY_LEFT] = a; break;
|
|
|
|
+ case GLFW_KEY_RIGHT: glfw.key_events[NK_KEY_RIGHT] = a; break;
|
|
|
|
+
|
|
|
|
+ case GLFW_KEY_PAGE_UP: glfw.key_events[NK_KEY_SCROLL_UP] = a; break;
|
|
|
|
+ case GLFW_KEY_PAGE_DOWN: glfw.key_events[NK_KEY_SCROLL_DOWN] = a; break;
|
|
|
|
+
|
|
|
|
+ /* have to add all keys used for nuklear to get correct repeat behavior
|
|
|
|
+ * NOTE these are scancodes so your custom layout won't matter unfortunately
|
|
|
|
+ * Also while including everything will prevent unnecessary input calls,
|
|
|
|
+ * only the ones with visible effects really matter, ie paste, undo, redo
|
|
|
|
+ * selecting all, copying or cutting 40 times before you release the keys
|
|
|
|
+ * doesn't actually cause any visible problems */
|
|
|
|
+
|
|
|
|
+ case GLFW_KEY_C: glfw.key_events[NK_KEY_COPY] = a; break;
|
|
|
|
+ case GLFW_KEY_V: glfw.key_events[NK_KEY_PASTE] = a; break;
|
|
|
|
+ case GLFW_KEY_X: glfw.key_events[NK_KEY_CUT] = a; break;
|
|
|
|
+ case GLFW_KEY_Z: glfw.key_events[NK_KEY_TEXT_UNDO] = a; break;
|
|
|
|
+ case GLFW_KEY_R: glfw.key_events[NK_KEY_TEXT_REDO] = a; break;
|
|
|
|
+ case GLFW_KEY_B: glfw.key_events[NK_KEY_TEXT_LINE_START] = a; break;
|
|
|
|
+ case GLFW_KEY_E: glfw.key_events[NK_KEY_TEXT_LINE_END] = a; break;
|
|
|
|
+ case GLFW_KEY_A: glfw.key_events[NK_KEY_TEXT_SELECT_ALL] = a; break;
|
|
|
|
+
|
|
|
|
+ case GLFW_KEY_ENTER:
|
|
|
|
+ case GLFW_KEY_KP_ENTER:
|
|
|
|
+ glfw.key_events[NK_KEY_ENTER] = a;
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ ;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
NK_API void nk_gflw3_scroll_callback(GLFWwindow *win, double xoff,
|
|
NK_API void nk_gflw3_scroll_callback(GLFWwindow *win, double xoff,
|
|
double yoff) {
|
|
double yoff) {
|
|
(void)win;
|
|
(void)win;
|
|
@@ -1627,6 +1668,7 @@ nk_glfw3_init(GLFWwindow *win, VkDevice logical_device,
|
|
if (init_state == NK_GLFW3_INSTALL_CALLBACKS) {
|
|
if (init_state == NK_GLFW3_INSTALL_CALLBACKS) {
|
|
glfwSetScrollCallback(win, nk_gflw3_scroll_callback);
|
|
glfwSetScrollCallback(win, nk_gflw3_scroll_callback);
|
|
glfwSetCharCallback(win, nk_glfw3_char_callback);
|
|
glfwSetCharCallback(win, nk_glfw3_char_callback);
|
|
|
|
+ glfwSetKeyCallback(win, nk_glfw3_key_callback);
|
|
glfwSetMouseButtonCallback(win, nk_glfw3_mouse_button_callback);
|
|
glfwSetMouseButtonCallback(win, nk_glfw3_mouse_button_callback);
|
|
}
|
|
}
|
|
nk_init_default(&glfw.ctx, 0);
|
|
nk_init_default(&glfw.ctx, 0);
|