xlib_gl2: add delta_time_seconds
This commit is contained in:
parent
42b9ea7943
commit
c3fe64a487
|
@ -46,10 +46,10 @@ NK_API void nk_x11_shutdown(void);
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
|
||||||
#ifndef NK_X11_DOUBLE_CLICK_LO
|
#ifndef NK_X11_DOUBLE_CLICK_LO
|
||||||
#define NK_X11_DOUBLE_CLICK_LO 20
|
#define NK_X11_DOUBLE_CLICK_LO 0.02
|
||||||
#endif
|
#endif
|
||||||
#ifndef NK_X11_DOUBLE_CLICK_HI
|
#ifndef NK_X11_DOUBLE_CLICK_HI
|
||||||
#define NK_X11_DOUBLE_CLICK_HI 200
|
#define NK_X11_DOUBLE_CLICK_HI 0.20
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct nk_x11_vertex {
|
struct nk_x11_vertex {
|
||||||
|
@ -71,15 +71,16 @@ static struct nk_x11 {
|
||||||
Cursor cursor;
|
Cursor cursor;
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
Window win;
|
Window win;
|
||||||
long last_button_click;
|
double last_button_click;
|
||||||
|
double time_of_last_frame;
|
||||||
} x11;
|
} x11;
|
||||||
|
|
||||||
NK_INTERN long
|
NK_INTERN double
|
||||||
nk_timestamp(void)
|
nk_get_time(void)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
if (gettimeofday(&tv, NULL) < 0) return 0;
|
if (gettimeofday(&tv, NULL) < 0) return 0;
|
||||||
return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000);
|
return ((double)tv.tv_sec + (double)tv.tv_usec/1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
NK_INTERN void
|
NK_INTERN void
|
||||||
|
@ -102,6 +103,10 @@ nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
|
||||||
int width, height;
|
int width, height;
|
||||||
XWindowAttributes attr;
|
XWindowAttributes attr;
|
||||||
|
|
||||||
|
double now = nk_get_time();
|
||||||
|
x11.ctx.delta_time_seconds = now - x11.time_of_last_frame;
|
||||||
|
x11.time_of_last_frame = now;
|
||||||
|
|
||||||
NK_UNUSED(max_vertex_buffer);
|
NK_UNUSED(max_vertex_buffer);
|
||||||
NK_UNUSED(max_element_buffer);
|
NK_UNUSED(max_element_buffer);
|
||||||
|
|
||||||
|
@ -311,10 +316,10 @@ nk_x11_handle_event(XEvent *evt)
|
||||||
const int x = evt->xbutton.x, y = evt->xbutton.y;
|
const int x = evt->xbutton.x, y = evt->xbutton.y;
|
||||||
if (evt->xbutton.button == Button1) {
|
if (evt->xbutton.button == Button1) {
|
||||||
if (down) { /* Double-Click Button handler */
|
if (down) { /* Double-Click Button handler */
|
||||||
long dt = nk_timestamp() - x11.last_button_click;
|
float dt = nk_get_time() - x11.last_button_click;
|
||||||
if (dt > NK_X11_DOUBLE_CLICK_LO && dt < NK_X11_DOUBLE_CLICK_HI)
|
if (dt > NK_X11_DOUBLE_CLICK_LO && dt < NK_X11_DOUBLE_CLICK_HI)
|
||||||
nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_true);
|
nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_true);
|
||||||
x11.last_button_click = nk_timestamp();
|
x11.last_button_click = nk_get_time();
|
||||||
} else nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_false);
|
} else nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_false);
|
||||||
nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
|
nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
|
||||||
} else if (evt->xbutton.button == Button2)
|
} else if (evt->xbutton.button == Button2)
|
||||||
|
@ -363,6 +368,7 @@ nk_x11_init(Display *dpy, Window win)
|
||||||
|
|
||||||
nk_buffer_init_default(&x11.ogl.cmds);
|
nk_buffer_init_default(&x11.ogl.cmds);
|
||||||
nk_init_default(&x11.ctx, 0);
|
nk_init_default(&x11.ctx, 0);
|
||||||
|
x11.time_of_last_frame = nk_get_time();
|
||||||
return &x11.ctx;
|
return &x11.ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue