0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-30 10:20:52 -05:00

added Mouse.setScale, Mouse.setPosition, mouse.absolute

This commit is contained in:
liabru 2014-05-03 18:45:48 +01:00
parent d41b396c7f
commit e63689c938

View file

@ -16,10 +16,12 @@ var Mouse;
var mouse = this; var mouse = this;
this.element = element || document.body; this.element = element || document.body;
this.absolute = { x: 0, y: 0 };
this.position = { x: 0, y: 0 }; this.position = { x: 0, y: 0 };
this.mousedownPosition = { x: 0, y: 0 }; this.mousedownPosition = { x: 0, y: 0 };
this.mouseupPosition = { x: 0, y: 0 }; this.mouseupPosition = { x: 0, y: 0 };
this.offset = { x: 0, y: 0 }; this.offset = { x: 0, y: 0 };
this.scale = { x: 1, y: 1 };
this.button = -1; this.button = -1;
this.sourceEvents = { this.sourceEvents = {
@ -37,8 +39,10 @@ var Mouse;
event.preventDefault(); event.preventDefault();
} }
mouse.position.x = position.x + mouse.offset.x; mouse.absolute.x = position.x;
mouse.position.y = position.y + mouse.offset.y; mouse.absolute.y = position.y;
mouse.position.x = (position.x + mouse.offset.x) * mouse.scale.x;
mouse.position.y = (position.y + mouse.offset.y) * mouse.scale.y;
mouse.sourceEvents.mousemove = event; mouse.sourceEvents.mousemove = event;
}; };
@ -53,10 +57,12 @@ var Mouse;
mouse.button = event.button; mouse.button = event.button;
} }
mouse.position.x = position.x + mouse.offset.x; mouse.absolute.x = position.x;
mouse.position.y = position.y + mouse.offset.y; mouse.absolute.y = position.y;
mouse.mousedownPosition.x = position.x + mouse.offset.x; mouse.position.x = (position.x + mouse.offset.x) * mouse.scale.x;
mouse.mousedownPosition.y = position.y + mouse.offset.y; mouse.position.y = (position.y + mouse.offset.y) * mouse.scale.y;
mouse.mousedownPosition.x = mouse.position.x;
mouse.mousedownPosition.y = mouse.position.y;
mouse.sourceEvents.mousedown = event; mouse.sourceEvents.mousedown = event;
}; };
@ -69,10 +75,12 @@ var Mouse;
} }
mouse.button = -1; mouse.button = -1;
mouse.position.x = position.x + mouse.offset.x; mouse.absolute.x = position.x;
mouse.position.y = position.y + mouse.offset.y; mouse.absolute.y = position.y;
mouse.mouseupPosition.x = position.x + mouse.offset.x; mouse.position.x = (position.x + mouse.offset.x) * mouse.scale.x;
mouse.mouseupPosition.y = position.y + mouse.offset.y; mouse.position.y = (position.y + mouse.offset.y) * mouse.scale.y;
mouse.mouseupPosition.x = mouse.position.x;
mouse.mouseupPosition.y = mouse.position.y;
mouse.sourceEvents.mouseup = event; mouse.sourceEvents.mouseup = event;
}; };
@ -118,6 +126,30 @@ var Mouse;
mouse.sourceEvents.mouseup = null; mouse.sourceEvents.mouseup = null;
}; };
/**
* Sets the offset
* @method setOffset
* @param {mouse} mouse
*/
Mouse.setOffset = function(mouse, offset) {
mouse.offset.x = offset.x;
mouse.offset.y = offset.y;
mouse.position.x = (mouse.absolute.x + mouse.offset.x) * mouse.scale.x;
mouse.position.y = (mouse.absolute.y + mouse.offset.y) * mouse.scale.y;
};
/**
* Sets the scale
* @method setScale
* @param {mouse} mouse
*/
Mouse.setScale = function(mouse, scale) {
mouse.scale.x = scale.x;
mouse.scale.y = scale.y;
mouse.position.x = (mouse.absolute.x + mouse.offset.x) * mouse.scale.x;
mouse.position.y = (mouse.absolute.y + mouse.offset.y) * mouse.scale.y;
};
/** /**
* Description * Description
* @method _getRelativeMousePosition * @method _getRelativeMousePosition