|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
goog.provide('Blockly.BlockSvg.render');
|
|
|
|
|
|
goog.require('Blockly.BlockSvg');
|
|
|
goog.require('Blockly.scratchBlocksUtils');
|
|
|
goog.require('Blockly.utils');
|
|
|
goog.require('Blockly.constants');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.GRID_UNIT = 4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.SEP_SPACE_X = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.SEP_SPACE_Y = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.MIN_BLOCK_X = 16 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.MIN_BLOCK_X_OUTPUT = 12 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.MIN_BLOCK_X_SHADOW_OUTPUT = 10 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.MIN_BLOCK_Y = 12 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.EXTRA_STATEMENT_ROW_Y = 8 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.MIN_BLOCK_X_WITH_STATEMENT = 40 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.MIN_BLOCK_Y_SINGLE_FIELD_OUTPUT = 8 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER = 10 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.MIN_STATEMENT_INPUT_HEIGHT = 6 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.NOTCH_WIDTH = 8 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.NOTCH_HEIGHT = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.CORNER_RADIUS = 1 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.STATEMENT_INPUT_EDGE_WIDTH = 4 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.STATEMENT_INPUT_INNER_SPACE = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.START_HAT_HEIGHT = 16;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.ICON_SEPARATOR_HEIGHT = 10 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.START_HAT_PATH = 'c 25,-22 71,-22 96,0';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.NOTCH_PATH_LEFT = `c 2 0 3 1 4 2 l 4 4 c 1 1 2 2 4 2 h 12 c 2 0 3 -1 4 -2 l 4 -4 c 1 -1 2 -2 4 -2`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.NOTCH_PATH_RIGHT = `c -2 0 -3 1 -4 2 l -4 4 c -1 1 -2 2 -4 2 h -12 c -2 0 -3 -1 -4 -2 l -4 -4 c -1 -1 -2 -2 -4 -2`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.NOTCH_SWITCH_PATH_LEFT = `c 2 0 3 1 4 2 l 4 4 c 1 1 2 2 4 2 c 2 0 4 -4 6 -4 c 2 0 4 4 6 4 c 2 0 3 -1 4 -2 l 4 -4 c 1 -1 2 -2 4 -2`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.NOTCH_SWITCH_PATH_RIGHT = `c -2 0 -3 1 -4 2 l -4 4 c -1 1 -2 2 -4 2 c -2 0 -4 -4 -6 -4 c -2 0 -4 4 -6 4 c -2 0 -3 -1 -4 -2 l -4 -4 c -1 -1 -2 -2 -4 -2`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.NOTCH_SWITCH_ENABLE = true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.NOTCH_START_PADDING = 3 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.TOP_RIGHT_CORNER =
|
|
|
'a ' + Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
|
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,1 ' +
|
|
|
Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
|
Blockly.BlockSvg.CORNER_RADIUS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.BOTTOM_RIGHT_CORNER =
|
|
|
' a ' + Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
|
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,1 -' +
|
|
|
Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
|
Blockly.BlockSvg.CORNER_RADIUS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.BOTTOM_LEFT_CORNER =
|
|
|
'a ' + Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
|
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,1 -' +
|
|
|
Blockly.BlockSvg.CORNER_RADIUS + ',-' +
|
|
|
Blockly.BlockSvg.CORNER_RADIUS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.INNER_TOP_LEFT_CORNER =
|
|
|
' 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.INPUT_SHAPE_LEAF =
|
|
|
`
|
|
|
M ${6 * Blockly.BlockSvg.GRID_UNIT} 0
|
|
|
l ${2 * Blockly.BlockSvg.GRID_UNIT} 0
|
|
|
a ${4 * Blockly.BlockSvg.GRID_UNIT} ${4 * Blockly.BlockSvg.GRID_UNIT} 0 0 1 ${4 * Blockly.BlockSvg.GRID_UNIT} ${4 * Blockly.BlockSvg.GRID_UNIT}
|
|
|
l 0 ${2.4 * Blockly.BlockSvg.GRID_UNIT}
|
|
|
a ${1.6 * Blockly.BlockSvg.GRID_UNIT} ${1.6 * Blockly.BlockSvg.GRID_UNIT} 0 0 1 -${1.6 * Blockly.BlockSvg.GRID_UNIT} ${1.6 * Blockly.BlockSvg.GRID_UNIT}
|
|
|
h -${4 * Blockly.BlockSvg.GRID_UNIT}
|
|
|
l -${2.4 * Blockly.BlockSvg.GRID_UNIT} 0
|
|
|
a ${4 * Blockly.BlockSvg.GRID_UNIT} ${4 * Blockly.BlockSvg.GRID_UNIT} 0 0 1 -${4 * Blockly.BlockSvg.GRID_UNIT} -${4 * Blockly.BlockSvg.GRID_UNIT}
|
|
|
l 0 -${2.4 * Blockly.BlockSvg.GRID_UNIT}
|
|
|
a ${1.6 * Blockly.BlockSvg.GRID_UNIT} ${1.6 * Blockly.BlockSvg.GRID_UNIT} 0 0 1 ${1.6 * Blockly.BlockSvg.GRID_UNIT} -${1.6 * Blockly.BlockSvg.GRID_UNIT}
|
|
|
z
|
|
|
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_PLUS_WIDTH = 12 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_PLUS =
|
|
|
`
|
|
|
M ${9 * Blockly.BlockSvg.GRID_UNIT} 0
|
|
|
a ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT} 0 0 1 ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT}
|
|
|
l 0 2
|
|
|
a ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT} 0 0 0 ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT}
|
|
|
a ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT} 0 0 1 ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT}
|
|
|
l 0 4
|
|
|
a ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT} 0 0 1 -${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT}
|
|
|
a ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT} 0 0 0 -${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT}
|
|
|
l 0 2
|
|
|
a ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT} 0 0 1 -${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT}
|
|
|
h -${6 * Blockly.BlockSvg.GRID_UNIT}
|
|
|
a ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT} 0 0 1 -${Blockly.BlockSvg.GRID_UNIT} -${Blockly.BlockSvg.GRID_UNIT}
|
|
|
l 0 -2
|
|
|
a ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT} 0 0 0 -${Blockly.BlockSvg.GRID_UNIT} -${Blockly.BlockSvg.GRID_UNIT}
|
|
|
a ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT} 0 0 1 -${Blockly.BlockSvg.GRID_UNIT} -${Blockly.BlockSvg.GRID_UNIT}
|
|
|
l 0 -4
|
|
|
a ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT} 0 0 1 ${Blockly.BlockSvg.GRID_UNIT} -${Blockly.BlockSvg.GRID_UNIT}
|
|
|
a ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT} 0 0 0 ${Blockly.BlockSvg.GRID_UNIT} -${Blockly.BlockSvg.GRID_UNIT}
|
|
|
l 0 -2
|
|
|
a ${Blockly.BlockSvg.GRID_UNIT} ${Blockly.BlockSvg.GRID_UNIT} 0 0 1 ${Blockly.BlockSvg.GRID_UNIT} -${Blockly.BlockSvg.GRID_UNIT}
|
|
|
z
|
|
|
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_LEAF_WIDTH = 12 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_HEXAGONAL =
|
|
|
'M ' + 4 * Blockly.BlockSvg.GRID_UNIT + ',0 ' +
|
|
|
' h ' + 4 * Blockly.BlockSvg.GRID_UNIT +
|
|
|
' l ' + 4 * Blockly.BlockSvg.GRID_UNIT + ',' + 4 * Blockly.BlockSvg.GRID_UNIT +
|
|
|
' l ' + -4 * Blockly.BlockSvg.GRID_UNIT + ',' + 4 * Blockly.BlockSvg.GRID_UNIT +
|
|
|
' h ' + -4 * Blockly.BlockSvg.GRID_UNIT +
|
|
|
' l ' + -4 * Blockly.BlockSvg.GRID_UNIT + ',' + -4 * Blockly.BlockSvg.GRID_UNIT +
|
|
|
' l ' + 4 * Blockly.BlockSvg.GRID_UNIT + ',' + -4 * Blockly.BlockSvg.GRID_UNIT +
|
|
|
' z';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_HEXAGONAL_WIDTH = 12 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_SQUARE =
|
|
|
Blockly.BlockSvg.TOP_LEFT_CORNER_START +
|
|
|
Blockly.BlockSvg.TOP_LEFT_CORNER +
|
|
|
' h ' + (12 * Blockly.BlockSvg.GRID_UNIT - 2 * Blockly.BlockSvg.CORNER_RADIUS) +
|
|
|
Blockly.BlockSvg.TOP_RIGHT_CORNER +
|
|
|
' v ' + (8 * Blockly.BlockSvg.GRID_UNIT - 2 * Blockly.BlockSvg.CORNER_RADIUS) +
|
|
|
Blockly.BlockSvg.BOTTOM_RIGHT_CORNER +
|
|
|
' h ' + (-12 * Blockly.BlockSvg.GRID_UNIT + 2 * Blockly.BlockSvg.CORNER_RADIUS) +
|
|
|
Blockly.BlockSvg.BOTTOM_LEFT_CORNER +
|
|
|
' z';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_SQUARE_WIDTH = 12 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_ROUND =
|
|
|
'M ' + (4 * Blockly.BlockSvg.GRID_UNIT) + ',0' +
|
|
|
' h ' + (4 * Blockly.BlockSvg.GRID_UNIT) +
|
|
|
' a ' + (4 * Blockly.BlockSvg.GRID_UNIT) + ' ' +
|
|
|
(4 * Blockly.BlockSvg.GRID_UNIT) + ' 0 0 1 0 ' + (8 * Blockly.BlockSvg.GRID_UNIT) +
|
|
|
' h ' + (-4 * Blockly.BlockSvg.GRID_UNIT) +
|
|
|
' a ' + (4 * Blockly.BlockSvg.GRID_UNIT) + ' ' +
|
|
|
(4 * Blockly.BlockSvg.GRID_UNIT) + ' 0 0 1 0 -' + (8 * Blockly.BlockSvg.GRID_UNIT) +
|
|
|
' z';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_ROUND_WIDTH = 12 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_HEIGHT = 8 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.FIELD_HEIGHT = 8 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.FIELD_WIDTH = 6 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.EDITABLE_FIELD_PADDING = 6;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.BOX_FIELD_PADDING = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.DROPDOWN_ARROW_PADDING = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.FIELD_WIDTH_MIN_EDIT = 8 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.FIELD_WIDTH_MAX_EDIT = Infinity;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.FIELD_HEIGHT_MAX_EDIT = Blockly.BlockSvg.FIELD_HEIGHT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.FIELD_TOP_PADDING = 0.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.MAX_DISPLAY_LENGTH = Infinity;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.INPUT_AND_FIELD_MIN_X = 12 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.INLINE_PADDING_Y = 1 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.FIELD_TEXTINPUT_FONTSIZE_INITIAL = 12;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.FIELD_TEXTINPUT_FONTSIZE_FINAL = 12;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.FIELD_TEXTINPUT_EXPAND_PAST_TRUNCATION = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.FIELD_TEXTINPUT_ANIMATE_POSITIONING = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.SHAPE_IN_SHAPE_PADDING = {
|
|
|
1 : {
|
|
|
0 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
1 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
2 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
3 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
4 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
5 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
6 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
7 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
8 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
9 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
10: 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
11: 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
},
|
|
|
2 : {
|
|
|
0 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
1 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
2 : 1 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
3 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
4 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
5 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
6 : 0 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
7 : 1 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
8 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
9 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
10: 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
11: 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
},
|
|
|
3 : {
|
|
|
0 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
1 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
2 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
3 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
4 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
5 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
6 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
7 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
8 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
9 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
10: 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
11: 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
},
|
|
|
4 : {
|
|
|
0 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
1 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
2 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
3 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
4 : 1 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
5 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
6 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
7 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
8 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
9 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
10: 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
11: 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
},
|
|
|
5 : {
|
|
|
0 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
1 : 4 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
2 : 4 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
3 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
4 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
5 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
6 : 4 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
7 : 4 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
8 : 4 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
9 : 4 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
10: 4 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
11: 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
},
|
|
|
6 : {
|
|
|
0 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
1 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
2 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
3 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
4 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
5 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
6 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
7 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
8 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
9 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
10: 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
11: 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
},
|
|
|
7 : {
|
|
|
0 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
1 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
2 : 1 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
3 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
4 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
5 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
6 : 0 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
7 : 1 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
8 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
9 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
10: 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
11: 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
},
|
|
|
8 : {
|
|
|
0 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
1 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
2 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
3 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
4 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
5 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
6 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
7 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
8 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
9 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
10: 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
11: 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
},
|
|
|
9 : {
|
|
|
0 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
1 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
2 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
3 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
4 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
5 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
6 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
7 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
8 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
9 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
10: 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
11: 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
},
|
|
|
10: {
|
|
|
0 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
1 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
2 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
3 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
4 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
5 : 3 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
6 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
7 : 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
8 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
9 : 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
10: 2 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
11: 5 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
},
|
|
|
11: {
|
|
|
0 : 6 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
1 : 6 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
2 : 6 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
3 : 6 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
4 : 6 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
5 : 6 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
6 : 6 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
7 : 6 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
8 : 6 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
9 : 6 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
10: 6 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
11: 6 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
},
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.DEFAULT_SHAPE_PADDING = Blockly.BlockSvg.GRID_UNIT * 5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.DEFINE_HAT_CORNER_RADIUS = 5 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.TOP_LEFT_CORNER_DEFINE_HAT =
|
|
|
'a ' + Blockly.BlockSvg.DEFINE_HAT_CORNER_RADIUS + ',' +
|
|
|
Blockly.BlockSvg.DEFINE_HAT_CORNER_RADIUS + ' 0 0,1 ' +
|
|
|
Blockly.BlockSvg.DEFINE_HAT_CORNER_RADIUS + ',-' +
|
|
|
Blockly.BlockSvg.DEFINE_HAT_CORNER_RADIUS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.TOP_RIGHT_CORNER_DEFINE_HAT =
|
|
|
'a ' + Blockly.BlockSvg.DEFINE_HAT_CORNER_RADIUS + ',' +
|
|
|
Blockly.BlockSvg.DEFINE_HAT_CORNER_RADIUS + ' 0 0,1 ' +
|
|
|
Blockly.BlockSvg.DEFINE_HAT_CORNER_RADIUS + ',' +
|
|
|
Blockly.BlockSvg.DEFINE_HAT_CORNER_RADIUS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.DEFINE_BLOCK_PADDING_RIGHT = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.updateColour = function() {
|
|
|
var strokeColour = this.getColourTertiary();
|
|
|
var renderShadowed = this.isShadow() &&
|
|
|
!Blockly.scratchBlocksUtils.isShadowArgumentReporter(this);
|
|
|
|
|
|
if (renderShadowed && this.parentBlock_) {
|
|
|
|
|
|
strokeColour = this.parentBlock_.getColourTertiary();
|
|
|
|
|
|
if (this.inputList[0] &&
|
|
|
this.inputList[0].fieldRow[0] &&
|
|
|
(this.inputList[0].fieldRow[0] instanceof Blockly.FieldColour ||
|
|
|
this.inputList[0].fieldRow[0] instanceof Blockly.FieldColourSlider)) {
|
|
|
strokeColour = Blockly.Colours.colourPickerStroke;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
this.svgPath_.setAttribute('stroke', strokeColour);
|
|
|
|
|
|
|
|
|
if (this.isGlowingBlock_ || renderShadowed) {
|
|
|
|
|
|
if (this.getShadowColour()) {
|
|
|
var fillColour = this.getShadowColour();
|
|
|
} else {
|
|
|
|
|
|
if (
|
|
|
renderShadowed &&
|
|
|
this.parentBlock_ &&
|
|
|
this.outputConnection &&
|
|
|
this.inputList.length == 1 &&
|
|
|
this.inputList[0].fieldRow.length == 1 &&
|
|
|
this.inputList[0].fieldRow[0] instanceof Blockly.FieldDropdown
|
|
|
) {
|
|
|
var fillColour = this.parentBlock_.getColourSecondary();
|
|
|
} else {
|
|
|
var fillColour = this.getColourSecondary();
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
var fillColour = this.getColour();
|
|
|
}
|
|
|
this.svgPath_.setAttribute('fill', fillColour);
|
|
|
|
|
|
|
|
|
this.svgPath_.setAttribute('fill-opacity', this.getOpacity());
|
|
|
|
|
|
|
|
|
for (var i = 0, input; input = this.inputList[i]; i++) {
|
|
|
if (input.outlinePath) {
|
|
|
input.outlinePath.setAttribute('fill', this.getColourTertiary());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
var icons = this.getIcons();
|
|
|
for (var i = 0; i < icons.length; i++) {
|
|
|
icons[i].updateColour();
|
|
|
}
|
|
|
|
|
|
|
|
|
for (var x = 0, input; input = this.inputList[x]; x++) {
|
|
|
for (var y = 0, field; field = input.fieldRow[y]; y++) {
|
|
|
field.setText(null);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.highlightForReplacement = function(add) {
|
|
|
if (add) {
|
|
|
var replacementGlowFilterId = this.workspace.options.replacementGlowFilterId
|
|
|
|| 'blocklyReplacementGlowFilter';
|
|
|
this.svgPath_.setAttribute('filter', 'url(#' + replacementGlowFilterId + ')');
|
|
|
Blockly.utils.addClass( (this.svgGroup_),
|
|
|
'blocklyReplaceable');
|
|
|
} else {
|
|
|
this.svgPath_.removeAttribute('filter');
|
|
|
Blockly.utils.removeClass( (this.svgGroup_),
|
|
|
'blocklyReplaceable');
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.highlightShapeForInput = function(conn, add) {
|
|
|
var input = this.getInputWithConnection(conn);
|
|
|
if (!input) {
|
|
|
throw 'No input found for the connection';
|
|
|
}
|
|
|
if (!input.outlinePath) {
|
|
|
return;
|
|
|
}
|
|
|
if (add) {
|
|
|
var replacementGlowFilterId = this.workspace.options.replacementGlowFilterId
|
|
|
|| 'blocklyReplacementGlowFilter';
|
|
|
input.outlinePath.setAttribute('filter',
|
|
|
'url(#' + replacementGlowFilterId + ')');
|
|
|
Blockly.utils.addClass( (this.svgGroup_),
|
|
|
'blocklyReplaceable');
|
|
|
} else {
|
|
|
input.outlinePath.removeAttribute('filter');
|
|
|
Blockly.utils.removeClass( (this.svgGroup_),
|
|
|
'blocklyReplaceable');
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.getHeightWidth = function() {
|
|
|
var height = this.height;
|
|
|
var width = this.width;
|
|
|
|
|
|
var nextBlock = this.getNextBlock();
|
|
|
if (nextBlock) {
|
|
|
var nextHeightWidth = nextBlock.getHeightWidth();
|
|
|
height += nextHeightWidth.height;
|
|
|
height -= Blockly.BlockSvg.NOTCH_HEIGHT;
|
|
|
width = Math.max(width, nextHeightWidth.width);
|
|
|
}
|
|
|
return {height: height, width: width};
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.render = function(opt_bubble) {
|
|
|
Blockly.Field.startCache();
|
|
|
this.rendered = true;
|
|
|
|
|
|
var cursorX = Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
if (this.RTL) {
|
|
|
cursorX = -cursorX;
|
|
|
}
|
|
|
|
|
|
var icons = this.getIcons();
|
|
|
var scratchCommentIcon = null;
|
|
|
for (var i = 0; i < icons.length; i++) {
|
|
|
if (icons[i] instanceof Blockly.ScratchBlockComment) {
|
|
|
|
|
|
|
|
|
scratchCommentIcon = icons[i];
|
|
|
} else {
|
|
|
cursorX = icons[i].renderIcon(cursorX);
|
|
|
}
|
|
|
}
|
|
|
cursorX += this.RTL ?
|
|
|
Blockly.BlockSvg.SEP_SPACE_X : -Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.isScratchExtension && this.outputConnection) {
|
|
|
cursorX += this.RTL ?
|
|
|
-Blockly.BlockSvg.GRID_UNIT : Blockly.BlockSvg.GRID_UNIT;
|
|
|
}
|
|
|
|
|
|
var inputRows = this.renderCompute_(cursorX);
|
|
|
this.renderDraw_(cursorX, inputRows);
|
|
|
this.renderMoveConnections_();
|
|
|
|
|
|
this.renderClassify_();
|
|
|
|
|
|
|
|
|
if (scratchCommentIcon) {
|
|
|
var iconX = this.RTL ? -inputRows.rightEdge : inputRows.rightEdge;
|
|
|
var inputMarginY = inputRows[0].height / 2;
|
|
|
scratchCommentIcon.renderIcon(iconX, inputMarginY);
|
|
|
}
|
|
|
|
|
|
if (opt_bubble !== false) {
|
|
|
|
|
|
var parentBlock = this.getParent();
|
|
|
if (parentBlock) {
|
|
|
parentBlock.render(true);
|
|
|
} else {
|
|
|
|
|
|
Blockly.resizeSvgContents(this.workspace);
|
|
|
}
|
|
|
}
|
|
|
Blockly.Field.stopCache();
|
|
|
|
|
|
this.updateIntersectionObserver();
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.renderFields_ = function(fieldList, cursorX,
|
|
|
cursorY) {
|
|
|
if (this.edgeShapeWidth_ && this.inputList.find(v => v.type == Blockly.NEXT_STATEMENT)) cursorX += this.edgeShapeWidth_ + Blockly.BlockSvg.CORNER_RADIUS * 2
|
|
|
if (this.RTL) {
|
|
|
cursorX = -cursorX;
|
|
|
}
|
|
|
for (var t = 0, field; field = fieldList[t]; t++) {
|
|
|
var root = field.getSvgRoot();
|
|
|
if (!root) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (this.previousConnection && !(field instanceof Blockly.FieldLabel) &&
|
|
|
!(field instanceof Blockly.FieldImage)) {
|
|
|
cursorX = this.RTL ?
|
|
|
Math.min(cursorX, -Blockly.BlockSvg.INPUT_AND_FIELD_MIN_X) :
|
|
|
Math.max(cursorX, Blockly.BlockSvg.INPUT_AND_FIELD_MIN_X);
|
|
|
}
|
|
|
|
|
|
|
|
|
var yOffset = -field.getSize().height / 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.isScratchExtension && (field === this.inputList[0].fieldRow[0])
|
|
|
&& (field instanceof Blockly.FieldImage) && this.previousConnection) {
|
|
|
yOffset += Blockly.BlockSvg.GRID_UNIT;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.isScratchExtension &&
|
|
|
!this.previousConnection && this.nextConnection &&
|
|
|
field instanceof Blockly.FieldVerticalSeparator) {
|
|
|
field.setLineHeight(Blockly.BlockSvg.ICON_SEPARATOR_HEIGHT -
|
|
|
Blockly.BlockSvg.GRID_UNIT);
|
|
|
}
|
|
|
|
|
|
var translateX, translateY;
|
|
|
var scale = '';
|
|
|
if (this.RTL) {
|
|
|
cursorX -= field.renderSep + field.renderWidth;
|
|
|
translateX = cursorX;
|
|
|
translateY = cursorY + yOffset;
|
|
|
if (field.renderWidth) {
|
|
|
cursorX -= Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
}
|
|
|
} else {
|
|
|
translateX = cursorX + field.renderSep;
|
|
|
translateY = cursorY + yOffset;
|
|
|
if (field.renderWidth) {
|
|
|
cursorX += field.renderSep + field.renderWidth +
|
|
|
Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
}
|
|
|
}
|
|
|
if (this.RTL &&
|
|
|
field instanceof Blockly.FieldImage &&
|
|
|
field.getFlipRTL()) {
|
|
|
scale = 'scale(-1 1)';
|
|
|
translateX += field.renderWidth;
|
|
|
}
|
|
|
root.setAttribute('transform',
|
|
|
'translate(' + translateX + ', ' + translateY + ') ' + scale);
|
|
|
|
|
|
|
|
|
if (this.isInsertionMarker()) {
|
|
|
root.setAttribute('display', 'none');
|
|
|
}
|
|
|
}
|
|
|
return this.RTL ? -cursorX : cursorX;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.renderCompute_ = function(iconWidth) {
|
|
|
var inputList = this.inputList;
|
|
|
var inputRows = [];
|
|
|
|
|
|
inputRows.rightEdge = 0;
|
|
|
|
|
|
inputRows.bottomEdge = 0;
|
|
|
var fieldValueWidth = 0;
|
|
|
var fieldStatementWidth = 0;
|
|
|
var hasValue = false;
|
|
|
var hasStatement = false;
|
|
|
var hasDummy = false;
|
|
|
var lastType = undefined;
|
|
|
|
|
|
|
|
|
var previousRow;
|
|
|
for (var i = 0, input; input = inputList[i]; i++) {
|
|
|
if (!input.isVisible()) {
|
|
|
continue;
|
|
|
}
|
|
|
var isSecondInputOnProcedure = (this.type == 'procedures_definition' ||
|
|
|
this.type == 'procedures_definition_return') &&
|
|
|
lastType && lastType == Blockly.NEXT_STATEMENT;
|
|
|
var row;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isSecondInputOnProcedure &&
|
|
|
(!lastType || lastType == Blockly.NEXT_STATEMENT ||
|
|
|
input.type == Blockly.NEXT_STATEMENT)) {
|
|
|
lastType = input.type;
|
|
|
row = this.createRowForInput_(input);
|
|
|
inputRows.push(row);
|
|
|
} else {
|
|
|
row = inputRows[inputRows.length - 1];
|
|
|
}
|
|
|
row.push(input);
|
|
|
|
|
|
|
|
|
input.renderHeight = this.computeInputHeight_(input, row, previousRow);
|
|
|
input.renderWidth = this.computeInputWidth_(input);
|
|
|
|
|
|
|
|
|
|
|
|
row.statementNotchAtBottom = true;
|
|
|
if (input.connection && input.connection.type === Blockly.NEXT_STATEMENT) {
|
|
|
var linkedBlock = input.connection.targetBlock();
|
|
|
if (linkedBlock && !linkedBlock.lastConnectionInStack()) {
|
|
|
row.statementNotchAtBottom = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if (input.connection) {
|
|
|
var linkedBlock = input.connection.targetBlock();
|
|
|
var paddedHeight = 0;
|
|
|
var paddedWidth = 0;
|
|
|
if (linkedBlock) {
|
|
|
|
|
|
var bBox = linkedBlock.getHeightWidth();
|
|
|
paddedHeight = bBox.height;
|
|
|
paddedWidth = bBox.width;
|
|
|
} else {
|
|
|
|
|
|
paddedHeight = Blockly.BlockSvg.INPUT_SHAPE_HEIGHT;
|
|
|
}
|
|
|
if (input.connection.type === Blockly.INPUT_VALUE) {
|
|
|
paddedHeight += 2 * Blockly.BlockSvg.INLINE_PADDING_Y;
|
|
|
}
|
|
|
if (input.connection.type === Blockly.NEXT_STATEMENT) {
|
|
|
|
|
|
if (row.statementNotchAtBottom) {
|
|
|
paddedHeight -= Blockly.BlockSvg.NOTCH_HEIGHT;
|
|
|
}
|
|
|
}
|
|
|
input.renderHeight = Math.max(input.renderHeight, paddedHeight);
|
|
|
input.renderWidth = Math.max(input.renderWidth, paddedWidth);
|
|
|
}
|
|
|
row.height = Math.max(row.height, input.renderHeight);
|
|
|
input.fieldWidth = 0;
|
|
|
if (inputRows.length == 1) {
|
|
|
|
|
|
input.fieldWidth += this.RTL ? -iconWidth : iconWidth;
|
|
|
}
|
|
|
var previousFieldEditable = false;
|
|
|
for (var j = 0, field; field = input.fieldRow[j]; j++) {
|
|
|
if (j != 0) {
|
|
|
input.fieldWidth += Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
}
|
|
|
|
|
|
var fieldSize = field.getSize();
|
|
|
field.renderWidth = fieldSize.width;
|
|
|
field.renderSep = (previousFieldEditable && field.EDITABLE) ?
|
|
|
Blockly.BlockSvg.SEP_SPACE_X : 0;
|
|
|
|
|
|
if (!isSecondInputOnProcedure) {
|
|
|
input.fieldWidth += field.renderWidth + field.renderSep;
|
|
|
}
|
|
|
row.height = Math.max(row.height, fieldSize.height);
|
|
|
previousFieldEditable = field.EDITABLE;
|
|
|
}
|
|
|
|
|
|
if (row.type != Blockly.BlockSvg.INLINE) {
|
|
|
if (row.type == Blockly.NEXT_STATEMENT) {
|
|
|
hasStatement = true;
|
|
|
fieldStatementWidth = Math.max(fieldStatementWidth, input.fieldWidth);
|
|
|
} else {
|
|
|
if (row.type == Blockly.INPUT_VALUE) {
|
|
|
hasValue = true;
|
|
|
} else if (row.type == Blockly.DUMMY_INPUT) {
|
|
|
hasDummy = true;
|
|
|
}
|
|
|
fieldValueWidth = Math.max(fieldValueWidth, input.fieldWidth);
|
|
|
}
|
|
|
}
|
|
|
previousRow = row;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (hasStatement) {
|
|
|
|
|
|
const input = inputList[inputList.length - 1];
|
|
|
const field = input.fieldRow[0];
|
|
|
if (field instanceof Blockly.FieldImage) {
|
|
|
|
|
|
const measureables = [];
|
|
|
for (var i = inputList.length - 1; i--; ) {
|
|
|
if (inputList[i].type == Blockly.NEXT_STATEMENT) break;
|
|
|
measureables.push(inputList[i]);
|
|
|
}
|
|
|
|
|
|
if (measureables.length) {
|
|
|
const newWidth = measureables.reduce((w, input) => w + (input.fieldWidth), 0);
|
|
|
input.fieldWidth = newWidth * (Blockly.BlockSvg.BOX_FIELD_PADDING / 4);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.computeOutputPadding_(inputRows);
|
|
|
|
|
|
|
|
|
inputRows.statementEdge = Blockly.BlockSvg.STATEMENT_INPUT_EDGE_WIDTH +
|
|
|
fieldStatementWidth;
|
|
|
|
|
|
|
|
|
inputRows.rightEdge = this.computeRightEdge_(inputRows.rightEdge,
|
|
|
hasStatement);
|
|
|
|
|
|
|
|
|
for (var i = 0; i < inputRows.length; i++) {
|
|
|
inputRows.bottomEdge += inputRows[i].height;
|
|
|
}
|
|
|
|
|
|
inputRows.hasValue = hasValue;
|
|
|
inputRows.hasStatement = hasStatement;
|
|
|
inputRows.hasDummy = hasDummy;
|
|
|
return inputRows;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.computeInputWidth_ = function(input) {
|
|
|
|
|
|
if (input.type == Blockly.INPUT_VALUE &&
|
|
|
(!input.connection || !input.connection.isConnected())) {
|
|
|
const shape = input.connection.getOutputShape();
|
|
|
switch (shape) {
|
|
|
case Blockly.OUTPUT_SHAPE_SQUARE:
|
|
|
return Blockly.BlockSvg.INPUT_SHAPE_SQUARE_WIDTH;
|
|
|
case Blockly.OUTPUT_SHAPE_ROUND:
|
|
|
return Blockly.BlockSvg.INPUT_SHAPE_ROUND_WIDTH;
|
|
|
case Blockly.OUTPUT_SHAPE_HEXAGONAL:
|
|
|
return Blockly.BlockSvg.INPUT_SHAPE_HEXAGONAL_WIDTH;
|
|
|
case Blockly.OUTPUT_SHAPE_LEAF:
|
|
|
return Blockly.BlockSvg.INPUT_SHAPE_LEAF_WIDTH;
|
|
|
case Blockly.OUTPUT_SHAPE_PLUS:
|
|
|
return Blockly.BlockSvg.INPUT_SHAPE_PLUS_WIDTH;
|
|
|
default: {
|
|
|
const customShape = Blockly.BlockSvg.CUSTOM_SHAPES.get(shape);
|
|
|
if (customShape) return customShape.emptyInputWidth;
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
return 0;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.computeInputHeight_ = function(input, row,
|
|
|
previousRow) {
|
|
|
if (this.inputList.length === 1 && this.outputConnection &&
|
|
|
(this.isShadow() &&
|
|
|
!Blockly.scratchBlocksUtils.isShadowArgumentReporter(this) &&
|
|
|
(this.type !== 'procedures_prototype' ||
|
|
|
this.type !== 'procedures_call')) &&
|
|
|
this.type !== 'polygon') {
|
|
|
|
|
|
return Blockly.BlockSvg.MIN_BLOCK_Y_SINGLE_FIELD_OUTPUT;
|
|
|
} else if (this.outputConnection) {
|
|
|
|
|
|
if (this.isScratchExtension || this.type === 'polygon') {
|
|
|
return Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER + 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
}
|
|
|
|
|
|
return Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER;
|
|
|
} else if (row.type == Blockly.NEXT_STATEMENT) {
|
|
|
|
|
|
return Blockly.BlockSvg.MIN_STATEMENT_INPUT_HEIGHT;
|
|
|
} else if (previousRow && previousRow.type == Blockly.NEXT_STATEMENT) {
|
|
|
|
|
|
return Blockly.BlockSvg.EXTRA_STATEMENT_ROW_Y;
|
|
|
} else {
|
|
|
|
|
|
|
|
|
if (this.isScratchExtension && this.previousConnection) {
|
|
|
return Blockly.BlockSvg.MIN_BLOCK_Y + 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
}
|
|
|
|
|
|
return Blockly.BlockSvg.MIN_BLOCK_Y;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.createRowForInput_ = function(input) {
|
|
|
|
|
|
var row = [];
|
|
|
if (input.type != Blockly.NEXT_STATEMENT) {
|
|
|
row.type = Blockly.BlockSvg.INLINE;
|
|
|
} else {
|
|
|
row.type = input.type;
|
|
|
}
|
|
|
row.height = 0;
|
|
|
|
|
|
row.paddingStart = Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
row.paddingEnd = Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
return row;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.computeRightEdge_ = function(curEdge, hasStatement) {
|
|
|
var edge = curEdge;
|
|
|
if (this.previousConnection || this.nextConnection) {
|
|
|
|
|
|
edge = Math.max(edge, Blockly.BlockSvg.MIN_BLOCK_X);
|
|
|
} else if (this.outputConnection) {
|
|
|
if (this.isShadow() &&
|
|
|
!Blockly.scratchBlocksUtils.isShadowArgumentReporter(this)) {
|
|
|
if (this.type === 'polygon') {
|
|
|
edge = edge
|
|
|
} else {
|
|
|
|
|
|
edge = Math.max(edge, Blockly.BlockSvg.MIN_BLOCK_X_SHADOW_OUTPUT);
|
|
|
}
|
|
|
} else {
|
|
|
|
|
|
edge = Math.max(edge, Blockly.BlockSvg.MIN_BLOCK_X_OUTPUT);
|
|
|
}
|
|
|
}
|
|
|
if (hasStatement) {
|
|
|
|
|
|
edge = Math.max(edge, Blockly.BlockSvg.MIN_BLOCK_X_WITH_STATEMENT);
|
|
|
}
|
|
|
|
|
|
|
|
|
if (this.insertionMarkerMinWidth_ > 0) {
|
|
|
edge = Math.max(edge, this.insertionMarkerMinWidth_);
|
|
|
}
|
|
|
return edge;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.computeOutputPadding_ = function(inputRows) {
|
|
|
|
|
|
if (!this.getOutputShape() || !this.outputConnection ||
|
|
|
(this.isShadow() &&
|
|
|
!Blockly.scratchBlocksUtils.isShadowArgumentReporter(this))) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (inputRows.length > 1) {
|
|
|
return;
|
|
|
}
|
|
|
var row = inputRows[0];
|
|
|
var shape = this.getOutputShape();
|
|
|
|
|
|
row.paddingStart = 0;
|
|
|
row.paddingEnd = 0;
|
|
|
|
|
|
var firstInput = row[0];
|
|
|
var firstField = firstInput.fieldRow[0];
|
|
|
var otherShape;
|
|
|
|
|
|
|
|
|
if (firstField || !firstInput.connection) {
|
|
|
otherShape = 0;
|
|
|
} else {
|
|
|
|
|
|
var inputConnection = firstInput.connection;
|
|
|
if (!inputConnection.targetConnection) {
|
|
|
|
|
|
otherShape = inputConnection.getOutputShape();
|
|
|
} else {
|
|
|
|
|
|
otherShape = inputConnection.targetConnection.getSourceBlock().getOutputShape();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (shape == Blockly.OUTPUT_SHAPE_HEXAGONAL &&
|
|
|
otherShape != Blockly.OUTPUT_SHAPE_HEXAGONAL) {
|
|
|
var deltaHeight = firstInput.renderHeight - Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER;
|
|
|
|
|
|
row.paddingStart += deltaHeight / 2;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
const customShape = Blockly.BlockSvg.CUSTOM_SHAPES.get(shape);
|
|
|
if (customShape && customShape.blockPaddingStart) {
|
|
|
row.paddingStart += customShape.blockPaddingStart(this, otherShape, firstInput, firstField, row);
|
|
|
}
|
|
|
|
|
|
const paddingStart = (Blockly.BlockSvg.SHAPE_IN_SHAPE_PADDING[shape] || {})[otherShape];
|
|
|
row.paddingStart += paddingStart === undefined ? Blockly.BlockSvg.DEFAULT_SHAPE_PADDING : paddingStart;
|
|
|
|
|
|
|
|
|
var lastInput = row[row.length - 1];
|
|
|
|
|
|
|
|
|
|
|
|
if (lastInput.connection) {
|
|
|
|
|
|
var inputConnection = lastInput.connection;
|
|
|
if (!inputConnection.targetConnection) {
|
|
|
|
|
|
otherShape = inputConnection.getOutputShape();
|
|
|
} else {
|
|
|
|
|
|
otherShape = inputConnection.targetConnection.getSourceBlock().getOutputShape();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (shape == Blockly.OUTPUT_SHAPE_HEXAGONAL &&
|
|
|
otherShape != Blockly.OUTPUT_SHAPE_HEXAGONAL) {
|
|
|
var deltaHeight = lastInput.renderHeight - Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER;
|
|
|
|
|
|
row.paddingEnd += deltaHeight / 2;
|
|
|
}
|
|
|
} else {
|
|
|
|
|
|
otherShape = 0;
|
|
|
}
|
|
|
|
|
|
if (customShape && customShape.blockPaddingEnd) {
|
|
|
const lastField = lastInput.fieldRow[lastInput.fieldRow.length - 1];
|
|
|
row.paddingEnd += customShape.blockPaddingEnd(this, otherShape, lastInput, lastField, row);
|
|
|
}
|
|
|
|
|
|
const paddingEnd = (Blockly.BlockSvg.SHAPE_IN_SHAPE_PADDING[shape] || {})[otherShape];
|
|
|
row.paddingEnd += paddingEnd === undefined ? Blockly.BlockSvg.DEFAULT_SHAPE_PADDING : paddingEnd;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.renderDraw_ = function(iconWidth, inputRows) {
|
|
|
this.startHat_ = false;
|
|
|
|
|
|
|
|
|
this.squareTopLeftCorner_ = false;
|
|
|
if (!this.outputConnection && !this.previousConnection) {
|
|
|
|
|
|
this.squareTopLeftCorner_ = true;
|
|
|
this.startHat_ = true;
|
|
|
inputRows.rightEdge = Math.max(inputRows.rightEdge, 100);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.edgeShapeWidth_ = 0;
|
|
|
this.edgeShape_ = null;
|
|
|
if (this.outputConnection) {
|
|
|
|
|
|
var shape = this.getOutputShape();
|
|
|
if (shape != Blockly.OUTPUT_SHAPE_SQUARE) {
|
|
|
this.edgeShapeWidth_ = inputRows.bottomEdge / 2;
|
|
|
this.edgeShape_ = shape;
|
|
|
this.squareTopLeftCorner_ = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
var steps = [];
|
|
|
|
|
|
this.renderDrawTop_(steps, inputRows.rightEdge);
|
|
|
var cursorY = this.renderDrawRight_(steps, inputRows, iconWidth);
|
|
|
this.renderDrawBottom_(steps, cursorY);
|
|
|
this.renderDrawLeft_(steps, cursorY);
|
|
|
|
|
|
var pathString = steps.join(' ');
|
|
|
this.svgPath_.setAttribute('d', pathString);
|
|
|
|
|
|
if (this.RTL) {
|
|
|
|
|
|
|
|
|
this.svgPath_.setAttribute('transform', 'scale(-1 1)');
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.renderClassify_ = function() {
|
|
|
var shapes = [];
|
|
|
|
|
|
if (this.outputConnection) {
|
|
|
if (this.isShadow_ && !(this.type === 'polygon' || this.type === 'procedures_prototype')) {
|
|
|
shapes.push('argument');
|
|
|
} else {
|
|
|
shapes.push('reporter');
|
|
|
}
|
|
|
switch (this.edgeShape_) {
|
|
|
case Blockly.OUTPUT_SHAPE_HEXAGONAL:
|
|
|
shapes.push('boolean');
|
|
|
break;
|
|
|
case Blockly.OUTPUT_SHAPE_ROUND:
|
|
|
shapes.push('round');
|
|
|
break;
|
|
|
case Blockly.OUTPUT_SHAPE_LEAF:
|
|
|
shapes.push('leaf');
|
|
|
break;
|
|
|
case Blockly.OUTPUT_SHAPE_PLUS:
|
|
|
shapes.push('plus');
|
|
|
break;
|
|
|
default: {
|
|
|
const isCustomShape = Blockly.BlockSvg.CUSTOM_SHAPES.has(this.edgeShape_);
|
|
|
if (isCustomShape) shapes.push('custom');
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
|
|
|
var inputList = this.inputList;
|
|
|
var statementCount = 0;
|
|
|
for (var i = 0, input; input = inputList[i]; i++) {
|
|
|
if (input.connection && input.connection.type === Blockly.NEXT_STATEMENT) {
|
|
|
statementCount++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (statementCount) {
|
|
|
shapes.push('c-block');
|
|
|
shapes.push('c-' + statementCount);
|
|
|
}
|
|
|
if (this.startHat_) {
|
|
|
shapes.push('hat');
|
|
|
} else if (!statementCount) {
|
|
|
shapes.push('stack');
|
|
|
}
|
|
|
if (!this.nextConnection) {
|
|
|
shapes.push('end');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
this.svgGroup_.setAttribute('data-shapes', shapes.join(' '));
|
|
|
|
|
|
if (this.getCategory()) {
|
|
|
this.svgGroup_.setAttribute('data-category', this.getCategory());
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.renderDrawTop_ = function(steps, rightEdge) {
|
|
|
if (this.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE ||
|
|
|
this.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE + '_return') {
|
|
|
steps.push('m 0, 0');
|
|
|
steps.push(Blockly.BlockSvg.TOP_LEFT_CORNER_DEFINE_HAT);
|
|
|
} else {
|
|
|
|
|
|
if (this.squareTopLeftCorner_) {
|
|
|
steps.push('m 0,0');
|
|
|
if (this.startHat_) {
|
|
|
steps.push(Blockly.BlockSvg.START_HAT_PATH);
|
|
|
}
|
|
|
|
|
|
if (this.edgeShapeWidth_) {
|
|
|
steps.push('m ' + this.edgeShapeWidth_ + ',0');
|
|
|
}
|
|
|
} else {
|
|
|
steps.push(Blockly.BlockSvg.TOP_LEFT_CORNER_START);
|
|
|
|
|
|
steps.push(Blockly.BlockSvg.TOP_LEFT_CORNER);
|
|
|
}
|
|
|
|
|
|
|
|
|
if (this.previousConnection) {
|
|
|
|
|
|
steps.push('H', Blockly.BlockSvg.NOTCH_START_PADDING);
|
|
|
if (Blockly.BlockSvg.NOTCH_SWITCH_ENABLE && (this.previousConnection.check_ || []).includes("switchCase")) {
|
|
|
steps.push(Blockly.BlockSvg.NOTCH_SWITCH_PATH_LEFT);
|
|
|
} else {
|
|
|
steps.push(Blockly.BlockSvg.NOTCH_PATH_LEFT);
|
|
|
}
|
|
|
|
|
|
var connectionX = (this.RTL ?
|
|
|
-Blockly.BlockSvg.NOTCH_WIDTH : Blockly.BlockSvg.NOTCH_WIDTH);
|
|
|
this.previousConnection.setOffsetInBlock(connectionX, 0);
|
|
|
}
|
|
|
}
|
|
|
this.width = rightEdge;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.renderDrawRight_ = function(steps,
|
|
|
inputRows, iconWidth) {
|
|
|
var cursorX = 0;
|
|
|
var cursorY = 0;
|
|
|
if (!this.isCollapsed()) {
|
|
|
var connectionX, connectionY;
|
|
|
for (var y = 0, row; row = inputRows[y]; y++) {
|
|
|
cursorX = row.paddingStart;
|
|
|
if (y == 0) {
|
|
|
cursorX += this.RTL ? -iconWidth : iconWidth;
|
|
|
}
|
|
|
|
|
|
if (row.type == Blockly.BlockSvg.INLINE) {
|
|
|
|
|
|
for (var x = 0, input; input = row[x]; x++) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fieldY = cursorY + row.height / 2;
|
|
|
|
|
|
var fieldX = Blockly.BlockSvg.getAlignedCursor_(cursorX, input,
|
|
|
inputRows.rightEdge);
|
|
|
|
|
|
cursorX = this.renderFields_(input.fieldRow, fieldX, fieldY);
|
|
|
if (input.type == Blockly.INPUT_VALUE) {
|
|
|
|
|
|
|
|
|
|
|
|
if (this.previousConnection) {
|
|
|
cursorX = Math.max(cursorX, Blockly.BlockSvg.INPUT_AND_FIELD_MIN_X);
|
|
|
}
|
|
|
connectionX = this.RTL ? -cursorX : cursorX;
|
|
|
|
|
|
var connectionYOffset = row.height / 2;
|
|
|
connectionY = cursorY + connectionYOffset;
|
|
|
input.connection.setOffsetInBlock(connectionX, connectionY);
|
|
|
this.renderInputShape_(input, cursorX, cursorY + connectionYOffset);
|
|
|
cursorX += input.renderWidth + Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
cursorX -= Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
cursorX += row.paddingEnd;
|
|
|
|
|
|
|
|
|
inputRows.rightEdge = Math.max(cursorX, inputRows.rightEdge, this.inputList.find(v => v.type == Blockly.NEXT_STATEMENT) ? Blockly.BlockSvg.MIN_BLOCK_X_WITH_STATEMENT + this.edgeShapeWidth_ : 0);
|
|
|
|
|
|
cursorX = Math.max(cursorX, inputRows.rightEdge);
|
|
|
this.width = Math.max(this.width, cursorX);
|
|
|
if (this.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE + '_return') {
|
|
|
this.renderDefineBlock_(steps, inputRows, row[0], row, cursorY, cursorX);
|
|
|
}
|
|
|
if (this.type != Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE + '_return') {
|
|
|
if (!this.edgeShape_ || this.inputList.find(v => v.type == Blockly.NEXT_STATEMENT)) {
|
|
|
|
|
|
steps.push('H', cursorX - Blockly.BlockSvg.CORNER_RADIUS);
|
|
|
steps.push(Blockly.BlockSvg.TOP_RIGHT_CORNER);
|
|
|
} else {
|
|
|
|
|
|
steps.push('H', cursorX - this.edgeShapeWidth_);
|
|
|
}
|
|
|
|
|
|
|
|
|
if (!this.edgeShape_ || this.inputList.find(v => v.type == Blockly.NEXT_STATEMENT)) {
|
|
|
steps.push('v', row.height - Blockly.BlockSvg.CORNER_RADIUS * 2);
|
|
|
}
|
|
|
}
|
|
|
} else if (row.type == Blockly.NEXT_STATEMENT) {
|
|
|
|
|
|
var input = row[0];
|
|
|
var fieldX = cursorX;
|
|
|
|
|
|
|
|
|
var fieldY = cursorY;
|
|
|
fieldY += Blockly.BlockSvg.MIN_STATEMENT_INPUT_HEIGHT;
|
|
|
this.renderFields_(input.fieldRow, fieldX, fieldY);
|
|
|
|
|
|
cursorX = inputRows.statementEdge + Blockly.BlockSvg.NOTCH_WIDTH;
|
|
|
|
|
|
if (this.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE) {
|
|
|
this.renderDefineBlock_(steps, inputRows, input, row, cursorY);
|
|
|
} else {
|
|
|
Blockly.BlockSvg.drawStatementInputFromTopRight_(steps, cursorX,
|
|
|
inputRows.rightEdge, row, this);
|
|
|
}
|
|
|
|
|
|
|
|
|
connectionX = this.RTL ? -cursorX : cursorX;
|
|
|
input.connection.setOffsetInBlock(connectionX, cursorY);
|
|
|
if (input.connection.isConnected()) {
|
|
|
this.width = Math.max(this.width, inputRows.statementEdge +
|
|
|
input.connection.targetBlock().getHeightWidth().width + (this.inputList.find(v => v.type == Blockly.NEXT_STATEMENT) ? this.edgeShapeWidth_ : 0));
|
|
|
}
|
|
|
if ((!(this.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE ||
|
|
|
this.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE + '_return')) &&
|
|
|
(y == inputRows.length - 1 ||
|
|
|
inputRows[y + 1].type == Blockly.NEXT_STATEMENT)) {
|
|
|
|
|
|
|
|
|
steps.push(Blockly.BlockSvg.TOP_RIGHT_CORNER);
|
|
|
steps.push('v', Blockly.BlockSvg.EXTRA_STATEMENT_ROW_Y - 2 * Blockly.BlockSvg.CORNER_RADIUS);
|
|
|
cursorY += Blockly.BlockSvg.EXTRA_STATEMENT_ROW_Y;
|
|
|
}
|
|
|
}
|
|
|
cursorY += row.height;
|
|
|
}
|
|
|
}
|
|
|
this.drawEdgeShapeRight_(steps);
|
|
|
if (!inputRows.length) {
|
|
|
cursorY = Blockly.BlockSvg.MIN_BLOCK_Y;
|
|
|
steps.push('V', cursorY);
|
|
|
}
|
|
|
if (this.edgeShape_ && this.inputList.find(v => v.type == Blockly.NEXT_STATEMENT)) steps[1] = `m ${cursorY / 2} 0`
|
|
|
return cursorY;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.renderInputShape_ = function(input, x, y) {
|
|
|
var inputShape = input.outlinePath;
|
|
|
if (!inputShape) {
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (input.connection.targetConnection) {
|
|
|
inputShape.setAttribute('style', 'visibility: hidden');
|
|
|
} else {
|
|
|
var inputShapeX = 0, inputShapeY = 0;
|
|
|
var inputShapeInfo =
|
|
|
Blockly.BlockSvg.getInputShapeInfo_(input.connection.getOutputShape());
|
|
|
if (this.RTL) {
|
|
|
inputShapeX = -x - inputShapeInfo.width;
|
|
|
} else {
|
|
|
inputShapeX = x;
|
|
|
}
|
|
|
inputShapeY = y - (Blockly.BlockSvg.INPUT_SHAPE_HEIGHT / 2);
|
|
|
inputShape.setAttribute('d', inputShapeInfo.path);
|
|
|
inputShape.setAttribute('transform',
|
|
|
'translate(' + inputShapeX + ',' + inputShapeY + ')');
|
|
|
inputShape.setAttribute('data-argument-type', inputShapeInfo.argType);
|
|
|
inputShape.setAttribute('style', 'visibility: visible');
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.renderDrawBottom_ = function(steps, cursorY) {
|
|
|
this.height = cursorY;
|
|
|
if (!this.edgeShape_ || this.inputList.find(v => v.type == Blockly.NEXT_STATEMENT)) {
|
|
|
steps.push(Blockly.BlockSvg.BOTTOM_RIGHT_CORNER);
|
|
|
}
|
|
|
if (this.nextConnection) {
|
|
|
|
|
|
var notchStart = (
|
|
|
Blockly.BlockSvg.NOTCH_WIDTH +
|
|
|
Blockly.BlockSvg.NOTCH_START_PADDING +
|
|
|
Blockly.BlockSvg.CORNER_RADIUS
|
|
|
);
|
|
|
steps.push('H', notchStart, ' ');
|
|
|
if (Blockly.BlockSvg.NOTCH_SWITCH_ENABLE && (this.nextConnection.check_ || []).includes("switchCase")) {
|
|
|
steps.push(Blockly.BlockSvg.NOTCH_SWITCH_PATH_RIGHT);
|
|
|
} else {
|
|
|
steps.push(Blockly.BlockSvg.NOTCH_PATH_RIGHT);
|
|
|
}
|
|
|
|
|
|
var connectionX = this.RTL ? -Blockly.BlockSvg.NOTCH_WIDTH :
|
|
|
Blockly.BlockSvg.NOTCH_WIDTH;
|
|
|
this.nextConnection.setOffsetInBlock(connectionX, cursorY);
|
|
|
|
|
|
this.height += Blockly.BlockSvg.NOTCH_HEIGHT;
|
|
|
}
|
|
|
|
|
|
if (!this.edgeShape_) {
|
|
|
steps.push('H', Blockly.BlockSvg.CORNER_RADIUS);
|
|
|
|
|
|
steps.push(Blockly.BlockSvg.BOTTOM_LEFT_CORNER);
|
|
|
} else {
|
|
|
steps.push('H', this.height / 2);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.renderDrawLeft_ = function(steps, cursorY) {
|
|
|
let scale = this.height / 2
|
|
|
|
|
|
if (this.outputConnection) {
|
|
|
|
|
|
this.outputConnection.setOffsetInBlock(0, this.height / 2);
|
|
|
}
|
|
|
if (this.edgeShape_) {
|
|
|
|
|
|
switch (this.edgeShape_) {
|
|
|
case Blockly.OUTPUT_SHAPE_ROUND:
|
|
|
|
|
|
steps.push('a ' + scale + ' ' + scale + ' 0 0 1 0 -' + scale * 2);
|
|
|
break;
|
|
|
case Blockly.OUTPUT_SHAPE_HEXAGONAL:
|
|
|
|
|
|
steps.push('l ' + -scale + ' ' + -scale +
|
|
|
' l ' + scale + ' ' + -scale);
|
|
|
break;
|
|
|
case Blockly.OUTPUT_SHAPE_LEAF:
|
|
|
|
|
|
steps.push(
|
|
|
`a ${scale} ${scale} 0 0 1 -${scale} -${scale} ` +
|
|
|
`l 0 -${scale * 0.6} ` +
|
|
|
`a ${scale * 0.4} ${scale * 0.4} 0 0 1 ${scale * 0.4} -${scale * 0.4}`
|
|
|
);
|
|
|
break;
|
|
|
case Blockly.OUTPUT_SHAPE_PLUS: {
|
|
|
|
|
|
const unit = 6;
|
|
|
const remainingHeight = scale * 2 - 36;
|
|
|
const remainingWidth = scale - 20;
|
|
|
steps.push(
|
|
|
`l -${remainingWidth} 0 ` +
|
|
|
`a ${unit} ${unit} 0 0 1 -${unit} -${unit} ` +
|
|
|
`a ${unit} ${unit} 0 0 0 -${unit} -${unit} ` +
|
|
|
`l -2 0 ` +
|
|
|
`a ${unit} ${unit} 0 0 1 -${unit} -${unit} ` +
|
|
|
`l 0 -${remainingHeight} ` +
|
|
|
`a ${unit} ${unit} 0 0 1 ${unit} -${unit} ` +
|
|
|
`l 2 0 ` +
|
|
|
`a ${unit} ${unit} 0 0 0 ${unit} -${unit} ` +
|
|
|
`a ${unit} ${unit} 0 0 1 ${unit} -${unit} ` +
|
|
|
`l ${remainingWidth} 0`
|
|
|
);
|
|
|
break;
|
|
|
}
|
|
|
default: {
|
|
|
const customShape = Blockly.BlockSvg.CUSTOM_SHAPES.get(this.edgeShape_);
|
|
|
if (customShape) {
|
|
|
const path = customShape.leftPath(this);
|
|
|
if (path && Array.isArray(path)) steps.push(...path);
|
|
|
else console.error(`Left Path Function for shape: ${this.edgeShape_} did not return an Array!`);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
steps.push('z');
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.drawEdgeShapeRight_ = function(steps) {
|
|
|
if (this.edgeShape_ && !this.inputList.find(v => v.type == Blockly.NEXT_STATEMENT)) {
|
|
|
|
|
|
switch (this.edgeShape_) {
|
|
|
case Blockly.OUTPUT_SHAPE_ROUND:
|
|
|
|
|
|
steps.push('a ' + this.edgeShapeWidth_ + ' ' + this.edgeShapeWidth_ +
|
|
|
' 0 0 1 0 ' + this.edgeShapeWidth_ * 2);
|
|
|
break;
|
|
|
case Blockly.OUTPUT_SHAPE_HEXAGONAL:
|
|
|
|
|
|
steps.push('l ' + this.edgeShapeWidth_ + ' ' + this.edgeShapeWidth_ +
|
|
|
' l ' + -this.edgeShapeWidth_ + ' ' + this.edgeShapeWidth_);
|
|
|
break;
|
|
|
case Blockly.OUTPUT_SHAPE_LEAF:
|
|
|
|
|
|
steps.push(
|
|
|
`a ${this.edgeShapeWidth_} ${this.edgeShapeWidth_} 0 0 1 ${this.edgeShapeWidth_} ${this.edgeShapeWidth_} ` +
|
|
|
`l 0 ${this.edgeShapeWidth_ * 0.6} ` +
|
|
|
`a ${this.edgeShapeWidth_ * 0.4} ${this.edgeShapeWidth_ * 0.4} 0 0 1 -${this.edgeShapeWidth_ * 0.4} ${this.edgeShapeWidth_ * 0.4}`
|
|
|
);
|
|
|
break;
|
|
|
case Blockly.OUTPUT_SHAPE_PLUS: {
|
|
|
|
|
|
const unit = 6;
|
|
|
const remainingHeight = this.edgeShapeWidth_ * 2 - 36;
|
|
|
const remainingWidth = this.edgeShapeWidth_ - 20;
|
|
|
steps.push(
|
|
|
`l ${remainingWidth} 0 ` +
|
|
|
`a ${unit} ${unit} 0 0 1 ${unit} ${unit} ` +
|
|
|
`a ${unit} ${unit} 0 0 0 ${unit} ${unit} ` +
|
|
|
`l 2 0 ` +
|
|
|
`a ${unit} ${unit} 0 0 1 ${unit} ${unit} ` +
|
|
|
`l 0 ${remainingHeight} ` +
|
|
|
`a ${unit} ${unit} 0 0 1 -${unit} ${unit} ` +
|
|
|
`l -2 0 ` +
|
|
|
`a ${unit} ${unit} 0 0 0 -${unit} ${unit} ` +
|
|
|
`a ${unit} ${unit} 0 0 1 -${unit} ${unit} ` +
|
|
|
`l -${remainingWidth} 0`
|
|
|
);
|
|
|
break;
|
|
|
}
|
|
|
default: {
|
|
|
const customShape = Blockly.BlockSvg.CUSTOM_SHAPES.get(this.edgeShape_);
|
|
|
if (customShape) {
|
|
|
const path = customShape.rightPath(this);
|
|
|
if (path && Array.isArray(path)) steps.push(...path);
|
|
|
else console.error(`Right Path Function for shape: ${this.edgeShape_} did not return an Array!`);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.positionNewBlock = function(newBlock, newConnection,
|
|
|
existingConnection) {
|
|
|
|
|
|
|
|
|
if (newConnection.type == Blockly.NEXT_STATEMENT) {
|
|
|
var dx = existingConnection.x_ - newConnection.x_;
|
|
|
var dy = existingConnection.y_ - newConnection.y_;
|
|
|
|
|
|
newBlock.moveBy(dx, dy);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.drawStatementInputFromTopRight_ = function(steps, cursorX,
|
|
|
rightEdge, row, block) {
|
|
|
Blockly.BlockSvg.drawStatementInputTop_(steps, cursorX, row, block);
|
|
|
steps.push('v', row.height - 2 * Blockly.BlockSvg.CORNER_RADIUS);
|
|
|
Blockly.BlockSvg.drawStatementInputBottom_(steps, rightEdge, row, block);
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.drawStatementInputTop_ = function(steps, cursorX, row, block) {
|
|
|
steps.push(Blockly.BlockSvg.BOTTOM_RIGHT_CORNER);
|
|
|
steps.push('H', cursorX + Blockly.BlockSvg.STATEMENT_INPUT_INNER_SPACE +
|
|
|
2 * Blockly.BlockSvg.CORNER_RADIUS + block.edgeShapeWidth_);
|
|
|
if (Blockly.BlockSvg.NOTCH_SWITCH_ENABLE && row[0].connection && (row[0].connection.check_ || []).includes("switchCase")) {
|
|
|
steps.push(Blockly.BlockSvg.NOTCH_SWITCH_PATH_RIGHT);
|
|
|
} else {
|
|
|
steps.push(Blockly.BlockSvg.NOTCH_PATH_RIGHT);
|
|
|
}
|
|
|
steps.push('h', '-' + Blockly.BlockSvg.STATEMENT_INPUT_INNER_SPACE);
|
|
|
steps.push(Blockly.BlockSvg.INNER_TOP_LEFT_CORNER);
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.drawStatementInputBottom_ = function(steps, rightEdge, row, block) {
|
|
|
steps.push(Blockly.BlockSvg.INNER_BOTTOM_LEFT_CORNER);
|
|
|
if (row.statementNotchAtBottom) {
|
|
|
steps.push('h ', Blockly.BlockSvg.STATEMENT_INPUT_INNER_SPACE);
|
|
|
if (Blockly.BlockSvg.NOTCH_SWITCH_ENABLE && row[0].connection && (row[0].connection.check_ || []).includes("switchCase")) {
|
|
|
steps.push(Blockly.BlockSvg.NOTCH_SWITCH_PATH_LEFT);
|
|
|
} else {
|
|
|
steps.push(Blockly.BlockSvg.NOTCH_PATH_LEFT);
|
|
|
}
|
|
|
}
|
|
|
steps.push('H', rightEdge - Blockly.BlockSvg.CORNER_RADIUS);
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.renderDefineBlock_ = function(steps, inputRows,
|
|
|
input, row, cursorY, cursorX) {
|
|
|
|
|
|
|
|
|
|
|
|
var hasFollowingText = row.length == 2;
|
|
|
|
|
|
|
|
|
var rightSide;
|
|
|
if (!cursorX) {
|
|
|
rightSide = inputRows.rightEdge;
|
|
|
if (input.connection && input.connection.targetBlock()) {
|
|
|
rightSide = inputRows.statementEdge +
|
|
|
input.connection.targetBlock().getHeightWidth().width +
|
|
|
Blockly.BlockSvg.DEFINE_BLOCK_PADDING_RIGHT;
|
|
|
} else {
|
|
|
|
|
|
rightSide = Math.max(Blockly.BlockSvg.MIN_BLOCK_X_WITH_STATEMENT, rightSide)
|
|
|
+ Blockly.BlockSvg.DEFINE_BLOCK_PADDING_RIGHT;
|
|
|
}
|
|
|
rightSide -= Blockly.BlockSvg.DEFINE_HAT_CORNER_RADIUS;
|
|
|
|
|
|
if (hasFollowingText) {
|
|
|
var followingTextInput = row[1];
|
|
|
var fieldStart = rightSide + 3 * Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
rightSide += followingTextInput.fieldRow[0].getSize().width;
|
|
|
rightSide += 2 * Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fieldY = cursorY;
|
|
|
fieldY += Blockly.BlockSvg.MIN_STATEMENT_INPUT_HEIGHT;
|
|
|
this.renderFields_(followingTextInput.fieldRow, fieldStart, fieldY);
|
|
|
}
|
|
|
} else {
|
|
|
rightSide = cursorX;
|
|
|
}
|
|
|
|
|
|
steps.push('H', rightSide);
|
|
|
steps.push(Blockly.BlockSvg.TOP_RIGHT_CORNER_DEFINE_HAT);
|
|
|
row.height += 3 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
steps.push('v', row.height);
|
|
|
|
|
|
row.height += Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.getInputShapeInfo_ = function(shape) {
|
|
|
var inputShapePath = null;
|
|
|
var inputShapeArgType = null;
|
|
|
var inputShapeWidth = 0;
|
|
|
|
|
|
switch (shape) {
|
|
|
case Blockly.OUTPUT_SHAPE_PLUS:
|
|
|
inputShapePath = Blockly.BlockSvg.INPUT_SHAPE_PLUS;
|
|
|
inputShapeWidth = Blockly.BlockSvg.INPUT_SHAPE_PLUS_WIDTH;
|
|
|
inputShapeArgType = 'plus';
|
|
|
break;
|
|
|
case Blockly.OUTPUT_SHAPE_LEAF:
|
|
|
inputShapePath = Blockly.BlockSvg.INPUT_SHAPE_LEAF;
|
|
|
inputShapeWidth = Blockly.BlockSvg.INPUT_SHAPE_LEAF_WIDTH;
|
|
|
inputShapeArgType = 'leaf';
|
|
|
break;
|
|
|
case Blockly.OUTPUT_SHAPE_HEXAGONAL:
|
|
|
inputShapePath = Blockly.BlockSvg.INPUT_SHAPE_HEXAGONAL;
|
|
|
inputShapeWidth = Blockly.BlockSvg.INPUT_SHAPE_HEXAGONAL_WIDTH;
|
|
|
inputShapeArgType = 'boolean';
|
|
|
break;
|
|
|
case Blockly.OUTPUT_SHAPE_ROUND:
|
|
|
inputShapePath = Blockly.BlockSvg.INPUT_SHAPE_ROUND;
|
|
|
inputShapeWidth = Blockly.BlockSvg.INPUT_SHAPE_ROUND_WIDTH;
|
|
|
inputShapeArgType = 'round';
|
|
|
break;
|
|
|
case Blockly.OUTPUT_SHAPE_SQUARE:
|
|
|
default: {
|
|
|
|
|
|
const customShape = Blockly.BlockSvg.CUSTOM_SHAPES.get(shape);
|
|
|
if (shape !== Blockly.OUTPUT_SHAPE_SQUARE && customShape) {
|
|
|
inputShapePath = customShape.emptyInputPath;
|
|
|
inputShapeWidth = customShape.emptyInputWidth;
|
|
|
inputShapeArgType = customShape.name;
|
|
|
} else {
|
|
|
|
|
|
inputShapePath = Blockly.BlockSvg.INPUT_SHAPE_SQUARE;
|
|
|
inputShapeWidth = Blockly.BlockSvg.INPUT_SHAPE_SQUARE_WIDTH;
|
|
|
inputShapeArgType = 'square';
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return {
|
|
|
path: inputShapePath,
|
|
|
argType: inputShapeArgType,
|
|
|
width: inputShapeWidth
|
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.getAlignedCursor_ = function(cursorX, input, rightEdge) {
|
|
|
|
|
|
if (input.align === Blockly.ALIGN_RIGHT) {
|
|
|
cursorX += rightEdge - input.fieldWidth -
|
|
|
(2 * Blockly.BlockSvg.SEP_SPACE_X);
|
|
|
} else if (input.align === Blockly.ALIGN_CENTRE) {
|
|
|
cursorX = Math.max(cursorX, rightEdge / 2 - input.fieldWidth / 2);
|
|
|
}
|
|
|
return cursorX;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.prototype.renderMoveConnections_ = function() {
|
|
|
var blockTL = this.getRelativeToSurfaceXY();
|
|
|
var branchedReporterTL = blockTL.clone().translate(this.edgeShapeWidth_, 0);
|
|
|
|
|
|
if (this.previousConnection) {
|
|
|
this.previousConnection.moveToOffset(blockTL);
|
|
|
}
|
|
|
if (this.outputConnection) {
|
|
|
this.outputConnection.moveToOffset(blockTL);
|
|
|
}
|
|
|
|
|
|
for (var i = 0; i < this.inputList.length; i++) {
|
|
|
var conn = this.inputList[i].connection;
|
|
|
if (conn) {
|
|
|
conn.moveToOffset(this.inputList[i].type == Blockly.NEXT_STATEMENT ? branchedReporterTL : blockTL);
|
|
|
if (conn.isConnected()) {
|
|
|
conn.tighten_();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (this.nextConnection) {
|
|
|
this.nextConnection.moveToOffset(blockTL);
|
|
|
if (this.nextConnection.isConnected()) {
|
|
|
this.nextConnection.tighten_();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.CUSTOM_SHAPES = new Map([
|
|
|
|
|
|
|
|
|
|
|
|
[Blockly.OUTPUT_SHAPE_OCTAGONAL, {
|
|
|
emptyInputPath: "M 8 0 h 32 l 8 8 l 0 16 l -8 8 h -32 l -8 -8 l 0 -16 l 8 -8 z",
|
|
|
emptyInputWidth: 14 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
leftPath: (block) => {
|
|
|
const scale = block.height / 2;
|
|
|
return [`l ${-scale / 2} 0 l ${-scale / 2} ${-scale / 2} l 0 ${-scale} l ${scale / 2} ${-scale / 2} l ${scale / 2} 0`];
|
|
|
},
|
|
|
rightPath: (block) => {
|
|
|
const scale = block.edgeShapeWidth_;
|
|
|
return [`l ${scale / 2} 0 l ${scale / 2} ${scale / 2} l 0 ${scale} l ${-scale / 2} ${scale / 2} l ${-scale / 2} 0`];
|
|
|
},
|
|
|
blockPaddingStart: (_, __, firstInput) => {
|
|
|
return Math.max(((firstInput.renderHeight - Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER) - 4) / 2, 0);
|
|
|
},
|
|
|
blockPaddingEnd: (_, __, lastInput) => {
|
|
|
return Math.max(((lastInput.renderHeight - Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER) - 4) / 2, 0);
|
|
|
},
|
|
|
}],
|
|
|
[Blockly.OUTPUT_SHAPE_BUMPED, {
|
|
|
emptyInputPath: "M 8 0 h 32 a 1 1 0 0 1 0 16 a 1 1 0 0 1 0 16 h -32 a 1 1 0 0 1 0 -16 a 1 1 0 0 1 0 -16 z",
|
|
|
emptyInputWidth: 14 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
leftPath: (block) => {
|
|
|
const scale = block.height / 2;
|
|
|
return [`a 1 1 0 0 1 0 ${-scale} a 1 1 0 0 1 0 ${-scale}`];
|
|
|
},
|
|
|
rightPath: (block) => {
|
|
|
const scale = block.edgeShapeWidth_;
|
|
|
return [`a 1 1 0 0 1 0 ${scale} a 1 1 0 0 1 0 ${scale}`];
|
|
|
},
|
|
|
blockPaddingStart: (_, __, firstInput) => {
|
|
|
return Math.max(((firstInput.renderHeight - ScratchBlocks.BlockSvg.MIN_BLOCK_Y_REPORTER) * .5) + 17, 16);
|
|
|
},
|
|
|
blockPaddingEnd: (_, __, lastInput) => {
|
|
|
return Math.max(((lastInput.renderHeight - ScratchBlocks.BlockSvg.MIN_BLOCK_Y_REPORTER) * .5) + 25, 20);
|
|
|
},
|
|
|
}],
|
|
|
[Blockly.OUTPUT_SHAPE_INDENTED, {
|
|
|
emptyInputPath: "M 16 0 h 16 h 16 l -16 16 l 16 16 h -16 h -16 h -16 l 16 -16 l -16 -16 z",
|
|
|
emptyInputWidth: 12 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
leftPath: (block) => {
|
|
|
const scale = block.height / 2;
|
|
|
return [`h ${-scale} l ${scale} ${-scale} l ${-scale} ${-scale}`];
|
|
|
},
|
|
|
rightPath: (block) => {
|
|
|
const scale = block.edgeShapeWidth_;
|
|
|
return [`h ${scale} l ${-scale} ${scale} l ${scale} ${scale} h ${-scale}`];
|
|
|
},
|
|
|
blockPaddingStart: (_, __, firstInput) => {
|
|
|
return Math.max(((firstInput.renderHeight - Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER)) / 2, 0) + 4;
|
|
|
},
|
|
|
blockPaddingEnd: (_, __, lastInput) => {
|
|
|
return Math.max(((lastInput.renderHeight - Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER)) / 2, 0) + 4;
|
|
|
},
|
|
|
}],
|
|
|
[Blockly.OUTPUT_SHAPE_SCRAPPED, {
|
|
|
emptyInputPath: "M 16 0 h 16 h 16 l -6 10 l -4 1 l 4 2 v 6 l -4 2 l 4 1 l 6 10 h -16 h -16 h -16 l 6 -10 l 4 -1 l -4 -2 v -6 l 4 -2 l -4 -1 l -6 -10 z",
|
|
|
emptyInputWidth: 12 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
leftPath: (block) => {
|
|
|
const scale = block.height / 2;
|
|
|
const s = scale / 16;
|
|
|
return [
|
|
|
`h ${-16 * s}`,
|
|
|
`l ${6 * s} ${-10 * s}`,
|
|
|
`l ${4 * s} ${-1 * s}`,
|
|
|
`l ${-4 * s} ${-2 * s}`,
|
|
|
`v ${-6 * s}`,
|
|
|
`l ${4 * s} ${-2 * s}`,
|
|
|
`l ${-4 * s} ${-1 * s}`,
|
|
|
`l ${-6 * s} ${-10 * s}`,
|
|
|
];
|
|
|
},
|
|
|
rightPath: (block) => {
|
|
|
const scale = block.edgeShapeWidth_;
|
|
|
const s = scale / 16;
|
|
|
return [
|
|
|
`h ${16 * s}`,
|
|
|
`l ${-6 * s} ${10 * s}`,
|
|
|
`l ${-4 * s} ${1 * s}`,
|
|
|
`l ${4 * s} ${2 * s}`,
|
|
|
`v ${6 * s}`,
|
|
|
`l ${-4 * s} ${2 * s}`,
|
|
|
`l ${4 * s} ${1 * s}`,
|
|
|
`l ${6 * s} ${10 * s}`,
|
|
|
`h ${-16 * s}`,
|
|
|
];
|
|
|
},
|
|
|
blockPaddingStart: (_, __, firstInput) => {
|
|
|
return Math.max(((firstInput.renderHeight - Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER)) / 3, 0);
|
|
|
},
|
|
|
blockPaddingEnd: (_, __, lastInput) => {
|
|
|
return Math.max(((lastInput.renderHeight - Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER)) / 3, 0);
|
|
|
},
|
|
|
}],
|
|
|
[Blockly.OUTPUT_SHAPE_ARROW, {
|
|
|
emptyInputPath: "M 16 0 h 16 c 0.059 0 0.1175 0.0014 0.1758 0.0042 c 0.6594 -0.0042 1.7729 -0.0042 3.2858 0.9866 l 13.0645 11.9969 c 0.1287 0.0979 0.2521 0.2057 0.3696 0.3231 c 0.4447 0.4447 0.7494 0.9762 0.9143 1.5401 l 0.0454 0.0755 l -0.0123 0.0452 c 0.0757 0.297 0.1133 0.6017 0.1126 0.9064 c 0.0007 0.3047 -0.0369 0.6093 -0.1126 0.9063 l 0.0123 0.0452 l -0.0454 0.0755 c -0.1649 0.5638 -0.4695 1.0954 -0.9143 1.5401 c -0.1175 0.1175 -0.241 0.2252 -0.3696 0.3231 l -13.0645 11.9969 c -0.9561 0.9699 -3.0641 1.2348 -3.4616 1.2349 h -16 h -12.2464 c -0.6168 0 -1.1976 -0.1543 -1.7058 -0.4265 l -0.0742 -0.0397 l -0.0567 -0.0341 c -0.4474 -0.2641 -0.8331 -0.6217 -1.1301 -1.046 c -0.7213 -0.9079 -0.9437 -2.082 -0.6674 -3.1542 l 0.0166 -0.0623 l 0.024 -0.0822 c 0.167 -0.5518 0.4684 -1.0716 0.9047 -1.5078 l 10.6386 -9.7693 l -10.6386 -9.7693 c -0.4362 -0.4362 -0.7377 -0.9559 -0.9047 -1.5078 l -0.0245 -0.0877 l -0.0161 -0.0568 c -0.3091 -1.1994 0.006 -2.5264 0.9451 -3.4655 c 0.8871 -0.8871 2.217 -0.9908 3.2649 -0.9908 h 11.6706 z",
|
|
|
emptyInputWidth: 12 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
leftPath: (block) => {
|
|
|
const scale = block.height / 2;
|
|
|
const s = scale / 16;
|
|
|
return [
|
|
|
`h ${-12.2464 * s}`,
|
|
|
`c ${-0.6168 * s} 0 ${-1.1976 * s} ${-0.1543 * s} ${-1.7058 * s} ${-0.4265 * s}`,
|
|
|
`l ${-0.0742 * s} ${-0.0397 * s}`,
|
|
|
`l ${-0.0567 * s} ${-0.0341 * s}`,
|
|
|
`c ${-0.4474 * s} ${-0.2641 * s} ${-0.8331 * s} ${-0.6217 * s} ${-1.1301 * s} ${-1.046 * s}`,
|
|
|
`c ${-0.7213 * s} ${-0.9079 * s} ${-0.9437 * s} ${-2.082 * s} ${-0.6674 * s} ${-3.1542 * s}`,
|
|
|
`l ${0.0166 * s} ${-0.0623 * s}`,
|
|
|
`l ${0.024 * s} ${-0.0822 * s}`,
|
|
|
`c ${0.167 * s} ${-0.5518 * s} ${0.4684 * s} ${-1.0716 * s} ${0.9047 * s} ${-1.5078 * s}`,
|
|
|
`l ${10.6386 * s} ${-9.7693 * s}`,
|
|
|
`l ${-10.6386 * s} ${-9.7693 * s}`,
|
|
|
`c ${-0.4362 * s} ${-0.4362 * s} ${-0.7377 * s} ${-0.9559 * s} ${-0.9047 * s} ${-1.5078 * s}`,
|
|
|
`l ${-0.0245 * s} ${-0.0877 * s}`,
|
|
|
`l ${-0.0161 * s} ${-0.0568 * s}`,
|
|
|
`c ${-0.3091 * s} ${-1.1994 * s} ${0.006 * s} ${-2.5264 * s} ${0.9451 * s} ${-3.4655 * s}`,
|
|
|
`c ${0.8871 * s} ${-0.8871 * s} ${2.217 * s} ${-0.9908 * s} ${3.2649 * s} ${-0.9908 * s}`,
|
|
|
`h ${11.6706 * s}`,
|
|
|
];
|
|
|
},
|
|
|
rightPath: (block) => {
|
|
|
const scale = block.edgeShapeWidth_;
|
|
|
const s = scale / 16;
|
|
|
return [
|
|
|
`c ${0.059 * s} 0 ${0.1175 * s} ${0.0014 * s} ${0.1758 * s} ${0.0042 * s}`,
|
|
|
`c ${0.6594 * s} ${-0.0042 * s} ${1.7729 * s} ${-0.0042 * s} ${3.2858 * s} ${0.9866 * s}`,
|
|
|
`l ${13.0645 * s} ${11.9969 * s}`,
|
|
|
`c ${0.1287 * s} ${0.0979 * s} ${0.2521 * s} ${0.2057 * s} ${0.3696 * s} ${0.3231 * s}`,
|
|
|
`c ${0.4447 * s} ${0.4447 * s} ${0.7494 * s} ${0.9762 * s} ${0.9143 * s} ${1.5401 * s}`,
|
|
|
`l ${0.0454 * s} ${0.0755 * s}`,
|
|
|
`l ${-0.0123 * s} ${0.0452 * s}`,
|
|
|
`c ${0.0757 * s} ${0.297 * s} ${0.1133 * s} ${0.6017 * s} ${0.1126 * s} ${0.9064 * s}`,
|
|
|
`c ${0.0007 * s} ${0.3047 * s} ${-0.0369 * s} ${0.6093 * s} ${-0.1126 * s} ${0.9063 * s}`,
|
|
|
`l ${0.0123 * s} ${0.0452 * s}`,
|
|
|
`l ${-0.0454 * s} ${0.0755 * s}`,
|
|
|
`c ${-0.1649 * s} ${0.5638 * s} ${-0.4695 * s} ${1.0954 * s} ${-0.9143 * s} ${1.5401 * s}`,
|
|
|
`c ${-0.1175 * s} ${0.1175 * s} ${-0.241 * s} ${0.2252 * s} ${-0.3696 * s} ${0.3231 * s}`,
|
|
|
`l ${-13.0645 * s} ${11.9969 * s}`,
|
|
|
`c ${-0.9561 * s} ${0.9699 * s} ${-3.0641 * s} ${1.2348 * s} ${-3.4616 * s} ${1.2349 * s}`,
|
|
|
];
|
|
|
},
|
|
|
blockPaddingStart: (_, __, firstInput) => {
|
|
|
return Math.max(((firstInput.renderHeight - Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER)) / 2, 0) + 4;
|
|
|
},
|
|
|
blockPaddingEnd: (_, __, lastInput) => {
|
|
|
return Math.max(((lastInput.renderHeight - Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER)) / 2, 0) + 4;
|
|
|
},
|
|
|
}],
|
|
|
[Blockly.OUTPUT_SHAPE_TICKET, {
|
|
|
emptyInputPath: "m 0 0 m 15 0 H 46 z L 2 0 A 2 2 0 0 0 0 2 L 0 8 A 2 2 0 0 0 2 10 L 7 10 c 4 2 4 9 0 11 L 2 21 A 2 2 0 0 0 0 23 L 0 30 A 2 2 0 0 0 2 32 L 46 32 A 2 2 0 0 0 48 30 L 48 23 A 2 2 0 0 0 46 21 L 41 21 c -4 -2 -4 -9 0 -11 L 46 10 A 2 2 0 0 0 48 8 L 48 2 A 2 2 0 0 0 46 0 z",
|
|
|
emptyInputWidth: 12 * Blockly.BlockSvg.GRID_UNIT,
|
|
|
|
|
|
leftPath: (block) => {
|
|
|
const w = block.edgeShapeWidth_;
|
|
|
return [
|
|
|
`h-${w - 1}`,
|
|
|
`a 2 2 0 0 1 -2 -2`,
|
|
|
`v-${w - (13.4 / 2) - 4}`,
|
|
|
`a 2 2 0 0 1 2 -2`,
|
|
|
`h10`,
|
|
|
`c4 -2 4 -12 0 -${13.4}`,
|
|
|
`h-10`,
|
|
|
`a 2 2 0 0 1 -2 -2`,
|
|
|
`v-${w - (13.4 / 2) - 4}`,
|
|
|
`a 2 2 0 0 1 2 -2`,
|
|
|
];
|
|
|
},
|
|
|
rightPath: (block) => {
|
|
|
const w = block.edgeShapeWidth_;
|
|
|
return [
|
|
|
`h${w}`,
|
|
|
`a 2 2 0 0 1 2 2`,
|
|
|
`v${w - (13.4 / 2) - 4}`,
|
|
|
`a 2 2 0 0 1 -2 2`,
|
|
|
`h-10`,
|
|
|
`c-4 2 -4 12 0 ${13.4}`,
|
|
|
`h10`,
|
|
|
`a 2 2 0 0 1 2 2`,
|
|
|
`v${w - (13.4 / 2) - 4}`,
|
|
|
`a 2 2 0 0 1 -2 2`,
|
|
|
];
|
|
|
},
|
|
|
}],
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BlockSvg.registerCustomShape = function(name, shapeInfo) {
|
|
|
if (!name || typeof shapeInfo !== 'object' || Array.isArray(shapeInfo)) {
|
|
|
console.error([
|
|
|
`Registration for Shape '${name}' failed`,
|
|
|
"Param 2 must be a object containing:",
|
|
|
"'emptyInputPath' (string) -- SVG path for the inside of an empty input slot",
|
|
|
"'emptyInputWidth' (number) -- (optional) Default width for a empty input slot",
|
|
|
"'leftPath' (function) -– Returns an array of SVG path parts for the left side of the block",
|
|
|
"'rightPath' (function) –- Returns an array of SVG path parts for the right side of the block",
|
|
|
"'blockPadding' (object) -- (optional) Object for block-in-block padding, similar to 'Blockly.BlockSvg.SHAPE_IN_SHAPE_PADDING', 'internal' entry for custom block padding, 'external' entry for other shapes padding",
|
|
|
"'blockPaddingStart' (function) -- (optional) Returns a number adding extra padding to the start of the block in 'computeOutputPadding_', used for boolean-like shapes.",
|
|
|
"'blockPaddingEnd' (function) -- (optional) Returns a number adding extra padding to the end of the block in 'computeOutputPadding_', used for boolean-like shapes.",
|
|
|
].join("\n"));
|
|
|
return;
|
|
|
}
|
|
|
if (typeof shapeInfo.emptyInputPath !== "string") {
|
|
|
console.error(`Registration for Shape '${name}' failed\nNo 'emptyInputPath' entry found in Param 2/invalid SVG path string`);
|
|
|
return;
|
|
|
}
|
|
|
if (typeof shapeInfo.leftPath !== "function") {
|
|
|
console.error(`Registration for Shape '${name}' failed\nNo 'leftPath' entry found in Param 2/entry is not a function`);
|
|
|
return;
|
|
|
}
|
|
|
if (typeof shapeInfo.rightPath !== "function") {
|
|
|
console.error(`Registration for Shape '${name}' failed\nNo 'rightPath' entry found in Param 2/entry is not a function`);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
name = "custom-" + String(name);
|
|
|
shapeInfo.name = name;
|
|
|
|
|
|
|
|
|
if (!shapeInfo.emptyInputWidth) shapeInfo.emptyInputWidth = 12 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
|
if (shapeInfo.blockPadding) {
|
|
|
const internalPads = shapeInfo.blockPadding.internal;
|
|
|
if (typeof internalPads === "object" && !Array.isArray(internalPads)) {
|
|
|
Blockly.BlockSvg.SHAPE_IN_SHAPE_PADDING[name] = internalPads;
|
|
|
} else {
|
|
|
console.warn(`No 'internal' padding object provided in custom shape ${name}, please refer to 'ScratchBlocks.BlockSvg.SHAPE_IN_SHAPE_PADDING', for formatting`);
|
|
|
}
|
|
|
|
|
|
const externalPads = shapeInfo.blockPadding.external;
|
|
|
if (typeof externalPads === "object" && !Array.isArray(externalPads)) {
|
|
|
const paddingEntries = Object.entries(Blockly.BlockSvg.SHAPE_IN_SHAPE_PADDING);
|
|
|
for (const shape of paddingEntries) {
|
|
|
if (!externalPads[shape[0]]) continue;
|
|
|
shape[1][name] = externalPads[shape[0]];
|
|
|
}
|
|
|
} else {
|
|
|
console.warn(`No 'external' padding object provided in custom shape ${name}, please refer to 'ScratchBlocks.BlockSvg.SHAPE_IN_SHAPE_PADDING', for formatting`);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if (shapeInfo.blockPaddingStart && typeof shapeInfo.blockPaddingStart !== "function") {
|
|
|
console.error(`Registration for Shape '${name}' failed\n'blockPaddingStart' entry found in Param 2/entry is not a function`);
|
|
|
return;
|
|
|
}
|
|
|
if (shapeInfo.blockPaddingEnd && typeof shapeInfo.blockPaddingEnd !== "function") {
|
|
|
console.error(`Registration for Shape '${name}' failed\n'blockPaddingEnd' entry found in Param 2/entry is not a function`);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
Blockly.BlockSvg.CUSTOM_SHAPES.set(name, shapeInfo);
|
|
|
};
|
|
|
|