Added flags indicate if an event was used in demo
Demos for x11 and sdl have been update so that `nk_xxx_handle_event' return true (1) if the given event was usefull and processed by nuklear and false (1) if not.
This commit is contained in:
parent
648aca3a6a
commit
c4315eaf5b
@ -17,7 +17,7 @@
|
||||
NK_API struct nk_context* nk_sdl_init(SDL_Window *win);
|
||||
NK_API void nk_sdl_font_stash_begin(struct nk_font_atlas **atlas);
|
||||
NK_API void nk_sdl_font_stash_end(void);
|
||||
NK_API void nk_sdl_handle_event(SDL_Event *evt);
|
||||
NK_API int nk_sdl_handle_event(SDL_Event *evt);
|
||||
NK_API void nk_sdl_render(enum nk_anti_aliasing , int max_vertex_buffer, int max_element_buffer);
|
||||
NK_API void nk_sdl_shutdown(void);
|
||||
|
||||
@ -215,7 +215,7 @@ nk_sdl_font_stash_end(void)
|
||||
nk_style_set_font(&sdl.ctx, &sdl.atlas.default_font->handle);
|
||||
}
|
||||
|
||||
NK_API void
|
||||
NK_API int
|
||||
nk_sdl_handle_event(SDL_Event *evt)
|
||||
{
|
||||
struct nk_context *ctx = &sdl.ctx;
|
||||
@ -277,7 +277,8 @@ nk_sdl_handle_event(SDL_Event *evt)
|
||||
if (state[SDL_SCANCODE_LCTRL])
|
||||
nk_input_key(ctx, NK_KEY_TEXT_WORD_RIGHT, down);
|
||||
else nk_input_key(ctx, NK_KEY_RIGHT, down);
|
||||
}
|
||||
} else return 0;
|
||||
return 1;
|
||||
} else if (evt->type == SDL_MOUSEBUTTONDOWN || evt->type == SDL_MOUSEBUTTONUP) {
|
||||
/* mouse button */
|
||||
int down = evt->type == SDL_MOUSEBUTTONDOWN;
|
||||
@ -288,18 +289,24 @@ nk_sdl_handle_event(SDL_Event *evt)
|
||||
nk_input_button(ctx, NK_BUTTON_MIDDLE, x, y, down);
|
||||
if (evt->button.button == SDL_BUTTON_RIGHT)
|
||||
nk_input_button(ctx, NK_BUTTON_RIGHT, x, y, down);
|
||||
else return 0;
|
||||
return 1;
|
||||
} else if (evt->type == SDL_MOUSEMOTION) {
|
||||
if (ctx->input.mouse.grabbed) {
|
||||
int x = (int)ctx->input.mouse.prev.x, y = (int)ctx->input.mouse.prev.y;
|
||||
nk_input_motion(ctx, x + evt->motion.xrel, y + evt->motion.yrel);
|
||||
} else nk_input_motion(ctx, evt->motion.x, evt->motion.y);
|
||||
return 1;
|
||||
} else if (evt->type == SDL_TEXTINPUT) {
|
||||
nk_glyph glyph;
|
||||
memcpy(glyph, evt->text.text, NK_UTF_SIZE);
|
||||
nk_input_glyph(ctx, glyph);
|
||||
return 1;
|
||||
} else if (evt->type == SDL_MOUSEWHEEL) {
|
||||
nk_input_scroll(ctx,(float)evt->wheel.y);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NK_API
|
||||
|
@ -19,7 +19,7 @@
|
||||
NK_API struct nk_context* nk_sdl_init(SDL_Window *win);
|
||||
NK_API void nk_sdl_font_stash_begin(struct nk_font_atlas **atlas);
|
||||
NK_API void nk_sdl_font_stash_end(void);
|
||||
NK_API void nk_sdl_handle_event(SDL_Event *evt);
|
||||
NK_API int nk_sdl_handle_event(SDL_Event *evt);
|
||||
NK_API void nk_sdl_render(enum nk_anti_aliasing , int max_vertex_buffer, int max_element_buffer);
|
||||
NK_API void nk_sdl_shutdown(void);
|
||||
NK_API void nk_sdl_device_destroy(void);
|
||||
@ -326,7 +326,7 @@ nk_sdl_font_stash_end(void)
|
||||
|
||||
}
|
||||
|
||||
NK_API void
|
||||
NK_API int
|
||||
nk_sdl_handle_event(SDL_Event *evt)
|
||||
{
|
||||
struct nk_context *ctx = &sdl.ctx;
|
||||
@ -388,7 +388,8 @@ nk_sdl_handle_event(SDL_Event *evt)
|
||||
if (state[SDL_SCANCODE_LCTRL])
|
||||
nk_input_key(ctx, NK_KEY_TEXT_WORD_RIGHT, down);
|
||||
else nk_input_key(ctx, NK_KEY_RIGHT, down);
|
||||
}
|
||||
} else return 0;
|
||||
return 1;
|
||||
} else if (evt->type == SDL_MOUSEBUTTONDOWN || evt->type == SDL_MOUSEBUTTONUP) {
|
||||
/* mouse button */
|
||||
int down = evt->type == SDL_MOUSEBUTTONDOWN;
|
||||
@ -399,18 +400,23 @@ nk_sdl_handle_event(SDL_Event *evt)
|
||||
nk_input_button(ctx, NK_BUTTON_MIDDLE, x, y, down);
|
||||
if (evt->button.button == SDL_BUTTON_RIGHT)
|
||||
nk_input_button(ctx, NK_BUTTON_RIGHT, x, y, down);
|
||||
return 1;
|
||||
} else if (evt->type == SDL_MOUSEMOTION) {
|
||||
if (ctx->input.mouse.grabbed) {
|
||||
int x = (int)ctx->input.mouse.prev.x, y = (int)ctx->input.mouse.prev.y;
|
||||
nk_input_motion(ctx, x + evt->motion.xrel, y + evt->motion.yrel);
|
||||
} else nk_input_motion(ctx, evt->motion.x, evt->motion.y);
|
||||
return 1;
|
||||
} else if (evt->type == SDL_TEXTINPUT) {
|
||||
nk_glyph glyph;
|
||||
memcpy(glyph, evt->text.text, NK_UTF_SIZE);
|
||||
nk_input_glyph(ctx, glyph);
|
||||
return 1;
|
||||
} else if (evt->type == SDL_MOUSEWHEEL) {
|
||||
nk_input_scroll(ctx,(float)evt->wheel.y);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NK_API
|
||||
|
@ -20,7 +20,7 @@ NK_API XFont* nk_xfont_create(Display *dpy, const char *name);
|
||||
NK_API void nk_xfont_del(Display *dpy, XFont *font);
|
||||
|
||||
NK_API struct nk_context* nk_xlib_init(XFont *font, Display *dpy, int screen, Window root, unsigned int w, unsigned int h);
|
||||
NK_API void nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt);
|
||||
NK_API int nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt);
|
||||
NK_API void nk_xlib_render(Drawable screen, struct nk_color clear);
|
||||
NK_API void nk_xlib_shutdown(void);
|
||||
NK_API void nk_xlib_set_font(XFont *font);
|
||||
@ -482,7 +482,7 @@ nk_xlib_set_font(XFont *xfont)
|
||||
nk_style_set_font(&xlib.ctx, &font);
|
||||
}
|
||||
|
||||
NK_API void
|
||||
NK_API int
|
||||
nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt)
|
||||
{
|
||||
struct nk_context *ctx = &xlib.ctx;
|
||||
@ -554,6 +554,7 @@ nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt)
|
||||
}
|
||||
}
|
||||
XFree(code);
|
||||
return 1;
|
||||
} else if (evt->type == ButtonPress || evt->type == ButtonRelease) {
|
||||
/* Button handler */
|
||||
int down = (evt->type == ButtonPress);
|
||||
@ -568,7 +569,8 @@ nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt)
|
||||
nk_input_scroll(ctx, 1.0f);
|
||||
else if (evt->xbutton.button == Button5)
|
||||
nk_input_scroll(ctx, -1.0f);
|
||||
|
||||
else return 0;
|
||||
return 1;
|
||||
} else if (evt->type == MotionNotify) {
|
||||
/* Mouse motion handler */
|
||||
const int x = evt->xmotion.x, y = evt->xmotion.y;
|
||||
@ -578,6 +580,7 @@ nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt)
|
||||
ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;
|
||||
XWarpPointer(xlib.dpy, None, xlib.surf->root, 0, 0, 0, 0, (int)ctx->input.mouse.pos.x, (int)ctx->input.mouse.pos.y);
|
||||
}
|
||||
return 1;
|
||||
} else if (evt->type == Expose || evt->type == ConfigureNotify) {
|
||||
/* Window resize handler */
|
||||
unsigned int width, height;
|
||||
@ -586,8 +589,12 @@ nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt)
|
||||
width = (unsigned int)attr.width;
|
||||
height = (unsigned int)attr.height;
|
||||
nk_xsurf_resize(xlib.surf, width, height);
|
||||
} else if (evt->type == KeymapNotify)
|
||||
return 1;
|
||||
} else if (evt->type == KeymapNotify) {
|
||||
XRefreshKeyboardMapping(&evt->xmapping);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NK_API void
|
||||
|
@ -17,7 +17,7 @@
|
||||
NK_API struct nk_context* nk_x11_init(Display *dpy, Window win);
|
||||
NK_API void nk_x11_font_stash_begin(struct nk_font_atlas **atlas);
|
||||
NK_API void nk_x11_font_stash_end(void);
|
||||
NK_API void nk_x11_handle_event(XEvent *evt);
|
||||
NK_API int nk_x11_handle_event(XEvent *evt);
|
||||
NK_API void nk_x11_render(enum nk_anti_aliasing, int max_vertex_buffer, int max_element_buffer);
|
||||
NK_API void nk_x11_shutdown(void);
|
||||
|
||||
@ -199,7 +199,7 @@ nk_x11_font_stash_end(void)
|
||||
nk_style_set_font(&x11.ctx, &x11.atlas.default_font->handle);
|
||||
}
|
||||
|
||||
NK_API void
|
||||
NK_API int
|
||||
nk_x11_handle_event(XEvent *evt)
|
||||
{
|
||||
struct nk_context *ctx = &x11.ctx;
|
||||
@ -269,6 +269,7 @@ nk_x11_handle_event(XEvent *evt)
|
||||
}
|
||||
}
|
||||
XFree(code);
|
||||
return 1;
|
||||
} else if (evt->type == ButtonPress || evt->type == ButtonRelease) {
|
||||
/* Button handler */
|
||||
int down = (evt->type == ButtonPress);
|
||||
@ -283,7 +284,8 @@ nk_x11_handle_event(XEvent *evt)
|
||||
nk_input_scroll(ctx, 1.0f);
|
||||
else if (evt->xbutton.button == Button5)
|
||||
nk_input_scroll(ctx, -1.0f);
|
||||
|
||||
else return 0;
|
||||
return 1;
|
||||
} else if (evt->type == MotionNotify) {
|
||||
/* Mouse motion handler */
|
||||
const int x = evt->xmotion.x, y = evt->xmotion.y;
|
||||
@ -293,8 +295,12 @@ nk_x11_handle_event(XEvent *evt)
|
||||
ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;
|
||||
XWarpPointer(x11.dpy, None, x11.win, 0, 0, 0, 0, (int)ctx->input.mouse.pos.x, (int)ctx->input.mouse.pos.y);
|
||||
}
|
||||
} else if (evt->type == KeymapNotify)
|
||||
return 1;
|
||||
} else if (evt->type == KeymapNotify) {
|
||||
XRefreshKeyboardMapping(&evt->xmapping);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NK_API struct nk_context*
|
||||
|
@ -17,7 +17,7 @@
|
||||
NK_API struct nk_context* nk_x11_init(Display *dpy, Window win);
|
||||
NK_API void nk_x11_font_stash_begin(struct nk_font_atlas **atlas);
|
||||
NK_API void nk_x11_font_stash_end(void);
|
||||
NK_API void nk_x11_handle_event(XEvent *evt);
|
||||
NK_API int nk_x11_handle_event(XEvent *evt);
|
||||
NK_API void nk_x11_render(enum nk_anti_aliasing, int max_vertex_buffer, int max_element_buffer);
|
||||
NK_API void nk_x11_shutdown(void);
|
||||
NK_API int nk_x11_device_create(void);
|
||||
@ -569,7 +569,7 @@ nk_x11_font_stash_end(void)
|
||||
nk_style_set_font(&x11.ctx, &x11.atlas.default_font->handle);
|
||||
}
|
||||
|
||||
NK_API void
|
||||
NK_API int
|
||||
nk_x11_handle_event(XEvent *evt)
|
||||
{
|
||||
struct nk_context *ctx = &x11.ctx;
|
||||
@ -580,7 +580,7 @@ nk_x11_handle_event(XEvent *evt)
|
||||
ctx->input.mouse.grab = 0;
|
||||
} else if (ctx->input.mouse.ungrab) {
|
||||
XWarpPointer(x11.dpy, None, x11.win, 0, 0, 0, 0,
|
||||
(int)ctx->input.mouse.prev.x, (int)ctx->input.mouse.prev.y);
|
||||
(int)ctx->input.mouse.pos.x, (int)ctx->input.mouse.pos.y);
|
||||
XUndefineCursor(x11.dpy, x11.win);
|
||||
ctx->input.mouse.ungrab = 0;
|
||||
}
|
||||
@ -639,6 +639,7 @@ nk_x11_handle_event(XEvent *evt)
|
||||
}
|
||||
}
|
||||
XFree(code);
|
||||
return 1;
|
||||
} else if (evt->type == ButtonPress || evt->type == ButtonRelease) {
|
||||
/* Button handler */
|
||||
int down = (evt->type == ButtonPress);
|
||||
@ -653,7 +654,8 @@ nk_x11_handle_event(XEvent *evt)
|
||||
nk_input_scroll(ctx, 1.0f);
|
||||
else if (evt->xbutton.button == Button5)
|
||||
nk_input_scroll(ctx, -1.0f);
|
||||
|
||||
else return 0;
|
||||
return 1;
|
||||
} else if (evt->type == MotionNotify) {
|
||||
/* Mouse motion handler */
|
||||
const int x = evt->xmotion.x, y = evt->xmotion.y;
|
||||
@ -663,8 +665,12 @@ nk_x11_handle_event(XEvent *evt)
|
||||
ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;
|
||||
XWarpPointer(x11.dpy, None, x11.win, 0, 0, 0, 0, (int)ctx->input.mouse.pos.x, (int)ctx->input.mouse.pos.y);
|
||||
}
|
||||
} else if (evt->type == KeymapNotify)
|
||||
return 1;
|
||||
} else if (evt->type == KeymapNotify) {
|
||||
XRefreshKeyboardMapping(&evt->xmapping);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NK_API struct nk_context*
|
||||
|
Loading…
Reference in New Issue
Block a user