aboutsummaryrefslogtreecommitdiff
path: root/src/library_glut.js
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2012-04-04 02:34:35 -0400
committerBehdad Esfahbod <behdad@behdad.org>2012-04-04 02:34:35 -0400
commit92e2a651b4ad1d7434f16c45fd00596320653e2f (patch)
tree6d9f4bc35821dc4e6345d62e0d0d2c16eb6c8849 /src/library_glut.js
parent0013b799fa7d1737343f133c7a4581dec4a311f6 (diff)
Fix GLUT mouse events position to be relative to canvas
Diffstat (limited to 'src/library_glut.js')
-rw-r--r--src/library_glut.js15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/library_glut.js b/src/library_glut.js
index 13163c23..84d800a9 100644
--- a/src/library_glut.js
+++ b/src/library_glut.js
@@ -16,6 +16,12 @@ var LibraryGLUT = {
buttons: 0,
modifiers: 0,
+ savePosition: function(event) {
+ /* TODO maybe loop here ala http://www.quirksmode.org/js/findpos.html */
+ GLUT.lastX = event['clientX'] - Module['canvas'].offsetLeft;
+ GLUT.lastY = event['clientY'] - Module['canvas'].offsetTop;
+ },
+
saveModifiers: function(event) {
GLUT.modifiers = 0;
if (event['shiftKey'])
@@ -27,8 +33,7 @@ var LibraryGLUT = {
},
onMousemove: function(event) {
- GLUT.lastX = event['clientX'];
- GLUT.lastY = event['clientY'];
+ GLUT.savePosition(event);
if (GLUT.buttons == 0 && GLUT.passiveMotionFunc) {
event.preventDefault();
GLUT.saveModifiers(event);
@@ -149,8 +154,7 @@ var LibraryGLUT = {
},
onMouseButtonDown: function(event){
- GLUT.lastX = event['clientX'];
- GLUT.lastY = event['clientY'];
+ GLUT.savePosition(event);
GLUT.buttons |= (1 << event['button']);
if(GLUT.mouseFunc){
@@ -161,8 +165,7 @@ var LibraryGLUT = {
},
onMouseButtonUp: function(event){
- GLUT.lastX = event['clientX'];
- GLUT.lastY = event['clientY'];
+ GLUT.savePosition(event);
GLUT.buttons &= ~(1 << event['button']);
if(GLUT.mouseFunc) {