fix #275 #237; implements watchers for mouse x and mouse y

pull/3/merge
Michael Ball 2013-12-18 03:54:27 -08:00
rodzic f48460fc25
commit 21a29e3706
1 zmienionych plików z 43 dodań i 2 usunięć

Wyświetl plik

@ -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
);
};