diff options
author | David Robillard <d@drobilla.net> | 2012-04-29 18:10:46 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-04-29 18:10:46 +0000 |
commit | d9732fbc106a6ac228912078888fbac65e78d26d (patch) | |
tree | d0b8c8f11c7cdcf8d117f853d680e4fa706d2a99 | |
parent | d4b2829de83ca5f0efd3d1ee2683ee400e63ffe2 (diff) |
Scroll support on Windows.
-rw-r--r-- | pugl/pugl.h | 2 | ||||
-rw-r--r-- | pugl/pugl_win.cpp | 16 | ||||
-rw-r--r-- | pugl/pugl_x11.c | 10 | ||||
-rw-r--r-- | pugl_test.c | 4 |
4 files changed, 24 insertions, 8 deletions
diff --git a/pugl/pugl.h b/pugl/pugl.h index f173525..e5021f3 100644 --- a/pugl/pugl.h +++ b/pugl/pugl.h @@ -55,7 +55,7 @@ typedef void (*PuglMouseFunc)(PuglWindow* handle, int button, bool down, int x, int y); typedef void (*PuglReshapeFunc)(PuglWindow* handle, int width, int height); -typedef void (*PuglScrollFunc)(PuglWindow* handle, int dx, int dy); +typedef void (*PuglScrollFunc)(PuglWindow* handle, float dx, float dy); /** Create a new GL window. diff --git a/pugl/pugl_win.cpp b/pugl/pugl_win.cpp index 5441409..a3354bf 100644 --- a/pugl/pugl_win.cpp +++ b/pugl/pugl_win.cpp @@ -39,6 +39,10 @@ wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) return 0; case WM_DESTROY: return 0; + case WM_MOUSEWHEEL: + case WM_MOUSEHWHEEL: + PostMessage(hwnd, message, wParam, lParam); + return 0; default: return DefWindowProc(hwnd, message, wParam, lParam); } @@ -201,6 +205,18 @@ puglProcessEvents(PuglWindow* win) case WM_RBUTTONUP: processMouseEvent(win, 3, false, msg.lParam); break; + case WM_MOUSEWHEEL: + if (win->scrollFunc) { + win->scrollFunc( + win, 0, (int16_t)HIWORD(msg.wParam) / (float)WHEEL_DELTA); + } + break; + case WM_MOUSEHWHEEL: + if (win->scrollFunc) { + win->scrollFunc( + win, (int16_t)HIWORD(msg.wParam) / float(WHEEL_DELTA), 0); + } + break; case WM_KEYDOWN: case WM_KEYUP: if (win->keyboardFunc) { diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index 735cdb1..c6cc2b5 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -240,12 +240,12 @@ puglProcessEvents(PuglWindow* win) case ButtonPress: if (event.xbutton.button >= 4 && event.xbutton.button <= 7) { if (win->scrollFunc) { - int dx = 0, dy = 0; + float dx = 0, dy = 0; switch (event.xbutton.button) { - case 4: dy = 1; break; - case 5: dy = -1; break; - case 6: dx = -1; break; - case 7: dx = 1; break; + case 4: dy = 1.0f; break; + case 5: dy = -1.0f; break; + case 6: dx = -1.0f; break; + case 7: dx = 1.0f; break; } win->scrollFunc(win, dx, dy); } diff --git a/pugl_test.c b/pugl_test.c index 57b9e5e..05efa61 100644 --- a/pugl_test.c +++ b/pugl_test.c @@ -110,9 +110,9 @@ onMouse(PuglWindow* win, int button, bool press, int x, int y) } static void -onScroll(PuglWindow* win, int dx, int dy) +onScroll(PuglWindow* win, float dx, float dy) { - fprintf(stderr, "Scroll %d %d\n", dx, dy); + fprintf(stderr, "Scroll %f %f\n", dx, dy); dist += dy / 4.0f; puglPostRedisplay(win); } |