Vertical demo blocks

* Implement example text-based vertical blocks

* Add vertical FIELD_TOP_PADDING (fix )

* Make MAX_DISPLAY_LENGTH per horizontal/vertical

Fixes 

* Vertical dark mode and playground disclaimer

* Remove generator reference from vertical demo
This commit is contained in:
Tim Mickel 2016-05-05 16:13:43 -04:00
parent cef7a3893e
commit f212b10870
9 changed files with 431 additions and 47 deletions

View file

@ -946,7 +946,7 @@ Blockly.Connection.prototype.closest=function(a,b,c){return this.dbOpposite_.sea
Blockly.Connection.prototype.setCheck=function(a){a?(goog.isArray(a)||(a=[a]),this.check_=a,this.isConnected()&&!this.checkType_(this.targetConnection)&&((this.isSuperior()?this.targetBlock():this.sourceBlock_).unplug(),this.sourceBlock_.bumpNeighbours_())):this.check_=null;return this};
Blockly.Connection.prototype.getOutputShape=function(){return this.check_?-1!==this.check_.indexOf("Boolean")?Blockly.Connection.BOOLEAN:-1!==this.check_.indexOf("String")?Blockly.Connection.STRING:Blockly.Connection.NUMBER:Blockly.Connection.NUMBER};Blockly.Connection.prototype.setShadowDom=function(a){this.shadowDom_=a};Blockly.Connection.prototype.getShadowDom=function(){return this.shadowDom_};Blockly.Connection.prototype.neighbours_=function(a){return this.dbOpposite_.getNeighbours(this,a)};
Blockly.Connection.prototype.setHidden=function(a){(this.hidden_=a)&&this.inDB_?this.db_.removeConnection_(this):a||this.inDB_||this.db_.addConnection(this)};Blockly.Connection.prototype.hideAll=function(){this.setHidden(!0);if(this.isConnected())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++)d[e].setHidden(!0);c=c.getIcons();for(d=0;d<c.length;d++)c[d].setVisible(!1)}};
Blockly.Connection.prototype.unhideAll=function(){this.setHidden(!1);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());a.length||(a[0]=b)}return a};Blockly.Field=function(a,b){this.size_=new goog.math.Size(Blockly.BlockSvg.FIELD_WIDTH,Blockly.BlockSvg.FIELD_HEIGHT);this.setValue(a);this.setValidator(b)};Blockly.Field.cacheWidths_=null;Blockly.Field.cacheReference_=0;Blockly.Field.prototype.name=void 0;Blockly.Field.prototype.maxDisplayLength=4;Blockly.Field.prototype.text_="";Blockly.Field.prototype.sourceBlock_=null;Blockly.Field.prototype.visible_=!0;Blockly.Field.prototype.validator_=null;Blockly.Field.NBSP="\u00a0";
Blockly.Connection.prototype.unhideAll=function(){this.setHidden(!1);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());a.length||(a[0]=b)}return a};Blockly.Field=function(a,b){this.size_=new goog.math.Size(Blockly.BlockSvg.FIELD_WIDTH,Blockly.BlockSvg.FIELD_HEIGHT);this.setValue(a);this.setValidator(b);this.maxDisplayLength=Blockly.BlockSvg.MAX_DISPLAY_LENGTH};Blockly.Field.cacheWidths_=null;Blockly.Field.cacheReference_=0;Blockly.Field.prototype.name=void 0;Blockly.Field.prototype.text_="";Blockly.Field.prototype.sourceBlock_=null;Blockly.Field.prototype.visible_=!0;Blockly.Field.prototype.validator_=null;Blockly.Field.NBSP="\u00a0";
Blockly.Field.prototype.EDITABLE=!0;
Blockly.Field.prototype.init=function(a){this.sourceBlock_||(this.sourceBlock_=a,this.fieldGroup_=Blockly.createSvgElement("g",{},null),this.visible_||(this.fieldGroup_.style.display="none"),this.textElement_=Blockly.createSvgElement("text",{"class":"blocklyText",x:this.sourceBlock_.RTL?-this.size_.width/2:this.size_.width/2,y:this.size_.height/2+Blockly.BlockSvg.FIELD_TOP_PADDING,"text-anchor":"middle"},this.fieldGroup_),this.updateEditable(),a.getSvgRoot().appendChild(this.fieldGroup_),this.mouseUpWrapper_=
Blockly.bindEvent_(this.getClickTarget_(),"mouseup",this,this.onMouseUp_),this.updateTextNode_(),Blockly.Events.isEnabled()&&Blockly.Events.fire(new Blockly.Events.Change(this.sourceBlock_,"field",this.name,"",this.getValue())))};Blockly.Field.prototype.dispose=function(){this.mouseUpWrapper_&&(Blockly.unbindEvent_(this.mouseUpWrapper_),this.mouseUpWrapper_=null);this.sourceBlock_=null;goog.dom.removeNode(this.fieldGroup_);this.validator_=this.textElement_=this.fieldGroup_=null};
@ -1213,7 +1213,7 @@ Blockly.BlockSvg.prototype.appendInput_=function(a,b){var c=Blockly.BlockSvg.sup
Blockly.BlockSvg.FIELD_HEIGHT_MAX_EDIT=10*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_TOP_PADDING=1.5*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.NUMBER_FIELD_CORNER_RADIUS=4*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.TEXT_FIELD_CORNER_RADIUS=1*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_DEFAULT_CORNER_RADIUS=4*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.MIN_BLOCK_X=8*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.MIN_BLOCK_Y=16*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.TAB_WIDTH=2*Blockly.BlockSvg.GRID_UNIT;
Blockly.BlockSvg.CORNER_RADIUS=1*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.HAT_CORNER_RADIUS=8*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.NOTCH_HEIGHT=8*Blockly.BlockSvg.GRID_UNIT+2;Blockly.BlockSvg.NOTCH_WIDTH=2*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.NOTCH_PATH_DOWN="c 0,2 1,3 2,4 l 4,4 c 1,1 2,2 2,4 v 12 c 0,2 -1,3 -2,4 l -4,4 c -1,1 -2,2 -2,4";Blockly.BlockSvg.NOTCH_PATH_UP="c 0,-2 1,-3 2,-4 l 4,-4 c 1,-1 2,-2 2,-4 v -12 c 0,-2 -1,-3 -2,-4 l -4,-4 c -1,-1 -2,-2 -2,-4";
Blockly.BlockSvg.IMAGE_FIELD_WIDTH=10*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.IMAGE_FIELD_HEIGHT=10*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_Y_OFFSET=-2*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.TOP_LEFT_CORNER_START="m "+Blockly.BlockSvg.CORNER_RADIUS+",0";Blockly.BlockSvg.TOP_LEFT_CORNER="A "+Blockly.BlockSvg.CORNER_RADIUS+","+Blockly.BlockSvg.CORNER_RADIUS+" 0 0,0 0,"+Blockly.BlockSvg.CORNER_RADIUS;
Blockly.BlockSvg.HAT_TOP_LEFT_CORNER_START="m "+Blockly.BlockSvg.HAT_CORNER_RADIUS+",0";Blockly.BlockSvg.HAT_TOP_LEFT_CORNER="A "+Blockly.BlockSvg.HAT_CORNER_RADIUS+","+Blockly.BlockSvg.HAT_CORNER_RADIUS+" 0 0,0 0,"+Blockly.BlockSvg.HAT_CORNER_RADIUS;Blockly.BlockSvg.renderingMetrics_=null;
Blockly.BlockSvg.HAT_TOP_LEFT_CORNER_START="m "+Blockly.BlockSvg.HAT_CORNER_RADIUS+",0";Blockly.BlockSvg.HAT_TOP_LEFT_CORNER="A "+Blockly.BlockSvg.HAT_CORNER_RADIUS+","+Blockly.BlockSvg.HAT_CORNER_RADIUS+" 0 0,0 0,"+Blockly.BlockSvg.HAT_CORNER_RADIUS;Blockly.BlockSvg.renderingMetrics_=null;Blockly.BlockSvg.MAX_DISPLAY_LENGTH=4;
Blockly.BlockSvg.metricsAreEquivalent_=function(a,b){return a.statement!=b.statement||a.imageField!=b.imageField||a.height!=b.height||a.width!=b.width||a.bayHeight!=b.bayHeight||a.bayWidth!=b.bayWidth||a.fieldRadius!=b.fieldRadius||a.startHat!=b.startHat?!1:!0};Blockly.BlockSvg.prototype.connectionUiEffect=function(){this.workspace.playAudio("click")};
Blockly.BlockSvg.prototype.updateColour=function(){var a=this.isGlowing_?this.getColourSecondary():this.getColour(),a=this.getColourTertiary();this.svgPath_.setAttribute("stroke",a);a=this.isGlowingBlock_?this.getColourSecondary():this.getColour();this.svgPath_.setAttribute("fill",a);this.svgPath_.setAttribute("fill-opacity",this.getOpacity());for(var a=0,b;b=this.inputList[a];a++)for(var c=0,d;d=b.fieldRow[c];c++)d.setText(null)};
Blockly.BlockSvg.prototype.getHeightWidth=function(a){var b=this.height,c=this.width;!a&&this.getFieldShadowBlock_()&&(b+=Blockly.BlockSvg.FIELD_Y_OFFSET,b+=Blockly.BlockSvg.FIELD_HEIGHT);var d=this.getNextBlock();d&&(a=d.getHeightWidth(a),c+=a.width,b=Math.max(b,a.height));return{height:b,width:c}};

View file

@ -946,7 +946,7 @@ Blockly.Connection.prototype.closest=function(a,b,c){return this.dbOpposite_.sea
Blockly.Connection.prototype.setCheck=function(a){a?(goog.isArray(a)||(a=[a]),this.check_=a,this.isConnected()&&!this.checkType_(this.targetConnection)&&((this.isSuperior()?this.targetBlock():this.sourceBlock_).unplug(),this.sourceBlock_.bumpNeighbours_())):this.check_=null;return this};
Blockly.Connection.prototype.getOutputShape=function(){return this.check_?-1!==this.check_.indexOf("Boolean")?Blockly.Connection.BOOLEAN:-1!==this.check_.indexOf("String")?Blockly.Connection.STRING:Blockly.Connection.NUMBER:Blockly.Connection.NUMBER};Blockly.Connection.prototype.setShadowDom=function(a){this.shadowDom_=a};Blockly.Connection.prototype.getShadowDom=function(){return this.shadowDom_};Blockly.Connection.prototype.neighbours_=function(a){return this.dbOpposite_.getNeighbours(this,a)};
Blockly.Connection.prototype.setHidden=function(a){(this.hidden_=a)&&this.inDB_?this.db_.removeConnection_(this):a||this.inDB_||this.db_.addConnection(this)};Blockly.Connection.prototype.hideAll=function(){this.setHidden(!0);if(this.isConnected())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++)d[e].setHidden(!0);c=c.getIcons();for(d=0;d<c.length;d++)c[d].setVisible(!1)}};
Blockly.Connection.prototype.unhideAll=function(){this.setHidden(!1);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());a.length||(a[0]=b)}return a};Blockly.Field=function(a,b){this.size_=new goog.math.Size(Blockly.BlockSvg.FIELD_WIDTH,Blockly.BlockSvg.FIELD_HEIGHT);this.setValue(a);this.setValidator(b)};Blockly.Field.cacheWidths_=null;Blockly.Field.cacheReference_=0;Blockly.Field.prototype.name=void 0;Blockly.Field.prototype.maxDisplayLength=4;Blockly.Field.prototype.text_="";Blockly.Field.prototype.sourceBlock_=null;Blockly.Field.prototype.visible_=!0;Blockly.Field.prototype.validator_=null;Blockly.Field.NBSP="\u00a0";
Blockly.Connection.prototype.unhideAll=function(){this.setHidden(!1);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());a.length||(a[0]=b)}return a};Blockly.Field=function(a,b){this.size_=new goog.math.Size(Blockly.BlockSvg.FIELD_WIDTH,Blockly.BlockSvg.FIELD_HEIGHT);this.setValue(a);this.setValidator(b);this.maxDisplayLength=Blockly.BlockSvg.MAX_DISPLAY_LENGTH};Blockly.Field.cacheWidths_=null;Blockly.Field.cacheReference_=0;Blockly.Field.prototype.name=void 0;Blockly.Field.prototype.text_="";Blockly.Field.prototype.sourceBlock_=null;Blockly.Field.prototype.visible_=!0;Blockly.Field.prototype.validator_=null;Blockly.Field.NBSP="\u00a0";
Blockly.Field.prototype.EDITABLE=!0;
Blockly.Field.prototype.init=function(a){this.sourceBlock_||(this.sourceBlock_=a,this.fieldGroup_=Blockly.createSvgElement("g",{},null),this.visible_||(this.fieldGroup_.style.display="none"),this.textElement_=Blockly.createSvgElement("text",{"class":"blocklyText",x:this.sourceBlock_.RTL?-this.size_.width/2:this.size_.width/2,y:this.size_.height/2+Blockly.BlockSvg.FIELD_TOP_PADDING,"text-anchor":"middle"},this.fieldGroup_),this.updateEditable(),a.getSvgRoot().appendChild(this.fieldGroup_),this.mouseUpWrapper_=
Blockly.bindEvent_(this.getClickTarget_(),"mouseup",this,this.onMouseUp_),this.updateTextNode_(),Blockly.Events.isEnabled()&&Blockly.Events.fire(new Blockly.Events.Change(this.sourceBlock_,"field",this.name,"",this.getValue())))};Blockly.Field.prototype.dispose=function(){this.mouseUpWrapper_&&(Blockly.unbindEvent_(this.mouseUpWrapper_),this.mouseUpWrapper_=null);this.sourceBlock_=null;goog.dom.removeNode(this.fieldGroup_);this.validator_=this.textElement_=this.fieldGroup_=null};
@ -1212,7 +1212,7 @@ Blockly.BlockSvg.prototype.removeInput=function(a,b){Blockly.BlockSvg.superClass
Blockly.BlockSvg.prototype.appendInput_=function(a,b){var c=Blockly.BlockSvg.superClass_.appendInput_.call(this,a,b);this.rendered&&(this.render(),this.bumpNeighbours_());return c};Blockly.BlockSvg.prototype.getConnections_=function(a){var b=[];if(a||this.rendered)if(this.outputConnection&&b.push(this.outputConnection),this.previousConnection&&b.push(this.previousConnection),this.nextConnection&&b.push(this.nextConnection),a||!this.collapsed_){a=0;for(var c;c=this.inputList[a];a++)c.connection&&b.push(c.connection)}return b};Blockly.BlockSvg.render={};Blockly.BlockSvg.GRID_UNIT=4;Blockly.BlockSvg.SEP_SPACE_X=10;Blockly.BlockSvg.SEP_SPACE_Y=10;Blockly.BlockSvg.INLINE_PADDING_Y=5;Blockly.BlockSvg.MIN_BLOCK_Y=25;Blockly.BlockSvg.TAB_HEIGHT=20;Blockly.BlockSvg.TAB_WIDTH=8;Blockly.BlockSvg.NOTCH_WIDTH=30;Blockly.BlockSvg.CORNER_RADIUS=4;Blockly.BlockSvg.START_HAT=!0;Blockly.BlockSvg.START_HAT_PATH="c 30,-15 70,-15 100,0";Blockly.BlockSvg.NOTCH_PATH_LEFT="l 6,4 3,0 6,-4";Blockly.BlockSvg.NOTCH_PATH_RIGHT="l -6,4 -3,0 -6,-4";
Blockly.BlockSvg.TAB_PATH_DOWN="v 5 c 0,10 -"+Blockly.BlockSvg.TAB_WIDTH+",-8 -"+Blockly.BlockSvg.TAB_WIDTH+",7.5 s "+Blockly.BlockSvg.TAB_WIDTH+",-2.5 "+Blockly.BlockSvg.TAB_WIDTH+",7.5";Blockly.BlockSvg.TOP_LEFT_CORNER_START="m 0,"+Blockly.BlockSvg.CORNER_RADIUS;Blockly.BlockSvg.TOP_LEFT_CORNER="A "+Blockly.BlockSvg.CORNER_RADIUS+","+Blockly.BlockSvg.CORNER_RADIUS+" 0 0,1 "+Blockly.BlockSvg.CORNER_RADIUS+",0";
Blockly.BlockSvg.INNER_TOP_LEFT_CORNER=Blockly.BlockSvg.NOTCH_PATH_RIGHT+" h -"+(Blockly.BlockSvg.NOTCH_WIDTH-15-Blockly.BlockSvg.CORNER_RADIUS)+" a "+Blockly.BlockSvg.CORNER_RADIUS+","+Blockly.BlockSvg.CORNER_RADIUS+" 0 0,0 -"+Blockly.BlockSvg.CORNER_RADIUS+","+Blockly.BlockSvg.CORNER_RADIUS;Blockly.BlockSvg.INNER_BOTTOM_LEFT_CORNER="a "+Blockly.BlockSvg.CORNER_RADIUS+","+Blockly.BlockSvg.CORNER_RADIUS+" 0 0,0 "+Blockly.BlockSvg.CORNER_RADIUS+","+Blockly.BlockSvg.CORNER_RADIUS;
Blockly.BlockSvg.FIELD_HEIGHT=8*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_WIDTH=12*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_WIDTH_MIN_EDIT=13*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_WIDTH_MAX_EDIT=Infinity;Blockly.BlockSvg.FIELD_HEIGHT_MAX_EDIT=Blockly.BlockSvg.FIELD_WIDTH;
Blockly.BlockSvg.FIELD_HEIGHT=8*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_WIDTH=12*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_WIDTH_MIN_EDIT=13*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_WIDTH_MAX_EDIT=Infinity;Blockly.BlockSvg.FIELD_HEIGHT_MAX_EDIT=Blockly.BlockSvg.FIELD_WIDTH;Blockly.BlockSvg.FIELD_TOP_PADDING=0;Blockly.BlockSvg.MAX_DISPLAY_LENGTH=Infinity;
Blockly.BlockSvg.prototype.updateColour=function(){var a=this.getColourTertiary();this.isShadow()&&this.parentBlock_&&(a=this.parentBlock_.getColourTertiary());this.svgPath_.setAttribute("stroke",a);a=this.isGlowingBlock_?this.getColourSecondary():this.getColour();this.svgPath_.setAttribute("fill",a);this.svgPath_.setAttribute("fill-opacity",this.getOpacity());for(var a=this.getIcons(),b=0;b<a.length;b++)a[b].updateColour();for(a=0;b=this.inputList[a];a++)for(var c=0,d;d=b.fieldRow[c];c++)d.setText(null)};
Blockly.BlockSvg.prototype.getHeightWidth=function(){var a=this.height,b=this.width,c=this.getNextBlock();c?(c=c.getHeightWidth(),a+=c.height-4,b=Math.max(b,c.width)):this.nextConnection||this.outputConnection||(a+=2);return{height:a,width:b}};
Blockly.BlockSvg.prototype.render=function(a){Blockly.Field.startCache();this.rendered=!0;var b=Blockly.BlockSvg.SEP_SPACE_X;this.RTL&&(b=-b);for(var c=this.getIcons(),d=0;d<c.length;d++)b=c[d].renderIcon(b);b+=this.RTL?Blockly.BlockSvg.SEP_SPACE_X:-Blockly.BlockSvg.SEP_SPACE_X;c=this.renderCompute_(b);this.renderDraw_(b,c);!1!==a&&((a=this.getParent())?a.render(!0):Blockly.fireUiEvent(window,"resize"));Blockly.Field.stopCache()};

128
blocks_vertical/control.js Normal file
View file

@ -0,0 +1,128 @@
/**
* @fileoverview Control blocks for Scratch (Horizontal)
* @author ascii@media.mit.edu <Andrew Sliwinski>
*/
'use strict';
goog.provide('Blockly.Blocks.control');
goog.require('Blockly.Blocks');
goog.require('Blockly.Colours');
Blockly.Blocks['control_forever'] = {
/**
* Block for repeat n times (external number).
* https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#5eke39
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "control_forever",
"message0": "forever %1 %2 %3",
"lastDummyAlign0": "RIGHT",
"args0": [
{
"type": "input_dummy"
},
{
"type": "input_statement",
"name": "SUBSTACK"
},
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "icons/control_forever.svg",
"width": 10,
"height": 10,
"alt": "*",
"flip_rtl": true
}
],
"inputsInline": true,
"previousStatement": null,
"colour": Blockly.Colours.control.primary,
"colourSecondary": Blockly.Colours.control.secondary,
"colourTertiary": Blockly.Colours.control.tertiary
});
}
};
Blockly.Blocks['control_repeat'] = {
/**
* Block for repeat n times (external number).
* https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#so57n9
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "control_repeat",
"message0": "repeat %1 times %2 %3",
"args0": [
{
"type": "input_value",
"name": "TIMES",
"check": "Number"
},
{
"type": "input_dummy"
},
{
"type": "input_statement",
"name": "SUBSTACK"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Colours.control.primary,
"colourSecondary": Blockly.Colours.control.secondary,
"colourTertiary": Blockly.Colours.control.tertiary
});
}
};
Blockly.Blocks['control_stop'] = {
/**
* Block for stop all scripts.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "control_stop",
"message0": "stop all scripts",
"args0": [
],
"inputsInline": true,
"previousStatement": null,
"colour": Blockly.Colours.control.primary,
"colourSecondary": Blockly.Colours.control.secondary,
"colourTertiary": Blockly.Colours.control.tertiary
});
}
};
Blockly.Blocks['control_wait'] = {
/**
* Block to wait (pause) stack.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "control_wait",
"message0": "wait %1 secs",
"args0": [
{
"type": "input_value",
"name": "DURATION",
"check": "Number"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Colours.control.primary,
"colourSecondary": Blockly.Colours.control.secondary,
"colourTertiary": Blockly.Colours.control.tertiary
});
}
};

112
blocks_vertical/event.js Normal file
View file

@ -0,0 +1,112 @@
/**
* @fileoverview Control blocks for Scratch (Horizontal)
* @author ascii@media.mit.edu <Andrew Sliwinski>
*/
'use strict';
goog.provide('Blockly.Blocks.event');
goog.require('Blockly.Blocks');
goog.require('Blockly.Colours');
Blockly.Blocks['event_whenflagclicked'] = {
/**
* Block for when flag clicked.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "event_whenflagclicked",
"message0": "when %1 clicked",
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "icons/event_whenflagclicked.svg",
"width": 20,
"height": 20,
"alt": "flag",
"flip_rtl": true
}
],
"inputsInline": true,
"nextStatement": null,
"colour": Blockly.Colours.event.primary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary
});
}
};
Blockly.Blocks['event_whenbroadcastreceived'] = {
/**
* Block for when broadcast received.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "event_whenbroadcastreceived",
"message0": "when I receive ...",
"args0": [
],
"inputsInline": true,
"nextStatement": null,
"colour": Blockly.Colours.event.primary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary
});
}
};
Blockly.Blocks['event_broadcast'] = {
/**
* Block to send a broadcast.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "event_broadcast",
"message0": "broadcast ...",
"args0": [
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Colours.event.primary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary
});
}
};
Blockly.Blocks['event_broadcast_text'] = {
/**
* Block to send a broadcast, with a text-box for testing fields.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "event_broadcast",
"message0": "%1 %2",
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "icons/event_broadcast.svg",
"width": 40,
"height": 40,
"alt": "Broadcast"
},
{
"type": "input_value",
"name": "STRING"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Colours.event.primary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary
});
}
};

145
blocks_vertical/wedo.js Normal file
View file

@ -0,0 +1,145 @@
/**
* @fileoverview Wedo blocks for Scratch (Horizontal)
* @author ascii@media.mit.edu <Andrew Sliwinski>
*/
'use strict';
goog.provide('Blockly.Blocks.wedo');
goog.require('Blockly.Blocks');
goog.require('Blockly.Colours');
Blockly.Blocks['wedo_setcolor'] = {
/**
* Block to set color of LED
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "wedo_setcolor",
"message0": "set color to ...",
"args0": [
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Colours.looks.primary,
"colourSecondary": Blockly.Colours.looks.secondary,
"colourTertiary": Blockly.Colours.looks.tertiary
});
}
};
Blockly.Blocks['wedo_motorclockwise'] = {
/**
* Block to spin motor clockwise.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "wedo_motorclockwise",
"message0": "turn motor clockwise for %1 secs",
"args0": [
{
"type": "input_value",
"name": "DURATION",
"check": "Number"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Colours.motion.primary,
"colourSecondary": Blockly.Colours.motion.secondary,
"colourTertiary": Blockly.Colours.motion.tertiary
});
}
};
Blockly.Blocks['wedo_motorcounterclockwise'] = {
/**
* Block to spin motor counter-clockwise.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "wedo_motorcounterclockwise",
"message0": "turn motor counterclockwise for %1 secs",
"args0": [
{
"type": "input_value",
"name": "DURATION",
"check": "Number"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Colours.motion.primary,
"colourSecondary": Blockly.Colours.motion.secondary,
"colourTertiary": Blockly.Colours.motion.tertiary
});
}
};
Blockly.Blocks['wedo_motorspeed'] = {
/**
* Block to set motor speed.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "wedo_motorspeed",
"message0": "set motor speed to ...",
"args0": [
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Colours.motion.primary,
"colourSecondary": Blockly.Colours.motion.secondary,
"colourTertiary": Blockly.Colours.motion.tertiary
});
}
};
Blockly.Blocks['wedo_whentilt'] = {
/**
* Block for when tilted.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "wedo_whentilt",
"message0": "when tilted ...",
"args0": [
],
"inputsInline": true,
"nextStatement": null,
"colour": Blockly.Colours.event.primary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary
});
}
};
Blockly.Blocks['wedo_whendistanceclose'] = {
/**
* Block for when distance sensor is close.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "wedo_whendistanceclose",
"message0": "when distance is near",
"args0": [
],
"inputsInline": true,
"nextStatement": null,
"colour": Blockly.Colours.event.primary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary
});
}
};

View file

@ -225,6 +225,12 @@ Blockly.BlockSvg.HAT_TOP_LEFT_CORNER =
*/
Blockly.BlockSvg.renderingMetrics_ = null;
/**
* Max text display length for a field (per-horizontal/vertical)
* @const
*/
Blockly.BlockSvg.MAX_DISPLAY_LENGTH = 4;
/**
* @param {!Object} first An object containing computed measurements of a
* block.

View file

@ -169,6 +169,18 @@ Blockly.BlockSvg.FIELD_WIDTH_MAX_EDIT = Infinity;
*/
Blockly.BlockSvg.FIELD_HEIGHT_MAX_EDIT = Blockly.BlockSvg.FIELD_WIDTH;
/**
* Top padding of user inputs
* @const
*/
Blockly.BlockSvg.FIELD_TOP_PADDING = 0;
/**
* Max text display length for a field (per-horizontal/vertical)
* @const
*/
Blockly.BlockSvg.MAX_DISPLAY_LENGTH = Infinity;
/**
* Change the colour of a block.
*/

View file

@ -50,6 +50,13 @@ Blockly.Field = function(text, opt_validator) {
Blockly.BlockSvg.FIELD_HEIGHT);
this.setValue(text);
this.setValidator(opt_validator);
/**
* Maximum characters of text to display before adding an ellipsis.
* Same for strings and numbers.
* @type {number}
*/
this.maxDisplayLength = Blockly.BlockSvg.MAX_DISPLAY_LENGTH;
};
/**
@ -74,13 +81,6 @@ Blockly.Field.cacheReference_ = 0;
*/
Blockly.Field.prototype.name = undefined;
/**
* Maximum characters of text to display before adding an ellipsis.
* Same for strings and numbers.
* @type {number}
*/
Blockly.Field.prototype.maxDisplayLength = 4;
/**
* Visible text to display.
* @type {string}

View file

@ -8,9 +8,9 @@
<script src="../msg/messages.js"></script>
<script src="../blocks/math.js"></script>
<script src="../blocks/text.js"></script>
<script src="../blocks_horizontal/control.js"></script>
<script src="../blocks_horizontal/event.js"></script>
<script src="../blocks_horizontal/wedo.js"></script>
<script src="../blocks_vertical/control.js"></script>
<script src="../blocks_vertical/event.js"></script>
<script src="../blocks_vertical/wedo.js"></script>
<script>
'use strict';
// Depending on the URL argument, render as LTR or RTL.
@ -48,6 +48,16 @@ function start() {
minScale: 0.25,
scaleSpeed: 1.1
},
colours: {
workspace: '#334771',
flyout: '#283856',
scrollbar: '#24324D',
scrollbarHover: '#0C111A',
insertionMarker: '#FFFFFF',
insertionMarkerOpacity: 0.3,
fieldShadow: 'rgba(255, 255, 255, 0.3)',
dragShadowOpacity: 0.6
}
});
// Restore previously displayed text.
var text = sessionStorage.getItem('textarea');
@ -79,12 +89,6 @@ function fromXml() {
taChange();
}
function toCode(lang) {
var output = document.getElementById('importExport');
output.value = Blockly[lang].workspaceToCode(workspace);
taChange();
}
// Disable the "Import from XML" button if the XML is invalid.
// Preserve text between page reloads.
function taChange() {
@ -202,18 +206,8 @@ h1 {
<category name="Events">
<block type="event_whenflagclicked"></block>
<block type="event_whenbroadcastreceived">
<value name="CHOICE">
<shadow type="dropdown_whenbroadcast">
<field name="CHOICE">blue</field>
</shadow>
</value>
</block>
<block type="event_broadcast">
<value name="CHOICE">
<shadow type="dropdown_broadcast">
<field name="CHOICE">blue</field>
</shadow>
</value>
</block>
</category>
@ -238,11 +232,6 @@ h1 {
<category name="Wedo">
<block type="wedo_setcolor">
<value name="CHOICE">
<shadow type="dropdown_wedo_setcolor">
<field name="CHOICE">mystery</field>
</shadow>
</value>
</block>
<block type="wedo_motorclockwise">
<value name="DURATION">
@ -259,18 +248,8 @@ h1 {
</value>
</block>
<block type="wedo_motorspeed">
<value name="CHOICE">
<shadow type="dropdown_wedo_motorspeed">
<field name="CHOICE">fast</field>
</shadow>
</value>
</block>
<block type="wedo_whentilt">
<value name="CHOICE">
<shadow type="dropdown_wedo_whentilt">
<field name="CHOICE">forward</field>
</shadow>
</value>
</block>
<block type="wedo_whendistanceclose"></block>
</category>
@ -279,6 +258,10 @@ h1 {
<h1>Vertical block rendering!</h1>
<strong style='color:red'>Note: vertical-mode Scratch Blocks rendering is
just getting started and we will have many updates for both functionality
and visual design in summer 2016.</strong>
<p><a href="javascript:void(workspace.setVisible(true))">Show</a>
- <a href="javascript:void(workspace.setVisible(false))">Hide</a></p>
@ -295,8 +278,6 @@ h1 {
&nbsp;
<input type="button" value="Import from XML" onclick="fromXml()" id="import">
<br>
<input type="button" value="To JavaScript" onclick="toCode('JavaScript')">
<br>
<textarea id="importExport" style="width: 26%; height: 12em"
onchange="taChange();" onkeyup="taChange()"></textarea>
</p>