From 21a29e37068a5e5df8bde64fb5200081fa734ae2 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Wed, 18 Dec 2013 03:54:27 -0800 Subject: fix #275 #237; implements watchers for mouse x and mouse y --- objects.js | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index d5afc83..9f75a98 100644 --- a/objects.js +++ b/objects.js @@ -124,7 +124,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2013-December-12'; +modules.objects = '2013-December-18'; var SpriteMorph; var StageMorph; @@ -1680,7 +1680,9 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push(watcherToggle('getLastAnswer')); blocks.push(block('getLastAnswer')); blocks.push('-'); + blocks.push(watcherToggle('reportMouseX')); blocks.push(block('reportMouseX')); + blocks.push(watcherToggle('reportMouseY')); blocks.push(block('reportMouseY')); blocks.push(block('reportMouseDown')); blocks.push('-'); @@ -3046,6 +3048,24 @@ SpriteMorph.prototype.getLastAnswer = function () { return this.parentThatIsA(StageMorph).lastAnswer; }; +// SpriteMorph mouse coordinates + +SpriteMorph.prototype.reportMouseX = function () { + var stage = this.parentThatIsA(StageMorph); + if (stage) { + return stage.reportMouseX(); + } + return 0; +}; + +SpriteMorph.prototype.reportMouseY = function () { + var stage = this.parentThatIsA(StageMorph); + if (stage) { + return stage.reportMouseY(); + } + return 0; +}; + // SpriteMorph variable watchers (for palette checkbox toggling) SpriteMorph.prototype.findVariableWatcher = function (varName) { @@ -3949,6 +3969,24 @@ StageMorph.prototype.getLastMessage = function () { return this.lastMessage || ''; }; +// StageMorph Mouse Corridnates + +StageMorph.prototype.reportMouseX = function () { + var world = this.world(); + if (world) { + return (world.hand.position().x - this.center().x) / this.scale; + } + return 0; +}; + +StageMorph.prototype.reportMouseY = function () { + var world = this.world(); + if (world) { + return (this.center().y - world.hand.position().y) / this.scale; + } + return 0; +}; + // StageMorph drag & drop StageMorph.prototype.wantsDropOf = function (aMorph) { @@ -4342,7 +4380,9 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(watcherToggle('getLastAnswer')); blocks.push(block('getLastAnswer')); blocks.push('-'); + blocks.push(watcherToggle('reportMouseX')); blocks.push(block('reportMouseX')); + blocks.push(watcherToggle('reportMouseY')); blocks.push(block('reportMouseY')); blocks.push(block('reportMouseDown')); blocks.push('-'); @@ -6004,7 +6044,8 @@ WatcherMorph.prototype.object = function () { WatcherMorph.prototype.isGlobal = function (selector) { return contains( - ['getTimer', 'getLastAnswer', 'getTempo', 'getLastMessage'], + ['getLastAnswer', 'getLastMessage', 'getTempo', 'getTimer', + 'reportMouseX', 'reportMouseY'], selector ); }; -- cgit v1.3.1