aboutsummaryrefslogtreecommitdiff
path: root/src/library_sdl.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-03-20 13:44:50 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-03-20 13:44:50 -0700
commit669c786e3554b280e31dcb7bd92931482547dae0 (patch)
tree110d48a9e6bf29ceed41ac6282dc37d2f0f3f433 /src/library_sdl.js
parentb22f6fbbbebb5df55ceb8fdc9f7c4d111c902c5e (diff)
parent421e70ecf266d6619415b53c1bc03d4a127a585d (diff)
Merge branch 'incoming'
Diffstat (limited to 'src/library_sdl.js')
-rw-r--r--src/library_sdl.js19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 9fc979d2..42207f23 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -524,8 +524,18 @@ var LibrarySDL = {
} else {
// Otherwise, calculate the movement based on the changes
// in the coordinates.
- var x = event.pageX - Module["canvas"].offsetLeft;
- var y = event.pageY - Module["canvas"].offsetTop;
+ var rect = Module["canvas"].getBoundingClientRect();
+ var x = event.pageX - (window.scrollX + rect.left);
+ var y = event.pageY - (window.scrollY + rect.top);
+
+ // the canvas might be CSS-scaled compared to its backbuffer;
+ // SDL-using content will want mouse coordinates in terms
+ // of backbuffer units.
+ var cw = Module["canvas"].width;
+ var ch = Module["canvas"].height;
+ x = x * (cw / rect.width);
+ y = y * (ch / rect.height);
+
var movementX = x - SDL.mouseX;
var movementY = y - SDL.mouseY;
}
@@ -912,10 +922,11 @@ var LibrarySDL = {
SDL_WarpMouse: function(x, y) {
return; // TODO: implement this in a non-buggy way. Need to keep relative mouse movements correct after calling this
+ var rect = Module["canvas"].getBoundingClientRect();
SDL.events.push({
type: 'mousemove',
- pageX: x + Module['canvas'].offsetLeft,
- pageY: y + Module['canvas'].offsetTop
+ pageX: x + (window.scrollX + rect.left),
+ pageY: y + (window.scrollY + rect.top)
});
},