mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
added Mouse.setScale, Mouse.setPosition, mouse.absolute
This commit is contained in:
parent
d41b396c7f
commit
e63689c938
1 changed files with 42 additions and 10 deletions
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -117,6 +125,30 @@ var Mouse;
|
||||||
mouse.sourceEvents.mousedown = null;
|
mouse.sourceEvents.mousedown = null;
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue