kopia lustrzana https://github.com/backface/turtlestitch
Scalable Comments, auto-positioning scaled scripts
including support for auto-positioning scaled scripts (so you don't have to clean-up when scaling blocks)pull/3/merge
rodzic
b19493897d
commit
3f19a21cad
21
blocks.js
21
blocks.js
|
@ -8738,9 +8738,13 @@ CommentMorph.uber = BoxMorph.prototype;
|
|||
|
||||
// CommentMorph preferences settings (pseudo-inherited from SyntaxElement):
|
||||
|
||||
CommentMorph.prototype.fontSize = SyntaxElementMorph.prototype.fontSize;
|
||||
CommentMorph.prototype.padding = 5;
|
||||
CommentMorph.prototype.rounding = 8;
|
||||
CommentMorph.prototype.refreshScale = function () {
|
||||
CommentMorph.prototype.fontSize = SyntaxElementMorph.prototype.fontSize;
|
||||
CommentMorph.prototype.padding = 5 * SyntaxElementMorph.prototype.scale;
|
||||
CommentMorph.prototype.rounding = 8 * SyntaxElementMorph.prototype.scale;
|
||||
};
|
||||
|
||||
CommentMorph.prototype.refreshScale();
|
||||
|
||||
// CommentMorph instance creation:
|
||||
|
||||
|
@ -8749,13 +8753,14 @@ function CommentMorph(contents) {
|
|||
}
|
||||
|
||||
CommentMorph.prototype.init = function (contents) {
|
||||
var myself = this;
|
||||
var myself = this,
|
||||
scale = SyntaxElementMorph.prototype.scale;
|
||||
this.block = null; // optional anchor block
|
||||
this.stickyOffset = null; // not to be persisted
|
||||
this.isCollapsed = false;
|
||||
this.titleBar = new BoxMorph(
|
||||
this.rounding,
|
||||
1.000001, // shadow bug in Chrome,
|
||||
1.000001 * scale, // shadow bug in Chrome,
|
||||
new Color(255, 255, 180)
|
||||
);
|
||||
this.titleBar.color = new Color(255, 255, 180);
|
||||
|
@ -8773,7 +8778,7 @@ CommentMorph.prototype.init = function (contents) {
|
|||
);
|
||||
this.contents.isEditable = true;
|
||||
this.contents.enableSelecting();
|
||||
this.contents.maxWidth = 90;
|
||||
this.contents.maxWidth = 90 * scale;
|
||||
this.contents.drawNew();
|
||||
this.handle = new HandleMorph(
|
||||
this.contents,
|
||||
|
@ -8782,13 +8787,13 @@ CommentMorph.prototype.init = function (contents) {
|
|||
-2,
|
||||
-2
|
||||
);
|
||||
this.handle.setExtent(new Point(11, 11));
|
||||
this.handle.setExtent(new Point(11 * scale, 11 * scale));
|
||||
this.anchor = null;
|
||||
|
||||
CommentMorph.uber.init.call(
|
||||
this,
|
||||
this.rounding,
|
||||
1.000001, // shadow bug in Chrome,
|
||||
1.000001 * scale, // shadow bug in Chrome,
|
||||
new Color(255, 255, 180)
|
||||
);
|
||||
this.color = new Color(255, 255, 220);
|
||||
|
|
9
gui.js
9
gui.js
|
@ -64,11 +64,11 @@ standardSettings, Sound, BlockMorph, ToggleMorph, InputSlotDialogMorph,
|
|||
ScriptsMorph, isNil, SymbolMorph, BlockExportDialogMorph,
|
||||
BlockImportDialogMorph, SnapTranslator, localize, List, InputSlotMorph,
|
||||
SnapCloud, Uint8Array, HandleMorph, SVG_Costume, fontHeight, hex_sha512,
|
||||
sb*/
|
||||
sb, CommentMorph*/
|
||||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.gui = '2013-March-18';
|
||||
modules.gui = '2013-March-19';
|
||||
|
||||
// Declarations
|
||||
|
||||
|
@ -2787,9 +2787,11 @@ IDE_Morph.prototype.userSetBlocksScale = function () {
|
|||
{
|
||||
'normal (1)' : 1,
|
||||
'demo (1.2)' : 1.2,
|
||||
'presentation (1.4)' : 1.4,
|
||||
'big (2)' : 2,
|
||||
'huge (4)' : 4,
|
||||
'giant (8)' : 8
|
||||
'giant (8)' : 8,
|
||||
'monstrous (10)' : 10
|
||||
},
|
||||
false, // read only?
|
||||
true // numeric
|
||||
|
@ -2808,6 +2810,7 @@ IDE_Morph.prototype.setBlocksScale = function (num) {
|
|||
projectData = this.serializer.serialize(this.stage);
|
||||
}
|
||||
SyntaxElementMorph.prototype.setScale(num);
|
||||
CommentMorph.prototype.refreshScale();
|
||||
SpriteMorph.prototype.initBlocks();
|
||||
this.spriteBar.tabBar.tabTo('scripts');
|
||||
this.createCategories();
|
||||
|
|
|
@ -1535,3 +1535,4 @@ ______
|
|||
------
|
||||
* Blocks: SyntaxElementMorph fixLayout() optimization for active highlights
|
||||
* Russian translation!! Yay, thanks, Svetlana Ptashnaya!!
|
||||
* Store, GUI, Blocks: Scaling support for Comments and serialization/deserialization
|
53
store.js
53
store.js
|
@ -56,11 +56,12 @@ detect, CustomCommandBlockMorph, CustomReporterBlockMorph, Color, List,
|
|||
newCanvas, Costume, Sound, Audio, IDE_Morph, ScriptsMorph, BlockMorph,
|
||||
ArgMorph, InputSlotMorph, TemplateSlotMorph, CommandSlotMorph,
|
||||
FunctionSlotMorph, MultiArgMorph, ColorSlotMorph, nop, CommentMorph, isNil,
|
||||
localize, sizeOf, ArgLabelMorph, SVG_Costume, MorphicPreferences*/
|
||||
localize, sizeOf, ArgLabelMorph, SVG_Costume, MorphicPreferences,
|
||||
SyntaxElementMorph*/
|
||||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.store = '2013-March-14';
|
||||
modules.store = '2013-March-19';
|
||||
|
||||
|
||||
// XML_Serializer ///////////////////////////////////////////////////////
|
||||
|
@ -702,7 +703,8 @@ SnapSerializer.prototype.populateCustomBlocks = function (
|
|||
|
||||
SnapSerializer.prototype.loadScripts = function (scripts, model) {
|
||||
// private
|
||||
var myself = this;
|
||||
var myself = this,
|
||||
scale = SyntaxElementMorph.prototype.scale;
|
||||
scripts.texture = 'scriptsPaneTexture.gif';
|
||||
model.children.forEach(function (child) {
|
||||
var element;
|
||||
|
@ -712,8 +714,8 @@ SnapSerializer.prototype.loadScripts = function (scripts, model) {
|
|||
return;
|
||||
}
|
||||
element.setPosition(new Point(
|
||||
+child.attributes.x || 0,
|
||||
+child.attributes.y || 0
|
||||
(+child.attributes.x || 0) * scale,
|
||||
(+child.attributes.y || 0) * scale
|
||||
).add(scripts.topLeft()));
|
||||
scripts.add(element);
|
||||
element.fixBlockColor(null, true); // force zebra coloring
|
||||
|
@ -726,8 +728,8 @@ SnapSerializer.prototype.loadScripts = function (scripts, model) {
|
|||
return;
|
||||
}
|
||||
element.setPosition(new Point(
|
||||
+child.attributes.x || 0,
|
||||
+child.attributes.y || 0
|
||||
(+child.attributes.x || 0) * scale,
|
||||
(+child.attributes.y || 0) * scale
|
||||
).add(scripts.topLeft()));
|
||||
scripts.add(element);
|
||||
}
|
||||
|
@ -737,6 +739,7 @@ SnapSerializer.prototype.loadScripts = function (scripts, model) {
|
|||
SnapSerializer.prototype.loadScriptsArray = function (model) {
|
||||
// private - answer an array containting the model's scripts
|
||||
var myself = this,
|
||||
scale = SyntaxElementMorph.prototype.scale,
|
||||
scripts = [];
|
||||
model.children.forEach(function (child) {
|
||||
var element;
|
||||
|
@ -746,8 +749,8 @@ SnapSerializer.prototype.loadScriptsArray = function (model) {
|
|||
return;
|
||||
}
|
||||
element.setPosition(new Point(
|
||||
+child.attributes.x || 0,
|
||||
+child.attributes.y || 0
|
||||
(+child.attributes.x || 0) * scale,
|
||||
(+child.attributes.y || 0) * scale
|
||||
));
|
||||
scripts.push(element);
|
||||
element.fixBlockColor(null, true); // force zebra coloring
|
||||
|
@ -757,8 +760,8 @@ SnapSerializer.prototype.loadScriptsArray = function (model) {
|
|||
return;
|
||||
}
|
||||
element.setPosition(new Point(
|
||||
+child.attributes.x || 0,
|
||||
+child.attributes.y || 0
|
||||
(+child.attributes.x || 0) * scale,
|
||||
(+child.attributes.y || 0) * scale
|
||||
));
|
||||
scripts.push(element);
|
||||
}
|
||||
|
@ -787,9 +790,10 @@ SnapSerializer.prototype.loadScript = function (model) {
|
|||
|
||||
SnapSerializer.prototype.loadComment = function (model) {
|
||||
// private
|
||||
var comment = new CommentMorph(model.contents);
|
||||
var comment = new CommentMorph(model.contents),
|
||||
scale = SyntaxElementMorph.prototype.scale;
|
||||
comment.isCollapsed = (model.attributes.collapsed === 'true');
|
||||
comment.setTextWidth(+model.attributes.w);
|
||||
comment.setTextWidth(+model.attributes.w * scale);
|
||||
return comment;
|
||||
};
|
||||
|
||||
|
@ -1369,6 +1373,7 @@ BlockMorph.prototype.toXML = BlockMorph.prototype.toScriptXML = function (
|
|||
) {
|
||||
var position,
|
||||
xml,
|
||||
scale = SyntaxElementMorph.prototype.scale,
|
||||
block = this;
|
||||
|
||||
// determine my position
|
||||
|
@ -1382,8 +1387,8 @@ BlockMorph.prototype.toXML = BlockMorph.prototype.toScriptXML = function (
|
|||
if (savePosition) {
|
||||
xml = serializer.format(
|
||||
'<script x="@" y="@">',
|
||||
position.x,
|
||||
position.y
|
||||
position.x / scale,
|
||||
position.y / scale
|
||||
);
|
||||
} else {
|
||||
xml = '<script>';
|
||||
|
@ -1418,7 +1423,8 @@ ReporterBlockMorph.prototype.toScriptXML = function (
|
|||
serializer,
|
||||
savePosition
|
||||
) {
|
||||
var position;
|
||||
var position,
|
||||
scale = SyntaxElementMorph.prototype.scale;
|
||||
|
||||
// determine my save-position
|
||||
if (this.parent) {
|
||||
|
@ -1430,8 +1436,8 @@ ReporterBlockMorph.prototype.toScriptXML = function (
|
|||
if (savePosition) {
|
||||
return serializer.format(
|
||||
'<script x="@" y="@">%</script>',
|
||||
position.x,
|
||||
position.y,
|
||||
position.x / scale,
|
||||
position.y / scale,
|
||||
this.toXML(serializer)
|
||||
);
|
||||
}
|
||||
|
@ -1613,12 +1619,13 @@ Context.prototype.toXML = function (serializer) {
|
|||
// Comments
|
||||
|
||||
CommentMorph.prototype.toXML = function (serializer) {
|
||||
var position;
|
||||
var position,
|
||||
scale = SyntaxElementMorph.prototype.scale;
|
||||
|
||||
if (this.block) { // attached to a block
|
||||
return serializer.format(
|
||||
'<comment w="@" collapsed="@">%</comment>',
|
||||
this.textWidth(),
|
||||
this.textWidth() / scale,
|
||||
this.isCollapsed,
|
||||
serializer.escape(this.text())
|
||||
);
|
||||
|
@ -1632,9 +1639,9 @@ CommentMorph.prototype.toXML = function (serializer) {
|
|||
}
|
||||
return serializer.format(
|
||||
'<comment x="@" y="@" w="@" collapsed="@">%</comment>',
|
||||
position.x,
|
||||
position.y,
|
||||
this.textWidth(),
|
||||
position.x / scale,
|
||||
position.y / scale,
|
||||
this.textWidth() / scale,
|
||||
this.isCollapsed,
|
||||
serializer.escape(this.text())
|
||||
);
|
||||
|
|
Ładowanie…
Reference in New Issue