2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Visual Blocks Editor
|
|
|
|
*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
* https://developers.google.com/blockly/
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @fileoverview Methods for graphically rendering a block as SVG.
|
|
|
|
* @author fraser@google.com (Neil Fraser)
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
goog.provide('Blockly.BlockSvg.render');
|
|
|
|
|
|
|
|
goog.require('Blockly.BlockSvg');
|
2018-04-30 15:55:31 -07:00
|
|
|
goog.require('Blockly.scratchBlocksUtils');
|
2017-10-10 13:25:53 -07:00
|
|
|
goog.require('Blockly.utils');
|
2016-02-24 10:19:59 -08:00
|
|
|
|
|
|
|
|
|
|
|
// UI constants for rendering blocks.
|
2016-04-11 16:49:07 -04:00
|
|
|
/**
|
|
|
|
* Grid unit to pixels conversion
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.GRID_UNIT = 4;
|
2016-05-27 13:21:40 -04:00
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* Horizontal space between elements.
|
|
|
|
* @const
|
|
|
|
*/
|
2016-05-27 13:21:40 -04:00
|
|
|
Blockly.BlockSvg.SEP_SPACE_X = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* Vertical space between elements.
|
|
|
|
* @const
|
|
|
|
*/
|
2016-05-27 13:21:40 -04:00
|
|
|
Blockly.BlockSvg.SEP_SPACE_Y = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
2016-05-27 13:21:40 -04:00
|
|
|
* Minimum width of a block.
|
2016-02-24 10:19:59 -08:00
|
|
|
* @const
|
|
|
|
*/
|
2016-07-26 11:52:05 -04:00
|
|
|
Blockly.BlockSvg.MIN_BLOCK_X = 16 * Blockly.BlockSvg.GRID_UNIT;
|
2016-05-27 13:21:40 -04:00
|
|
|
|
2016-06-08 17:13:44 -04:00
|
|
|
/**
|
2016-07-26 11:52:05 -04:00
|
|
|
* Minimum width of a block with output (reporters).
|
2016-06-08 17:13:44 -04:00
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.MIN_BLOCK_X_OUTPUT = 12 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-07-26 11:52:05 -04:00
|
|
|
/**
|
|
|
|
* Minimum width of a shadow block with output (single fields).
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.MIN_BLOCK_X_SHADOW_OUTPUT = 10 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* Minimum height of a block.
|
|
|
|
* @const
|
|
|
|
*/
|
2016-05-27 13:21:40 -04:00
|
|
|
Blockly.BlockSvg.MIN_BLOCK_Y = 12 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
2016-05-27 13:21:40 -04:00
|
|
|
* Height of extra row after a statement input.
|
2016-02-24 10:19:59 -08:00
|
|
|
* @const
|
|
|
|
*/
|
2016-05-27 13:21:40 -04:00
|
|
|
Blockly.BlockSvg.EXTRA_STATEMENT_ROW_Y = 8 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
2016-05-27 13:21:40 -04:00
|
|
|
* Minimum width of a C- or E-shaped block.
|
2016-02-24 10:19:59 -08:00
|
|
|
* @const
|
|
|
|
*/
|
2016-05-27 13:21:40 -04:00
|
|
|
Blockly.BlockSvg.MIN_BLOCK_X_WITH_STATEMENT = 40 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-06-08 17:13:44 -04:00
|
|
|
/**
|
2016-07-26 11:52:05 -04:00
|
|
|
* Minimum height of a shadow block with output and a single field.
|
2016-06-08 17:13:44 -04:00
|
|
|
* This is used for shadow blocks that only contain a field - which are smaller than even reporters.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.MIN_BLOCK_Y_SINGLE_FIELD_OUTPUT = 8 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-07-26 11:52:05 -04:00
|
|
|
/**
|
|
|
|
* Minimum height of a non-shadow block with output, i.e. a reporter.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER = 10 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
2016-05-27 13:21:40 -04:00
|
|
|
* Minimum space for a statement input height.
|
2016-02-24 10:19:59 -08:00
|
|
|
* @const
|
|
|
|
*/
|
2016-05-27 13:21:40 -04:00
|
|
|
Blockly.BlockSvg.MIN_STATEMENT_INPUT_HEIGHT = 6 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Width of vertical notch.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.NOTCH_WIDTH = 8 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Height of vertical notch.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.NOTCH_HEIGHT = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* Rounded corner radius.
|
|
|
|
* @const
|
|
|
|
*/
|
2016-07-26 11:52:05 -04:00
|
|
|
Blockly.BlockSvg.CORNER_RADIUS = 1 * Blockly.BlockSvg.GRID_UNIT;
|
2016-05-23 18:54:48 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Minimum width of statement input edge on the left, in px.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.STATEMENT_INPUT_EDGE_WIDTH = 4 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
2016-05-27 13:21:40 -04:00
|
|
|
* Inner space between edge of statement input and notch.
|
2016-02-24 10:19:59 -08:00
|
|
|
* @const
|
|
|
|
*/
|
2016-05-27 13:21:40 -04:00
|
|
|
Blockly.BlockSvg.STATEMENT_INPUT_INNER_SPACE = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-04-12 14:59:58 -07:00
|
|
|
/**
|
|
|
|
* Height of the top hat.
|
|
|
|
* @const
|
|
|
|
*/
|
2016-05-27 13:21:40 -04:00
|
|
|
Blockly.BlockSvg.START_HAT_HEIGHT = 16;
|
|
|
|
|
2017-12-11 17:28:29 -05:00
|
|
|
/**
|
|
|
|
* Height of the vertical separator line for icons that appear at the left edge
|
|
|
|
* of a block, such as extension icons.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.ICON_SEPARATOR_HEIGHT = 10 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* Path of the top hat's curve.
|
|
|
|
* @const
|
|
|
|
*/
|
2016-05-27 13:21:40 -04:00
|
|
|
Blockly.BlockSvg.START_HAT_PATH = 'c 25,-22 71,-22 96,0';
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* SVG path for drawing next/previous notch from left to right.
|
|
|
|
* @const
|
|
|
|
*/
|
2016-05-27 13:21:40 -04:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* SVG path for drawing next/previous notch from right to left.
|
|
|
|
* @const
|
|
|
|
*/
|
2016-05-27 13:21:40 -04:00
|
|
|
Blockly.BlockSvg.NOTCH_PATH_RIGHT = (
|
2018-06-21 10:03:37 -04:00
|
|
|
'c -2,0 -3,1 -4,2 ' +
|
2016-05-27 13:21:40 -04:00
|
|
|
'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'
|
|
|
|
);
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
2016-05-27 13:21:40 -04:00
|
|
|
* Amount of padding before the notch.
|
2016-02-24 10:19:59 -08:00
|
|
|
* @const
|
|
|
|
*/
|
2016-05-27 13:21:40 -04:00
|
|
|
Blockly.BlockSvg.NOTCH_START_PADDING = 3 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* SVG start point for drawing the top-left corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.TOP_LEFT_CORNER_START =
|
|
|
|
'm 0,' + Blockly.BlockSvg.CORNER_RADIUS;
|
2016-05-27 13:21:40 -04:00
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* SVG path for drawing the rounded top-left corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.TOP_LEFT_CORNER =
|
|
|
|
'A ' + Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
|
|
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,1 ' +
|
|
|
|
Blockly.BlockSvg.CORNER_RADIUS + ',0';
|
2016-05-12 16:28:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SVG path for drawing the rounded top-right corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SVG path for drawing the rounded bottom-right corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SVG path for drawing the rounded bottom-left corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
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;
|
2016-05-27 13:21:40 -04:00
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* SVG path for drawing the top-left corner of a statement input.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
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;
|
2016-05-27 13:21:40 -04:00
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* SVG path for drawing the bottom-left corner of a statement input.
|
|
|
|
* Includes the rounded inside corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
2016-06-13 19:02:24 -04:00
|
|
|
/**
|
2016-06-23 19:04:20 -04:00
|
|
|
* SVG path for an empty hexagonal input shape.
|
2016-06-13 19:02:24 -04:00
|
|
|
* @const
|
|
|
|
*/
|
2016-06-23 19:04:20 -04:00
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_HEXAGONAL =
|
2016-06-13 19:02:24 -04:00
|
|
|
'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';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Width of empty boolean input shape.
|
|
|
|
* @const
|
|
|
|
*/
|
2016-07-26 11:52:05 -04:00
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_HEXAGONAL_WIDTH = 12 * Blockly.BlockSvg.GRID_UNIT;
|
2016-06-13 19:02:24 -04:00
|
|
|
|
|
|
|
/**
|
2016-06-23 19:04:20 -04:00
|
|
|
* SVG path for an empty square input shape.
|
2016-06-13 19:02:24 -04:00
|
|
|
* @const
|
|
|
|
*/
|
2016-06-23 19:04:20 -04:00
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_SQUARE =
|
2016-06-13 19:02:24 -04:00
|
|
|
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';
|
|
|
|
|
|
|
|
/**
|
2016-06-23 19:04:20 -04:00
|
|
|
* Width of empty square input shape.
|
2016-06-13 19:02:24 -04:00
|
|
|
* @const
|
|
|
|
*/
|
2016-10-03 09:05:27 -04:00
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_SQUARE_WIDTH = 10 * Blockly.BlockSvg.GRID_UNIT;
|
2016-06-13 19:02:24 -04:00
|
|
|
|
|
|
|
/**
|
2016-06-23 19:04:20 -04:00
|
|
|
* SVG path for an empty round input shape.
|
2016-06-13 19:02:24 -04:00
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
|
2016-06-23 19:04:20 -04:00
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_ROUND =
|
2016-06-13 19:02:24 -04:00
|
|
|
'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';
|
|
|
|
|
|
|
|
/**
|
2016-06-23 19:04:20 -04:00
|
|
|
* Width of empty round input shape.
|
2016-06-13 19:02:24 -04:00
|
|
|
* @const
|
|
|
|
*/
|
2016-10-03 09:05:27 -04:00
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_ROUND_WIDTH = 12 * Blockly.BlockSvg.GRID_UNIT;
|
2016-06-13 19:02:24 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Height of empty input shape.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.INPUT_SHAPE_HEIGHT = 8 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-04-11 16:49:07 -04:00
|
|
|
/**
|
|
|
|
* Height of user inputs
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.FIELD_HEIGHT = 8 * Blockly.BlockSvg.GRID_UNIT;
|
2016-04-15 16:44:30 -04:00
|
|
|
|
2016-04-11 16:49:07 -04:00
|
|
|
/**
|
|
|
|
* Width of user inputs
|
|
|
|
* @const
|
|
|
|
*/
|
2016-07-26 11:52:05 -04:00
|
|
|
Blockly.BlockSvg.FIELD_WIDTH = 6 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Editable field padding (left/right of the text).
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.EDITABLE_FIELD_PADDING = 6;
|
2016-04-11 16:49:07 -04:00
|
|
|
|
2016-07-27 16:29:02 -04:00
|
|
|
/**
|
|
|
|
* Square box field padding (left/right of the text).
|
|
|
|
* @const
|
|
|
|
*/
|
2016-10-04 17:42:21 -04:00
|
|
|
Blockly.BlockSvg.BOX_FIELD_PADDING = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drop-down arrow padding.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.DROPDOWN_ARROW_PADDING = 2 * Blockly.BlockSvg.GRID_UNIT;
|
2016-07-27 16:29:02 -04:00
|
|
|
|
2016-04-15 16:44:30 -04:00
|
|
|
/**
|
|
|
|
* Minimum width of user inputs during editing
|
|
|
|
* @const
|
|
|
|
*/
|
2016-06-08 17:13:44 -04:00
|
|
|
Blockly.BlockSvg.FIELD_WIDTH_MIN_EDIT = 8 * Blockly.BlockSvg.GRID_UNIT;
|
2016-04-15 16:44:30 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum width of user inputs during editing
|
|
|
|
* @const
|
|
|
|
*/
|
2016-06-23 12:44:01 -04:00
|
|
|
Blockly.BlockSvg.FIELD_WIDTH_MAX_EDIT = Infinity;
|
2016-04-15 16:44:30 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum height of user inputs during editing
|
|
|
|
* @const
|
|
|
|
*/
|
2016-06-08 17:13:44 -04:00
|
|
|
Blockly.BlockSvg.FIELD_HEIGHT_MAX_EDIT = Blockly.BlockSvg.FIELD_HEIGHT;
|
2016-04-15 16:44:30 -04:00
|
|
|
|
2016-05-05 16:13:43 -04:00
|
|
|
/**
|
|
|
|
* Top padding of user inputs
|
|
|
|
* @const
|
|
|
|
*/
|
2016-07-26 11:52:05 -04:00
|
|
|
Blockly.BlockSvg.FIELD_TOP_PADDING = 0.5 * Blockly.BlockSvg.GRID_UNIT;
|
2016-06-08 17:13:44 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Corner radius of number inputs
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.NUMBER_FIELD_CORNER_RADIUS = 4 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Corner radius of text inputs
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.TEXT_FIELD_CORNER_RADIUS = 1 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default radius for a field, in px.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.FIELD_DEFAULT_CORNER_RADIUS = 4 * Blockly.BlockSvg.GRID_UNIT;
|
2016-05-05 16:13:43 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Max text display length for a field (per-horizontal/vertical)
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.MAX_DISPLAY_LENGTH = Infinity;
|
|
|
|
|
2016-05-27 13:21:40 -04:00
|
|
|
/**
|
2017-07-20 23:42:35 -04:00
|
|
|
* Minimum X of inputs and fields for blocks with a previous connection.
|
2016-05-27 13:21:40 -04:00
|
|
|
* Ensures that inputs will not overlap with the top notch of blocks.
|
|
|
|
* @const
|
|
|
|
*/
|
2017-07-20 23:42:35 -04:00
|
|
|
Blockly.BlockSvg.INPUT_AND_FIELD_MIN_X = 12 * Blockly.BlockSvg.GRID_UNIT;
|
2016-05-27 13:21:40 -04:00
|
|
|
|
2016-06-08 17:13:44 -04:00
|
|
|
/**
|
|
|
|
* Vertical padding around inline elements.
|
|
|
|
* @const
|
|
|
|
*/
|
2016-07-26 11:52:05 -04:00
|
|
|
Blockly.BlockSvg.INLINE_PADDING_Y = 1 * Blockly.BlockSvg.GRID_UNIT;
|
2016-06-08 17:13:44 -04:00
|
|
|
|
2016-06-15 18:08:32 -04:00
|
|
|
/**
|
|
|
|
* Point size of text field before animation. Must match size in CSS.
|
|
|
|
* See implementation in field_textinput.
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.FIELD_TEXTINPUT_FONTSIZE_INITIAL = 12;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Point size of text field after animation.
|
|
|
|
* See implementation in field_textinput.
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.FIELD_TEXTINPUT_FONTSIZE_FINAL = 12;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether text fields are allowed to expand past their truncated block size.
|
|
|
|
* @const{boolean}
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.FIELD_TEXTINPUT_EXPAND_PAST_TRUNCATION = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether text fields should animate their positioning.
|
|
|
|
* @const{boolean}
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.FIELD_TEXTINPUT_ANIMATE_POSITIONING = false;
|
|
|
|
|
2016-07-26 11:52:05 -04:00
|
|
|
/**
|
|
|
|
* Map of output/input shapes and the amount they should cause a block to be padded.
|
|
|
|
* Outer key is the outer shape, inner key is the inner shape.
|
|
|
|
* When a block with the outer shape contains an input block with the inner shape
|
|
|
|
* on its left or right edge, that side is extended by the padding specified.
|
|
|
|
* See also: `Blockly.BlockSvg.computeOutputPadding_`.
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.SHAPE_IN_SHAPE_PADDING = {
|
|
|
|
1: { // Outer shape: hexagon.
|
|
|
|
0: 5 * Blockly.BlockSvg.GRID_UNIT, // Field in hexagon.
|
|
|
|
1: 2 * Blockly.BlockSvg.GRID_UNIT, // Hexagon in hexagon.
|
|
|
|
2: 5 * Blockly.BlockSvg.GRID_UNIT, // Round in hexagon.
|
|
|
|
3: 5 * Blockly.BlockSvg.GRID_UNIT // Square in hexagon.
|
|
|
|
},
|
|
|
|
2: { // Outer shape: round.
|
|
|
|
0: 3 * Blockly.BlockSvg.GRID_UNIT, // Field in round.
|
|
|
|
1: 3 * Blockly.BlockSvg.GRID_UNIT, // Hexagon in round.
|
|
|
|
2: 1 * Blockly.BlockSvg.GRID_UNIT, // Round in round.
|
|
|
|
3: 2 * Blockly.BlockSvg.GRID_UNIT // Square in round.
|
|
|
|
},
|
|
|
|
3: { // Outer shape: square.
|
|
|
|
0: 2 * Blockly.BlockSvg.GRID_UNIT, // Field in square.
|
|
|
|
1: 2 * Blockly.BlockSvg.GRID_UNIT, // Hexagon in square.
|
|
|
|
2: 2 * Blockly.BlockSvg.GRID_UNIT, // Round in square.
|
|
|
|
3: 2 * Blockly.BlockSvg.GRID_UNIT // Square in square.
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-10-12 11:41:48 -07:00
|
|
|
/**
|
|
|
|
* Corner radius of the hat on the define block.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.DEFINE_HAT_CORNER_RADIUS = 5 * Blockly.BlockSvg.GRID_UNIT;
|
2017-10-04 13:44:30 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SVG path for drawing the rounded top-left corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SVG path for drawing the rounded top-left corner.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
2017-10-12 11:41:48 -07:00
|
|
|
/**
|
|
|
|
* Padding on the right side of the internal block on the define block.
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.DEFINE_BLOCK_PADDING_RIGHT = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* Change the colour of a block.
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.updateColour = function() {
|
2016-04-26 13:04:37 -04:00
|
|
|
var strokeColour = this.getColourTertiary();
|
2018-04-30 15:55:31 -07:00
|
|
|
var renderShadowed = this.isShadow() &&
|
|
|
|
!Blockly.scratchBlocksUtils.isShadowArgumentReporter(this);
|
2017-10-10 13:25:53 -07:00
|
|
|
|
|
|
|
if (renderShadowed && this.parentBlock_) {
|
2016-04-26 13:04:37 -04:00
|
|
|
// Pull shadow block stroke colour from parent block's tertiary if possible.
|
|
|
|
strokeColour = this.parentBlock_.getColourTertiary();
|
2016-07-26 14:30:09 -04:00
|
|
|
// Special case: if we contain a colour field, set to a special stroke colour.
|
|
|
|
if (this.inputList[0] &&
|
|
|
|
this.inputList[0].fieldRow[0] &&
|
2017-09-19 10:13:41 -04:00
|
|
|
(this.inputList[0].fieldRow[0] instanceof Blockly.FieldColour ||
|
|
|
|
this.inputList[0].fieldRow[0] instanceof Blockly.FieldColourSlider)) {
|
2016-07-26 14:30:09 -04:00
|
|
|
strokeColour = Blockly.Colours.colourPickerStroke;
|
|
|
|
}
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
2016-04-26 13:04:37 -04:00
|
|
|
|
|
|
|
// Render block stroke
|
|
|
|
this.svgPath_.setAttribute('stroke', strokeColour);
|
|
|
|
|
|
|
|
// Render block fill
|
2017-10-10 13:25:53 -07:00
|
|
|
if (this.isGlowingBlock_ || renderShadowed) {
|
2018-10-23 13:55:28 -07:00
|
|
|
// Use the block's shadow colour if possible.
|
|
|
|
if (this.getShadowColour()) {
|
|
|
|
var fillColour = this.getShadowColour();
|
|
|
|
} else {
|
|
|
|
var fillColour = this.getColourSecondary();
|
|
|
|
}
|
2017-10-10 13:25:53 -07:00
|
|
|
} else {
|
|
|
|
var fillColour = this.getColour();
|
|
|
|
}
|
2016-04-26 13:04:37 -04:00
|
|
|
this.svgPath_.setAttribute('fill', fillColour);
|
2016-02-24 10:19:59 -08:00
|
|
|
|
2016-04-14 18:04:17 -04:00
|
|
|
// Render opacity
|
|
|
|
this.svgPath_.setAttribute('fill-opacity', this.getOpacity());
|
|
|
|
|
2016-06-13 19:02:24 -04:00
|
|
|
// Update colours of input shapes.
|
2017-11-09 13:29:48 -08:00
|
|
|
for (var i = 0, input; input = this.inputList[i]; i++) {
|
|
|
|
if (input.outlinePath) {
|
|
|
|
input.outlinePath.setAttribute('fill', this.getColourTertiary());
|
|
|
|
}
|
2016-06-13 19:02:24 -04:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
// Render icon(s) if applicable
|
|
|
|
var icons = this.getIcons();
|
|
|
|
for (var i = 0; i < icons.length; i++) {
|
|
|
|
icons[i].updateColour();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bump every dropdown to change its colour.
|
|
|
|
for (var x = 0, input; input = this.inputList[x]; x++) {
|
|
|
|
for (var y = 0, field; field = input.fieldRow[y]; y++) {
|
|
|
|
field.setText(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-14 23:12:33 -07:00
|
|
|
/**
|
|
|
|
* Visual effect to show that if the dragging block is dropped, this block will
|
|
|
|
* be replaced. If a shadow block it will disappear. Otherwise it will bump.
|
|
|
|
* @param {boolean} add True if highlighting should be added.
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.highlightForReplacement = function(add) {
|
|
|
|
if (add) {
|
2018-05-31 12:23:20 -07:00
|
|
|
var replacementGlowFilterId = this.workspace.options.replacementGlowFilterId
|
|
|
|
|| 'blocklyReplacementGlowFilter';
|
|
|
|
this.svgPath_.setAttribute('filter', 'url(#' + replacementGlowFilterId + ')');
|
2017-02-02 14:17:43 -05:00
|
|
|
Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_),
|
2016-11-18 16:20:29 -08:00
|
|
|
'blocklyReplaceable');
|
2016-06-14 23:12:33 -07:00
|
|
|
} else {
|
2016-06-21 16:20:37 -04:00
|
|
|
this.svgPath_.removeAttribute('filter');
|
2017-02-02 14:17:43 -05:00
|
|
|
Blockly.utils.removeClass(/** @type {!Element} */ (this.svgGroup_),
|
2016-11-18 16:20:29 -08:00
|
|
|
'blocklyReplaceable');
|
2016-06-14 23:12:33 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Visual effect to show that if the dragging block is dropped it will connect
|
|
|
|
* to this input.
|
|
|
|
* @param {Blockly.Connection} conn The connection on the input to highlight.
|
|
|
|
* @param {boolean} add True if highlighting should be added.
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.highlightShapeForInput = function(conn, add) {
|
|
|
|
var input = this.getInputWithConnection(conn);
|
|
|
|
if (!input) {
|
|
|
|
throw 'No input found for the connection';
|
|
|
|
}
|
2017-11-09 13:29:48 -08:00
|
|
|
if (!input.outlinePath) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-14 23:12:33 -07:00
|
|
|
if (add) {
|
2018-05-31 12:23:20 -07:00
|
|
|
var replacementGlowFilterId = this.workspace.options.replacementGlowFilterId
|
|
|
|
|| 'blocklyReplacementGlowFilter';
|
2017-11-09 13:29:48 -08:00
|
|
|
input.outlinePath.setAttribute('filter',
|
2018-05-31 12:23:20 -07:00
|
|
|
'url(#' + replacementGlowFilterId + ')');
|
2017-02-02 14:17:43 -05:00
|
|
|
Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_),
|
2016-11-18 16:20:29 -08:00
|
|
|
'blocklyReplaceable');
|
2016-06-14 23:12:33 -07:00
|
|
|
} else {
|
2017-11-09 13:29:48 -08:00
|
|
|
input.outlinePath.removeAttribute('filter');
|
2017-02-02 14:17:43 -05:00
|
|
|
Blockly.utils.removeClass(/** @type {!Element} */ (this.svgGroup_),
|
2016-11-18 16:20:29 -08:00
|
|
|
'blocklyReplaceable');
|
2016-06-14 23:12:33 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* Returns a bounding box describing the dimensions of this block
|
|
|
|
* and any blocks stacked below it.
|
|
|
|
* @return {!{height: number, width: number}} Object with height and width properties.
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.getHeightWidth = function() {
|
|
|
|
var height = this.height;
|
|
|
|
var width = this.width;
|
|
|
|
// Recursively add size of subsequent blocks.
|
|
|
|
var nextBlock = this.getNextBlock();
|
|
|
|
if (nextBlock) {
|
|
|
|
var nextHeightWidth = nextBlock.getHeightWidth();
|
2016-05-27 13:21:40 -04:00
|
|
|
height += nextHeightWidth.height;
|
2016-06-10 15:54:02 -04:00
|
|
|
height -= Blockly.BlockSvg.NOTCH_HEIGHT; // Exclude height of connected notch.
|
2016-02-24 10:19:59 -08:00
|
|
|
width = Math.max(width, nextHeightWidth.width);
|
|
|
|
}
|
|
|
|
return {height: height, width: width};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the block.
|
|
|
|
* Lays out and reflows a block based on its contents and settings.
|
|
|
|
* @param {boolean=} opt_bubble If false, just render this block.
|
|
|
|
* If true, also render block's parent, grandparent, etc. Defaults to true.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
// Move the icons into position.
|
|
|
|
var icons = this.getIcons();
|
2018-05-25 17:21:31 -04:00
|
|
|
var scratchCommentIcon = null;
|
2016-02-24 10:19:59 -08:00
|
|
|
for (var i = 0; i < icons.length; i++) {
|
2018-05-25 17:21:31 -04:00
|
|
|
if (icons[i] instanceof Blockly.ScratchBlockComment) {
|
|
|
|
// Don't render scratch block comment icon until
|
|
|
|
// after the inputs
|
|
|
|
scratchCommentIcon = icons[i];
|
|
|
|
} else {
|
|
|
|
cursorX = icons[i].renderIcon(cursorX);
|
|
|
|
}
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
|
|
|
cursorX += this.RTL ?
|
|
|
|
Blockly.BlockSvg.SEP_SPACE_X : -Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
|
// If there are no icons, cursorX will be 0, otherwise it will be the
|
|
|
|
// width that the first label needs to move over by.
|
|
|
|
|
2017-12-14 14:42:58 -05:00
|
|
|
// If this is an extension reporter block, add a horizontal offset.
|
|
|
|
if (this.isScratchExtension && this.outputConnection) {
|
2017-12-11 18:14:08 -05:00
|
|
|
cursorX += this.RTL ?
|
2017-12-11 18:12:27 -05:00
|
|
|
-Blockly.BlockSvg.GRID_UNIT : Blockly.BlockSvg.GRID_UNIT;
|
2017-12-04 16:50:21 -05:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
var inputRows = this.renderCompute_(cursorX);
|
|
|
|
this.renderDraw_(cursorX, inputRows);
|
2017-10-11 17:02:56 -07:00
|
|
|
this.renderMoveConnections_();
|
2016-10-03 09:05:27 -04:00
|
|
|
|
2016-09-28 09:20:30 -06:00
|
|
|
this.renderClassify_();
|
2016-02-24 10:19:59 -08:00
|
|
|
|
2018-05-25 17:21:31 -04:00
|
|
|
// Position the Scratch Block Comment Icon at the end of the block
|
|
|
|
if (scratchCommentIcon) {
|
|
|
|
var iconX = this.RTL ? -inputRows.rightEdge : inputRows.rightEdge;
|
|
|
|
var inputMarginY = inputRows[0].height / 2;
|
|
|
|
scratchCommentIcon.renderIcon(iconX, inputMarginY);
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
if (opt_bubble !== false) {
|
|
|
|
// Render all blocks above this one (propagate a reflow).
|
|
|
|
var parentBlock = this.getParent();
|
|
|
|
if (parentBlock) {
|
|
|
|
parentBlock.render(true);
|
|
|
|
} else {
|
|
|
|
// Top-most block. Fire an event to allow scrollbars to resize.
|
Merge google/develop June 22 (#441)
* Localisation updates from https://translatewiki.net.
* test page that creates random blocks and randomly drags them around the page
* Localisation updates from https://translatewiki.net.
* add missing return in fake drag
* get rid of drag_tests file:
* Generated JS helper functions should be camelCase.
Complying with Google style guide.
* Localisation updates from https://translatewiki.net.
* Fix extra category error. Clean up code, rename variables, reduce line lengths, fix lint issues.
* Remove claim that good.string.quote should be used.
* Change the blockly workspace resizing strategy. (#386)
* Add a new method to be called when the contents of the workspace change and
the scrollbars need to be adjusted but the the chrome (trash, toolbox, etc)
are expected to stay in the same place.
Change a bunch of calls to svgResize to either be removed or call the new
method instead. This is a nice performance win since the offsetHeight/Width
call in svgResize can be expensive, especially when called as often as we do -
there was some layout thrashing.
This also paves the way for moving calls to recordDeleteAreas
(which is also expensive) to a more cacheable spot than on every
mouse down/touch event.
of things (namely the scrollbars)
* Fix size of graph demo when it first loads by calling svgResize.
The graph starts with fixed width and was relying on a resize event
to fire (which I believe was removed in commit
217c681b86b0f2df76c479c9efae62e6e).
* Fix the resizing of the code demo. The demo's tab min-width used to
match the toolbox's width was only being set on a resize event, but
commit 217c681b86b0f2df76c479c9efae62e6e changed how that worked.
* Fix up some comments.
* Use specific workspaces rather than Blockly.getMainWorkspace().
* Make workspace required for resizeSvgContents and update
some calls to send real workspaces rather than ones that are
null.
Remove the private tag on terminateDrag_ because it is only
actually called from outside the BlockSvg object.
* Remove a rogue period.
* Recategorize BlockSvg.terminateDrag_ to @package instead of @private so that
other developers don't use it, but it still can be used by other Blockly classes.
* Add a TODO to fix issue #307.
* Add @package to workspace resizeContents.
* Routine recompile
* Fix unit tests.
* Fix inheritance on rendered connection.
Closure compiler on maximum compression breaks badly due to lack of
@extends attribute.
* Add toolbox location and toolbox mode options to playground.
* Increase commonality between playgrounds.
* Properly deal with shadow statement blocks in stacks.
* Localisation updates from https://translatewiki.net.
* Use a comment block for function comments in generated JS, Python and Dart.
* Fix typo in flyout.js (#403)
* Fix typo in flyout.js (#402)
* Line wrap comments in generated code.
* Remove reference to undefined variable (#413)
REASON_MUST_DISCONNECT was removed by a refactor in 2a1ffa1.
* Fix airstrike by grabbing the correct toolbox element. (#411)
Probably broken in 266e2ffa9a017d21d7ca2f151730d6ecfcecf173.
* Localisation updates from https://translatewiki.net.
* Fix issue #406 by calling resize from the keypress handler on text inputs. (#408)
* Remove shadow blocks from Accessible Blockly demo. Update README.
* Generate for loops on one line.
* Introduce a common translation pipe; remove local stringMap attributes. Fix variable name error in paste functions. Minor linting.
* Fix precedence on isIndex blocks.
* Add indexing setting for JavaScript Generation (#419)
Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default.
* Remove unused functions and dependencies.
* Remove the unnecessary construction of new services.
* Fix sort block in JS to satisfy tests.
* Trigger a contents resize in block's moveBy. (#422)
This fixes #420 but and it also fixes some other similar problems
with copy/paste and other users of moveBy.
* Consolidate the usages of the 'blockly-disabled' label.
* Fix error when undoing a shadow block replacement. Issue #415.
* Unify setActiveDesc() and updateSelectedNode() in the TreeService. Move function calls made directly within the template to the correct hooks.
* Standardize naming of components.
* Prevent collisions between user functions and helper functions.
* Localisation updates from https://translatewiki.net.
* Fix #425. Attash the resize handler to the workspace so it can be removed (#429)
when workspace.dispose() is called.
* Change the TreeService to a singleton.
* Remove unneeded generated parens around function calls in indexOf blocks.
* Fix #423 by calling workspace's resize when the flyout reflows. (#430)
* Updating URLs to reflect new docs. (#418)
* Updating URLs to reflect new docs. Removing -blockly in URLs.
* Rebuilt.
* Routine recompile
* Prevent selected block from ending up underneath a bumped block.
* Fix undo on fields with validators with side effects.
* Don't fire change event on fields that haven't been named yet.
* Localisation updates from https://translatewiki.net.
* Fix tree focus issues.
* Fix remaining focus issues on block deletion.
* cache delete areas instead of recalculating them onMouseDown
* Cache screen CTM for performance improvement.
* Call svgResizeContents from block_svg's dipose so that deleting blocks (#434)
from the context menu (or anywhere really) causes the workspace to
recalculate its size.
Remove the call to svgResizeContents from onMouseUp's logic for
determining whether the block is being dropped in the trash
since it calls dispose.
One side effect of this is that when you delete multiple blocks
resize gets called for each of them and the scrollbars move during
the operation. This is most obviously seen by doing an airstrike
in the playground and then deleting all the blocks at once.
* Allow terminal blocks to replace other terminal blocks (#433)
* Allow terminal blocks to replace other terminal blocks
* Updated test to allow replacing terminal blocks
* Refactor how activeDescendant is set. Introduce helper functions to ensure that calls like pasteAbove() preserve the focus.
* Localisation updates from https://translatewiki.net.
* Remove unnecessary logging.
* Reduce unneeded parentheses in JS and Python.
* Start using field_number.
* Make it easy to disable unconnected blocks.
* Routine recompile.
* Check if matrix is null in mouseToSvg
* Remove js/ localizations pre-merge
* Fix change to block_render_svg
* Fix error in xml.js
* Playground merge
* Add simple toolboxes to playgrounds
* Fix flyout reference in events listener
* Move tokenizeIntepolation into Blockly.utils namespace.
* Use simpler message interpolation in Code demo.
* Create console stub for IE 9.
* Don't output blockId if not set (e.g., toolbox category event). (#443)
* Fix block in multi-playground
* Increase commonality between playgrounds.
# Conflicts:
# tests/multi_playground.html
# tests/playground.html
* Remove "show flyouts" button
* Recompile for merge June 22
2016-06-22 17:50:16 -04:00
|
|
|
Blockly.resizeSvgContents(this.workspace);
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Blockly.Field.stopCache();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render a list of fields starting at the specified location.
|
|
|
|
* @param {!Array.<!Blockly.Field>} fieldList List of fields.
|
|
|
|
* @param {number} cursorX X-coordinate to start the fields.
|
2016-05-27 13:21:40 -04:00
|
|
|
* @param {number} cursorY Y-coordinate around which fields are centered.
|
2016-02-24 10:19:59 -08:00
|
|
|
* @return {number} X-coordinate of the end of the field row (plus a gap).
|
|
|
|
* @private
|
|
|
|
*/
|
2018-05-02 15:32:28 -07:00
|
|
|
Blockly.BlockSvg.prototype.renderFields_ = function(fieldList, cursorX,
|
|
|
|
cursorY) {
|
2016-02-24 10:19:59 -08:00
|
|
|
if (this.RTL) {
|
|
|
|
cursorX = -cursorX;
|
|
|
|
}
|
|
|
|
for (var t = 0, field; field = fieldList[t]; t++) {
|
|
|
|
var root = field.getSvgRoot();
|
|
|
|
if (!root) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-24 13:16:29 -04:00
|
|
|
// In blocks with a notch, fields should be bumped to a min X,
|
|
|
|
// to avoid overlapping with the notch. Label and image fields are
|
|
|
|
// excluded.
|
2017-08-24 13:15:14 -04:00
|
|
|
if (this.previousConnection && !(field instanceof Blockly.FieldLabel) &&
|
|
|
|
!(field instanceof Blockly.FieldImage)) {
|
2017-07-21 00:16:15 -04:00
|
|
|
cursorX = this.RTL ?
|
|
|
|
Math.min(cursorX, -Blockly.BlockSvg.INPUT_AND_FIELD_MIN_X) :
|
|
|
|
Math.max(cursorX, Blockly.BlockSvg.INPUT_AND_FIELD_MIN_X);
|
2017-07-20 23:42:35 -04:00
|
|
|
}
|
2016-05-27 13:21:40 -04:00
|
|
|
// Offset the field upward by half its height.
|
|
|
|
// This vertically centers the fields around cursorY.
|
|
|
|
var yOffset = -field.getSize().height / 2;
|
2017-12-04 16:50:34 -05:00
|
|
|
|
2017-12-14 14:42:58 -05:00
|
|
|
// If this is an extension block, and this field is the first field, and
|
|
|
|
// it is an image field, and this block has a previous connection, bump
|
|
|
|
// the image down by one grid unit to align it vertically.
|
|
|
|
if (this.isScratchExtension && (field === this.inputList[0].fieldRow[0])
|
|
|
|
&& (field instanceof Blockly.FieldImage) && this.previousConnection) {
|
2017-12-04 16:50:34 -05:00
|
|
|
yOffset += Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
}
|
|
|
|
|
2017-12-15 13:47:23 -05:00
|
|
|
// If this is an extension hat block, adjust the height of the vertical
|
|
|
|
// separator without adjusting the field height. The effect is to move
|
|
|
|
// the bottom end of the line up one grid unit.
|
|
|
|
if (this.isScratchExtension &&
|
|
|
|
!this.previousConnection && this.nextConnection &&
|
|
|
|
field instanceof Blockly.FieldVerticalSeparator) {
|
|
|
|
field.setLineHeight(Blockly.BlockSvg.ICON_SEPARATOR_HEIGHT -
|
|
|
|
Blockly.BlockSvg.GRID_UNIT);
|
|
|
|
}
|
|
|
|
|
2017-07-31 23:32:06 -04:00
|
|
|
var translateX, translateY;
|
|
|
|
var scale = '';
|
2016-02-24 10:19:59 -08:00
|
|
|
if (this.RTL) {
|
|
|
|
cursorX -= field.renderSep + field.renderWidth;
|
2017-07-31 23:32:06 -04:00
|
|
|
translateX = cursorX;
|
|
|
|
translateY = cursorY + yOffset;
|
2016-02-24 10:19:59 -08:00
|
|
|
if (field.renderWidth) {
|
|
|
|
cursorX -= Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
|
}
|
|
|
|
} else {
|
2017-07-31 23:32:06 -04:00
|
|
|
translateX = cursorX + field.renderSep;
|
|
|
|
translateY = cursorY + yOffset;
|
2016-02-24 10:19:59 -08:00
|
|
|
if (field.renderWidth) {
|
|
|
|
cursorX += field.renderSep + field.renderWidth +
|
|
|
|
Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
|
}
|
|
|
|
}
|
2017-07-31 23:32:06 -04:00
|
|
|
if (this.RTL &&
|
|
|
|
field instanceof Blockly.FieldImage &&
|
|
|
|
field.getFlipRTL()) {
|
|
|
|
scale = 'scale(-1 1)';
|
|
|
|
translateX += field.renderWidth;
|
|
|
|
}
|
|
|
|
root.setAttribute('transform',
|
2018-05-02 15:32:28 -07:00
|
|
|
'translate(' + translateX + ', ' + translateY + ') ' + scale);
|
2017-12-11 15:46:32 -05:00
|
|
|
|
2016-06-06 17:34:50 -04:00
|
|
|
// Fields are invisible on insertion marker.
|
|
|
|
if (this.isInsertionMarker()) {
|
|
|
|
root.setAttribute('display', 'none');
|
|
|
|
}
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
|
|
|
return this.RTL ? -cursorX : cursorX;
|
2018-05-02 15:32:28 -07:00
|
|
|
};
|
2016-02-24 10:19:59 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the height and widths for each row and field.
|
|
|
|
* @param {number} iconWidth Offset of first row due to icons.
|
|
|
|
* @return {!Array.<!Array.<!Object>>} 2D array of objects, each containing
|
|
|
|
* position information.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.renderCompute_ = function(iconWidth) {
|
|
|
|
var inputList = this.inputList;
|
|
|
|
var inputRows = [];
|
2016-05-27 13:21:40 -04:00
|
|
|
// Block will be drawn from 0 (left edge) to rightEdge, in px.
|
|
|
|
inputRows.rightEdge = 0;
|
2016-06-08 17:13:44 -04:00
|
|
|
// Drawn from 0 to bottomEdge vertically.
|
|
|
|
inputRows.bottomEdge = 0;
|
2016-02-24 10:19:59 -08:00
|
|
|
var fieldValueWidth = 0; // Width of longest external value field.
|
|
|
|
var fieldStatementWidth = 0; // Width of longest statement field.
|
|
|
|
var hasValue = false;
|
|
|
|
var hasStatement = false;
|
|
|
|
var hasDummy = false;
|
|
|
|
var lastType = undefined;
|
|
|
|
|
2016-05-27 13:21:40 -04:00
|
|
|
// Previously created row, for special-casing row heights on C- and E- shaped blocks.
|
|
|
|
var previousRow;
|
2016-02-24 10:19:59 -08:00
|
|
|
for (var i = 0, input; input = inputList[i]; i++) {
|
|
|
|
if (!input.isVisible()) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-10-25 14:08:08 -07:00
|
|
|
var isSecondInputOnProcedure = this.type == 'procedures_definition' &&
|
|
|
|
lastType && lastType == Blockly.NEXT_STATEMENT;
|
2016-02-24 10:19:59 -08:00
|
|
|
var row;
|
2018-10-25 14:08:08 -07:00
|
|
|
// Don't create a new row for the second dummy input on a procedure block.
|
|
|
|
// See github.com/LLK/scratch-blocks/issues/1658
|
|
|
|
// In all other cases, statement and value inputs catch all preceding dummy
|
|
|
|
// inputs, and cause a line break before following inputs.
|
|
|
|
if (!isSecondInputOnProcedure &&
|
|
|
|
(!lastType || lastType == Blockly.NEXT_STATEMENT ||
|
|
|
|
input.type == Blockly.NEXT_STATEMENT)) {
|
2016-02-24 10:19:59 -08:00
|
|
|
lastType = input.type;
|
2017-09-26 17:09:33 -07:00
|
|
|
row = this.createRowForInput_(input);
|
2016-02-24 10:19:59 -08:00
|
|
|
inputRows.push(row);
|
|
|
|
} else {
|
|
|
|
row = inputRows[inputRows.length - 1];
|
|
|
|
}
|
|
|
|
row.push(input);
|
|
|
|
|
2017-09-26 17:09:33 -07:00
|
|
|
// Compute minimum dimensions for this input.
|
|
|
|
input.renderHeight = this.computeInputHeight_(input, row, previousRow);
|
|
|
|
input.renderWidth = this.computeInputWidth_(input);
|
2016-06-10 15:54:02 -04:00
|
|
|
|
|
|
|
// If the input is a statement input, determine if a notch
|
|
|
|
// should be drawn at the inner bottom of the C.
|
|
|
|
row.statementNotchAtBottom = true;
|
|
|
|
if (input.connection && input.connection.type === Blockly.NEXT_STATEMENT) {
|
|
|
|
var linkedBlock = input.connection.targetBlock();
|
|
|
|
if (linkedBlock && !linkedBlock.lastConnectionInStack()) {
|
|
|
|
row.statementNotchAtBottom = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-13 19:02:24 -04:00
|
|
|
// Expand input size.
|
|
|
|
if (input.connection) {
|
2016-02-24 10:19:59 -08:00
|
|
|
var linkedBlock = input.connection.targetBlock();
|
2016-06-13 19:02:24 -04:00
|
|
|
var paddedHeight = 0;
|
|
|
|
var paddedWidth = 0;
|
|
|
|
if (linkedBlock) {
|
|
|
|
// A block is connected to the input - use its size.
|
|
|
|
var bBox = linkedBlock.getHeightWidth();
|
|
|
|
paddedHeight = bBox.height;
|
|
|
|
paddedWidth = bBox.width;
|
|
|
|
} else {
|
|
|
|
// No block connected - use the size of the rendered empty input shape.
|
|
|
|
paddedHeight = Blockly.BlockSvg.INPUT_SHAPE_HEIGHT;
|
|
|
|
}
|
2016-06-08 17:13:44 -04:00
|
|
|
if (input.connection.type === Blockly.INPUT_VALUE) {
|
|
|
|
paddedHeight += 2 * Blockly.BlockSvg.INLINE_PADDING_Y;
|
|
|
|
}
|
2016-06-10 15:54:02 -04:00
|
|
|
if (input.connection.type === Blockly.NEXT_STATEMENT) {
|
|
|
|
// Subtract height of notch, only if the last block in the stack has a next connection.
|
|
|
|
if (row.statementNotchAtBottom) {
|
|
|
|
paddedHeight -= Blockly.BlockSvg.NOTCH_HEIGHT;
|
|
|
|
}
|
|
|
|
}
|
2016-06-08 17:13:44 -04:00
|
|
|
input.renderHeight = Math.max(input.renderHeight, paddedHeight);
|
2016-06-13 19:02:24 -04:00
|
|
|
input.renderWidth = Math.max(input.renderWidth, paddedWidth);
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
|
|
|
row.height = Math.max(row.height, input.renderHeight);
|
|
|
|
input.fieldWidth = 0;
|
|
|
|
if (inputRows.length == 1) {
|
|
|
|
// The first row gets shifted to accommodate any icons.
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
// Get the dimensions of the field.
|
|
|
|
var fieldSize = field.getSize();
|
|
|
|
field.renderWidth = fieldSize.width;
|
|
|
|
field.renderSep = (previousFieldEditable && field.EDITABLE) ?
|
|
|
|
Blockly.BlockSvg.SEP_SPACE_X : 0;
|
2018-10-25 14:08:08 -07:00
|
|
|
// See github.com/LLK/scratch-blocks/issues/1658
|
|
|
|
if (!isSecondInputOnProcedure) {
|
|
|
|
input.fieldWidth += field.renderWidth + field.renderSep;
|
|
|
|
}
|
2016-02-24 10:19:59 -08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2016-05-27 13:21:40 -04:00
|
|
|
previousRow = row;
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
2016-07-26 11:52:05 -04:00
|
|
|
// Compute padding for output blocks.
|
|
|
|
// Data is attached to the row.
|
|
|
|
this.computeOutputPadding_(inputRows);
|
2016-02-24 10:19:59 -08:00
|
|
|
// Compute the statement edge.
|
|
|
|
// This is the width of a block where statements are nested.
|
2016-05-23 18:54:48 -04:00
|
|
|
inputRows.statementEdge = Blockly.BlockSvg.STATEMENT_INPUT_EDGE_WIDTH +
|
2016-02-24 10:19:59 -08:00
|
|
|
fieldStatementWidth;
|
2017-09-26 17:09:33 -07:00
|
|
|
|
2016-05-27 13:21:40 -04:00
|
|
|
// Compute the preferred right edge.
|
2017-09-26 17:09:33 -07:00
|
|
|
inputRows.rightEdge = this.computeRightEdge_(inputRows.rightEdge,
|
|
|
|
hasStatement);
|
|
|
|
|
|
|
|
// Bottom edge is sum of row heights
|
|
|
|
for (var i = 0; i < inputRows.length; i++) {
|
|
|
|
inputRows.bottomEdge += inputRows[i].height;
|
|
|
|
}
|
|
|
|
|
|
|
|
inputRows.hasValue = hasValue;
|
|
|
|
inputRows.hasStatement = hasStatement;
|
|
|
|
inputRows.hasDummy = hasDummy;
|
|
|
|
return inputRows;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute the minimum width of this input based on the connection type and
|
|
|
|
* outputs.
|
|
|
|
* @param {!Blockly.Input} input The input to measure.
|
|
|
|
* @return {number} the computed width of this input.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.computeInputWidth_ = function(input) {
|
|
|
|
// Empty input shape widths.
|
|
|
|
if (input.type == Blockly.INPUT_VALUE &&
|
|
|
|
(!input.connection || !input.connection.isConnected())) {
|
|
|
|
switch (input.connection.getOutputShape()) {
|
|
|
|
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;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute the minimum height of this input.
|
|
|
|
* @param {!Blockly.Input} input The input to measure.
|
|
|
|
* @param {!Object} row The row of the block that is currently being measured.
|
|
|
|
* @param {!Object} previousRow The previous row of the block, which was just
|
|
|
|
* measured.
|
|
|
|
* @return {number} the computed height of this input.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.computeInputHeight_ = function(input, row,
|
|
|
|
previousRow) {
|
2017-10-09 15:06:03 -07:00
|
|
|
if (this.inputList.length === 1 && this.outputConnection &&
|
2018-04-30 15:55:31 -07:00
|
|
|
(this.isShadow() &&
|
|
|
|
!Blockly.scratchBlocksUtils.isShadowArgumentReporter(this))) {
|
2017-09-26 17:09:33 -07:00
|
|
|
// "Lone" field blocks are smaller.
|
|
|
|
return Blockly.BlockSvg.MIN_BLOCK_Y_SINGLE_FIELD_OUTPUT;
|
|
|
|
} else if (this.outputConnection) {
|
2017-12-14 14:42:58 -05:00
|
|
|
// If this is an extension reporter block, make it taller.
|
|
|
|
if (this.isScratchExtension) {
|
2017-12-05 11:13:53 -05:00
|
|
|
return Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER + 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
}
|
2017-09-26 17:09:33 -07:00
|
|
|
// All other reporters.
|
|
|
|
return Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER;
|
|
|
|
} else if (row.type == Blockly.NEXT_STATEMENT) {
|
|
|
|
// Statement input.
|
|
|
|
return Blockly.BlockSvg.MIN_STATEMENT_INPUT_HEIGHT;
|
|
|
|
} else if (previousRow && previousRow.type == Blockly.NEXT_STATEMENT) {
|
|
|
|
// Extra row for below statement input.
|
|
|
|
return Blockly.BlockSvg.EXTRA_STATEMENT_ROW_Y;
|
|
|
|
} else {
|
2017-12-14 14:42:58 -05:00
|
|
|
// If this is an extension block, and it has a previous connection,
|
2017-12-05 11:06:58 -05:00
|
|
|
// make it taller.
|
2017-12-14 14:42:58 -05:00
|
|
|
if (this.isScratchExtension && this.previousConnection) {
|
2017-12-04 16:49:59 -05:00
|
|
|
return Blockly.BlockSvg.MIN_BLOCK_Y + 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
|
|
}
|
2017-09-26 17:09:33 -07:00
|
|
|
// All other blocks.
|
|
|
|
return Blockly.BlockSvg.MIN_BLOCK_Y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a row for an input and associated fields.
|
|
|
|
* @param {!Blockly.Input} input The input that the row is based on.
|
|
|
|
* @return {!Object} The new row, with the correct type and default sizing info.
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.createRowForInput_ = function(input) {
|
|
|
|
// Create new row.
|
|
|
|
var row = [];
|
|
|
|
if (input.type != Blockly.NEXT_STATEMENT) {
|
|
|
|
row.type = Blockly.BlockSvg.INLINE;
|
|
|
|
} else {
|
|
|
|
row.type = input.type;
|
|
|
|
}
|
|
|
|
row.height = 0;
|
|
|
|
// Default padding for a block: same as separators between fields/inputs.
|
|
|
|
row.paddingStart = Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
|
row.paddingEnd = Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
|
return row;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute the preferred right edge of the block.
|
|
|
|
* @param {number} curEdge The previously calculated right edge.
|
|
|
|
* @param {boolean} hasStatement Whether this block has a statement input.
|
|
|
|
* @return {number} The preferred right edge of the block.
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.computeRightEdge_ = function(curEdge, hasStatement) {
|
|
|
|
var edge = curEdge;
|
2016-05-27 13:21:40 -04:00
|
|
|
if (this.previousConnection || this.nextConnection) {
|
|
|
|
// Blocks with notches
|
2017-09-26 17:09:33 -07:00
|
|
|
edge = Math.max(edge, Blockly.BlockSvg.MIN_BLOCK_X);
|
2016-06-08 17:13:44 -04:00
|
|
|
} else if (this.outputConnection) {
|
2018-04-30 15:55:31 -07:00
|
|
|
if (this.isShadow() &&
|
|
|
|
!Blockly.scratchBlocksUtils.isShadowArgumentReporter(this)) {
|
2016-07-26 11:52:05 -04:00
|
|
|
// Single-fields
|
2017-09-26 17:09:33 -07:00
|
|
|
edge = Math.max(edge, Blockly.BlockSvg.MIN_BLOCK_X_SHADOW_OUTPUT);
|
2016-07-26 11:52:05 -04:00
|
|
|
} else {
|
|
|
|
// Reporters
|
2017-09-26 17:09:33 -07:00
|
|
|
edge = Math.max(edge, Blockly.BlockSvg.MIN_BLOCK_X_OUTPUT);
|
2016-07-26 11:52:05 -04:00
|
|
|
}
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
2016-05-27 13:21:40 -04:00
|
|
|
if (hasStatement) {
|
|
|
|
// Statement blocks (C- or E- shaped) have a longer minimum width.
|
2017-09-26 17:09:33 -07:00
|
|
|
edge = Math.max(edge, Blockly.BlockSvg.MIN_BLOCK_X_WITH_STATEMENT);
|
2016-06-08 17:13:44 -04:00
|
|
|
}
|
|
|
|
|
2016-08-16 18:03:05 -04:00
|
|
|
// Ensure insertion markers are at least insertionMarkerMinWidth_ wide.
|
|
|
|
if (this.insertionMarkerMinWidth_ > 0) {
|
2017-09-26 17:09:33 -07:00
|
|
|
edge = Math.max(edge, this.insertionMarkerMinWidth_);
|
2016-08-16 18:03:05 -04:00
|
|
|
}
|
2017-09-26 17:09:33 -07:00
|
|
|
return edge;
|
2016-02-24 10:19:59 -08:00
|
|
|
};
|
|
|
|
|
2016-07-26 11:52:05 -04:00
|
|
|
/**
|
|
|
|
* For a block with output,
|
|
|
|
* determine start and end padding, based on connected inputs.
|
|
|
|
* Padding will depend on the shape of the output, the shape of the input,
|
|
|
|
* and possibly the size of the input.
|
|
|
|
* @param {!Array.<!Array.<!Object>>} inputRows Partially calculated rows.
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.computeOutputPadding_ = function(inputRows) {
|
|
|
|
// Only apply to blocks with outputs and not single fields (shadows).
|
2017-10-09 15:06:03 -07:00
|
|
|
if (!this.getOutputShape() || !this.outputConnection ||
|
2018-04-30 15:55:31 -07:00
|
|
|
(this.isShadow() &&
|
|
|
|
!Blockly.scratchBlocksUtils.isShadowArgumentReporter(this))) {
|
2016-07-26 11:52:05 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Blocks with outputs must have single row to be padded.
|
|
|
|
if (inputRows.length > 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var row = inputRows[0];
|
|
|
|
var shape = this.getOutputShape();
|
|
|
|
// Reset any padding: it's about to be set.
|
|
|
|
row.paddingStart = 0;
|
|
|
|
row.paddingEnd = 0;
|
|
|
|
// Start row padding: based on first input or first field.
|
|
|
|
var firstInput = row[0];
|
|
|
|
var firstField = firstInput.fieldRow[0];
|
|
|
|
var otherShape;
|
|
|
|
// In checking the left/start side, a field takes precedence over any input.
|
|
|
|
// That's because a field will be rendered before any value input.
|
|
|
|
if (firstField) {
|
|
|
|
otherShape = 0; // Field comes first in the row.
|
|
|
|
} else {
|
|
|
|
// Value input comes first in the row.
|
|
|
|
var inputConnection = firstInput.connection;
|
|
|
|
if (!inputConnection.targetConnection) {
|
|
|
|
// Not connected: use the drawn shape.
|
|
|
|
otherShape = inputConnection.getOutputShape();
|
|
|
|
} else {
|
|
|
|
// Connected: use the connected block's output shape.
|
|
|
|
otherShape = inputConnection.targetConnection.getSourceBlock().getOutputShape();
|
|
|
|
}
|
|
|
|
// Special case for hexagonal output: if the connection is larger height
|
|
|
|
// than a standard reporter, add some start padding.
|
|
|
|
// https://github.com/LLK/scratch-blocks/issues/376
|
|
|
|
if (shape == Blockly.OUTPUT_SHAPE_HEXAGONAL &&
|
|
|
|
otherShape != Blockly.OUTPUT_SHAPE_HEXAGONAL) {
|
|
|
|
var deltaHeight = firstInput.renderHeight - Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER;
|
|
|
|
// One grid unit per level of nesting.
|
|
|
|
row.paddingStart += deltaHeight / 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
row.paddingStart += Blockly.BlockSvg.SHAPE_IN_SHAPE_PADDING[shape][otherShape];
|
|
|
|
// End row padding: based on last input or last field.
|
|
|
|
var lastInput = row[row.length - 1];
|
|
|
|
// In checking the right/end side, any value input takes precedence over any field.
|
|
|
|
// That's because fields are rendered before inputs...the last item
|
|
|
|
// in the row will be an input, if one exists.
|
|
|
|
if (lastInput.connection) {
|
|
|
|
// Value input last in the row.
|
|
|
|
var inputConnection = lastInput.connection;
|
|
|
|
if (!inputConnection.targetConnection) {
|
|
|
|
// Not connected: use the drawn shape.
|
|
|
|
otherShape = inputConnection.getOutputShape();
|
|
|
|
} else {
|
|
|
|
// Connected: use the connected block's output shape.
|
|
|
|
otherShape = inputConnection.targetConnection.getSourceBlock().getOutputShape();
|
|
|
|
}
|
|
|
|
// Special case for hexagonal output: if the connection is larger height
|
|
|
|
// than a standard reporter, add some end padding.
|
|
|
|
// https://github.com/LLK/scratch-blocks/issues/376
|
|
|
|
if (shape == Blockly.OUTPUT_SHAPE_HEXAGONAL &&
|
|
|
|
otherShape != Blockly.OUTPUT_SHAPE_HEXAGONAL) {
|
|
|
|
var deltaHeight = lastInput.renderHeight - Blockly.BlockSvg.MIN_BLOCK_Y_REPORTER;
|
|
|
|
// One grid unit per level of nesting.
|
|
|
|
row.paddingEnd += deltaHeight / 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No input in this row - mark as field.
|
|
|
|
otherShape = 0;
|
|
|
|
}
|
|
|
|
row.paddingEnd += Blockly.BlockSvg.SHAPE_IN_SHAPE_PADDING[shape][otherShape];
|
|
|
|
};
|
2016-02-24 10:19:59 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the path of the block.
|
|
|
|
* Move the fields to the correct locations.
|
|
|
|
* @param {number} iconWidth Offset of first row due to icons.
|
|
|
|
* @param {!Array.<!Array.<!Object>>} inputRows 2D array of objects, each
|
|
|
|
* containing position information.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.renderDraw_ = function(iconWidth, inputRows) {
|
|
|
|
this.startHat_ = false;
|
2016-05-12 16:28:56 -04:00
|
|
|
// Should the top left corners be rounded or square?
|
|
|
|
// Currently, it is squared only if it's a hat.
|
|
|
|
this.squareTopLeftCorner_ = false;
|
2016-05-27 13:21:40 -04:00
|
|
|
if (!this.outputConnection && !this.previousConnection) {
|
2016-05-12 16:28:56 -04:00
|
|
|
// No output or previous connection.
|
2016-02-24 10:19:59 -08:00
|
|
|
this.squareTopLeftCorner_ = true;
|
2016-05-12 16:28:56 -04:00
|
|
|
this.startHat_ = true;
|
|
|
|
inputRows.rightEdge = Math.max(inputRows.rightEdge, 100);
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
|
|
|
|
2016-06-08 17:13:44 -04:00
|
|
|
// Amount of space to skip drawing the top and bottom,
|
|
|
|
// to make room for the left and right to draw shapes (curves or angles).
|
|
|
|
this.edgeShapeWidth_ = 0;
|
|
|
|
this.edgeShape_ = null;
|
|
|
|
if (this.outputConnection) {
|
|
|
|
// Width of the curve/pointy-curve
|
2016-06-23 19:04:20 -04:00
|
|
|
var shape = this.getOutputShape();
|
|
|
|
if (shape === Blockly.OUTPUT_SHAPE_HEXAGONAL || shape === Blockly.OUTPUT_SHAPE_ROUND) {
|
2016-06-08 17:13:44 -04:00
|
|
|
this.edgeShapeWidth_ = inputRows.bottomEdge / 2;
|
|
|
|
this.edgeShape_ = shape;
|
|
|
|
this.squareTopLeftCorner_ = true;
|
|
|
|
}
|
|
|
|
}
|
2016-02-24 10:19:59 -08:00
|
|
|
|
|
|
|
// Assemble the block's path.
|
|
|
|
var steps = [];
|
|
|
|
|
2017-10-11 17:02:56 -07:00
|
|
|
this.renderDrawTop_(steps, inputRows.rightEdge);
|
|
|
|
var cursorY = this.renderDrawRight_(steps, inputRows, iconWidth);
|
|
|
|
this.renderDrawBottom_(steps, cursorY);
|
|
|
|
this.renderDrawLeft_(steps);
|
2016-02-24 10:19:59 -08:00
|
|
|
|
|
|
|
var pathString = steps.join(' ');
|
|
|
|
this.svgPath_.setAttribute('d', pathString);
|
|
|
|
|
|
|
|
if (this.RTL) {
|
|
|
|
// Mirror the block's path.
|
|
|
|
// This is awesome.
|
|
|
|
this.svgPath_.setAttribute('transform', 'scale(-1 1)');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-28 09:20:30 -06:00
|
|
|
/**
|
2016-09-30 14:42:39 -06:00
|
|
|
* Give the block an attribute 'data-shapes' that lists its shape[s], and an
|
|
|
|
* attribute 'data-category' with its category.
|
2016-09-28 09:20:30 -06:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.renderClassify_ = function() {
|
|
|
|
var shapes = [];
|
2016-10-03 09:05:27 -04:00
|
|
|
|
2016-09-28 09:20:30 -06:00
|
|
|
if (this.outputConnection) {
|
|
|
|
if (this.isShadow_) {
|
|
|
|
shapes.push('argument');
|
|
|
|
} else {
|
|
|
|
shapes.push('reporter');
|
|
|
|
}
|
|
|
|
if (this.edgeShape_ === Blockly.OUTPUT_SHAPE_HEXAGONAL) {
|
|
|
|
shapes.push('boolean');
|
|
|
|
} else if (this.edgeShape_ === Blockly.OUTPUT_SHAPE_ROUND) {
|
|
|
|
shapes.push('round');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// count the number of statement inputs
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
2016-10-03 09:05:27 -04:00
|
|
|
|
2016-09-28 09:20:30 -06:00
|
|
|
if (statementCount) {
|
|
|
|
shapes.push('c-block');
|
|
|
|
shapes.push('c-' + statementCount);
|
|
|
|
}
|
|
|
|
if (this.startHat_) {
|
|
|
|
shapes.push('hat'); // c-block+hats are possible (e.x. reprter procedures)
|
|
|
|
} else if (!statementCount) {
|
|
|
|
shapes.push('stack'); //only call it "stack" if it's not a c-block
|
|
|
|
}
|
|
|
|
if (!this.nextConnection) {
|
|
|
|
shapes.push('end');
|
|
|
|
}
|
|
|
|
}
|
2016-10-03 09:05:27 -04:00
|
|
|
|
2016-09-28 09:20:30 -06:00
|
|
|
this.svgGroup_.setAttribute('data-shapes', shapes.join(' '));
|
2016-10-03 09:05:27 -04:00
|
|
|
|
2016-10-03 06:17:45 -06:00
|
|
|
if (this.getCategory()) {
|
|
|
|
this.svgGroup_.setAttribute('data-category', this.getCategory());
|
2016-09-30 14:42:39 -06:00
|
|
|
}
|
2016-09-28 09:20:30 -06:00
|
|
|
};
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* Render the top edge of the block.
|
|
|
|
* @param {!Array.<string>} steps Path of block outline.
|
|
|
|
* @param {number} rightEdge Minimum width of block.
|
|
|
|
* @private
|
|
|
|
*/
|
2017-10-11 17:02:56 -07:00
|
|
|
Blockly.BlockSvg.prototype.renderDrawTop_ = function(steps, rightEdge) {
|
2017-11-15 14:16:34 -08:00
|
|
|
if (this.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE) {
|
2017-10-04 13:44:30 -07:00
|
|
|
steps.push('m 0, 0');
|
|
|
|
steps.push(Blockly.BlockSvg.TOP_LEFT_CORNER_DEFINE_HAT);
|
2016-02-24 10:19:59 -08:00
|
|
|
} else {
|
2017-10-04 13:44:30 -07:00
|
|
|
// Position the cursor at the top-left starting point.
|
|
|
|
if (this.squareTopLeftCorner_) {
|
|
|
|
steps.push('m 0,0');
|
|
|
|
if (this.startHat_) {
|
|
|
|
steps.push(Blockly.BlockSvg.START_HAT_PATH);
|
|
|
|
}
|
|
|
|
// Skip space for the output shape
|
|
|
|
if (this.edgeShapeWidth_) {
|
|
|
|
steps.push('m ' + this.edgeShapeWidth_ + ',0');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
steps.push(Blockly.BlockSvg.TOP_LEFT_CORNER_START);
|
|
|
|
// Top-left rounded corner.
|
|
|
|
steps.push(Blockly.BlockSvg.TOP_LEFT_CORNER);
|
|
|
|
}
|
2016-02-24 10:19:59 -08:00
|
|
|
|
2017-10-04 13:44:30 -07:00
|
|
|
// Top edge.
|
|
|
|
if (this.previousConnection) {
|
|
|
|
// Space before the notch
|
|
|
|
steps.push('H', Blockly.BlockSvg.NOTCH_START_PADDING);
|
|
|
|
steps.push(Blockly.BlockSvg.NOTCH_PATH_LEFT);
|
|
|
|
// Create previous block connection.
|
2017-10-11 17:02:56 -07:00
|
|
|
var connectionX = (this.RTL ?
|
2017-10-04 13:44:30 -07:00
|
|
|
-Blockly.BlockSvg.NOTCH_WIDTH : Blockly.BlockSvg.NOTCH_WIDTH);
|
2017-10-11 17:02:56 -07:00
|
|
|
this.previousConnection.setOffsetInBlock(connectionX, 0);
|
2017-10-04 13:44:30 -07:00
|
|
|
}
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
|
|
|
this.width = rightEdge;
|
2018-05-02 15:32:28 -07:00
|
|
|
};
|
2016-02-24 10:19:59 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the right edge of the block.
|
|
|
|
* @param {!Array.<string>} steps Path of block outline.
|
|
|
|
* @param {!Array.<!Array.<!Object>>} inputRows 2D array of objects, each
|
|
|
|
* containing position information.
|
|
|
|
* @param {number} iconWidth Offset of first row due to icons.
|
|
|
|
* @return {number} Height of block.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.renderDrawRight_ = function(steps,
|
2017-10-11 17:02:56 -07:00
|
|
|
inputRows, iconWidth) {
|
2016-05-27 13:21:40 -04:00
|
|
|
var cursorX = 0;
|
|
|
|
var cursorY = 0;
|
2016-02-24 10:19:59 -08:00
|
|
|
var connectionX, connectionY;
|
|
|
|
for (var y = 0, row; row = inputRows[y]; y++) {
|
2016-07-26 11:52:05 -04:00
|
|
|
cursorX = row.paddingStart;
|
2016-02-24 10:19:59 -08:00
|
|
|
if (y == 0) {
|
|
|
|
cursorX += this.RTL ? -iconWidth : iconWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (row.type == Blockly.BlockSvg.INLINE) {
|
|
|
|
// Inline inputs.
|
|
|
|
for (var x = 0, input; input = row[x]; x++) {
|
2016-05-27 13:21:40 -04:00
|
|
|
// Align fields vertically within the row.
|
|
|
|
// Moves the field to half of the row's height.
|
|
|
|
// In renderFields_, the field is further centered
|
|
|
|
// by its own rendered height.
|
2017-10-09 11:39:52 -07:00
|
|
|
var fieldY = cursorY + row.height / 2;
|
|
|
|
|
|
|
|
var fieldX = Blockly.BlockSvg.getAlignedCursor_(cursorX, input,
|
|
|
|
inputRows.rightEdge);
|
2016-06-10 14:53:22 -04:00
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
cursorX = this.renderFields_(input.fieldRow, fieldX, fieldY);
|
|
|
|
if (input.type == Blockly.INPUT_VALUE) {
|
|
|
|
// Create inline input connection.
|
2017-07-20 23:42:35 -04:00
|
|
|
// In blocks with a notch, inputs should be bumped to a min X,
|
|
|
|
// to avoid overlapping with the notch.
|
|
|
|
if (this.previousConnection) {
|
|
|
|
cursorX = Math.max(cursorX, Blockly.BlockSvg.INPUT_AND_FIELD_MIN_X);
|
2016-05-27 13:21:40 -04:00
|
|
|
}
|
2017-10-11 17:02:56 -07:00
|
|
|
connectionX = this.RTL ? -cursorX : cursorX;
|
2016-06-08 17:13:44 -04:00
|
|
|
// Attempt to center the connection vertically.
|
|
|
|
var connectionYOffset = row.height / 2;
|
2017-10-11 17:02:56 -07:00
|
|
|
connectionY = cursorY + connectionYOffset;
|
|
|
|
input.connection.setOffsetInBlock(connectionX, connectionY);
|
2016-07-26 11:52:05 -04:00
|
|
|
this.renderInputShape_(input, cursorX, cursorY + connectionYOffset);
|
2016-06-08 17:13:44 -04:00
|
|
|
cursorX += input.renderWidth + Blockly.BlockSvg.SEP_SPACE_X;
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
|
|
|
}
|
2016-07-26 11:52:05 -04:00
|
|
|
// Remove final separator and replace it with right-padding.
|
|
|
|
cursorX -= Blockly.BlockSvg.SEP_SPACE_X;
|
|
|
|
cursorX += row.paddingEnd;
|
2016-05-23 18:54:34 -04:00
|
|
|
// Update right edge for all inputs, such that all rows
|
|
|
|
// stretch to be at least the size of all previous rows.
|
|
|
|
inputRows.rightEdge = Math.max(cursorX, inputRows.rightEdge);
|
|
|
|
// Move to the right edge
|
2016-02-24 10:19:59 -08:00
|
|
|
cursorX = Math.max(cursorX, inputRows.rightEdge);
|
|
|
|
this.width = Math.max(this.width, cursorX);
|
2016-06-08 17:13:44 -04:00
|
|
|
if (!this.edgeShape_) {
|
2016-07-26 11:52:05 -04:00
|
|
|
// Include corner radius in drawing the horizontal line.
|
|
|
|
steps.push('H', cursorX - Blockly.BlockSvg.CORNER_RADIUS - this.edgeShapeWidth_);
|
2016-06-08 17:13:44 -04:00
|
|
|
steps.push(Blockly.BlockSvg.TOP_RIGHT_CORNER);
|
2016-07-26 11:52:05 -04:00
|
|
|
} else {
|
|
|
|
// Don't include corner radius - no corner (edge shape drawn).
|
|
|
|
steps.push('H', cursorX - this.edgeShapeWidth_);
|
2016-06-08 17:13:44 -04:00
|
|
|
}
|
2016-05-12 16:28:56 -04:00
|
|
|
// Subtract CORNER_RADIUS * 2 to account for the top right corner
|
|
|
|
// and also the bottom right corner. Only move vertically the non-corner length.
|
2016-06-08 17:13:44 -04:00
|
|
|
if (!this.edgeShape_) {
|
|
|
|
steps.push('v', row.height - Blockly.BlockSvg.CORNER_RADIUS * 2);
|
|
|
|
}
|
2016-02-24 10:19:59 -08:00
|
|
|
} else if (row.type == Blockly.NEXT_STATEMENT) {
|
|
|
|
// Nested statement.
|
|
|
|
var input = row[0];
|
|
|
|
var fieldX = cursorX;
|
2017-10-04 13:44:30 -07:00
|
|
|
// Align fields vertically within the row.
|
|
|
|
// In renderFields_, the field is further centered by its own height.
|
2016-02-24 10:19:59 -08:00
|
|
|
var fieldY = cursorY;
|
2017-10-04 13:44:30 -07:00
|
|
|
fieldY += Blockly.BlockSvg.MIN_STATEMENT_INPUT_HEIGHT;
|
2016-02-24 10:19:59 -08:00
|
|
|
this.renderFields_(input.fieldRow, fieldX, fieldY);
|
2016-05-27 13:21:40 -04:00
|
|
|
// Move to the start of the notch.
|
|
|
|
cursorX = inputRows.statementEdge + Blockly.BlockSvg.NOTCH_WIDTH;
|
2017-10-04 13:44:30 -07:00
|
|
|
|
2017-11-15 14:16:34 -08:00
|
|
|
if (this.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE) {
|
2018-10-25 14:08:08 -07:00
|
|
|
this.renderDefineBlock_(steps, inputRows, input, row, cursorY);
|
2017-10-04 13:44:30 -07:00
|
|
|
} else {
|
|
|
|
Blockly.BlockSvg.drawStatementInputFromTopRight_(steps, cursorX,
|
|
|
|
inputRows.rightEdge, row);
|
|
|
|
}
|
2016-02-24 10:19:59 -08:00
|
|
|
|
|
|
|
// Create statement connection.
|
2017-10-11 17:02:56 -07:00
|
|
|
connectionX = this.RTL ? -cursorX : cursorX;
|
|
|
|
input.connection.setOffsetInBlock(connectionX, cursorY);
|
2016-03-30 15:09:42 -07:00
|
|
|
if (input.connection.isConnected()) {
|
2016-09-30 16:18:21 -04:00
|
|
|
this.width = Math.max(this.width, inputRows.statementEdge +
|
|
|
|
input.connection.targetBlock().getHeightWidth().width);
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
2017-11-15 14:16:34 -08:00
|
|
|
if (this.type != Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE &&
|
2017-10-04 13:44:30 -07:00
|
|
|
(y == inputRows.length - 1 ||
|
|
|
|
inputRows[y + 1].type == Blockly.NEXT_STATEMENT)) {
|
2016-02-24 10:19:59 -08:00
|
|
|
// If the final input is a statement stack, add a small row underneath.
|
|
|
|
// Consecutive statement stacks are also separated by a small divider.
|
2016-05-23 18:54:34 -04:00
|
|
|
steps.push(Blockly.BlockSvg.TOP_RIGHT_CORNER);
|
2016-05-27 13:21:40 -04:00
|
|
|
steps.push('v', Blockly.BlockSvg.EXTRA_STATEMENT_ROW_Y - 2 * Blockly.BlockSvg.CORNER_RADIUS);
|
|
|
|
cursorY += Blockly.BlockSvg.EXTRA_STATEMENT_ROW_Y;
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cursorY += row.height;
|
|
|
|
}
|
2017-10-02 15:03:09 -07:00
|
|
|
this.drawEdgeShapeRight_(steps);
|
2016-02-24 10:19:59 -08:00
|
|
|
if (!inputRows.length) {
|
|
|
|
cursorY = Blockly.BlockSvg.MIN_BLOCK_Y;
|
|
|
|
steps.push('V', cursorY);
|
|
|
|
}
|
|
|
|
return cursorY;
|
|
|
|
};
|
|
|
|
|
2016-06-13 19:02:24 -04:00
|
|
|
/**
|
|
|
|
* Render the input shapes.
|
|
|
|
* If there's a connected block, hide the input shape.
|
|
|
|
* Otherwise, draw and set the position of the input shape.
|
|
|
|
* @param {!Blockly.Input} input Input to be rendered.
|
|
|
|
* @param {Number} x X offset of input.
|
|
|
|
* @param {Number} y Y offset of input.
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.renderInputShape_ = function(input, x, y) {
|
2017-11-09 13:29:48 -08:00
|
|
|
var inputShape = input.outlinePath;
|
2016-08-16 18:03:05 -04:00
|
|
|
if (!inputShape) {
|
|
|
|
// No input shape for this input - e.g., the block is an insertion marker.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Input shapes are only visibly rendered on non-connected slots.
|
|
|
|
if (input.connection.targetConnection) {
|
2016-06-13 19:02:24 -04:00
|
|
|
inputShape.setAttribute('style', 'visibility: hidden');
|
|
|
|
} else {
|
|
|
|
var inputShapeX = 0, inputShapeY = 0;
|
2017-10-09 11:32:41 -07:00
|
|
|
var inputShapeInfo =
|
2017-10-09 11:41:23 -07:00
|
|
|
Blockly.BlockSvg.getInputShapeInfo_(input.connection.getOutputShape());
|
2016-06-13 19:02:24 -04:00
|
|
|
if (this.RTL) {
|
2017-10-09 11:32:41 -07:00
|
|
|
inputShapeX = -x - inputShapeInfo.width;
|
2016-06-13 19:02:24 -04:00
|
|
|
} else {
|
|
|
|
inputShapeX = x;
|
|
|
|
}
|
|
|
|
inputShapeY = y - (Blockly.BlockSvg.INPUT_SHAPE_HEIGHT / 2);
|
2017-10-09 11:32:41 -07:00
|
|
|
inputShape.setAttribute('d', inputShapeInfo.path);
|
2016-06-13 19:02:24 -04:00
|
|
|
inputShape.setAttribute('transform',
|
2018-05-02 15:32:28 -07:00
|
|
|
'translate(' + inputShapeX + ',' + inputShapeY + ')');
|
2017-10-09 11:32:41 -07:00
|
|
|
inputShape.setAttribute('data-argument-type', inputShapeInfo.argType);
|
2016-06-13 19:02:24 -04:00
|
|
|
inputShape.setAttribute('style', 'visibility: visible');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-24 10:19:59 -08:00
|
|
|
/**
|
|
|
|
* Render the bottom edge of the block.
|
|
|
|
* @param {!Array.<string>} steps Path of block outline.
|
|
|
|
* @param {number} cursorY Height of block.
|
|
|
|
* @private
|
|
|
|
*/
|
2017-10-11 17:02:56 -07:00
|
|
|
Blockly.BlockSvg.prototype.renderDrawBottom_ = function(steps, cursorY) {
|
2016-05-12 16:28:56 -04:00
|
|
|
this.height = cursorY;
|
2016-06-08 17:13:44 -04:00
|
|
|
if (!this.edgeShape_) {
|
|
|
|
steps.push(Blockly.BlockSvg.BOTTOM_RIGHT_CORNER);
|
|
|
|
}
|
2016-02-24 10:19:59 -08:00
|
|
|
if (this.nextConnection) {
|
2016-05-27 13:21:40 -04:00
|
|
|
// Move to the right-side of the notch.
|
|
|
|
var notchStart = (
|
|
|
|
Blockly.BlockSvg.NOTCH_WIDTH +
|
|
|
|
Blockly.BlockSvg.NOTCH_START_PADDING +
|
|
|
|
Blockly.BlockSvg.CORNER_RADIUS
|
|
|
|
);
|
|
|
|
steps.push('H', notchStart, ' ');
|
|
|
|
steps.push(Blockly.BlockSvg.NOTCH_PATH_RIGHT);
|
2016-02-24 10:19:59 -08:00
|
|
|
// Create next block connection.
|
2017-10-11 17:02:56 -07:00
|
|
|
var connectionX = this.RTL ? -Blockly.BlockSvg.NOTCH_WIDTH :
|
|
|
|
Blockly.BlockSvg.NOTCH_WIDTH;
|
|
|
|
this.nextConnection.setOffsetInBlock(connectionX, cursorY);
|
2016-06-10 15:54:02 -04:00
|
|
|
// Include height of notch in block height.
|
|
|
|
this.height += Blockly.BlockSvg.NOTCH_HEIGHT;
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
2016-05-12 16:28:56 -04:00
|
|
|
// Bottom horizontal line
|
2016-06-08 17:13:44 -04:00
|
|
|
if (!this.edgeShape_) {
|
|
|
|
steps.push('H', Blockly.BlockSvg.CORNER_RADIUS);
|
|
|
|
// Bottom left corner
|
|
|
|
steps.push(Blockly.BlockSvg.BOTTOM_LEFT_CORNER);
|
|
|
|
} else {
|
|
|
|
steps.push('H', this.edgeShapeWidth_);
|
|
|
|
}
|
2016-02-24 10:19:59 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the left edge of the block.
|
|
|
|
* @param {!Array.<string>} steps Path of block outline.
|
|
|
|
* @param {number} cursorY Height of block.
|
|
|
|
* @private
|
|
|
|
*/
|
2017-10-11 17:02:56 -07:00
|
|
|
Blockly.BlockSvg.prototype.renderDrawLeft_ = function(steps) {
|
2016-02-24 10:19:59 -08:00
|
|
|
if (this.outputConnection) {
|
2016-06-17 13:37:06 -04:00
|
|
|
// Scratch-style reporters have output connection y at half block height.
|
2017-10-11 17:02:56 -07:00
|
|
|
this.outputConnection.setOffsetInBlock(0, this.height / 2);
|
2016-02-24 10:19:59 -08:00
|
|
|
}
|
2016-06-08 17:13:44 -04:00
|
|
|
if (this.edgeShape_) {
|
2016-06-23 19:04:20 -04:00
|
|
|
// Draw the left-side edge shape.
|
|
|
|
if (this.edgeShape_ === Blockly.OUTPUT_SHAPE_ROUND) {
|
|
|
|
// Draw a rounded arc.
|
2018-06-21 10:03:37 -04:00
|
|
|
steps.push('a ' + this.edgeShapeWidth_ + ' ' + this.edgeShapeWidth_ + ' 0 0 1 0 -' + this.edgeShapeWidth_ * 2);
|
2016-06-23 19:04:20 -04:00
|
|
|
} else if (this.edgeShape_ === Blockly.OUTPUT_SHAPE_HEXAGONAL) {
|
|
|
|
// Draw a half-hexagon.
|
2016-06-08 17:13:44 -04:00
|
|
|
steps.push('l ' + -this.edgeShapeWidth_ + ' ' + -this.edgeShapeWidth_ +
|
|
|
|
' l ' + this.edgeShapeWidth_ + ' ' + -this.edgeShapeWidth_);
|
|
|
|
}
|
|
|
|
}
|
2016-02-24 10:19:59 -08:00
|
|
|
steps.push('z');
|
|
|
|
};
|
2016-04-19 10:10:56 +02:00
|
|
|
|
2017-10-02 15:03:09 -07:00
|
|
|
/**
|
|
|
|
* Draw the edge shape (rounded or hexagonal) on the right side of a block with
|
|
|
|
* an output.
|
|
|
|
* @param {!Array.<string>} steps Path of block outline.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.drawEdgeShapeRight_ = function(steps) {
|
|
|
|
if (this.edgeShape_) {
|
|
|
|
// Draw the right-side edge shape.
|
|
|
|
if (this.edgeShape_ === Blockly.OUTPUT_SHAPE_ROUND) {
|
|
|
|
// Draw a rounded arc.
|
|
|
|
steps.push('a ' + this.edgeShapeWidth_ + ' ' + this.edgeShapeWidth_ +
|
|
|
|
' 0 0 1 0 ' + this.edgeShapeWidth_ * 2);
|
|
|
|
} else if (this.edgeShape_ === Blockly.OUTPUT_SHAPE_HEXAGONAL) {
|
|
|
|
// Draw an half-hexagon.
|
|
|
|
steps.push('l ' + this.edgeShapeWidth_ + ' ' + this.edgeShapeWidth_ +
|
|
|
|
' l ' + -this.edgeShapeWidth_ + ' ' + this.edgeShapeWidth_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-19 10:10:56 +02:00
|
|
|
/**
|
|
|
|
* Position an new block correctly, so that it doesn't move the existing block
|
|
|
|
* when connected to it.
|
2016-04-19 18:48:18 +02:00
|
|
|
* @param {!Blockly.Block} newBlock The block to position - either the first
|
|
|
|
* block in a dragged stack or an insertion marker.
|
|
|
|
* @param {!Blockly.Connection} newConnection The connection on the new block's
|
2016-04-20 09:46:13 +02:00
|
|
|
* stack - either a connection on newBlock, or the last NEXT_STATEMENT
|
|
|
|
* connection on the stack if the stack's being dropped before another
|
|
|
|
* block.
|
2016-04-19 18:48:18 +02:00
|
|
|
* @param {!Blockly.Connection} existingConnection The connection on the
|
|
|
|
* existing block, which newBlock should line up with.
|
2016-04-19 10:10:56 +02:00
|
|
|
*/
|
2018-05-02 15:32:28 -07:00
|
|
|
Blockly.BlockSvg.prototype.positionNewBlock = function(newBlock, newConnection,
|
|
|
|
existingConnection) {
|
2016-04-19 10:10:56 +02:00
|
|
|
// We only need to position the new block if it's before the existing one,
|
|
|
|
// otherwise its position is set by the previous block.
|
|
|
|
if (newConnection.type == Blockly.NEXT_STATEMENT) {
|
|
|
|
var dx = existingConnection.x_ - newConnection.x_;
|
|
|
|
var dy = existingConnection.y_ - newConnection.y_;
|
|
|
|
|
2016-04-19 11:28:25 +02:00
|
|
|
newBlock.moveBy(dx, dy);
|
2016-04-19 10:10:56 +02:00
|
|
|
}
|
2018-05-02 15:32:28 -07:00
|
|
|
};
|
2017-10-02 14:52:13 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the outline of a statement input, starting at the top right corner.
|
|
|
|
* @param {!Array.<string>} steps Path of block outline.
|
|
|
|
* @param {number} cursorX The x position of the start of the notch at the top
|
|
|
|
* of the input.
|
|
|
|
* @param {number} rightEdge The far right edge of the block, which determines
|
|
|
|
* how wide the statement input is.
|
|
|
|
* @param {!Array.<!Object>} row An object containing information about the
|
|
|
|
* current row, including its height and whether it should have a notch at
|
|
|
|
* the bottom.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.drawStatementInputFromTopRight_ = function(steps, cursorX,
|
|
|
|
rightEdge, row) {
|
|
|
|
Blockly.BlockSvg.drawStatementInputTop_(steps, cursorX);
|
|
|
|
steps.push('v', row.height - 2 * Blockly.BlockSvg.CORNER_RADIUS);
|
|
|
|
Blockly.BlockSvg.drawStatementInputBottom_(steps, rightEdge, row);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the top of the outline of a statement input, starting at the top right
|
|
|
|
* corner.
|
|
|
|
* @param {!Array.<string>} steps Path of block outline.
|
|
|
|
* @param {number} cursorX The x position of the start of the notch at the top
|
|
|
|
* of the input.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.drawStatementInputTop_ = function(steps, cursorX) {
|
|
|
|
steps.push(Blockly.BlockSvg.BOTTOM_RIGHT_CORNER);
|
|
|
|
steps.push('H', cursorX + Blockly.BlockSvg.STATEMENT_INPUT_INNER_SPACE +
|
|
|
|
2 * Blockly.BlockSvg.CORNER_RADIUS);
|
|
|
|
steps.push(Blockly.BlockSvg.NOTCH_PATH_RIGHT);
|
|
|
|
steps.push('h', '-' + Blockly.BlockSvg.STATEMENT_INPUT_INNER_SPACE);
|
|
|
|
steps.push(Blockly.BlockSvg.INNER_TOP_LEFT_CORNER);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the bottom of the outline of a statement input, starting at the inner
|
|
|
|
* left corner.
|
|
|
|
* @param {!Array.<string>} steps Path of block outline.
|
|
|
|
* @param {number} rightEdge The far right edge of the block, which determines
|
|
|
|
* how wide the statement input is.
|
|
|
|
* @param {!Array.<!Object>} row An object containing information about the
|
|
|
|
* current row, including its height and whether it should have a notch at
|
|
|
|
* the bottom.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.drawStatementInputBottom_ = function(steps, rightEdge, row) {
|
|
|
|
steps.push(Blockly.BlockSvg.INNER_BOTTOM_LEFT_CORNER);
|
|
|
|
if (row.statementNotchAtBottom) {
|
|
|
|
steps.push('h ', Blockly.BlockSvg.STATEMENT_INPUT_INNER_SPACE);
|
|
|
|
steps.push(Blockly.BlockSvg.NOTCH_PATH_LEFT);
|
|
|
|
}
|
|
|
|
steps.push('H', rightEdge - Blockly.BlockSvg.CORNER_RADIUS);
|
|
|
|
};
|
2017-10-04 13:44:30 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Render part of the hat and the right side of the define block to fully wrap
|
|
|
|
* the connected statement block.
|
|
|
|
* Scratch-specific.
|
|
|
|
* @param {!Array.<string>} steps Path of block outline.
|
|
|
|
* @param {!Array.<!Array.<!Object>>} inputRows 2D array of objects, each
|
|
|
|
* containing position information.
|
|
|
|
* @param {!Blockly.Input} input The input that is currently being rendered.
|
|
|
|
* @param {!Array.<!Object>} row An object containing information about the
|
|
|
|
* current row, including its height and whether it should have a notch at
|
|
|
|
* the bottom.
|
2018-10-25 14:08:08 -07:00
|
|
|
* @param {number} cursorY The y position of the start of this row. Used to
|
|
|
|
* position the following dummy input's fields.
|
2017-10-04 13:44:30 -07:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.renderDefineBlock_ = function(steps, inputRows,
|
2018-10-25 14:08:08 -07:00
|
|
|
input, row, cursorY) {
|
|
|
|
// Following text shows up as a dummy input after the statement input, which
|
|
|
|
// we are forcing to stay inline with the statement input instead of letting
|
|
|
|
// it drop to a new line.
|
|
|
|
var hasFollowingText = row.length == 2;
|
|
|
|
|
2017-10-04 13:44:30 -07:00
|
|
|
// Figure out where the right side of the block is.
|
|
|
|
var rightSide = inputRows.rightEdge;
|
|
|
|
if (input.connection && input.connection.targetBlock()) {
|
|
|
|
rightSide = inputRows.statementEdge +
|
2017-10-12 11:41:48 -07:00
|
|
|
input.connection.targetBlock().getHeightWidth().width +
|
|
|
|
Blockly.BlockSvg.DEFINE_BLOCK_PADDING_RIGHT;
|
2017-10-04 13:44:30 -07:00
|
|
|
} else {
|
2018-11-13 15:49:37 +01:00
|
|
|
// Handles the case where block is being rendered as an insertion marker
|
|
|
|
rightSide = Math.max(Blockly.BlockSvg.MIN_BLOCK_X_WITH_STATEMENT, rightSide)
|
|
|
|
+ Blockly.BlockSvg.DEFINE_BLOCK_PADDING_RIGHT;
|
2017-10-04 13:44:30 -07:00
|
|
|
}
|
2017-10-12 11:41:48 -07:00
|
|
|
rightSide -= Blockly.BlockSvg.DEFINE_HAT_CORNER_RADIUS;
|
2017-10-04 13:44:30 -07:00
|
|
|
|
2018-10-25 14:08:08 -07:00
|
|
|
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;
|
|
|
|
|
|
|
|
// Align fields vertically within the row.
|
|
|
|
// In renderFields_, the field is further centered by its own height.
|
|
|
|
// The dummy input's fields did not get laid out normally because we're
|
|
|
|
// forcing them to stay inline with a statement input.
|
|
|
|
var fieldY = cursorY;
|
|
|
|
fieldY += Blockly.BlockSvg.MIN_STATEMENT_INPUT_HEIGHT;
|
|
|
|
this.renderFields_(followingTextInput.fieldRow, fieldStart, fieldY);
|
|
|
|
}
|
2017-10-04 13:44:30 -07:00
|
|
|
// Draw the top and the right corner of the hat.
|
|
|
|
steps.push('H', rightSide);
|
|
|
|
steps.push(Blockly.BlockSvg.TOP_RIGHT_CORNER_DEFINE_HAT);
|
2017-10-12 11:41:48 -07:00
|
|
|
row.height += 3 * Blockly.BlockSvg.GRID_UNIT;
|
2017-10-04 13:44:30 -07:00
|
|
|
// Draw the right side of the block around the statement input.
|
2017-10-12 11:41:48 -07:00
|
|
|
steps.push('v', row.height);
|
2017-10-18 17:24:02 -07:00
|
|
|
// row.height will be used to update the cursor in the calling function.
|
|
|
|
row.height += Blockly.BlockSvg.GRID_UNIT;
|
2017-10-04 13:44:30 -07:00
|
|
|
|
|
|
|
};
|
2017-10-09 11:32:41 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get some information about the input shape to draw, based on the type of the
|
|
|
|
* connection.
|
|
|
|
* @param {number} shape An enum representing the shape of the connection we're
|
|
|
|
* drawing around.
|
|
|
|
* @return {!Object} An object containing an SVG path, a string representation
|
|
|
|
* of the argument type, and a width.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.getInputShapeInfo_ = function(shape) {
|
|
|
|
var inputShapePath = null;
|
|
|
|
var inputShapeArgType = null;
|
|
|
|
var inputShapeWidth = 0;
|
|
|
|
|
|
|
|
switch (shape) {
|
|
|
|
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: // If the input connection is not connected, draw a hole shape.
|
|
|
|
inputShapePath = Blockly.BlockSvg.INPUT_SHAPE_SQUARE;
|
|
|
|
inputShapeWidth = Blockly.BlockSvg.INPUT_SHAPE_SQUARE_WIDTH;
|
|
|
|
inputShapeArgType = 'square';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
path: inputShapePath,
|
|
|
|
argType: inputShapeArgType,
|
|
|
|
width: inputShapeWidth
|
|
|
|
};
|
|
|
|
};
|
2017-10-09 11:39:52 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the correct cursor position for the given input, based on alignment,
|
|
|
|
* the total size of the block, and the size of the input.
|
|
|
|
* @param {number} cursorX The minimum x value of the cursor.
|
|
|
|
* @param {!Blockly.Input} input The input to align the fields for.
|
|
|
|
* @param {number} rightEdge The maximum width of the block. Right-aligned
|
|
|
|
* fields are positioned based on this number.
|
|
|
|
* @return {number} The new cursor position.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.getAlignedCursor_ = function(cursorX, input, rightEdge) {
|
|
|
|
// Align inline field rows (left/right/centre).
|
|
|
|
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;
|
|
|
|
};
|
2017-10-11 17:02:56 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update all of the connections on this block with the new locaitons calculated
|
|
|
|
* in renderCompute, and move all of the connected blocks based on the new
|
|
|
|
* connection locations.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.BlockSvg.prototype.renderMoveConnections_ = function() {
|
|
|
|
var blockTL = this.getRelativeToSurfaceXY();
|
|
|
|
// Don't tighten previous or output connections because they are inferior.
|
|
|
|
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(blockTL);
|
|
|
|
if (conn.isConnected()) {
|
|
|
|
conn.tighten_();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.nextConnection) {
|
|
|
|
this.nextConnection.moveToOffset(blockTL);
|
|
|
|
if (this.nextConnection.isConnected()) {
|
|
|
|
this.nextConnection.tighten_();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|