Skip to content

Commit

Permalink
Added horizontal scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
vurtun committed Mar 21, 2017
1 parent a979372 commit 23eea23
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 90 deletions.
15 changes: 5 additions & 10 deletions demo/allegro5/nuklear_allegro5.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,16 @@ static float
nk_allegro5_font_get_text_width(nk_handle handle, float height, const char *text, int len)
{
NkAllegro5Font *font = (NkAllegro5Font*)handle.ptr;

if (!font || !text) {
return 0;
}

/* We must copy into a new buffer with exact length null-terminated
as nuklear uses variable size buffers and al_get_text_width doesn't
accept a length, it infers length from null-termination
(which is unsafe API design by allegro devs!) */
char strcpy[len+1];
strncpy((char*)&strcpy, text, len);
strcpy[len] = '\0';

return al_get_text_width(font->font, strcpy);
}

Expand Down Expand Up @@ -289,7 +286,7 @@ nk_allegro5_handle_event(ALLEGRO_EVENT *ev)
case ALLEGRO_EVENT_MOUSE_AXES: {
nk_input_motion(ctx, ev->mouse.x, ev->mouse.y);
if (ev->mouse.dz != 0) {
nk_input_scroll(ctx, (float)ev->mouse.dz / al_get_mouse_wheel_precision());
nk_input_scroll(ctx, nk_vec2(0,(float)ev->mouse.dz / al_get_mouse_wheel_precision()));
}
} break;
case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
Expand Down Expand Up @@ -342,7 +339,7 @@ nk_allegro5_handle_event(ALLEGRO_EVENT *ev)
case ALLEGRO_EVENT_KEY_UP: {
int kc = ev->keyboard.keycode;
int down = ev->type == ALLEGRO_EVENT_KEY_DOWN;

if (kc == ALLEGRO_KEY_LSHIFT || kc == ALLEGRO_KEY_RSHIFT) nk_input_key(ctx, NK_KEY_SHIFT, down);
else if (kc == ALLEGRO_KEY_DELETE) nk_input_key(ctx, NK_KEY_DEL, down);
else if (kc == ALLEGRO_KEY_ENTER) nk_input_key(ctx, NK_KEY_ENTER, down);
Expand All @@ -367,7 +364,7 @@ nk_allegro5_handle_event(ALLEGRO_EVENT *ev)
int kc = ev->keyboard.keycode;
int control_mask = (ev->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL) ||
(ev->keyboard.modifiers & ALLEGRO_KEYMOD_COMMAND);

if (kc == ALLEGRO_KEY_C && control_mask) {
nk_input_key(ctx, NK_KEY_COPY, 1);
} else if (kc == ALLEGRO_KEY_V && control_mask) {
Expand All @@ -380,9 +377,7 @@ nk_allegro5_handle_event(ALLEGRO_EVENT *ev)
nk_input_key(ctx, NK_KEY_TEXT_REDO, 1);
} else if (kc == ALLEGRO_KEY_A && control_mask) {
nk_input_key(ctx, NK_KEY_TEXT_SELECT_ALL, 1);
}
else {

} else {
if (kc != ALLEGRO_KEY_BACKSPACE &&
kc != ALLEGRO_KEY_LEFT &&
kc != ALLEGRO_KEY_RIGHT &&
Expand All @@ -398,7 +393,6 @@ nk_allegro5_handle_event(ALLEGRO_EVENT *ev)
nk_input_unicode(ctx, ev->keyboard.unichar);
}
}

} break;
default: break;
}
Expand Down Expand Up @@ -462,3 +456,4 @@ void nk_allegro5_shutdown(void)
}

#endif /* NK_ALLEGRO5_IMPLEMENTATION */

2 changes: 1 addition & 1 deletion demo/d3d11/nuklear_d3d11.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ nk_d3d11_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
return 1;

case WM_MOUSEWHEEL:
nk_input_scroll(&d3d11.ctx, (float)(short)HIWORD(wparam) / WHEEL_DELTA);
nk_input_scroll(&d3d11.ctx, nk_vec2(0,(float)(short)HIWORD(wparam) / WHEEL_DELTA));
return 1;

case WM_MOUSEMOVE:
Expand Down
2 changes: 1 addition & 1 deletion demo/gdi/nuklear_gdi.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ nk_gdi_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
return 1;

case WM_MOUSEWHEEL:
nk_input_scroll(&gdi.ctx, (float)(short)HIWORD(wparam) / WHEEL_DELTA);
nk_input_scroll(&gdi.ctx, nk_vec2(0,(float)(short)HIWORD(wparam) / WHEEL_DELTA));
return 1;

case WM_MOUSEMOVE:
Expand Down
2 changes: 1 addition & 1 deletion demo/gdip/nuklear_gdip.h
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ nk_gdip_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
return 1;

case WM_MOUSEWHEEL:
nk_input_scroll(&gdip.ctx, (float)(short)HIWORD(wparam) / WHEEL_DELTA);
nk_input_scroll(&gdip.ctx, nk_vec2(0,(float)(short)HIWORD(wparam) / WHEEL_DELTA));
return 1;

case WM_MOUSEMOVE:
Expand Down
7 changes: 4 additions & 3 deletions demo/glfw_opengl2/nuklear_glfw_gl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static struct nk_glfw {
struct nk_vec2 fb_scale;
unsigned int text[NK_GLFW_TEXT_MAX];
int text_len;
float scroll;
struct nk_vec2 scroll;
} glfw;

NK_INTERN void
Expand Down Expand Up @@ -200,7 +200,8 @@ NK_API void
nk_gflw3_scroll_callback(GLFWwindow *win, double xoff, double yoff)
{
(void)win; (void)xoff;
glfw.scroll += (float)yoff;
glfw.scroll.x += (float)xoff;
glfw.scroll.y += (float)yoff;
}

NK_INTERN void
Expand Down Expand Up @@ -333,7 +334,7 @@ nk_glfw3_new_frame(void)
nk_input_scroll(ctx, glfw.scroll);
nk_input_end(&glfw.ctx);
glfw.text_len = 0;
glfw.scroll = 0;
glfw.scroll = nk_vec2(0,0);
}

NK_API
Expand Down
7 changes: 4 additions & 3 deletions demo/glfw_opengl3/nuklear_glfw_gl3.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static struct nk_glfw {
struct nk_vec2 fb_scale;
unsigned int text[NK_GLFW_TEXT_MAX];
int text_len;
float scroll;
struct nk_vec2 scroll;
} glfw;

#ifdef __APPLE__
Expand Down Expand Up @@ -308,7 +308,8 @@ NK_API void
nk_gflw3_scroll_callback(GLFWwindow *win, double xoff, double yoff)
{
(void)win; (void)xoff;
glfw.scroll += (float)yoff;
glfw.scroll.x += (float)xoff;
glfw.scroll.y += (float)yoff;
}

NK_INTERN void
Expand Down Expand Up @@ -441,7 +442,7 @@ nk_glfw3_new_frame(void)
nk_input_scroll(ctx, glfw.scroll);
nk_input_end(&glfw.ctx);
glfw.text_len = 0;
glfw.scroll = 0;
glfw.scroll = nk_vec2(0,0);
}

NK_API
Expand Down
2 changes: 1 addition & 1 deletion demo/sdl_opengl2/nuklear_sdl_gl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ nk_sdl_handle_event(SDL_Event *evt)
nk_input_glyph(ctx, glyph);
return 1;
} else if (evt->type == SDL_MOUSEWHEEL) {
nk_input_scroll(ctx,(float)evt->wheel.y);
nk_input_scroll(ctx,nk_vec2((float)evt->wheel.x,(float)evt->wheel.y));
return 1;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion demo/sdl_opengl3/nuklear_sdl_gl3.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ nk_sdl_handle_event(SDL_Event *evt)
nk_input_glyph(ctx, glyph);
return 1;
} else if (evt->type == SDL_MOUSEWHEEL) {
nk_input_scroll(ctx,(float)evt->wheel.y);
nk_input_scroll(ctx,nk_vec2((float)evt->wheel.x,(float)evt->wheel.y));
return 1;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion demo/sfml_opengl2/nuklear_sfml_gl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ nk_sfml_handle_event(sf::Event* evt)
nk_input_unicode(ctx, evt->text.unicode);
return 1;
} else if(evt->type == sf::Event::MouseWheelScrolled) {
nk_input_scroll(ctx, evt->mouseWheelScroll.delta);
nk_input_scroll(ctx, nk_vec2(0,evt->mouseWheelScroll.delta));
return 1;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion demo/sfml_opengl3/nuklear_sfml_gl3.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ nk_sfml_handle_event(sf::Event* evt)
nk_input_unicode(ctx, evt->text.unicode);
return 1;
} else if(evt->type == sf::Event::MouseWheelScrolled) {
nk_input_scroll(ctx, evt->mouseWheelScroll.delta);
nk_input_scroll(ctx, nk_vec2(0,evt->mouseWheelScroll.delta));
return 1;
}
return 0;
Expand Down
4 changes: 2 additions & 2 deletions demo/x11/nuklear_xlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,9 @@ nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt)
else if (evt->xbutton.button == Button3)
nk_input_button(ctx, NK_BUTTON_RIGHT, x, y, down);
else if (evt->xbutton.button == Button4)
nk_input_scroll(ctx, 1.0f);
nk_input_scroll(ctx, nk_vec2(0, 1.0f));
else if (evt->xbutton.button == Button5)
nk_input_scroll(ctx, -1.0f);
nk_input_scroll(ctx, nk_vec2(0, -1.0f));
else return 0;
return 1;
} else if (evt->type == MotionNotify) {
Expand Down
4 changes: 2 additions & 2 deletions demo/x11_opengl2/nuklear_xlib_gl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ nk_x11_handle_event(XEvent *evt)
else if (evt->xbutton.button == Button3)
nk_input_button(ctx, NK_BUTTON_RIGHT, x, y, down);
else if (evt->xbutton.button == Button4)
nk_input_scroll(ctx, 1.0f);
nk_input_scroll(ctx, nk_vec2(0,1.0f));
else if (evt->xbutton.button == Button5)
nk_input_scroll(ctx, -1.0f);
nk_input_scroll(ctx, nk_vec2(0,-1.0f));
else return 0;
return 1;
} else if (evt->type == MotionNotify) {
Expand Down
4 changes: 2 additions & 2 deletions demo/x11_opengl3/nuklear_xlib_gl3.h
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,9 @@ nk_x11_handle_event(XEvent *evt)
else if (evt->xbutton.button == Button3)
nk_input_button(ctx, NK_BUTTON_RIGHT, x, y, down);
else if (evt->xbutton.button == Button4)
nk_input_scroll(ctx, 1.0f);
nk_input_scroll(ctx, nk_vec2(0,1.0f));
else if (evt->xbutton.button == Button5)
nk_input_scroll(ctx, -1.0f);
nk_input_scroll(ctx, nk_vec2(0,-1.0f));
else return 0;
return 1;
} else if (evt->type == MotionNotify) {
Expand Down
Loading

0 comments on commit 23eea23

Please sign in to comment.