diff options
| author | Gubolin <gubolin@fantasymail.de> | 2015-01-03 11:24:35 +0100 |
|---|---|---|
| committer | Gubolin <gubolin@fantasymail.de> | 2015-01-03 11:24:35 +0100 |
| commit | 4bb6d3c0e3af8c379d6a63934110cde1a8e31449 (patch) | |
| tree | 52b287d291b69d87ad72db2ea81fae8ba5ef0aaa /objects.js | |
| parent | 618e034eb86b3ad7e7f4955b900862a27a0ce44c (diff) | |
| parent | 0a239b703c8c7fde5540ce63c4236522a22ee049 (diff) | |
| download | snap-4bb6d3c0e3af8c379d6a63934110cde1a8e31449.tar.gz snap-4bb6d3c0e3af8c379d6a63934110cde1a8e31449.zip | |
merge upstream
Diffstat (limited to 'objects.js')
| -rw-r--r-- | objects.js | 144 |
1 files changed, 99 insertions, 45 deletions
@@ -125,7 +125,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2014-July-30'; +modules.objects = '2014-December-04'; var SpriteMorph; var StageMorph; @@ -1218,6 +1218,13 @@ SpriteMorph.prototype.initBlocks = function () { category: 'lists', spec: 'map %repRing over %l' }, + doForEach: { + dev: true, + type: 'command', + category: 'lists', + spec: 'for %upvar in %l %cs', + defaults: [localize('each item')] + }, // Code mapping - experimental doMapCodeOrHeader: { // experimental @@ -1741,6 +1748,20 @@ SpriteMorph.prototype.blockTemplates = function (category) { return menu; } + function addVar(pair) { + if (pair) { + if (myself.variables.silentFind(pair[0])) { + myself.inform('that name is already in use'); + } else { + myself.addVariable(pair[0], pair[1]); + myself.toggleVariableWatcher(pair[0], pair[1]); + myself.blocksCache[cat] = null; + myself.paletteCache[cat] = null; + myself.parentThatIsA(IDE_Morph).refreshPalette(); + } + } + } + if (cat === 'motion') { blocks.push(block('forward')); @@ -2051,15 +2072,7 @@ SpriteMorph.prototype.blockTemplates = function (category) { function () { new VariableDialogMorph( null, - function (pair) { - if (pair && !myself.variables.silentFind(pair[0])) { - myself.addVariable(pair[0], pair[1]); - myself.toggleVariableWatcher(pair[0], pair[1]); - myself.blocksCache[cat] = null; - myself.paletteCache[cat] = null; - myself.parentThatIsA(IDE_Morph).refreshPalette(); - } - }, + addVar, myself ).prompt( 'Variable name', @@ -2141,6 +2154,8 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push(txt); blocks.push('-'); blocks.push(block('reportMap')); + blocks.push('-'); + blocks.push(block('doForEach')); } ///////////////////////////////// @@ -2248,8 +2263,8 @@ SpriteMorph.prototype.freshPalette = function (category) { var defs = SpriteMorph.prototype.blocks, hiddens = StageMorph.prototype.hiddenPrimitives; return Object.keys(hiddens).some(function (any) { - return defs[any].category === category || - contains((more[category] || []), any); + return !isNil(defs[any]) && (defs[any].category === category + || contains((more[category] || []), any)); }); } @@ -2288,7 +2303,7 @@ SpriteMorph.prototype.freshPalette = function (category) { var hiddens = StageMorph.prototype.hiddenPrimitives, defs = SpriteMorph.prototype.blocks; Object.keys(hiddens).forEach(function (sel) { - if (defs[sel].category === category) { + if (defs[sel] && (defs[sel].category === category)) { delete StageMorph.prototype.hiddenPrimitives[sel]; } }); @@ -3316,8 +3331,11 @@ SpriteMorph.prototype.setCenter = function (aPoint, justMe) { SpriteMorph.prototype.nestingBounds = function () { // same as fullBounds(), except that it uses "parts" instead of children - var result; - result = this.bounds; + // and special cases the costume-less "arrow" shape's bounding box + var result = this.bounds; + if (!this.costume && this.penBounds) { + result = this.penBounds.translateBy(this.position()); + } this.parts.forEach(function (part) { if (part.isVisible) { result = result.merge(part.nestingBounds()); @@ -3541,6 +3559,7 @@ SpriteMorph.prototype.allMessageNames = function () { }; SpriteMorph.prototype.allHatBlocksFor = function (message) { + if (typeof message === 'number') {message = message.toString(); } return this.scripts.children.filter(function (morph) { var event; if (morph.selector) { @@ -4470,17 +4489,33 @@ StageMorph.prototype.drawOn = function (aCanvas, aRect) { hs = h / this.scale; context.save(); context.scale(this.scale, this.scale); - context.drawImage( - this.penTrails(), - src.left() / this.scale, - src.top() / this.scale, - ws, - hs, - area.left() / this.scale, - area.top() / this.scale, - ws, - hs - ); + try { + context.drawImage( + this.penTrails(), + src.left() / this.scale, + src.top() / this.scale, + ws, + hs, + area.left() / this.scale, + area.top() / this.scale, + ws, + hs + ); + } catch (err) { // sometimes triggered only by Firefox + // console.log(err); + context.restore(); + context.drawImage( + this.penTrails(), + 0, + 0, + this.dimensions.x, + this.dimensions.y, + this.left(), + this.top(), + this.dimensions.x * this.scale, + this.dimensions.y * this.scale + ); + } context.restore(); } }; @@ -4763,6 +4798,7 @@ StageMorph.prototype.fireKeyEvent = function (key) { var evt = key.toLowerCase(), hats = [], procs = [], + ide = this.parentThatIsA(IDE_Morph), myself = this; this.keysPressed[evt] = true; @@ -4770,19 +4806,24 @@ StageMorph.prototype.fireKeyEvent = function (key) { return this.fireGreenFlagEvent(); } if (evt === 'ctrl f') { - return this.parentThatIsA(IDE_Morph).currentSprite.searchBlocks(); + if (!ide.isAppMode) {ide.currentSprite.searchBlocks(); } + return; } if (evt === 'ctrl n') { - return this.parentThatIsA(IDE_Morph).createNewProject(); + if (!ide.isAppMode) {ide.createNewProject(); } + return; } if (evt === 'ctrl o') { - return this.parentThatIsA(IDE_Morph).openProjectsBrowser(); + if (!ide.isAppMode) {ide.openProjectsBrowser(); } + return; } if (evt === 'ctrl s') { - return this.parentThatIsA(IDE_Morph).save(); + if (!ide.isAppMode) {ide.save(); } + return; } if (evt === 'ctrl shift s') { - return this.parentThatIsA(IDE_Morph).saveProjectsBrowser(); + if (!ide.isAppMode) {return ide.saveProjectsBrowser(); } + return; } if (evt === 'esc') { return this.fireStopAllEvent(); @@ -4924,6 +4965,20 @@ StageMorph.prototype.blockTemplates = function (category) { ); } + function addVar(pair) { + if (pair) { + if (myself.variables.silentFind(pair[0])) { + myself.inform('that name is already in use'); + } else { + myself.addVariable(pair[0], pair[1]); + myself.toggleVariableWatcher(pair[0], pair[1]); + myself.blocksCache[cat] = null; + myself.paletteCache[cat] = null; + myself.parentThatIsA(IDE_Morph).refreshPalette(); + } + } + } + if (cat === 'motion') { txt = new TextMorph(localize( @@ -5183,15 +5238,7 @@ StageMorph.prototype.blockTemplates = function (category) { function () { new VariableDialogMorph( null, - function (pair) { - if (pair && !myself.variables.silentFind(pair[0])) { - myself.addVariable(pair[0], pair[1]); - myself.toggleVariableWatcher(pair[0], pair[1]); - myself.blocksCache[cat] = null; - myself.paletteCache[cat] = null; - myself.parentThatIsA(IDE_Morph).refreshPalette(); - } - }, + addVar, myself ).prompt( 'Variable name', @@ -5267,6 +5314,8 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(txt); blocks.push('-'); blocks.push(block('reportMap')); + blocks.push('-'); + blocks.push(block('doForEach')); } ///////////////////////////////// @@ -5405,7 +5454,7 @@ StageMorph.prototype.thumbnail = function (extentPoint, excludedSprite) { this.dimensions.y * this.scale ); this.children.forEach(function (morph) { - if (morph !== excludedSprite) { + if (morph.isVisible && (morph !== excludedSprite)) { fb = morph.fullBounds(); fimg = morph.fullImage(); if (fimg.width && fimg.height) { @@ -6514,10 +6563,14 @@ CellMorph.prototype.drawNew = function () { } this.contentsMorph.setColor(new Color(255, 255, 255)); } else if (typeof this.contents === 'boolean') { - this.contentsMorph = SpriteMorph.prototype.booleanMorph.call( + img = SpriteMorph.prototype.booleanMorph.call( null, this.contents - ); + ).fullImage(); + this.contentsMorph = new Morph(); + this.contentsMorph.silentSetWidth(img.width); + this.contentsMorph.silentSetHeight(img.height); + this.contentsMorph.image = img; } else if (this.contents instanceof HTMLCanvasElement) { this.contentsMorph = new Morph(); this.contentsMorph.silentSetWidth(this.contents.width); @@ -6842,7 +6895,8 @@ WatcherMorph.prototype.update = function () { if (this.target && this.getter) { this.updateLabel(); if (this.target instanceof VariableFrame) { - newValue = this.target.vars[this.getter]; + newValue = this.target.vars[this.getter] ? + this.target.vars[this.getter].value : undefined; } else { newValue = this.target[this.getter](); } @@ -6927,7 +6981,7 @@ WatcherMorph.prototype.fixLayout = function () { this.sliderMorph.button.pressColor.b += 100; this.sliderMorph.setHeight(fontSize); this.sliderMorph.action = function (num) { - myself.target.vars[myself.getter] = Math.round(num); + myself.target.vars[myself.getter].value = Math.round(num); }; this.add(this.sliderMorph); } |
