mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-20 18:09:43 -04:00
Improve rendering speed.
This commit is contained in:
parent
3e893da239
commit
aa5afd18f6
5 changed files with 43 additions and 14 deletions
|
@ -849,8 +849,8 @@ Blockly.Comment.prototype.setVisible=function(a){if(a!=this.isVisible())if(!this
|
|||
this.foreignObject_=this.textarea_=this.bubble_=null);this.setText(b);this.setBubbleSize(c.width,c.height)}};Blockly.Comment.prototype.textareaFocus_=function(a){this.bubble_.promote_();this.textarea_.focus()};Blockly.Comment.prototype.getBubbleSize=function(){return this.isVisible()?this.bubble_.getBubbleSize():{width:this.width_,height:this.height_}};Blockly.Comment.prototype.setBubbleSize=function(a,b){this.textarea_?this.bubble_.setBubbleSize(a,b):(this.width_=a,this.height_=b)};
|
||||
Blockly.Comment.prototype.getText=function(){return this.textarea_?this.textarea_.value:this.text_};Blockly.Comment.prototype.setText=function(a){this.textarea_?this.textarea_.value=a:this.text_=a};Blockly.Comment.prototype.dispose=function(){this.block_.comment=null;Blockly.Icon.prototype.dispose.call(this)};
|
||||
// Copyright 2011 Google Inc. Apache License 2.0
|
||||
Blockly.Connection=function(a,b){this.sourceBlock_=a;this.targetConnection=null;this.type=b;this.y_=this.x_=0;this.inDB_=!1;this.dbList_=this.sourceBlock_.workspace.connectionDBList};
|
||||
Blockly.Connection.prototype.dispose=function(){if(this.targetConnection)throw"Disconnect connection before disposing of it.";this.inDB_&&(this.dbList_[this.type].removeConnection_(this),this.inDB_=!1);Blockly.highlightedConnection_==this&&(Blockly.highlightedConnection_=null);Blockly.localConnection_==this&&(Blockly.localConnection_=null)};Blockly.Connection.prototype.isSuperior=function(){return this.type==Blockly.INPUT_VALUE||this.type==Blockly.NEXT_STATEMENT};
|
||||
Blockly.Connection=function(a,b){this.sourceBlock_=a;this.targetConnection=null;this.type=b;this.y_=this.x_=0;this.dbList_=a.workspace.connectionDBList;this.hidden_=!this.dbList_;this.inDB_=!1};
|
||||
Blockly.Connection.prototype.dispose=function(){if(this.targetConnection)throw"Disconnect connection before disposing of it.";this.inDB_&&this.dbList_[this.type].removeConnection_(this);Blockly.highlightedConnection_==this&&(Blockly.highlightedConnection_=null);Blockly.localConnection_==this&&(Blockly.localConnection_=null)};Blockly.Connection.prototype.isSuperior=function(){return this.type==Blockly.INPUT_VALUE||this.type==Blockly.NEXT_STATEMENT};
|
||||
Blockly.Connection.prototype.connect=function(a){if(this.sourceBlock_==a.sourceBlock_)throw"Attempted to connect a block to itself.";if(this.sourceBlock_.workspace!==a.sourceBlock_.workspace)throw"Blocks are on different workspaces.";if(Blockly.OPPOSITE_TYPE[this.type]!=a.type)throw"Attempt to connect incompatible types.";if(this.type==Blockly.INPUT_VALUE||this.type==Blockly.OUTPUT_VALUE){if(this.targetConnection)throw"Source connection already connected (value).";if(a.targetConnection){var b=a.targetBlock();
|
||||
b.setParent(null);if(!b.outputConnection)throw"Orphan block does not have an output connection.";for(var c=this.sourceBlock_;c=Blockly.Connection.singleConnection_(c,b);)if(c.targetBlock())c=c.targetBlock();else{c.connect(b.outputConnection);b=null;break}b&&setTimeout(function(){b.outputConnection.bumpAwayFrom_(a)},Blockly.BUMP_DELAY)}}else{if(this.targetConnection)throw"Source connection already connected (block).";if(a.targetConnection){if(this.type!=Blockly.PREVIOUS_STATEMENT)throw"Can only do a mid-stack connection with the top of a block.";
|
||||
b=a.targetBlock();b.setParent(null);if(!b.previousConnection)throw"Orphan block does not have a previous connection.";for(c=this.sourceBlock_;c.nextConnection;)if(c.nextConnection.targetConnection)c=c.getNextBlock();else{b.previousConnection.checkType_(c.nextConnection)&&(c.nextConnection.connect(b.previousConnection),b=null);break}b&&setTimeout(function(){b.previousConnection.bumpAwayFrom_(a)},Blockly.BUMP_DELAY)}}var d;this.isSuperior()?(c=this.sourceBlock_,d=a.sourceBlock_):(c=a.sourceBlock_,d=
|
||||
|
@ -858,7 +858,7 @@ this.sourceBlock_);this.targetConnection=a;a.targetConnection=this;d.setParent(c
|
|||
Blockly.Connection.prototype.disconnect=function(){var a=this.targetConnection;if(!a)throw"Source connection not connected.";if(a.targetConnection!=this)throw"Target connection not connected to source connection.";this.targetConnection=a.targetConnection=null;var b;this.isSuperior()?(b=this.sourceBlock_,a=a.sourceBlock_):(b=a.sourceBlock_,a=this.sourceBlock_);b.rendered&&b.render();a.rendered&&(a.updateDisabled(),a.render())};
|
||||
Blockly.Connection.prototype.targetBlock=function(){return this.targetConnection?this.targetConnection.sourceBlock_:null};
|
||||
Blockly.Connection.prototype.bumpAwayFrom_=function(a){if(0==Blockly.dragMode_){var b=this.sourceBlock_.getRootBlock();if(!b.isInFlyout){var c=!1;if(!b.isMovable()){b=a.sourceBlock_.getRootBlock();if(!b.isMovable())return;a=this;c=!0}b.getSvgRoot().parentNode.appendChild(b.getSvgRoot());var d=a.x_+Blockly.SNAP_RADIUS-this.x_;a=a.y_+Blockly.SNAP_RADIUS-this.y_;c&&(a=-a);Blockly.RTL&&(d=-d);b.moveBy(d,a)}}};
|
||||
Blockly.Connection.prototype.moveTo=function(a,b){this.inDB_&&this.dbList_[this.type].removeConnection_(this);this.x_=a;this.y_=b;this.dbList_&&this.dbList_[this.type].addConnection_(this)};Blockly.Connection.prototype.moveBy=function(a,b){this.moveTo(this.x_+a,this.y_+b)};
|
||||
Blockly.Connection.prototype.moveTo=function(a,b){this.inDB_&&this.dbList_[this.type].removeConnection_(this);this.x_=a;this.y_=b;this.hidden_||this.dbList_[this.type].addConnection_(this)};Blockly.Connection.prototype.moveBy=function(a,b){this.moveTo(this.x_+a,this.y_+b)};Blockly.Connection.prototype.setHidden=function(a){(this.hidden_=a)&&this.inDB_?this.dbList_[this.type].removeConnection_(this):a||this.inDB_||this.dbList_[this.type].addConnection_(this)};
|
||||
Blockly.Connection.prototype.highlight=function(){var a;this.type==Blockly.INPUT_VALUE||this.type==Blockly.OUTPUT_VALUE?(a=Blockly.RTL?-Blockly.BlockSvg.TAB_WIDTH:Blockly.BlockSvg.TAB_WIDTH,a="m 0,0 v 5 c 0,10 "+-a+",-8 "+-a+",7.5 s "+a+",-2.5 "+a+",7.5 v 5"):a=Blockly.RTL?"m 20,0 h -5 "+Blockly.BlockSvg.NOTCH_PATH_RIGHT+" h -5":"m -20,0 h 5 "+Blockly.BlockSvg.NOTCH_PATH_LEFT+" h 5";var b=this.sourceBlock_.getRelativeToSurfaceXY();Blockly.Connection.highlightedPath_=Blockly.createSvgElement("path",
|
||||
{"class":"blocklyHighlightedConnectionPath",d:a,transform:"translate("+(this.x_-b.x)+", "+(this.y_-b.y)+")"},this.sourceBlock_.getSvgRoot())};Blockly.Connection.prototype.unhighlight=function(){goog.dom.removeNode(Blockly.Connection.highlightedPath_);delete Blockly.Connection.highlightedPath_};
|
||||
Blockly.Connection.prototype.tighten_=function(){var a=Math.round(this.targetConnection.x_-this.x_),b=Math.round(this.targetConnection.y_-this.y_);if(0!=a||0!=b){var c=this.targetBlock(),d=c.getSvgRoot();if(!d)throw"block is not rendered.";d=Blockly.getRelativeXY_(d);c.getSvgRoot().setAttribute("transform","translate("+(d.x-a)+", "+(d.y-b)+")");c.moveConnections_(-a,-b)}};
|
||||
|
@ -867,7 +867,7 @@ f=this.x_+b,g=this.y_+c;b=0;for(var h=c=e.length-2;b<h;)e[h].y_<g?b=h:c=h,h=Math
|
|||
Blockly.Connection.prototype.setCheck=function(a){a?(goog.isArray(a)||(a=[a]),this.check_=a,this.targetConnection&&!this.checkType_(this.targetConnection)&&(this.isSuperior()?this.targetBlock().setParent(null):this.sourceBlock_.setParent(null),this.sourceBlock_.bumpNeighbours_())):this.check_=null;return this};
|
||||
Blockly.Connection.prototype.neighbours_=function(a){function b(b){var f=d-c[b].x_,g=e-c[b].y_;Math.sqrt(f*f+g*g)<=a&&k.push(c[b]);return g<a}for(var c=this.dbList_[Blockly.OPPOSITE_TYPE[this.type]],d=this.x_,e=this.y_,f=0,g=c.length-2,h=g;f<h;)c[h].y_<e?f=h:g=h,h=Math.floor((f+g)/2);var g=f=h,k=[];if(c.length){for(;0<=f&&b(f);)f--;do g++;while(g<c.length&&b(g))}return k};
|
||||
Blockly.Connection.prototype.hideAll=function(){this.inDB_&&this.dbList_[this.type].removeConnection_(this);if(this.targetConnection)for(var a=this.targetBlock().getDescendants(),b=0;b<a.length;b++){for(var c=a[b],d=c.getConnections_(!0),e=0;e<d.length;e++){var f=d[e];f.inDB_&&this.dbList_[f.type].removeConnection_(f)}c=c.getIcons();for(d=0;d<c.length;d++)c[d].setVisible(!1)}};
|
||||
Blockly.Connection.prototype.unhideAll=function(){this.inDB_||this.dbList_[this.type].addConnection_(this);var a=[];if(this.type!=Blockly.INPUT_VALUE&&this.type!=Blockly.NEXT_STATEMENT)return a;var b=this.targetBlock();if(b){var c;b.isCollapsed()?(c=[],b.outputConnection&&c.push(b.outputConnection),b.nextConnection&&c.push(b.nextConnection),b.previousConnection&&c.push(b.previousConnection)):c=b.getConnections_(!0);for(var d=0;d<c.length;d++)a.push.apply(a,c[d].unhideAll());0==a.length&&(a[0]=b)}return a};
|
||||
Blockly.Connection.prototype.unhideAll=function(){this.hidden_||this.dbList_[this.type].addConnection_(this);var a=[];if(this.type!=Blockly.INPUT_VALUE&&this.type!=Blockly.NEXT_STATEMENT)return a;var b=this.targetBlock();if(b){var c;b.isCollapsed()?(c=[],b.outputConnection&&c.push(b.outputConnection),b.nextConnection&&c.push(b.nextConnection),b.previousConnection&&c.push(b.previousConnection)):c=b.getConnections_(!0);for(var d=0;d<c.length;d++)a.push.apply(a,c[d].unhideAll());0==a.length&&(a[0]=b)}return a};
|
||||
Blockly.ConnectionDB=function(){};Blockly.ConnectionDB.prototype=[];Blockly.ConnectionDB.constructor=Blockly.ConnectionDB;Blockly.ConnectionDB.prototype.addConnection_=function(a){if(a.inDB_)throw"Connection already in database.";for(var b=0,c=this.length;b<c;){var d=Math.floor((b+c)/2);if(this[d].y_<a.y_)b=d+1;else if(this[d].y_>a.y_)c=d;else{b=d;break}}this.splice(b,0,a);a.inDB_=!0};
|
||||
Blockly.ConnectionDB.prototype.removeConnection_=function(a){if(!a.inDB_)throw"Connection not in database.";a.inDB_=!1;for(var b=0,c=this.length-2,d=c;b<d;)this[d].y_<a.y_?b=d:c=d,d=Math.floor((b+c)/2);for(c=b=d;0<=b&&this[b].y_==a.y_;){if(this[b]==a){this.splice(b,1);return}b--}do{if(this[c]==a){this.splice(c,1);return}c++}while(c<this.length&&this[c].y_==a.y_);throw"Unable to find connection in connectionDB.";};
|
||||
Blockly.ConnectionDB.init=function(a){var b=[];b[Blockly.INPUT_VALUE]=new Blockly.ConnectionDB;b[Blockly.OUTPUT_VALUE]=new Blockly.ConnectionDB;b[Blockly.NEXT_STATEMENT]=new Blockly.ConnectionDB;b[Blockly.PREVIOUS_STATEMENT]=new Blockly.ConnectionDB;a.connectionDBList=b};
|
||||
|
@ -942,7 +942,7 @@ b.setAttribute("collapsed",!0);a.disabled&&b.setAttribute("disabled",!0);a.isDel
|
|||
Blockly.Xml.domToPrettyText=function(a){a=Blockly.Xml.domToText(a).split("<");for(var b="",c=1;c<a.length;c++){var d=a[c];"/"==d[0]&&(b=b.substring(2));a[c]=b+"<"+d;"/"!=d[0]&&"/>"!=d.slice(-2)&&(b+=" ")}a=a.join("\n");a=a.replace(/(<(\w+)\b[^>]*>[^\n]*)\n *<\/\2>/g,"$1</$2>");return a.replace(/^\n/,"")};
|
||||
Blockly.Xml.textToDom=function(a){a=(new DOMParser).parseFromString(a,"text/xml");if(!a||!a.firstChild||"xml"!=a.firstChild.nodeName.toLowerCase()||a.firstChild!==a.lastChild)throw"Blockly.Xml.textToDom did not obtain a valid XML tree.";return a.firstChild};
|
||||
Blockly.Xml.domToWorkspace=function(a,b){var c;Blockly.RTL&&(c=a.getWidth());for(var d=0,e;e=b.childNodes[d];d++)if("block"==e.nodeName.toLowerCase()){var f=Blockly.Xml.domToBlock(a,e),g=parseInt(e.getAttribute("x"),10);e=parseInt(e.getAttribute("y"),10);isNaN(g)||isNaN(e)||f.moveBy(Blockly.RTL?c-g:g,e)}};
|
||||
Blockly.Xml.domToBlock=function(a,b,c){b=Blockly.Xml.domToBlockHeadless_(a,b,c);if(a.rendered){a=b.getDescendants();for(c=a.length-1;0<=c;c--)a[c].initSvg();for(c=a.length-1;0<=c;c--)a[c].render(!1);b.updateDisabled();Blockly.fireUiEvent(window,"resize")}return b};
|
||||
Blockly.Xml.domToBlock=function(a,b,c){b=Blockly.Xml.domToBlockHeadless_(a,b,c);if(a.rendered){a=b.getDescendants();for(c=a.length-1;0<=c;c--)a[c].setConnectionsHidden(!0),a[c].initSvg();for(c=a.length-1;0<=c;c--)a[c].render(!1);for(c=a.length-1;0<=c;c--)a[c].setConnectionsHidden(!1);b.updateDisabled();Blockly.fireUiEvent(window,"resize")}return b};
|
||||
Blockly.Xml.domToBlockHeadless_=function(a,b,c){var d=null,e=b.getAttribute("type");if(!e)throw"Block type unspecified: \n"+b.outerHTML;var f=b.getAttribute("id");if(c&&f){d=Blockly.Block.getById(f,a);if(!d)throw"Couldn't get Block with id: "+f;f=d.getParent();d.workspace&&d.dispose(!0,!1,!0);d.fill(a,e);d.parent_=f}else d=Blockly.Block.obtain(a,e);for(var g=null,f=0,h;h=b.childNodes[f];f++)if(3!=h.nodeType||!h.data.match(/^\s*$/)){for(var g=null,k=0,l;l=h.childNodes[k];k++)3==l.nodeType&&l.data.match(/^\s*$/)||
|
||||
(g=l);k=h.getAttribute("name");switch(h.nodeName.toLowerCase()){case "mutation":d.domToMutation&&(d.domToMutation(h),d.initSvg&&d.initSvg());break;case "comment":d.setCommentText(h.textContent);var p=h.getAttribute("pinned");p&&setTimeout(function(){d.comment&&d.comment.setVisible&&d.comment.setVisible("true"==p)},1);g=parseInt(h.getAttribute("w"),10);h=parseInt(h.getAttribute("h"),10);!isNaN(g)&&!isNaN(h)&&d.comment&&d.comment.setVisible&&d.comment.setBubbleSize(g,h);break;case "title":case "field":d.setFieldValue(h.textContent,
|
||||
k);break;case "value":case "statement":h=d.getInput(k);if(!h)throw"Input "+k+" does not exist in block "+e;if(g&&"block"==g.nodeName.toLowerCase())if(g=Blockly.Xml.domToBlockHeadless_(a,g,c),g.outputConnection)h.connection.connect(g.outputConnection);else if(g.previousConnection)h.connection.connect(g.previousConnection);else throw"Child block does not have output or previous statement.";break;case "next":if(g&&"block"==g.nodeName.toLowerCase()){if(!d.nextConnection)throw"Next statement does not exist.";
|
||||
|
@ -993,9 +993,10 @@ Blockly.Block.prototype.bumpNeighbours_=function(){if(0==Blockly.dragMode_){var
|
|||
Blockly.Block.prototype.getSurroundParent=function(){for(var a=this;;){do{var b=a,a=a.getParent();if(!a)return null}while(a.getNextBlock()==b);return a}};Blockly.Block.prototype.getNextBlock=function(){return this.nextConnection&&this.nextConnection.targetBlock()};Blockly.Block.prototype.getRootBlock=function(){var a,b=this;do a=b,b=a.parentBlock_;while(b);return a};Blockly.Block.prototype.getChildren=function(){return this.childBlocks_};
|
||||
Blockly.Block.prototype.setParent=function(a){if(this.parentBlock_){for(var b=this.parentBlock_.childBlocks_,c,d=0;c=b[d];d++)if(c==this){b.splice(d,1);break}this.parentBlock_=null;this.previousConnection&&this.previousConnection.targetConnection&&this.previousConnection.disconnect();this.outputConnection&&this.outputConnection.targetConnection&&this.outputConnection.disconnect()}else goog.array.contains(this.workspace.getTopBlocks(!1),this)&&this.workspace.removeTopBlock(this);(this.parentBlock_=
|
||||
a)?a.childBlocks_.push(this):this.workspace.addTopBlock(this)};Blockly.Block.prototype.getDescendants=function(){for(var a=[this],b,c=0;b=this.childBlocks_[c];c++)a.push.apply(a,b.getDescendants());return a};Blockly.Block.prototype.isDeletable=function(){return this.deletable_&&!Blockly.readOnly};Blockly.Block.prototype.setDeletable=function(a){this.deletable_=a;this.svg_&&this.svg_.updateMovable()};Blockly.Block.prototype.isMovable=function(){return this.movable_&&!Blockly.readOnly};
|
||||
Blockly.Block.prototype.setMovable=function(a){this.movable_=a};Blockly.Block.prototype.isEditable=function(){return this.editable_&&!Blockly.readOnly};Blockly.Block.prototype.setEditable=function(a){this.editable_=a;a=0;for(var b;b=this.inputList[a];a++)for(var c=0,d;d=b.fieldRow[c];c++)d.updateEditable();b=this.getIcons();for(a=0;a<b.length;a++)b[a].updateEditable()};Blockly.Block.prototype.setHelpUrl=function(a){this.helpUrl=a};Blockly.Block.prototype.setTooltip=function(a){this.tooltip=a};
|
||||
Blockly.Block.prototype.getColour=function(){return this.colourHue_};Blockly.Block.prototype.setColour=function(a){this.colourHue_=a;this.rendered&&this.updateColour()};Blockly.Block.prototype.getField_=function(a){for(var b=0,c;c=this.inputList[b];b++)for(var d=0,e;e=c.fieldRow[d];d++)if(e.name===a)return e;return null};Blockly.Block.prototype.getFieldValue=function(a){return(a=this.getField_(a))?a.getValue():null};
|
||||
Blockly.Block.prototype.getTitleValue=function(a){console.log("Deprecated call to getTitleValue, use getFieldValue instead.");return this.getFieldValue(a)};Blockly.Block.prototype.setFieldValue=function(a,b){var c=this.getField_(b);goog.asserts.assertObject(c,'Field "%s" not found.',b);c.setValue(a)};Blockly.Block.prototype.setTitleValue=function(a,b){console.log("Deprecated call to setTitleValue, use setFieldValue instead.");this.setFieldValue(a,b)};
|
||||
Blockly.Block.prototype.setMovable=function(a){this.movable_=a};Blockly.Block.prototype.isEditable=function(){return this.editable_&&!Blockly.readOnly};Blockly.Block.prototype.setEditable=function(a){this.editable_=a;a=0;for(var b;b=this.inputList[a];a++)for(var c=0,d;d=b.fieldRow[c];c++)d.updateEditable();b=this.getIcons();for(a=0;a<b.length;a++)b[a].updateEditable()};Blockly.Block.prototype.setConnectionsHidden=function(a){for(var b=this.getConnections_(!0),c=0,d;d=b[c];c++)d.setHidden(a)};
|
||||
Blockly.Block.prototype.setHelpUrl=function(a){this.helpUrl=a};Blockly.Block.prototype.setTooltip=function(a){this.tooltip=a};Blockly.Block.prototype.getColour=function(){return this.colourHue_};Blockly.Block.prototype.setColour=function(a){this.colourHue_=a;this.rendered&&this.updateColour()};Blockly.Block.prototype.getField_=function(a){for(var b=0,c;c=this.inputList[b];b++)for(var d=0,e;e=c.fieldRow[d];d++)if(e.name===a)return e;return null};
|
||||
Blockly.Block.prototype.getFieldValue=function(a){return(a=this.getField_(a))?a.getValue():null};Blockly.Block.prototype.getTitleValue=function(a){console.log("Deprecated call to getTitleValue, use getFieldValue instead.");return this.getFieldValue(a)};Blockly.Block.prototype.setFieldValue=function(a,b){var c=this.getField_(b);goog.asserts.assertObject(c,'Field "%s" not found.',b);c.setValue(a)};
|
||||
Blockly.Block.prototype.setTitleValue=function(a,b){console.log("Deprecated call to setTitleValue, use setFieldValue instead.");this.setFieldValue(a,b)};
|
||||
Blockly.Block.prototype.setPreviousStatement=function(a,b){this.previousConnection&&(goog.asserts.assert(!this.previousConnection.targetConnection,"Must disconnect previous statement before removing connection."),this.previousConnection.dispose(),this.previousConnection=null);a&&(goog.asserts.assert(!this.outputConnection,"Remove output connection prior to adding previous connection."),void 0===b&&(b=null),this.previousConnection=new Blockly.Connection(this,Blockly.PREVIOUS_STATEMENT),this.previousConnection.setCheck(b));
|
||||
this.rendered&&(this.render(),this.bumpNeighbours_())};Blockly.Block.prototype.setNextStatement=function(a,b){this.nextConnection&&(goog.asserts.assert(!this.nextConnection.targetConnection,"Must disconnect next statement before removing connection."),this.nextConnection.dispose(),this.nextConnection=null);a&&(void 0===b&&(b=null),this.nextConnection=new Blockly.Connection(this,Blockly.NEXT_STATEMENT),this.nextConnection.setCheck(b));this.rendered&&(this.render(),this.bumpNeighbours_())};
|
||||
Blockly.Block.prototype.setOutput=function(a,b){this.outputConnection&&(goog.asserts.assert(!this.outputConnection.targetConnection,"Must disconnect output value before removing connection."),this.outputConnection.dispose(),this.outputConnection=null);a&&(goog.asserts.assert(!this.previousConnection,"Remove previous connection prior to adding output connection."),void 0===b&&(b=null),this.outputConnection=new Blockly.Connection(this,Blockly.OUTPUT_VALUE),this.outputConnection.setCheck(b));this.rendered&&
|
||||
|
|
|
@ -512,6 +512,17 @@ Blockly.Block.prototype.setEditable = function(editable) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set whether the connections are hidden (not tracked in a database) or not.
|
||||
* @param {boolean} hidden True if connections are hidden.
|
||||
*/
|
||||
Blockly.Block.prototype.setConnectionsHidden = function(hidden) {
|
||||
var myConnections = this.getConnections_(true);
|
||||
for (var i = 0, connection; connection = myConnections[i]; i++) {
|
||||
connection.setHidden(hidden);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the URL of this block's help page.
|
||||
* @param {string|Function} url URL string for block help, or function that
|
||||
|
|
|
@ -40,9 +40,10 @@ Blockly.Connection = function(source, type) {
|
|||
this.type = type;
|
||||
this.x_ = 0;
|
||||
this.y_ = 0;
|
||||
this.inDB_ = false;
|
||||
// Shortcut for the databases for this connection's workspace.
|
||||
this.dbList_ = this.sourceBlock_.workspace.connectionDBList;
|
||||
this.dbList_ = source.workspace.connectionDBList;
|
||||
this.hidden_ = !this.dbList_;
|
||||
this.inDB_ = false;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -54,7 +55,6 @@ Blockly.Connection.prototype.dispose = function() {
|
|||
}
|
||||
if (this.inDB_) {
|
||||
this.dbList_[this.type].removeConnection_(this);
|
||||
this.inDB_ = false;
|
||||
}
|
||||
if (Blockly.highlightedConnection_ == this) {
|
||||
Blockly.highlightedConnection_ = null;
|
||||
|
@ -322,7 +322,7 @@ Blockly.Connection.prototype.moveTo = function(x, y) {
|
|||
this.x_ = x;
|
||||
this.y_ = y;
|
||||
// Insert it into its new location in the database.
|
||||
if (this.dbList_) {
|
||||
if (!this.hidden_) {
|
||||
this.dbList_[this.type].addConnection_(this);
|
||||
}
|
||||
};
|
||||
|
@ -336,6 +336,19 @@ Blockly.Connection.prototype.moveBy = function(dx, dy) {
|
|||
this.moveTo(this.x_ + dx, this.y_ + dy);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set whether this connections is hidden (not tracked in a database) or not.
|
||||
* @param {boolean} hidden True if connection is hidden.
|
||||
*/
|
||||
Blockly.Connection.prototype.setHidden = function(hidden) {
|
||||
this.hidden_ = hidden;
|
||||
if (hidden && this.inDB_) {
|
||||
this.dbList_[this.type].removeConnection_(this);
|
||||
} else if (!hidden && !this.inDB_) {
|
||||
this.dbList_[this.type].addConnection_(this);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add highlighting around this connection.
|
||||
*/
|
||||
|
@ -653,7 +666,7 @@ Blockly.Connection.prototype.hideAll = function() {
|
|||
* @return {!Array.<!Blockly.Block>} List of blocks to render.
|
||||
*/
|
||||
Blockly.Connection.prototype.unhideAll = function() {
|
||||
if (!this.inDB_) {
|
||||
if (!this.hidden_) {
|
||||
this.dbList_[this.type].addConnection_(this);
|
||||
}
|
||||
// All blocks that need unhiding must be unhidden before any rendering takes
|
||||
|
|
|
@ -248,11 +248,15 @@ Blockly.Xml.domToBlock = function(workspace, xmlBlock, opt_reuseBlock) {
|
|||
var blocks = topBlock.getDescendants();
|
||||
// Render each block.
|
||||
for (var i = blocks.length - 1; i >= 0; i--) {
|
||||
blocks[i].setConnectionsHidden(true);
|
||||
blocks[i].initSvg();
|
||||
}
|
||||
for (var i = blocks.length - 1; i >= 0; i--) {
|
||||
blocks[i].render(false);
|
||||
}
|
||||
for (var i = blocks.length - 1; i >= 0; i--) {
|
||||
blocks[i].setConnectionsHidden(false);
|
||||
}
|
||||
topBlock.updateDisabled();
|
||||
// Fire an event to allow scrollbars to resize.
|
||||
Blockly.fireUiEvent(window, 'resize');
|
||||
|
|
|
@ -439,7 +439,7 @@ h1 {
|
|||
<p>
|
||||
Stress test:
|
||||
<input type="button" value="Airstrike!" onclick="airstrike(100)">
|
||||
<input type="button" value="Spaghetti!" onclick="spaghetti(6)">
|
||||
<input type="button" value="Spaghetti!" onclick="spaghetti(8)">
|
||||
</p>
|
||||
|
||||
<!-- Realtime setup buttons. -->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue