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
jmoenig 2013-03-19 10:34:10 +01:00
rodzic b19493897d
commit 3f19a21cad
4 zmienionych plików z 51 dodań i 35 usunięć

Wyświetl plik

@ -8738,9 +8738,13 @@ CommentMorph.uber = BoxMorph.prototype;
// CommentMorph preferences settings (pseudo-inherited from SyntaxElement): // CommentMorph preferences settings (pseudo-inherited from SyntaxElement):
CommentMorph.prototype.fontSize = SyntaxElementMorph.prototype.fontSize; CommentMorph.prototype.refreshScale = function () {
CommentMorph.prototype.padding = 5; CommentMorph.prototype.fontSize = SyntaxElementMorph.prototype.fontSize;
CommentMorph.prototype.rounding = 8; CommentMorph.prototype.padding = 5 * SyntaxElementMorph.prototype.scale;
CommentMorph.prototype.rounding = 8 * SyntaxElementMorph.prototype.scale;
};
CommentMorph.prototype.refreshScale();
// CommentMorph instance creation: // CommentMorph instance creation:
@ -8749,13 +8753,14 @@ function CommentMorph(contents) {
} }
CommentMorph.prototype.init = function (contents) { CommentMorph.prototype.init = function (contents) {
var myself = this; var myself = this,
scale = SyntaxElementMorph.prototype.scale;
this.block = null; // optional anchor block this.block = null; // optional anchor block
this.stickyOffset = null; // not to be persisted this.stickyOffset = null; // not to be persisted
this.isCollapsed = false; this.isCollapsed = false;
this.titleBar = new BoxMorph( this.titleBar = new BoxMorph(
this.rounding, this.rounding,
1.000001, // shadow bug in Chrome, 1.000001 * scale, // shadow bug in Chrome,
new Color(255, 255, 180) new Color(255, 255, 180)
); );
this.titleBar.color = 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.isEditable = true;
this.contents.enableSelecting(); this.contents.enableSelecting();
this.contents.maxWidth = 90; this.contents.maxWidth = 90 * scale;
this.contents.drawNew(); this.contents.drawNew();
this.handle = new HandleMorph( this.handle = new HandleMorph(
this.contents, this.contents,
@ -8782,13 +8787,13 @@ CommentMorph.prototype.init = function (contents) {
-2, -2,
-2 -2
); );
this.handle.setExtent(new Point(11, 11)); this.handle.setExtent(new Point(11 * scale, 11 * scale));
this.anchor = null; this.anchor = null;
CommentMorph.uber.init.call( CommentMorph.uber.init.call(
this, this,
this.rounding, this.rounding,
1.000001, // shadow bug in Chrome, 1.000001 * scale, // shadow bug in Chrome,
new Color(255, 255, 180) new Color(255, 255, 180)
); );
this.color = new Color(255, 255, 220); this.color = new Color(255, 255, 220);

9
gui.js
Wyświetl plik

@ -64,11 +64,11 @@ standardSettings, Sound, BlockMorph, ToggleMorph, InputSlotDialogMorph,
ScriptsMorph, isNil, SymbolMorph, BlockExportDialogMorph, ScriptsMorph, isNil, SymbolMorph, BlockExportDialogMorph,
BlockImportDialogMorph, SnapTranslator, localize, List, InputSlotMorph, BlockImportDialogMorph, SnapTranslator, localize, List, InputSlotMorph,
SnapCloud, Uint8Array, HandleMorph, SVG_Costume, fontHeight, hex_sha512, SnapCloud, Uint8Array, HandleMorph, SVG_Costume, fontHeight, hex_sha512,
sb*/ sb, CommentMorph*/
// Global stuff //////////////////////////////////////////////////////// // Global stuff ////////////////////////////////////////////////////////
modules.gui = '2013-March-18'; modules.gui = '2013-March-19';
// Declarations // Declarations
@ -2787,9 +2787,11 @@ IDE_Morph.prototype.userSetBlocksScale = function () {
{ {
'normal (1)' : 1, 'normal (1)' : 1,
'demo (1.2)' : 1.2, 'demo (1.2)' : 1.2,
'presentation (1.4)' : 1.4,
'big (2)' : 2, 'big (2)' : 2,
'huge (4)' : 4, 'huge (4)' : 4,
'giant (8)' : 8 'giant (8)' : 8,
'monstrous (10)' : 10
}, },
false, // read only? false, // read only?
true // numeric true // numeric
@ -2808,6 +2810,7 @@ IDE_Morph.prototype.setBlocksScale = function (num) {
projectData = this.serializer.serialize(this.stage); projectData = this.serializer.serialize(this.stage);
} }
SyntaxElementMorph.prototype.setScale(num); SyntaxElementMorph.prototype.setScale(num);
CommentMorph.prototype.refreshScale();
SpriteMorph.prototype.initBlocks(); SpriteMorph.prototype.initBlocks();
this.spriteBar.tabBar.tabTo('scripts'); this.spriteBar.tabBar.tabTo('scripts');
this.createCategories(); this.createCategories();

Wyświetl plik

@ -1534,4 +1534,5 @@ ______
130319 130319
------ ------
* Blocks: SyntaxElementMorph fixLayout() optimization for active highlights * Blocks: SyntaxElementMorph fixLayout() optimization for active highlights
* Russian translation!! Yay, thanks, Svetlana Ptashnaya!! * Russian translation!! Yay, thanks, Svetlana Ptashnaya!!
* Store, GUI, Blocks: Scaling support for Comments and serialization/deserialization

Wyświetl plik

@ -56,11 +56,12 @@ detect, CustomCommandBlockMorph, CustomReporterBlockMorph, Color, List,
newCanvas, Costume, Sound, Audio, IDE_Morph, ScriptsMorph, BlockMorph, newCanvas, Costume, Sound, Audio, IDE_Morph, ScriptsMorph, BlockMorph,
ArgMorph, InputSlotMorph, TemplateSlotMorph, CommandSlotMorph, ArgMorph, InputSlotMorph, TemplateSlotMorph, CommandSlotMorph,
FunctionSlotMorph, MultiArgMorph, ColorSlotMorph, nop, CommentMorph, isNil, FunctionSlotMorph, MultiArgMorph, ColorSlotMorph, nop, CommentMorph, isNil,
localize, sizeOf, ArgLabelMorph, SVG_Costume, MorphicPreferences*/ localize, sizeOf, ArgLabelMorph, SVG_Costume, MorphicPreferences,
SyntaxElementMorph*/
// Global stuff //////////////////////////////////////////////////////// // Global stuff ////////////////////////////////////////////////////////
modules.store = '2013-March-14'; modules.store = '2013-March-19';
// XML_Serializer /////////////////////////////////////////////////////// // XML_Serializer ///////////////////////////////////////////////////////
@ -702,7 +703,8 @@ SnapSerializer.prototype.populateCustomBlocks = function (
SnapSerializer.prototype.loadScripts = function (scripts, model) { SnapSerializer.prototype.loadScripts = function (scripts, model) {
// private // private
var myself = this; var myself = this,
scale = SyntaxElementMorph.prototype.scale;
scripts.texture = 'scriptsPaneTexture.gif'; scripts.texture = 'scriptsPaneTexture.gif';
model.children.forEach(function (child) { model.children.forEach(function (child) {
var element; var element;
@ -712,8 +714,8 @@ SnapSerializer.prototype.loadScripts = function (scripts, model) {
return; return;
} }
element.setPosition(new Point( element.setPosition(new Point(
+child.attributes.x || 0, (+child.attributes.x || 0) * scale,
+child.attributes.y || 0 (+child.attributes.y || 0) * scale
).add(scripts.topLeft())); ).add(scripts.topLeft()));
scripts.add(element); scripts.add(element);
element.fixBlockColor(null, true); // force zebra coloring element.fixBlockColor(null, true); // force zebra coloring
@ -726,8 +728,8 @@ SnapSerializer.prototype.loadScripts = function (scripts, model) {
return; return;
} }
element.setPosition(new Point( element.setPosition(new Point(
+child.attributes.x || 0, (+child.attributes.x || 0) * scale,
+child.attributes.y || 0 (+child.attributes.y || 0) * scale
).add(scripts.topLeft())); ).add(scripts.topLeft()));
scripts.add(element); scripts.add(element);
} }
@ -737,6 +739,7 @@ SnapSerializer.prototype.loadScripts = function (scripts, model) {
SnapSerializer.prototype.loadScriptsArray = function (model) { SnapSerializer.prototype.loadScriptsArray = function (model) {
// private - answer an array containting the model's scripts // private - answer an array containting the model's scripts
var myself = this, var myself = this,
scale = SyntaxElementMorph.prototype.scale,
scripts = []; scripts = [];
model.children.forEach(function (child) { model.children.forEach(function (child) {
var element; var element;
@ -746,8 +749,8 @@ SnapSerializer.prototype.loadScriptsArray = function (model) {
return; return;
} }
element.setPosition(new Point( element.setPosition(new Point(
+child.attributes.x || 0, (+child.attributes.x || 0) * scale,
+child.attributes.y || 0 (+child.attributes.y || 0) * scale
)); ));
scripts.push(element); scripts.push(element);
element.fixBlockColor(null, true); // force zebra coloring element.fixBlockColor(null, true); // force zebra coloring
@ -757,8 +760,8 @@ SnapSerializer.prototype.loadScriptsArray = function (model) {
return; return;
} }
element.setPosition(new Point( element.setPosition(new Point(
+child.attributes.x || 0, (+child.attributes.x || 0) * scale,
+child.attributes.y || 0 (+child.attributes.y || 0) * scale
)); ));
scripts.push(element); scripts.push(element);
} }
@ -787,9 +790,10 @@ SnapSerializer.prototype.loadScript = function (model) {
SnapSerializer.prototype.loadComment = function (model) { SnapSerializer.prototype.loadComment = function (model) {
// private // private
var comment = new CommentMorph(model.contents); var comment = new CommentMorph(model.contents),
scale = SyntaxElementMorph.prototype.scale;
comment.isCollapsed = (model.attributes.collapsed === 'true'); comment.isCollapsed = (model.attributes.collapsed === 'true');
comment.setTextWidth(+model.attributes.w); comment.setTextWidth(+model.attributes.w * scale);
return comment; return comment;
}; };
@ -1369,6 +1373,7 @@ BlockMorph.prototype.toXML = BlockMorph.prototype.toScriptXML = function (
) { ) {
var position, var position,
xml, xml,
scale = SyntaxElementMorph.prototype.scale,
block = this; block = this;
// determine my position // determine my position
@ -1382,8 +1387,8 @@ BlockMorph.prototype.toXML = BlockMorph.prototype.toScriptXML = function (
if (savePosition) { if (savePosition) {
xml = serializer.format( xml = serializer.format(
'<script x="@" y="@">', '<script x="@" y="@">',
position.x, position.x / scale,
position.y position.y / scale
); );
} else { } else {
xml = '<script>'; xml = '<script>';
@ -1418,7 +1423,8 @@ ReporterBlockMorph.prototype.toScriptXML = function (
serializer, serializer,
savePosition savePosition
) { ) {
var position; var position,
scale = SyntaxElementMorph.prototype.scale;
// determine my save-position // determine my save-position
if (this.parent) { if (this.parent) {
@ -1430,8 +1436,8 @@ ReporterBlockMorph.prototype.toScriptXML = function (
if (savePosition) { if (savePosition) {
return serializer.format( return serializer.format(
'<script x="@" y="@">%</script>', '<script x="@" y="@">%</script>',
position.x, position.x / scale,
position.y, position.y / scale,
this.toXML(serializer) this.toXML(serializer)
); );
} }
@ -1613,12 +1619,13 @@ Context.prototype.toXML = function (serializer) {
// Comments // Comments
CommentMorph.prototype.toXML = function (serializer) { CommentMorph.prototype.toXML = function (serializer) {
var position; var position,
scale = SyntaxElementMorph.prototype.scale;
if (this.block) { // attached to a block if (this.block) { // attached to a block
return serializer.format( return serializer.format(
'<comment w="@" collapsed="@">%</comment>', '<comment w="@" collapsed="@">%</comment>',
this.textWidth(), this.textWidth() / scale,
this.isCollapsed, this.isCollapsed,
serializer.escape(this.text()) serializer.escape(this.text())
); );
@ -1632,9 +1639,9 @@ CommentMorph.prototype.toXML = function (serializer) {
} }
return serializer.format( return serializer.format(
'<comment x="@" y="@" w="@" collapsed="@">%</comment>', '<comment x="@" y="@" w="@" collapsed="@">%</comment>',
position.x, position.x / scale,
position.y, position.y / scale,
this.textWidth(), this.textWidth() / scale,
this.isCollapsed, this.isCollapsed,
serializer.escape(this.text()) serializer.escape(this.text())
); );