summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Ball <cycomachead@gmail.com>2013-12-18 03:54:27 -0800
committerMichael Ball <cycomachead@gmail.com>2013-12-18 03:54:27 -0800
commit21a29e37068a5e5df8bde64fb5200081fa734ae2 (patch)
treec7d1f42120d8c687a7131e13ad614a436788035f
parentf48460fc2544fe6af4f20f79aa8e56d92a3423b6 (diff)
downloadsnap-byow-21a29e37068a5e5df8bde64fb5200081fa734ae2.tar.gz
snap-byow-21a29e37068a5e5df8bde64fb5200081fa734ae2.zip
fix #275 #237; implements watchers for mouse x and mouse y
-rw-r--r--objects.js45
1 files changed, 43 insertions, 2 deletions
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
);
};