From 06d35dae6c6810c3db369b0cf6902c1af3e6f956 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Wed, 17 Apr 2013 17:28:49 +0200 Subject: Export picture of all scripts * new entry in the ScriptsMorph's userMenu lets you export a picture of all scripts, including comments. * place sticky comments on World layer on dragging their anchor block, fixes both #8 and #18 * additional settings for developing the backend --- blocks.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'blocks.js') diff --git a/blocks.js b/blocks.js index 061e176..b77a369 100644 --- a/blocks.js +++ b/blocks.js @@ -153,7 +153,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2013-April-05'; +modules.blocks = '2013-April-17'; var SyntaxElementMorph; var BlockMorph; @@ -4285,6 +4285,11 @@ ScriptsMorph.prototype.userMenu = function () { } menu.addItem('clean up', 'cleanUp', 'arrange scripts\nvertically'); menu.addItem('add comment', 'addComment'); + menu.addItem( + 'scripts pic...', + 'exportScriptsPicture', + 'open a new window\nwith a picture of all scripts' + ); if (ide) { menu.addLine(); menu.addItem( @@ -4343,6 +4348,29 @@ ScriptsMorph.prototype.cleanUp = function () { this.adjustBounds(); }; +ScriptsMorph.prototype.exportScriptsPicture = function () { + var boundingBox, pic, ctx; + if (this.children.length === 0) {return; } + boundingBox = this.children[0].fullBounds(); + this.children.forEach(function (child) { + if (child.isVisible) { + boundingBox = boundingBox.merge(child.fullBounds()); + } + }); + pic = newCanvas(boundingBox.extent()); + ctx = pic.getContext('2d'); + this.children.forEach(function (child) { + var pos = child.position(); + if (child.isVisible) { + ctx.drawImage( + child.fullImageClassic(), + pos.x - boundingBox.origin.x, + pos.y - boundingBox.origin.y + ); + } + }); + window.open(pic.toDataURL()); +}; ScriptsMorph.prototype.addComment = function () { new CommentMorph().pickUp(this.world()); @@ -9057,6 +9085,7 @@ CommentMorph.prototype.align = function (topBlock, ignoreLayer) { CommentMorph.prototype.startFollowing = function (topBlock) { var myself = this; this.align(topBlock); + this.world().add(this); this.addShadow(); this.stickyOffset = this.position().subtract(this.block.position()); this.step = function () { -- cgit v1.3.1