This commit is contained in:
Danny Yoo 2011-09-16 13:17:52 -04:00
parent 5ccaf1ca46
commit b7bcc97e78

View File

@ -923,19 +923,32 @@ var rawJsworld = {};
// http://stackoverflow.com/questions/55677/how-do-i-get-the-coordinates-of-a-mouse-click-on-a-canvas-element // http://stackoverflow.com/questions/55677/how-do-i-get-the-coordinates-of-a-mouse-click-on-a-canvas-element
function on_mouse(mouse) { function on_mouse(mouse) {
return function() { return function() {
var isButtonDown = false;
var makeWrapped = function(type) { var makeWrapped = function(type) {
return function(e) { return function(e) {
preventDefault(e);
stopPropagation(e);
var x = e.pageX, y = e.pageY; var x = e.pageX, y = e.pageY;
var currentElement = e.target; var currentElement = e.target;
do { do {
x -= currentElement.offsetLeft; x -= currentElement.offsetLeft;
y -= currentElement.offsetTop; y -= currentElement.offsetTop;
} while(currentElement = currentElement.offsetParent); } while(currentElement = currentElement.offsetParent);
preventDefault(e);
stopPropagation(e); if (type === 'button-down') {
change_world(function(w, k) { isButtonDown = true;
mouse(w, x, y, type, k); } else if (type === 'button-up') {
}, doNothing); isButtonDown = false;
}
if (type === 'move' && isButtonDown) {
change_world(function(w, k) {
mouse(w, x, y, 'drag', k);
}, doNothing);
} else {
change_world(function(w, k) {
mouse(w, x, y, type, k);
}, doNothing);
}
}; };
}; };
var wrappedDown = makeWrapped('button-down'); var wrappedDown = makeWrapped('button-down');