Permalink
Browse files

update snap

  • Loading branch information...
sdpython committed Jul 19, 2015
1 parent f17dac4 commit ebffea4efd777f70de7a8ad843568d6eef1a81e6
@@ -0,0 +1,25 @@
Snap! Build Your Own Blocks
http://snap.berkeley.edu
a visual, blocks based programming language
inspired by Scratch
written by Jens Mönig and Brian Harvey
jens@moenig.org, bh@cs.berkeley.edu
Copyright (C) 2015 by Jens Mönig and Brian Harvey
Snap! is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -155,8 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2015-March-09';
modules.blocks = '2015-June-25';
var SyntaxElementMorph;
var BlockMorph;
@@ -360,6 +359,10 @@ SyntaxElementMorph.prototype.init = function () {
this.cachedInputs = null;
};
// SyntaxElementMorph stepping:
SyntaxElementMorph.prototype.step = null;
// SyntaxElementMorph accessing:
SyntaxElementMorph.prototype.parts = function () {
@@ -1111,9 +1114,9 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
acos : ['acos'],
atan : ['atan'],
ln : ['ln'],
// log : 'log',
'e^' : ['e^']
// '10^' : '10^'
log : ['log'],
'e^' : ['e^'],
'10^' : ['10^']
},
true
);
@@ -1417,16 +1420,19 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
new Point() : this.embossing;
part.drawNew();
} else {
part = new StringMorph(spec);
part.fontName = this.labelFontName;
part.fontStyle = this.labelFontStyle;
part.fontSize = this.fontSize;
part.color = new Color(255, 255, 255);
part.isBold = true;
part.shadowColor = this.color.darker(this.labelContrast);
part.shadowOffset = MorphicPreferences.isFlat ?
new Point() : this.embossing;
part.drawNew();
part = new StringMorph(
spec, // text
this.fontSize, // fontSize
this.labelFontStyle, // fontStyle
true, // bold
false, // italic
false, // isNumeric
MorphicPreferences.isFlat ?
new Point() : this.embossing, // shadowOffset
this.color.darker(this.labelContrast), // shadowColor
new Color(255, 255, 255), // color
this.labelFontName // fontName
);
}
return part;
};
@@ -2058,7 +2064,8 @@ BlockMorph.prototype.setSpec = function (spec) {
}
part = myself.labelPart(word);
myself.add(part);
if (!(part instanceof CommandSlotMorph)) {
if (!(part instanceof CommandSlotMorph ||
part instanceof StringMorph)) {
part.drawNew();
}
if (part instanceof RingMorph) {
@@ -2225,7 +2232,7 @@ BlockMorph.prototype.userMenu = function () {
);
if (this instanceof CommandBlockMorph && this.nextBlock()) {
menu.addItem(
this.thumbnail(0.5, 60, false),
this.thumbnail(0.5, 60),
function () {
var cpy = this.fullCopy(),
nb = cpy.nextBlock(),
@@ -3066,6 +3073,11 @@ BlockMorph.prototype.fullCopy = function () {
ans.allChildren().filter(function (block) {
if (block instanceof SyntaxElementMorph) {
block.cachedInputs = null;
if (block instanceof InputSlotMorph) {
block.contents().clearSelection();
}
} else if (block instanceof CursorMorph) {
block.destroy();
}
return !isNil(block.comment);
}).forEach(function (block) {
@@ -3098,38 +3110,34 @@ BlockMorph.prototype.mouseClickLeft = function () {
// BlockMorph thumbnail
BlockMorph.prototype.thumbnail = function (scale, clipWidth, noShadow) {
var block = this.fullCopy(),
nb = block.nextBlock(),
BlockMorph.prototype.thumbnail = function (scale, clipWidth) {
var nb = this.nextBlock(),
fadeout = 12,
ext,
trgt,
ctx,
gradient;
if (nb) {nb.destroy(); }
if (!noShadow) {block.addShadow(); }
ext = block.fullBounds().extent();
if (!noShadow) {
ext = ext.subtract(this.shadowBlur *
(useBlurredShadows && !MorphicPreferences.isFlat ? 1 : 2));
}
if (nb) {nb.isVisible = false; }
ext = this.fullBounds().extent();
trgt = newCanvas(new Point(
Math.min(ext.x * scale, clipWidth || ext.x),
clipWidth ? Math.min(ext.x * scale, clipWidth) : ext.x * scale,
ext.y * scale
));
ctx = trgt.getContext('2d');
ctx.scale(scale, scale);
ctx.drawImage(block.fullImage(), 0, 0);
ctx.drawImage(this.fullImage(), 0, 0);
// draw fade-out
if (trgt.width === clipWidth) {
if (clipWidth && ext.x * scale > clipWidth) {
gradient = ctx.createLinearGradient(
trgt.width / scale - fadeout,
0,
trgt.width / scale,
0
);
gradient.addColorStop(0, new Color(255, 255, 255, 0).toString());
gradient.addColorStop(1, 'white');
gradient.addColorStop(0, 'transparent');
gradient.addColorStop(1, 'black');
ctx.globalCompositeOperation = 'destination-out';
ctx.fillStyle = gradient;
ctx.fillRect(
trgt.width / scale - fadeout,
@@ -3138,6 +3146,7 @@ BlockMorph.prototype.thumbnail = function (scale, clipWidth, noShadow) {
trgt.height / scale
);
}
if (nb) {nb.isVisible = true; }
return trgt;
};
@@ -6912,7 +6921,8 @@ InputSlotMorph.prototype.setChoices = function (dict, readonly) {
// InputSlotMorph layout:
InputSlotMorph.prototype.fixLayout = function () {
var contents = this.contents(),
var width, height, arrowWidth,
contents = this.contents(),
arrow = this.arrow();
contents.isNumeric = this.isNumeric;
@@ -6929,35 +6939,32 @@ InputSlotMorph.prototype.fixLayout = function () {
arrow.setSize(this.fontSize);
arrow.show();
} else {
arrow.setSize(0);
arrow.hide();
}
this.setHeight(
contents.height()
+ this.edge * 2
// + this.typeInPadding * 2
);
arrowWidth = arrow.isVisible ? arrow.width() : 0;
height = contents.height() + this.edge * 2; // + this.typeInPadding * 2
if (this.isNumeric) {
this.setWidth(contents.width()
+ Math.floor(arrow.width() * 0.5)
+ this.height()
+ this.typeInPadding * 2
);
width = contents.width()
+ Math.floor(arrowWidth * 0.5)
+ height
+ this.typeInPadding * 2;
} else {
this.setWidth(Math.max(
width = Math.max(
contents.width()
+ arrow.width()
+ arrowWidth
+ this.edge * 2
+ this.typeInPadding * 2,
contents.rawHeight ? // single vs. multi-line contents
contents.rawHeight() + arrow.width()
: contents.height() / 1.2 + arrow.width(),
contents.rawHeight() + arrowWidth
: contents.height() / 1.2 + arrowWidth,
this.minWidth // for text-type slots
));
);
}
this.setExtent(new Point(width, height));
if (this.isNumeric) {
contents.setPosition(new Point(
Math.floor(this.height() / 2),
Math.floor(height / 2),
this.edge
).add(new Point(this.typeInPadding, 0)).add(this.position()));
} else {
@@ -6967,10 +6974,12 @@ InputSlotMorph.prototype.fixLayout = function () {
).add(new Point(this.typeInPadding, 0)).add(this.position()));
}
arrow.setPosition(new Point(
this.right() - arrow.width() - this.edge,
contents.top()
));
if (arrow.isVisible) {
arrow.setPosition(new Point(
this.right() - arrowWidth - this.edge,
contents.top()
));
}
if (this.parent) {
if (this.parent.fixLayout) {
@@ -6987,6 +6996,15 @@ InputSlotMorph.prototype.fixLayout = function () {
// InputSlotMorph events:
InputSlotMorph.prototype.mouseDownLeft = function (pos) {
if (this.isReadOnly || this.arrow().bounds.containsPoint(pos)) {
this.escalateEvent('mouseDownLeft', pos);
} else {
this.contents().edit();
this.contents().selectAll();
}
};
InputSlotMorph.prototype.mouseClickLeft = function (pos) {
if (this.arrow().bounds.containsPoint(pos)) {
this.dropDownMenu();
@@ -106,7 +106,7 @@ SymbolMorph, isNil*/
// Global stuff ////////////////////////////////////////////////////////
modules.byob = '2015-March-02';
modules.byob = '2015-June-25';
// Declarations
@@ -2049,7 +2049,13 @@ BlockLabelFragment.prototype.defTemplateSpecFragment = function () {
)) {
suff = ' \u03BB';
} else if (this.defaultValue) {
suff = ' = ' + this.defaultValue.toString();
if (this.type === '%n') {
suff = ' # = ' + this.defaultValue.toString();
} else { // 'any' or 'text'
suff = ' = ' + this.defaultValue.toString();
}
} else if (this.type === '%n') {
suff = ' #';
}
return this.labelString + suff;
};
@@ -3291,15 +3297,17 @@ BlockExportDialogMorph.prototype.selectNone = function () {
// BlockExportDialogMorph ops
BlockExportDialogMorph.prototype.exportBlocks = function () {
var str = this.serializer.serialize(this.blocks);
var str = encodeURIComponent(
this.serializer.serialize(this.blocks)
);
if (this.blocks.length > 0) {
window.open(encodeURI('data:text/xml,<blocks app="'
window.open('data:text/xml,<blocks app="'
+ this.serializer.app
+ '" version="'
+ this.serializer.version
+ '">'
+ str
+ '</blocks>'));
+ '</blocks>');
} else {
new DialogBoxMorph().inform(
'Export blocks',
Oops, something went wrong.

0 comments on commit ebffea4

Please sign in to comment.