made "pen down?" attribute inheritable

pull/89/head
jmoenig 2019-06-02 15:54:28 +02:00
rodzic ee9eb87977
commit 13b10457e5
3 zmienionych plików z 46 dodań i 4 usunięć

Wyświetl plik

@ -88,6 +88,7 @@
### 2019-06-02 ### 2019-06-02
* Objects, Store: made "pen down?" and "shown?" attributes watchable onstage * Objects, Store: made "pen down?" and "shown?" attributes watchable onstage
* Objects, Blocks: made "shown?" attribute inheritable * Objects, Blocks: made "shown?" attribute inheritable
* Objects, Blocks: made "pen down?" attribute inheritable
### 2019-06-01 ### 2019-06-01
* Objects: new "pen down?" predicate * Objects: new "pen down?" predicate

Wyświetl plik

@ -2777,7 +2777,8 @@ BlockMorph.prototype.userMenu = function () {
getCostumeIdx: 'costume #', getCostumeIdx: 'costume #',
getVolume: 'volume', getVolume: 'volume',
getPan: 'balance', getPan: 'balance',
reportShown: 'shown?' reportShown: 'shown?',
getPenDown: 'pen down?'
}[this.selector]; }[this.selector];
if (field && rcvr && rcvr.exemplar) { if (field && rcvr && rcvr.exemplar) {
menu.addLine(); menu.addLine();

Wyświetl plik

@ -129,6 +129,7 @@ SpriteMorph.prototype.attributes =
'balance', 'balance',
'sounds', 'sounds',
'shown?', 'shown?',
'pen down?',
'scripts' 'scripts'
]; ];
@ -2282,7 +2283,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(block('down')); blocks.push(block('down'));
blocks.push(block('up')); blocks.push(block('up'));
blocks.push(watcherToggle('getPenDown')); blocks.push(watcherToggle('getPenDown'));
blocks.push(block('getPenDown')); blocks.push(block('getPenDown', this.inheritsAttribute('pen down?')));
blocks.push('-'); blocks.push('-');
blocks.push(block('setColor')); blocks.push(block('setColor'));
blocks.push(block('changePenHSVA')); blocks.push(block('changePenHSVA'));
@ -4290,7 +4291,40 @@ SpriteMorph.prototype.changeSize = function (delta) {
this.setSize(this.size + (+delta || 0)); this.setSize(this.size + (+delta || 0));
}; };
// SpriteMorph pen up and down:
SpriteMorph.prototype.down = function () {
this.setPenDown(true);
}
SpriteMorph.prototype.up = function () {
this.setPenDown(false);
}
SpriteMorph.prototype.setPenDown = function (bool, noShadow) {
if (bool) {
SpriteMorph.uber.down.call(this);
} else {
SpriteMorph.uber.up.call(this);
}
// propagate to children that inherit my visibility
if (!noShadow) {
this.shadowAttribute('pen down?');
}
this.instances.forEach(function (instance) {
if (instance.cachedPropagation) {
if (instance.inheritsAttribute('pen down?')) {
instance.setPenDown(bool, true);
}
}
});
};
SpriteMorph.prototype.getPenDown = function () { SpriteMorph.prototype.getPenDown = function () {
if (this.inheritsAttribute('pen down?')) {
return this.exemplar.getPenDown();
}
return this.isDown; return this.isDown;
}; };
@ -6210,7 +6244,8 @@ SpriteMorph.prototype.updatePropagationCache = function () {
'costume #', 'costume #',
'volume', 'volume',
'balance', 'balance',
'shown?' 'shown?',
'pen down?'
], ],
function (att) { function (att) {
return contains(myself.inheritedAttributes, att); return contains(myself.inheritedAttributes, att);
@ -6338,6 +6373,10 @@ SpriteMorph.prototype.refreshInheritedAttribute = function (aName) {
this.cachedPropagation = true; this.cachedPropagation = true;
this.setVisibility(this.reportShown(), true); this.setVisibility(this.reportShown(), true);
break; break;
case 'pen down?':
this.cachedPropagation = true;
this.setPenDown(this.getPenDown(), true);
break;
case 'balance': case 'balance':
this.cachedPropagation = true; this.cachedPropagation = true;
this.setPan(this.getPan(), true); this.setPan(this.getPan(), true);
@ -10784,7 +10823,8 @@ WatcherMorph.prototype.update = function () {
getScale: 'size', getScale: 'size',
getVolume: 'volume', getVolume: 'volume',
getPan: 'balance', getPan: 'balance',
reportShown: 'shown?' reportShown: 'shown?',
getPenDown: 'pen down?'
} [this.getter]; } [this.getter];
isGhosted = att ? this.target.inheritsAttribute(att) : false; isGhosted = att ? this.target.inheritsAttribute(att) : false;
} }