diff options
author | Éloi Rivard <azmeuk@gmail.com> | 2013-03-27 14:29:57 +0100 |
---|---|---|
committer | Éloi Rivard <azmeuk@gmail.com> | 2013-04-04 11:17:36 +0200 |
commit | 26a2095480bfbf51275671695c0ac8c1c995cc7f (patch) | |
tree | bfbba8138f7713de06098e8f596b5d5d9e4c2b7a | |
parent | f65172d9f2fc779b9b0207d8769a10d530a7a5b7 (diff) |
* Fixed mouse position.
-rw-r--r-- | src/library_glfw.js | 24 | ||||
-rw-r--r-- | tests/glfw/glfwsample.c | 11 |
2 files changed, 21 insertions, 14 deletions
diff --git a/src/library_glfw.js b/src/library_glfw.js index f0e96a0a..41fef63f 100644 --- a/src/library_glfw.js +++ b/src/library_glfw.js @@ -175,16 +175,18 @@ var LibraryGLFW = { return; GLFW.savePosition(event); - if(event.target == Module["canvas"] || status == 0){//GLFW_RELEASE - if(status == 1){//GLFW_PRESS - try { - event.target.setCapture(); - } catch (e) {} - } - event.preventDefault(); - //DOM and glfw have the same button codes - Runtime.dynCall('vii', GLFW.mouseButtonFunc, [event['button'], status]); - } + if(event.target != Module["canvas"]) + return; + + if(status == 1){//GLFW_PRESS + try { + event.target.setCapture(); + } catch (e) {} + } + + event.preventDefault(); + //DOM and glfw have the same button codes + Runtime.dynCall('vii', GLFW.mouseButtonFunc, [event['button'], status]); }, onMouseButtonDown: function(event){ @@ -427,7 +429,7 @@ var LibraryGLFW = { }, glfwGetMouseButton : function( button ) { - return GLFW.buttons & button; + return (GLFW.buttons & (1 << button)) > 0; }, glfwGetMousePos : function( xpos, ypos ) { diff --git a/tests/glfw/glfwsample.c b/tests/glfw/glfwsample.c index 3d9be100..79b504b6 100644 --- a/tests/glfw/glfwsample.c +++ b/tests/glfw/glfwsample.c @@ -67,8 +67,8 @@ void Init() glfwSetWindowSizeCallback(OnResize); glfwSetWindowRefreshCallback(OnRefresh); glfwSetMouseWheelCallback(OnMouseWheel); - //glfwSetMousePosCallback(OnMouseMove); - //glfwSetMouseButtonCallback(OnMouseClick); + glfwSetMousePosCallback(OnMouseMove); + glfwSetMouseButtonCallback(OnMouseClick); // set the projection matrix to a normal frustum with a max depth of 50 glMatrixMode(GL_PROJECTION); @@ -323,7 +323,12 @@ void OnMouseClick( int button, int action ){ } void OnMouseMove( int x, int y ){ - printf("Mouse has been moved to %i %i\n", x, y); + int lState = glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT); + + if (lState == GLFW_PRESS) + printf("Dragged %i to %i %i\n", GLFW_MOUSE_BUTTON_LEFT, x, y); + if(lState == GLFW_RELEASE) + printf("Moved %i to %i %i\n", GLFW_MOUSE_BUTTON_LEFT, x, y); } void OnMouseWheel( int pos ){ |