diff --git a/demo/allegro5/nuklear_allegro5.h b/demo/allegro5/nuklear_allegro5.h index 0e72f16..239f7c1 100644 --- a/demo/allegro5/nuklear_allegro5.h +++ b/demo/allegro5/nuklear_allegro5.h @@ -66,6 +66,7 @@ static struct nk_allegro5 { int touch_down_id; struct nk_context ctx; struct nk_buffer cmds; + float delta_time_seconds_last; } allegro5; @@ -177,6 +178,11 @@ nk_allegro5_render() { const struct nk_command *cmd; + /* Update the timer */ + float now = (float)al_get_time(); + allegro5.ctx.delta_time_seconds = now - allegro5.delta_time_seconds_last; + allegro5.delta_time_seconds_last = now; + al_set_target_backbuffer(allegro5.dsp); nk_foreach(cmd, &allegro5.ctx) @@ -498,6 +504,7 @@ nk_allegro5_init(NkAllegro5Font *allegro5font, ALLEGRO_DISPLAY *dsp, allegro5.height = height; allegro5.is_touch_down = 0; allegro5.touch_down_id = -1; + allegro5.delta_time_seconds_last = (float)al_get_time(); nk_init_default(&allegro5.ctx, font); allegro5.ctx.clip.copy = nk_allegro5_clipboard_copy; diff --git a/demo/common/overview.c b/demo/common/overview.c index 056f97a..5ce339f 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -3,11 +3,11 @@ overview(struct nk_context *ctx) { /* window flags */ static nk_bool show_menu = nk_true; - static nk_flags window_flags = NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_SCALABLE|NK_WINDOW_MOVABLE|NK_WINDOW_MINIMIZABLE; + static nk_flags window_flags = NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_SCALABLE|NK_WINDOW_MOVABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_SCROLL_AUTO_HIDE; nk_flags actual_window_flags = 0; /* widget flags */ - static nk_bool disable_widgets = nk_false; + static nk_bool disable_widgets = nk_false; /* popups */ static enum nk_style_header_align header_align = NK_HEADER_RIGHT; diff --git a/demo/glfw_opengl2/nuklear_glfw_gl2.h b/demo/glfw_opengl2/nuklear_glfw_gl2.h index 8412ae4..1d03b56 100644 --- a/demo/glfw_opengl2/nuklear_glfw_gl2.h +++ b/demo/glfw_opengl2/nuklear_glfw_gl2.h @@ -79,6 +79,7 @@ static struct nk_glfw { double last_button_click; int is_double_click_down; struct nk_vec2 double_click_pos; + float delta_time_seconds_last; } glfw; NK_INTERN void @@ -273,6 +274,8 @@ nk_glfw3_init(GLFWwindow *win, enum nk_glfw_init_state init_state) glfw.is_double_click_down = nk_false; glfw.double_click_pos = nk_vec2(0, 0); + glfw.delta_time_seconds_last = (float)glfwGetTime(); + return &glfw.ctx; } @@ -303,6 +306,11 @@ nk_glfw3_new_frame(void) struct nk_context *ctx = &glfw.ctx; struct GLFWwindow *win = glfw.win; + /* update the timer */ + float delta_time_now = (float)glfwGetTime(); + glfw.ctx.delta_time_seconds = delta_time_now - glfw.delta_time_seconds_last; + 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; diff --git a/demo/glfw_opengl3/nuklear_glfw_gl3.h b/demo/glfw_opengl3/nuklear_glfw_gl3.h index a0cba70..41678db 100644 --- a/demo/glfw_opengl3/nuklear_glfw_gl3.h +++ b/demo/glfw_opengl3/nuklear_glfw_gl3.h @@ -53,6 +53,7 @@ struct nk_glfw { double last_button_click; int is_double_click_down; struct nk_vec2 double_click_pos; + float delta_time_seconds_last; }; NK_API struct nk_context* nk_glfw3_init(struct nk_glfw* glfw, GLFWwindow *win, enum nk_glfw_init_state); @@ -389,6 +390,8 @@ nk_glfw3_init(struct nk_glfw* glfw, GLFWwindow *win, enum nk_glfw_init_state ini glfw->is_double_click_down = nk_false; glfw->double_click_pos = nk_vec2(0, 0); + glfw->delta_time_seconds_last = (float)glfwGetTime(); + return &glfw->ctx; } @@ -419,6 +422,11 @@ nk_glfw3_new_frame(struct nk_glfw* glfw) struct nk_context *ctx = &glfw->ctx; struct GLFWwindow *win = glfw->win; + /* update the timer */ + float delta_time_now = (float)glfwGetTime(); + glfw->ctx.delta_time_seconds = delta_time_now - glfw->delta_time_seconds_last; + 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; diff --git a/demo/glfw_vulkan/nuklear_glfw_vulkan.h b/demo/glfw_vulkan/nuklear_glfw_vulkan.h index 371a174..8189f8d 100644 --- a/demo/glfw_vulkan/nuklear_glfw_vulkan.h +++ b/demo/glfw_vulkan/nuklear_glfw_vulkan.h @@ -379,6 +379,7 @@ static struct nk_glfw { double last_button_click; int is_double_click_down; struct nk_vec2 double_click_pos; + float delta_time_seconds_last; } glfw; struct Mat4f { @@ -1254,6 +1255,11 @@ NK_API void nk_glfw3_new_frame(void) { struct nk_context *ctx = &glfw.ctx; struct GLFWwindow *win = glfw.win; + /* update the timer */ + float delta_time_now = (float)glfwGetTime(); + glfw.ctx.delta_time_seconds = delta_time_now - glfw.delta_time_seconds_last; + glfw.delta_time_seconds_last = delta_time_now; + nk_input_begin(ctx); for (i = 0; i < glfw.text_len; ++i) nk_input_unicode(ctx, glfw.text[i]); diff --git a/demo/rawfb/nuklear_rawfb.h b/demo/rawfb/nuklear_rawfb.h index cc1fe8c..f1bbab9 100644 --- a/demo/rawfb/nuklear_rawfb.h +++ b/demo/rawfb/nuklear_rawfb.h @@ -1033,6 +1033,7 @@ nk_rawfb_render(const struct rawfb_context *rawfb, const unsigned char enable_clear) { const struct nk_command *cmd; + if (enable_clear) nk_rawfb_clear(rawfb, clear); diff --git a/demo/sdl_opengl2/nuklear_sdl_gl2.h b/demo/sdl_opengl2/nuklear_sdl_gl2.h index 623ef06..9911058 100644 --- a/demo/sdl_opengl2/nuklear_sdl_gl2.h +++ b/demo/sdl_opengl2/nuklear_sdl_gl2.h @@ -51,7 +51,7 @@ static struct nk_sdl { struct nk_sdl_device ogl; struct nk_context ctx; struct nk_font_atlas atlas; - float time_of_last_frame; + Uint64 time_of_last_frame; } sdl; NK_INTERN void @@ -75,8 +75,8 @@ nk_sdl_render(enum nk_anti_aliasing AA) int display_width, display_height; struct nk_vec2 scale; - float now = ((float)SDL_GetTicks64()) / 1000; - sdl.ctx.delta_time_seconds = now - sdl.time_of_last_frame; + Uint64 now = SDL_GetTicks64(); + sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000; sdl.time_of_last_frame = now; SDL_GetWindowSize(sdl.win, &width, &height); @@ -217,7 +217,7 @@ nk_sdl_init(SDL_Window *win) sdl.ctx.clip.paste = nk_sdl_clipboard_paste; sdl.ctx.clip.userdata = nk_handle_ptr(0); nk_buffer_init_default(&sdl.ogl.cmds); - sdl.time_of_last_frame = ((float)SDL_GetTicks64()) / 1000; + sdl.time_of_last_frame = SDL_GetTicks64(); return &sdl.ctx; } diff --git a/demo/sdl_opengl3/nuklear_sdl_gl3.h b/demo/sdl_opengl3/nuklear_sdl_gl3.h index b0ee35d..e5fda41 100644 --- a/demo/sdl_opengl3/nuklear_sdl_gl3.h +++ b/demo/sdl_opengl3/nuklear_sdl_gl3.h @@ -67,7 +67,7 @@ static struct nk_sdl { struct nk_sdl_device ogl; struct nk_context ctx; struct nk_font_atlas atlas; - float time_of_last_frame; + Uint64 time_of_last_frame; } sdl; #ifdef __APPLE__ @@ -199,8 +199,8 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b { -1.0f, 1.0f, 0.0f, 1.0f }, }; - float now = ((float)SDL_GetTicks64()) / 1000; - sdl.ctx.delta_time_seconds = now - sdl.time_of_last_frame; + Uint64 now = SDL_GetTicks64(); + sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000; sdl.time_of_last_frame = now; SDL_GetWindowSize(sdl.win, &width, &height); @@ -326,7 +326,7 @@ nk_sdl_init(SDL_Window *win) sdl.ctx.clip.paste = nk_sdl_clipboard_paste; sdl.ctx.clip.userdata = nk_handle_ptr(0); nk_sdl_device_create(); - sdl.time_of_last_frame = ((float)SDL_GetTicks64()) / 1000; + sdl.time_of_last_frame = SDL_GetTicks64(); return &sdl.ctx; } diff --git a/demo/sdl_opengles2/nuklear_sdl_gles2.h b/demo/sdl_opengles2/nuklear_sdl_gles2.h index 75acd0d..b146023 100644 --- a/demo/sdl_opengles2/nuklear_sdl_gles2.h +++ b/demo/sdl_opengles2/nuklear_sdl_gles2.h @@ -71,7 +71,7 @@ static struct nk_sdl { struct nk_sdl_device ogl; struct nk_context ctx; struct nk_font_atlas atlas; - float time_of_last_frame; + Uint64 time_of_last_frame; } sdl; @@ -187,8 +187,8 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b { -1.0f, 1.0f, 0.0f, 1.0f }, }; - float now = ((float)SDL_GetTicks64()) / 1000; - sdl.ctx.delta_time_seconds = now - sdl.time_of_last_frame; + Uint64 now = SDL_GetTicks64(); + sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000; sdl.time_of_last_frame = now; SDL_GetWindowSize(sdl.win, &width, &height); @@ -326,7 +326,7 @@ nk_sdl_init(SDL_Window *win) sdl.ctx.clip.paste = nk_sdl_clipboard_paste; sdl.ctx.clip.userdata = nk_handle_ptr(0); nk_sdl_device_create(); - sdl.time_of_last_frame = ((float)SDL_GetTicks64()) / 1000; + sdl.time_of_last_frame = SDL_GetTicks64(); return &sdl.ctx; } diff --git a/demo/sdl_renderer/nuklear_sdl_renderer.h b/demo/sdl_renderer/nuklear_sdl_renderer.h index a8990c6..064549b 100644 --- a/demo/sdl_renderer/nuklear_sdl_renderer.h +++ b/demo/sdl_renderer/nuklear_sdl_renderer.h @@ -64,10 +64,9 @@ static struct nk_sdl { struct nk_sdl_device ogl; struct nk_context ctx; struct nk_font_atlas atlas; + Uint64 time_of_last_frame; } sdl; - - NK_INTERN void nk_sdl_device_upload_atlas(const void *image, int width, int height) { @@ -113,6 +112,11 @@ nk_sdl_render(enum nk_anti_aliasing AA) {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_sdl_vertex, col)}, {NK_VERTEX_LAYOUT_END} }; + + Uint64 now = SDL_GetTicks64(); + sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000; + sdl.time_of_last_frame = now; + NK_MEMSET(&config, 0, sizeof(config)); config.vertex_layout = vertex_layout; config.vertex_size = sizeof(struct nk_sdl_vertex); @@ -241,6 +245,7 @@ nk_sdl_init(SDL_Window *win, SDL_Renderer *renderer) #endif sdl.win = win; sdl.renderer = renderer; + sdl.time_of_last_frame = SDL_GetTicks64(); nk_init_default(&sdl.ctx, 0); sdl.ctx.clip.copy = nk_sdl_clipboard_copy; sdl.ctx.clip.paste = nk_sdl_clipboard_paste;