fix mouse sensing function (#12)

pull/29/head
Michael Aschauer 2017-02-28 22:26:29 +01:00
rodzic 3d3e0f5e61
commit 2328386de9
3 zmienionych plików z 51 dodań i 0 usunięć

Wyświetl plik

@ -35,6 +35,7 @@
<!-- turtlestitch additions -->
<script type="text/javascript" src="stitchcode/turtleShepherd.js"></script>
<script type="text/javascript" src="stitchcode/blocks.js"></script>
<script type="text/javascript" src="stitchcode/threads.js"></script>
<script type="text/javascript" src="stitchcode/objects.js"></script>
<script type="text/javascript" src="stitchcode/gui.js"></script>
<script type="text/javascript" src="stitchcode/gui-cloud.js"></script>

Wyświetl plik

@ -716,6 +716,25 @@ StageMorph.prototype.mouseLeave = function () {
this.referencePos = null;
};
// StageMorph Mouse Coordinates
StageMorph.prototype.reportMouseX = function () {
var world = this.world();
if (world) {
return ((world.hand.position().x - this.center().x) / this.scale) / this.camera.zoomFactor * 2 + this.controls.center.x;
}
return 0;
};
StageMorph.prototype.reportMouseY = function () {
var world = this.world();
if (world) {
return ((this.center().y - world.hand.position().y) / this.scale) / this.camera.zoomFactor * 2 + this.controls.center.y;
}
return 0;
};
StageMorph.prototype.originalAdd = StageMorph.prototype.add;
StageMorph.prototype.add = function (morph) {
this.originalAdd(morph);

Wyświetl plik

@ -0,0 +1,31 @@
Process.prototype.reportMouseX = function () {
var stage, world;
if (this.homeContext.receiver) {
stage = this.homeContext.receiver.parentThatIsA(StageMorph);
if (stage) {
world = stage.world();
if (world) {
var factor = stage.renderer.isParallelProjection ? 65 / stage.camera.zoomFactor : stage.controls.object.position.length() / 10;
return ((world.hand.position().x - stage.center().x)
/ stage.scale) / stage.camera.zoomFactor * 2 + stage.controls.center.x;
}
}
}
return 0;
};
Process.prototype.reportMouseY = function () {
var stage, world;
if (this.homeContext.receiver) {
stage = this.homeContext.receiver.parentThatIsA(StageMorph);
if (stage) {
world = stage.world();
if (world) {
var factor = stage.renderer.isParallelProjection ? 65 / stage.camera.zoomFactor : stage.controls.object.position.length() / 10;
return ((stage.center().y - world.hand.position().y)
/ stage.scale) / stage.camera.zoomFactor * 2 + stage.controls.center.y;
}
}
}
return 0;
};