diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-02-11 11:24:59 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-02-11 11:27:19 -0800 |
commit | 8a5ba3478c7ced2916a768a9071ef11815fb2773 (patch) | |
tree | 200cf58273a57ad05792b7aba2455ba823267c8b | |
parent | 5c53a8fe91f6e133337a6b2f3dcbf28eed86b234 (diff) |
refactor mouse wheel handling code to be shared across SDL, glfw, glut
-rw-r--r-- | src/library_browser.js | 4 | ||||
-rw-r--r-- | src/library_glfw.js | 8 | ||||
-rw-r--r-- | src/library_glut.js | 2 | ||||
-rw-r--r-- | src/library_sdl.js | 2 |
4 files changed, 7 insertions, 9 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index d6526d9c..50a8fc6f 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -446,6 +446,10 @@ mergeInto(LibraryManager.library, { 0; }, + getMouseWheelDelta: function(event) { + return Math.max(-1, Math.min(1, event.type === 'DOMMouseScroll' ? event.detail : -event.wheelDelta)); + }, + mouseX: 0, mouseY: 0, mouseMovementX: 0, diff --git a/src/library_glfw.js b/src/library_glfw.js index 17e8956a..b54205ad 100644 --- a/src/library_glfw.js +++ b/src/library_glfw.js @@ -197,13 +197,7 @@ var LibraryGLFW = { }, onMouseWheel: function(event) { - if (event.detail > 0) { - GLFW.wheelPos++; - } - - if (event.detail < 0) { - GLFW.wheelPos--; - } + GLFW.wheelPos += Browser.getMouseWheelDelta(event); if (GLFW.mouseWheelFunc && event.target == Module["canvas"]) { Runtime.dynCall('vi', GLFW.mouseWheelFunc, [GLFW.wheelPos]); diff --git a/src/library_glut.js b/src/library_glut.js index 65ac10c4..167e5272 100644 --- a/src/library_glut.js +++ b/src/library_glut.js @@ -229,7 +229,7 @@ var LibraryGLUT = { // cross-browser wheel delta var e = window.event || event; // old IE support - var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail))); + var delta = -Browser.getMouseWheelDelta(event); var button = 3; // wheel up if (delta < 0) { diff --git a/src/library_sdl.js b/src/library_sdl.js index 8c70ceee..0e82203c 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -411,7 +411,7 @@ var LibrarySDL = { } if (event.type == 'DOMMouseScroll' || event.type == 'mousewheel') { - var button = (event.type == 'DOMMouseScroll' ? event.detail : -event.wheelDelta) > 0 ? 4 : 3; + var button = Browser.getMouseWheelDelta(event) > 0 ? 4 : 3; var event2 = { type: 'mousedown', button: button, |