From 2328386de948d2a0508fee1b7d93d51096873cbd Mon Sep 17 00:00:00 2001 From: Michael Aschauer Date: Tue, 28 Feb 2017 22:26:29 +0100 Subject: [PATCH] fix mouse sensing function (#12) --- index.html | 1 + stitchcode/objects.js | 19 +++++++++++++++++++ stitchcode/threads.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 stitchcode/threads.js diff --git a/index.html b/index.html index df535426..fceda24d 100644 --- a/index.html +++ b/index.html @@ -35,6 +35,7 @@ + diff --git a/stitchcode/objects.js b/stitchcode/objects.js index eecfc378..237eae40 100644 --- a/stitchcode/objects.js +++ b/stitchcode/objects.js @@ -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); diff --git a/stitchcode/threads.js b/stitchcode/threads.js new file mode 100644 index 00000000..fe0c6779 --- /dev/null +++ b/stitchcode/threads.js @@ -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; +};