diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-05-13 18:17:32 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-05-13 18:17:32 -0700 |
commit | 61dccae13400390bcc41fefb88099b262d97361c (patch) | |
tree | 65db28fb77445cf67ca932382effb10d06a6b253 /src | |
parent | d7c7e70c6c54cb8dd3dea208a53f01f2404fa61d (diff) |
use Browser mouse calculations in glfw
Diffstat (limited to 'src')
-rw-r--r-- | src/library_glfw.js | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/library_glfw.js b/src/library_glfw.js index 8bf3616f..5e76071f 100644 --- a/src/library_glfw.js +++ b/src/library_glfw.js @@ -35,8 +35,6 @@ var LibraryGLFW = { params: null, initTime: null, wheelPos: 0, - lastX: 0, - lastY: 0, buttons: 0, keys: 0, initWindowWidth: 640, @@ -145,28 +143,20 @@ var LibraryGLFW = { GLFW.onKeyChanged(event, 0);//GLFW_RELEASE }, - savePosition: function(event) { - /* TODO maybe loop here ala http://www.quirksmode.org/js/findpos.html */ - GLFW.lastX = event['clientX'] - Module['canvas'].offsetLeft; - GLFW.lastY = event['clientY'] - Module['canvas'].offsetTop; - }, - onMousemove: function(event) { /* Send motion event only if the motion changed, prevents * spamming our app with uncessary callback call. It does happen in * Chrome on Windows. */ - var newX = event['clientX'] - Module['canvas'].offsetLeft; - var newY = event['clientY'] - Module['canvas'].offsetTop; - if (newX == GLFW.lastX && newY == GLFW.lastY) { - return; - } - - GLFW.savePosition(event); + var lastX = Browser.mouseX; + var lastY = Browser.mouseY; + Browser.calculateMouseEvent(event); + var newX = Browser.mouseX; + var newY = Browser.mouseY; if (event.target == Module["canvas"] && GLFW.mousePosFunc) { event.preventDefault(); - Runtime.dynCall('vii', GLFW.mousePosFunc, [GLFW.lastX, GLFW.lastY]); + Runtime.dynCall('vii', GLFW.mousePosFunc, [lastX, lastY]); } }, @@ -175,7 +165,8 @@ var LibraryGLFW = { return; } - GLFW.savePosition(event); + Browser.calculateMouseEvent(event); + if (event.target != Module["canvas"]) { return; } @@ -441,8 +432,8 @@ var LibraryGLFW = { }, glfwGetMousePos: function(xpos, ypos) { - setValue(xpos, GLFW.lastX, 'i32'); - setValue(ypos, GLFW.lastY, 'i32'); + setValue(xpos, Browser.mouseX, 'i32'); + setValue(ypos, Browser.mouseY, 'i32'); }, //I believe it is not possible to move the mouse with javascript |