aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-05-31 16:12:22 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-05-31 16:12:22 -0700
commitaceedc8636fd4fd4c1df95a64176e07a425a435d (patch)
tree330903518b0d093aa47feb9b918a54d2108b4644
parent358260eefc7cfc3571d9bf6b26e26c74c77f57e0 (diff)
un-press all mouse buttons when the mouse leaves the canvas, prevents bug with mouse button staying down after leaving, until reentering and clicking
-rw-r--r--src/library_sdl.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 442057c8..50df78f3 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -305,6 +305,17 @@ var LibrarySDL = {
event.preventDefault();
}
break;
+ case 'mouseout':
+ // Un-press all mouse buttons, because we might miss the release outside of the canvas
+ for (var i = 0; i < 3; i++) {
+ SDL.events.push({
+ type: 'mouseup',
+ button: i,
+ pageX: event.pageX,
+ pageY: event.pageY
+ });
+ }
+ break;
}
return false;
},
@@ -382,8 +393,7 @@ var LibrarySDL = {
SDL.mouseY = y;
break;
}
- default:
- throw 'Unhandled SDL event: ' + event.type;
+ default: throw 'Unhandled SDL event: ' + event.type;
}
},
@@ -507,7 +517,7 @@ var LibrarySDL = {
},
SDL_SetVideoMode: function(width, height, depth, flags) {
- ['mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll'].forEach(function(event) {
+ ['mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll', 'mouseout'].forEach(function(event) {
Module['canvas'].addEventListener(event, SDL.receiveEvent, true);
});
Module['canvas'].width = width;