@blockdia/scratch-blocks 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -0
- package/LICENSE +674 -0
- package/README.md +57 -0
- package/TRADEMARK +1 -0
- package/blockly_compressed_horizontal.js +2268 -0
- package/blockly_compressed_vertical.js +2296 -0
- package/blockly_uncompressed_horizontal.js +1212 -0
- package/blockly_uncompressed_vertical.js +1212 -0
- package/blocks_common/colour.js +61 -0
- package/blocks_common/math.js +159 -0
- package/blocks_common/matrix.js +54 -0
- package/blocks_common/note.js +58 -0
- package/blocks_common/text.js +57 -0
- package/blocks_compressed.js +37 -0
- package/blocks_compressed_horizontal.js +68 -0
- package/blocks_compressed_vertical.js +216 -0
- package/blocks_horizontal/control.js +212 -0
- package/blocks_horizontal/default_toolbox.js +139 -0
- package/blocks_horizontal/event.js +190 -0
- package/blocks_horizontal/wedo.js +325 -0
- package/blocks_vertical/control.js +532 -0
- package/blocks_vertical/data.js +666 -0
- package/blocks_vertical/default_toolbox.js +571 -0
- package/blocks_vertical/event.js +329 -0
- package/blocks_vertical/extensions.js +294 -0
- package/blocks_vertical/looks.js +591 -0
- package/blocks_vertical/motion.js +587 -0
- package/blocks_vertical/operators.js +470 -0
- package/blocks_vertical/procedures.js +1051 -0
- package/blocks_vertical/sensing.js +555 -0
- package/blocks_vertical/sound.js +246 -0
- package/blocks_vertical/vertical_extensions.js +289 -0
- package/build/gen_blocks.js +1 -0
- package/build/test_expect.js +1 -0
- package/build/test_input.js +1 -0
- package/build.py +647 -0
- package/cleanup.sh +101 -0
- package/core/block.js +1837 -0
- package/core/block_animations.js +107 -0
- package/core/block_drag_surface.js +299 -0
- package/core/block_dragger.js +424 -0
- package/core/block_events.js +531 -0
- package/core/block_render_svg_horizontal.js +892 -0
- package/core/block_render_svg_vertical.js +1734 -0
- package/core/block_svg.js +1355 -0
- package/core/blockly.js +620 -0
- package/core/blocks.js +37 -0
- package/core/bubble.js +664 -0
- package/core/bubble_dragger.js +285 -0
- package/core/colours.js +177 -0
- package/core/comment.js +293 -0
- package/core/comment_events.js +539 -0
- package/core/connection.js +776 -0
- package/core/connection_db.js +300 -0
- package/core/constants.js +408 -0
- package/core/contextmenu.js +534 -0
- package/core/css.js +1354 -0
- package/core/data_category.js +490 -0
- package/core/dragged_connection_manager.js +260 -0
- package/core/dropdowndiv.js +408 -0
- package/core/events.js +429 -0
- package/core/events_abstract.js +113 -0
- package/core/extensions.js +450 -0
- package/core/field.js +810 -0
- package/core/field_angle.js +410 -0
- package/core/field_checkbox.js +133 -0
- package/core/field_colour.js +253 -0
- package/core/field_colour_slider.js +387 -0
- package/core/field_date.js +353 -0
- package/core/field_dropdown.js +447 -0
- package/core/field_iconmenu.js +309 -0
- package/core/field_image.js +200 -0
- package/core/field_label.js +136 -0
- package/core/field_label_serializable.js +125 -0
- package/core/field_matrix.js +566 -0
- package/core/field_note.js +850 -0
- package/core/field_number.js +366 -0
- package/core/field_numberdropdown.js +77 -0
- package/core/field_textdropdown.js +164 -0
- package/core/field_textinput.js +675 -0
- package/core/field_textinput_removable.js +105 -0
- package/core/field_variable.js +385 -0
- package/core/field_variable_getter.js +185 -0
- package/core/field_vertical_separator.js +161 -0
- package/core/flyout_base.js +935 -0
- package/core/flyout_button.js +324 -0
- package/core/flyout_dragger.js +83 -0
- package/core/flyout_extension_category_header.js +159 -0
- package/core/flyout_horizontal.js +475 -0
- package/core/flyout_vertical.js +770 -0
- package/core/generator.js +426 -0
- package/core/gesture.js +1010 -0
- package/core/grid.js +227 -0
- package/core/icon.js +205 -0
- package/core/inject.js +496 -0
- package/core/input.js +285 -0
- package/core/insertion_marker_manager.js +678 -0
- package/core/intersection_observer.js +102 -0
- package/core/msg.js +62 -0
- package/core/mutator.js +426 -0
- package/core/names.js +198 -0
- package/core/options.js +244 -0
- package/core/procedures.js +739 -0
- package/core/rendered_connection.js +417 -0
- package/core/scratch_block_comment.js +646 -0
- package/core/scratch_blocks_utils.js +246 -0
- package/core/scratch_bubble.js +699 -0
- package/core/scratch_events.js +131 -0
- package/core/scratch_msgs.js +85 -0
- package/core/scrollbar.js +875 -0
- package/core/toolbox.js +803 -0
- package/core/tooltip.js +337 -0
- package/core/touch.js +226 -0
- package/core/trashcan.js +343 -0
- package/core/ui_events.js +91 -0
- package/core/ui_menu_utils.js +68 -0
- package/core/utils.js +825 -0
- package/core/variable_events.js +259 -0
- package/core/variable_map.js +415 -0
- package/core/variable_model.js +116 -0
- package/core/variables.js +674 -0
- package/core/warning.js +199 -0
- package/core/widgetdiv.js +344 -0
- package/core/workspace.js +673 -0
- package/core/workspace_audio.js +170 -0
- package/core/workspace_comment.js +426 -0
- package/core/workspace_comment_render_svg.js +706 -0
- package/core/workspace_comment_svg.js +609 -0
- package/core/workspace_drag_surface_svg.js +195 -0
- package/core/workspace_dragger.js +132 -0
- package/core/workspace_svg.js +2382 -0
- package/core/xml.js +930 -0
- package/core/zoom_controls.js +301 -0
- package/dist/horizontal.js +222 -0
- package/dist/vertical.js +222 -0
- package/dist/web/horizontal.js +232 -0
- package/dist/web/vertical.js +232 -0
- package/i18n/common.py +234 -0
- package/i18n/create_messages.py +162 -0
- package/i18n/create_scratch_msgs.js +69 -0
- package/i18n/dedup_json.py +73 -0
- package/i18n/js_to_json.js +46 -0
- package/i18n/js_to_json.py +136 -0
- package/i18n/json_to_js.js +52 -0
- package/i18n/json_to_js.py +185 -0
- package/i18n/sync_tx_translations.js +111 -0
- package/i18n/test_scratch_msgs.js +87 -0
- package/i18n/tests.py +47 -0
- package/i18n/xliff_to_json.py +232 -0
- package/local_build.sh +70 -0
- package/media/click.mp3 +0 -0
- package/media/click.ogg +0 -0
- package/media/click.wav +0 -0
- package/media/comment-arrow-down.svg +10 -0
- package/media/comment-arrow-up.svg +10 -0
- package/media/delete-x.svg +10 -0
- package/media/delete.mp3 +0 -0
- package/media/delete.ogg +0 -0
- package/media/delete.wav +0 -0
- package/media/dropdown-arrow-dark.svg +1 -0
- package/media/dropdown-arrow.svg +1 -0
- package/media/extensions/microbit-block-icon.svg +130 -0
- package/media/extensions/music-block-icon.svg +17 -0
- package/media/extensions/pen-block-icon.svg +19 -0
- package/media/extensions/wedo2-block-icon.svg +36 -0
- package/media/eyedropper.svg +22 -0
- package/media/green-flag.svg +17 -0
- package/media/handclosed.cur +0 -0
- package/media/handdelete.cur +0 -0
- package/media/handopen.cur +0 -0
- package/media/icons/arrow.svg +12 -0
- package/media/icons/arrow_button.svg +1 -0
- package/media/icons/control_forever.svg +1 -0
- package/media/icons/control_repeat.svg +1 -0
- package/media/icons/control_stop.svg +1 -0
- package/media/icons/control_wait.svg +1 -0
- package/media/icons/event_broadcast_blue.svg +1 -0
- package/media/icons/event_broadcast_coral.svg +1 -0
- package/media/icons/event_broadcast_green.svg +1 -0
- package/media/icons/event_broadcast_magenta.svg +1 -0
- package/media/icons/event_broadcast_orange.svg +1 -0
- package/media/icons/event_broadcast_purple.svg +1 -0
- package/media/icons/event_when-broadcast-received_blue.svg +1 -0
- package/media/icons/event_when-broadcast-received_coral.svg +1 -0
- package/media/icons/event_when-broadcast-received_green.svg +1 -0
- package/media/icons/event_when-broadcast-received_magenta.svg +1 -0
- package/media/icons/event_when-broadcast-received_orange.svg +1 -0
- package/media/icons/event_when-broadcast-received_purple.svg +1 -0
- package/media/icons/event_whenflagclicked.svg +1 -0
- package/media/icons/remove.svg +19 -0
- package/media/icons/set-led_blue.svg +1 -0
- package/media/icons/set-led_coral.svg +1 -0
- package/media/icons/set-led_green.svg +1 -0
- package/media/icons/set-led_magenta.svg +1 -0
- package/media/icons/set-led_mystery.svg +1 -0
- package/media/icons/set-led_orange.svg +1 -0
- package/media/icons/set-led_purple.svg +1 -0
- package/media/icons/set-led_white.svg +1 -0
- package/media/icons/set-led_yellow.svg +1 -0
- package/media/icons/wedo_motor-clockwise.svg +1 -0
- package/media/icons/wedo_motor-counterclockwise.svg +1 -0
- package/media/icons/wedo_motor-speed_fast.svg +1 -0
- package/media/icons/wedo_motor-speed_med.svg +1 -0
- package/media/icons/wedo_motor-speed_slow.svg +1 -0
- package/media/icons/wedo_when-distance_close.svg +1 -0
- package/media/icons/wedo_when-tilt-backward.svg +1 -0
- package/media/icons/wedo_when-tilt-forward.svg +1 -0
- package/media/icons/wedo_when-tilt-left.svg +1 -0
- package/media/icons/wedo_when-tilt-right.svg +1 -0
- package/media/icons/wedo_when-tilt.svg +1 -0
- package/media/repeat.svg +18 -0
- package/media/rotate-left.svg +1 -0
- package/media/rotate-right.svg +1 -0
- package/media/sprites.png +0 -0
- package/media/status-not-ready.svg +13 -0
- package/media/status-ready.svg +13 -0
- package/media/zoom-in.svg +1 -0
- package/media/zoom-out.svg +1 -0
- package/media/zoom-reset.svg +1 -0
- package/msg/js/en.js +290 -0
- package/msg/json/en.json +285 -0
- package/msg/messages.js +359 -0
- package/msg/scratch_msgs.js +22969 -0
- package/package.json +60 -0
- package/pull_from_blockly.sh +151 -0
- package/renovate.json5 +15 -0
- package/shim/blockly_compressed_horizontal-blocks_compressed.js +1 -0
- package/shim/blockly_compressed_horizontal.Blockly.js +1 -0
- package/shim/blockly_compressed_horizontal.goog.js +1 -0
- package/shim/blockly_compressed_horizontal.js +1 -0
- package/shim/blockly_compressed_vertical-blocks_compressed.js +1 -0
- package/shim/blockly_compressed_vertical.Blockly.js +1 -0
- package/shim/blockly_compressed_vertical.goog.js +1 -0
- package/shim/blockly_compressed_vertical.js +1 -0
- package/shim/blocks_compressed_horizontal-blockly_compressed_horizontal-messages.js +1 -0
- package/shim/blocks_compressed_horizontal.js +1 -0
- package/shim/blocks_compressed_vertical-blockly_compressed_vertical-messages.js +1 -0
- package/shim/blocks_compressed_vertical.js +1 -0
- package/shim/gh-pages.js +1 -0
- package/shim/horizontal.js +1 -0
- package/shim/index.js +17 -0
- package/shim/vertical.js +1 -0
- package/universal-python.js +82 -0
|
@@ -0,0 +1,892 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Visual Blocks Editor
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2012 Google Inc.
|
|
6
|
+
* https://developers.google.com/blockly/
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @fileoverview Methods for graphically rendering a block as SVG.
|
|
23
|
+
* @author fraser@google.com (Neil Fraser)
|
|
24
|
+
*/
|
|
25
|
+
'use strict';
|
|
26
|
+
|
|
27
|
+
goog.provide('Blockly.BlockSvg.render');
|
|
28
|
+
|
|
29
|
+
goog.require('Blockly.BlockSvg');
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// UI constants for rendering blocks.
|
|
33
|
+
/**
|
|
34
|
+
* Grid unit to pixels conversion
|
|
35
|
+
* @const
|
|
36
|
+
*/
|
|
37
|
+
Blockly.BlockSvg.GRID_UNIT = 4;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Horizontal space between elements.
|
|
41
|
+
* @const
|
|
42
|
+
*/
|
|
43
|
+
Blockly.BlockSvg.SEP_SPACE_X = 3 * Blockly.BlockSvg.GRID_UNIT;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Vertical space between elements.
|
|
47
|
+
* @const
|
|
48
|
+
*/
|
|
49
|
+
Blockly.BlockSvg.SEP_SPACE_Y = 3 * Blockly.BlockSvg.GRID_UNIT;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Vertical space above blocks with statements.
|
|
53
|
+
* @const
|
|
54
|
+
*/
|
|
55
|
+
Blockly.BlockSvg.STATEMENT_BLOCK_SPACE = 3 * Blockly.BlockSvg.GRID_UNIT;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Height of user inputs
|
|
59
|
+
* @const
|
|
60
|
+
*/
|
|
61
|
+
Blockly.BlockSvg.FIELD_HEIGHT = 8 * Blockly.BlockSvg.GRID_UNIT;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Width of user inputs
|
|
65
|
+
* @const
|
|
66
|
+
*/
|
|
67
|
+
Blockly.BlockSvg.FIELD_WIDTH = 12 * Blockly.BlockSvg.GRID_UNIT;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Editable field padding (left/right of the text).
|
|
71
|
+
* @const
|
|
72
|
+
*/
|
|
73
|
+
Blockly.BlockSvg.EDITABLE_FIELD_PADDING = 0;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Minimum width of user inputs during editing
|
|
77
|
+
* @const
|
|
78
|
+
*/
|
|
79
|
+
Blockly.BlockSvg.FIELD_WIDTH_MIN_EDIT = 13 * Blockly.BlockSvg.GRID_UNIT;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Maximum width of user inputs during editing
|
|
83
|
+
* @const
|
|
84
|
+
*/
|
|
85
|
+
Blockly.BlockSvg.FIELD_WIDTH_MAX_EDIT = 24 * Blockly.BlockSvg.GRID_UNIT;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Maximum height of user inputs during editing
|
|
89
|
+
* @const
|
|
90
|
+
*/
|
|
91
|
+
Blockly.BlockSvg.FIELD_HEIGHT_MAX_EDIT = 10 * Blockly.BlockSvg.GRID_UNIT;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Top padding of user inputs
|
|
95
|
+
* @const
|
|
96
|
+
*/
|
|
97
|
+
Blockly.BlockSvg.FIELD_TOP_PADDING = 0.25 * Blockly.BlockSvg.GRID_UNIT;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Corner radius of number inputs
|
|
101
|
+
* @const
|
|
102
|
+
*/
|
|
103
|
+
Blockly.BlockSvg.NUMBER_FIELD_CORNER_RADIUS = 4 * Blockly.BlockSvg.GRID_UNIT;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Corner radius of text inputs
|
|
107
|
+
* @const
|
|
108
|
+
*/
|
|
109
|
+
Blockly.BlockSvg.TEXT_FIELD_CORNER_RADIUS = 1 * Blockly.BlockSvg.GRID_UNIT;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Default radius for a field, in px.
|
|
113
|
+
* @const
|
|
114
|
+
*/
|
|
115
|
+
Blockly.BlockSvg.FIELD_DEFAULT_CORNER_RADIUS = 4 * Blockly.BlockSvg.GRID_UNIT;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Minimum width of a block.
|
|
119
|
+
* @const
|
|
120
|
+
*/
|
|
121
|
+
Blockly.BlockSvg.MIN_BLOCK_X = 1 / 2 * 16 * Blockly.BlockSvg.GRID_UNIT;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Minimum height of a block.
|
|
125
|
+
* @const
|
|
126
|
+
*/
|
|
127
|
+
Blockly.BlockSvg.MIN_BLOCK_Y = 16 * Blockly.BlockSvg.GRID_UNIT;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Width of horizontal puzzle tab.
|
|
131
|
+
* @const
|
|
132
|
+
*/
|
|
133
|
+
Blockly.BlockSvg.TAB_WIDTH = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Rounded corner radius.
|
|
137
|
+
* @const
|
|
138
|
+
*/
|
|
139
|
+
Blockly.BlockSvg.CORNER_RADIUS = 1 * Blockly.BlockSvg.GRID_UNIT;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Rounded corner radius.
|
|
143
|
+
* @const
|
|
144
|
+
*/
|
|
145
|
+
Blockly.BlockSvg.HAT_CORNER_RADIUS = 8 * Blockly.BlockSvg.GRID_UNIT;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Full height of connector notch including rounded corner.
|
|
149
|
+
* @const
|
|
150
|
+
*/
|
|
151
|
+
Blockly.BlockSvg.NOTCH_HEIGHT = 8 * Blockly.BlockSvg.GRID_UNIT + 2;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Width of connector notch
|
|
155
|
+
* @const
|
|
156
|
+
*/
|
|
157
|
+
Blockly.BlockSvg.NOTCH_WIDTH = 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* SVG path for drawing next/previous notch from top to bottom.
|
|
161
|
+
* Drawn in pixel units since Bezier control points are off the grid.
|
|
162
|
+
* @const
|
|
163
|
+
*/
|
|
164
|
+
Blockly.BlockSvg.NOTCH_PATH_DOWN =
|
|
165
|
+
'c 0,2 1,3 2,4 ' +
|
|
166
|
+
'l 4,4 ' +
|
|
167
|
+
'c 1,1 2,2 2,4 ' +
|
|
168
|
+
'v 12 ' +
|
|
169
|
+
'c 0,2 -1,3 -2,4 ' +
|
|
170
|
+
'l -4,4 ' +
|
|
171
|
+
'c -1,1 -2,2 -2,4';
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* SVG path for drawing next/previous notch from bottom to top.
|
|
175
|
+
* Drawn in pixel units since Bezier control points are off the grid.
|
|
176
|
+
* @const
|
|
177
|
+
*/
|
|
178
|
+
Blockly.BlockSvg.NOTCH_PATH_UP =
|
|
179
|
+
'c 0,-2 1,-3 2,-4 ' +
|
|
180
|
+
'l 4,-4 ' +
|
|
181
|
+
'c 1,-1 2,-2 2,-4 ' +
|
|
182
|
+
'v -12 ' +
|
|
183
|
+
'c 0,-2 -1,-3 -2,-4 ' +
|
|
184
|
+
'l -4,-4 ' +
|
|
185
|
+
'c -1,-1 -2,-2 -2,-4';
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Width of rendered image field in px
|
|
189
|
+
* @const
|
|
190
|
+
*/
|
|
191
|
+
Blockly.BlockSvg.IMAGE_FIELD_WIDTH = 10 * Blockly.BlockSvg.GRID_UNIT;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Height of rendered image field in px
|
|
195
|
+
* @const
|
|
196
|
+
*/
|
|
197
|
+
Blockly.BlockSvg.IMAGE_FIELD_HEIGHT = 10 * Blockly.BlockSvg.GRID_UNIT;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* y-offset of the top of the field shadow block from the bottom of the block.
|
|
201
|
+
* @const
|
|
202
|
+
*/
|
|
203
|
+
Blockly.BlockSvg.FIELD_Y_OFFSET = -2 * Blockly.BlockSvg.GRID_UNIT;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* SVG start point for drawing the top-left corner.
|
|
207
|
+
* @const
|
|
208
|
+
*/
|
|
209
|
+
Blockly.BlockSvg.TOP_LEFT_CORNER_START =
|
|
210
|
+
'm ' + Blockly.BlockSvg.CORNER_RADIUS + ',0';
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* SVG path for drawing the rounded top-left corner.
|
|
214
|
+
* @const
|
|
215
|
+
*/
|
|
216
|
+
Blockly.BlockSvg.TOP_LEFT_CORNER =
|
|
217
|
+
'A ' + Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
218
|
+
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 ' +
|
|
219
|
+
'0,' + Blockly.BlockSvg.CORNER_RADIUS;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* SVG start point for drawing the top-left corner.
|
|
223
|
+
* @const
|
|
224
|
+
*/
|
|
225
|
+
Blockly.BlockSvg.HAT_TOP_LEFT_CORNER_START =
|
|
226
|
+
'm ' + Blockly.BlockSvg.HAT_CORNER_RADIUS + ',0';
|
|
227
|
+
/**
|
|
228
|
+
* SVG path for drawing the rounded top-left corner.
|
|
229
|
+
* @const
|
|
230
|
+
*/
|
|
231
|
+
Blockly.BlockSvg.HAT_TOP_LEFT_CORNER =
|
|
232
|
+
'A ' + Blockly.BlockSvg.HAT_CORNER_RADIUS + ',' +
|
|
233
|
+
Blockly.BlockSvg.HAT_CORNER_RADIUS + ' 0 0,0 ' +
|
|
234
|
+
'0,' + Blockly.BlockSvg.HAT_CORNER_RADIUS;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @type {Object} An object containing computed measurements of this block.
|
|
238
|
+
* @private
|
|
239
|
+
*/
|
|
240
|
+
Blockly.BlockSvg.renderingMetrics_ = null;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Max text display length for a field (per-horizontal/vertical)
|
|
244
|
+
* @const
|
|
245
|
+
*/
|
|
246
|
+
Blockly.BlockSvg.MAX_DISPLAY_LENGTH = 4;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Point size of text field before animation. Must match size in CSS.
|
|
250
|
+
* See implementation in field_textinput.
|
|
251
|
+
*/
|
|
252
|
+
Blockly.BlockSvg.FIELD_TEXTINPUT_FONTSIZE_INITIAL = 12;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Point size of text field after animation.
|
|
256
|
+
* See implementation in field_textinput.
|
|
257
|
+
*/
|
|
258
|
+
Blockly.BlockSvg.FIELD_TEXTINPUT_FONTSIZE_FINAL = 14;
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Whether text fields are allowed to expand past their truncated block size.
|
|
262
|
+
* @const{boolean}
|
|
263
|
+
*/
|
|
264
|
+
Blockly.BlockSvg.FIELD_TEXTINPUT_EXPAND_PAST_TRUNCATION = true;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Whether text fields should animate their positioning.
|
|
268
|
+
* @const{boolean}
|
|
269
|
+
*/
|
|
270
|
+
Blockly.BlockSvg.FIELD_TEXTINPUT_ANIMATE_POSITIONING = true;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* @param {!Object} first An object containing computed measurements of a
|
|
274
|
+
* block.
|
|
275
|
+
* @param {!Object} second Another object containing computed measurements of a
|
|
276
|
+
* block.
|
|
277
|
+
* @return {boolean} Whether the two sets of metrics are equivalent.
|
|
278
|
+
* @private
|
|
279
|
+
*/
|
|
280
|
+
Blockly.BlockSvg.metricsAreEquivalent_ = function(first, second) {
|
|
281
|
+
if (first.statement != second.statement) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
if (first.imageField != second.imageField) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if ((first.height != second.height) ||
|
|
289
|
+
(first.width != second.width) ||
|
|
290
|
+
(first.bayHeight != second.bayHeight) ||
|
|
291
|
+
(first.bayWidth != second.bayWidth) ||
|
|
292
|
+
(first.fieldRadius != second.fieldRadius) ||
|
|
293
|
+
(first.startHat != second.startHat)) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
return true;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Play some UI effects (sound) after a connection has been established.
|
|
301
|
+
*/
|
|
302
|
+
Blockly.BlockSvg.prototype.connectionUiEffect = function() {
|
|
303
|
+
this.workspace.getAudioManager().play('click');
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Change the colour of a block.
|
|
308
|
+
*/
|
|
309
|
+
Blockly.BlockSvg.prototype.updateColour = function() {
|
|
310
|
+
var fillColour = (this.isGlowing_) ? this.getColourSecondary() : this.getColour();
|
|
311
|
+
var strokeColour = this.getColourTertiary();
|
|
312
|
+
|
|
313
|
+
// Render block stroke
|
|
314
|
+
this.svgPath_.setAttribute('stroke', strokeColour);
|
|
315
|
+
|
|
316
|
+
// Render block fill
|
|
317
|
+
var fillColour = (this.isGlowingBlock_) ? this.getColourSecondary() : this.getColour();
|
|
318
|
+
this.svgPath_.setAttribute('fill', fillColour);
|
|
319
|
+
|
|
320
|
+
// Render opacity
|
|
321
|
+
this.svgPath_.setAttribute('fill-opacity', this.getOpacity());
|
|
322
|
+
|
|
323
|
+
// Bump every dropdown to change its colour.
|
|
324
|
+
for (var x = 0, input; input = this.inputList[x]; x++) {
|
|
325
|
+
for (var y = 0, field; field = input.fieldRow[y]; y++) {
|
|
326
|
+
field.setText(null);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Visual effect to show that if the dragging block is dropped, this block will
|
|
333
|
+
* be replaced. If a shadow block it will disappear. Otherwise it will bump.
|
|
334
|
+
* @param {boolean} add True if highlighting should be added.
|
|
335
|
+
*/
|
|
336
|
+
Blockly.BlockSvg.prototype.highlightForReplacement = function(add) {
|
|
337
|
+
if (add) {
|
|
338
|
+
var replacementGlowFilterId = this.workspace.options.replacementGlowFilterId
|
|
339
|
+
|| 'blocklyReplacementGlowFilter';
|
|
340
|
+
this.svgPath_.setAttribute('filter', 'url(#' + replacementGlowFilterId + ')');
|
|
341
|
+
Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_),
|
|
342
|
+
'blocklyReplaceable');
|
|
343
|
+
} else {
|
|
344
|
+
this.svgPath_.removeAttribute('filter');
|
|
345
|
+
Blockly.utils.removeClass(/** @type {!Element} */ (this.svgGroup_),
|
|
346
|
+
'blocklyReplaceable');
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Returns a bounding box describing the dimensions of this block
|
|
352
|
+
* and any blocks stacked below it.
|
|
353
|
+
* @param {boolean=} opt_ignoreFields True if we should ignore fields in the
|
|
354
|
+
* size calculation, and just give the size of the base block(s).
|
|
355
|
+
* @return {!{height: number, width: number}} Object with height and width properties.
|
|
356
|
+
*/
|
|
357
|
+
Blockly.BlockSvg.prototype.getHeightWidth = function(opt_ignoreFields) {
|
|
358
|
+
var height = this.height;
|
|
359
|
+
var width = this.width;
|
|
360
|
+
// Add the size of the field shadow block.
|
|
361
|
+
if (!opt_ignoreFields && this.getFieldShadowBlock_()) {
|
|
362
|
+
height += Blockly.BlockSvg.FIELD_Y_OFFSET;
|
|
363
|
+
height += Blockly.BlockSvg.FIELD_HEIGHT;
|
|
364
|
+
}
|
|
365
|
+
// Recursively add size of subsequent blocks.
|
|
366
|
+
var nextBlock = this.getNextBlock();
|
|
367
|
+
if (nextBlock) {
|
|
368
|
+
var nextHeightWidth = nextBlock.getHeightWidth(opt_ignoreFields);
|
|
369
|
+
width += nextHeightWidth.width;
|
|
370
|
+
width -= Blockly.BlockSvg.NOTCH_WIDTH; // Exclude width of connected notch.
|
|
371
|
+
height = Math.max(height, nextHeightWidth.height);
|
|
372
|
+
}
|
|
373
|
+
return {height: height, width: width};
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Render the block.
|
|
378
|
+
* Lays out and reflows a block based on its contents and settings.
|
|
379
|
+
* @param {boolean=} opt_bubble If false, just render this block.
|
|
380
|
+
* If true, also render block's parent, grandparent, etc. Defaults to true.
|
|
381
|
+
*/
|
|
382
|
+
Blockly.BlockSvg.prototype.render = function(opt_bubble) {
|
|
383
|
+
Blockly.Field.startCache();
|
|
384
|
+
this.rendered = true;
|
|
385
|
+
|
|
386
|
+
var oldMetrics = this.renderingMetrics_;
|
|
387
|
+
var metrics = this.renderCompute_();
|
|
388
|
+
|
|
389
|
+
// Don't redraw if we don't need to.
|
|
390
|
+
if (oldMetrics &&
|
|
391
|
+
Blockly.BlockSvg.metricsAreEquivalent_(oldMetrics, metrics)) {
|
|
392
|
+
// Skipping the redraw is fine, but we may still have to tighten up our
|
|
393
|
+
// connections with child blocks.
|
|
394
|
+
if (metrics.statement && metrics.statement.connection &&
|
|
395
|
+
metrics.statement.targetConnection) {
|
|
396
|
+
metrics.statement.connection.tighten_();
|
|
397
|
+
}
|
|
398
|
+
if (this.nextConnection && this.nextConnection.targetConnection) {
|
|
399
|
+
this.nextConnection.tighten_();
|
|
400
|
+
}
|
|
401
|
+
} else {
|
|
402
|
+
this.height = metrics.height;
|
|
403
|
+
this.width = metrics.width;
|
|
404
|
+
this.renderDraw_(metrics);
|
|
405
|
+
this.renderClassify_(metrics);
|
|
406
|
+
this.renderingMetrics_ = metrics;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (opt_bubble !== false) {
|
|
410
|
+
// Render all blocks above this one (propagate a reflow).
|
|
411
|
+
var parentBlock = this.getParent();
|
|
412
|
+
if (parentBlock) {
|
|
413
|
+
parentBlock.render(true);
|
|
414
|
+
} else {
|
|
415
|
+
// Top-most block. Fire an event to allow scrollbars to resize.
|
|
416
|
+
Blockly.resizeSvgContents(this.workspace);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
Blockly.Field.stopCache();
|
|
420
|
+
|
|
421
|
+
this.updateIntersectionObserver();
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Computes the height and widths for each row and field.
|
|
426
|
+
* @return {!Array.<!Array.<!Object>>} 2D array of objects, each containing
|
|
427
|
+
* position information.
|
|
428
|
+
* @private
|
|
429
|
+
*/
|
|
430
|
+
Blockly.BlockSvg.prototype.renderCompute_ = function() {
|
|
431
|
+
var metrics = {
|
|
432
|
+
statement: null,
|
|
433
|
+
imageField: null,
|
|
434
|
+
iconMenu: null,
|
|
435
|
+
width: 0,
|
|
436
|
+
height: 0,
|
|
437
|
+
bayHeight: 0,
|
|
438
|
+
bayWidth: 0,
|
|
439
|
+
bayNotchAtRight: true,
|
|
440
|
+
fieldRadius: 0,
|
|
441
|
+
startHat: false,
|
|
442
|
+
endCap: false
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
// Does block have a statement?
|
|
446
|
+
for (var i = 0, input; input = this.inputList[i]; i++) {
|
|
447
|
+
if (input.type == Blockly.NEXT_STATEMENT) {
|
|
448
|
+
metrics.statement = input;
|
|
449
|
+
// Compute minimum input size.
|
|
450
|
+
metrics.bayHeight = Blockly.BlockSvg.MIN_BLOCK_Y;
|
|
451
|
+
metrics.bayWidth = Blockly.BlockSvg.MIN_BLOCK_X;
|
|
452
|
+
// Expand input size if there is a connection.
|
|
453
|
+
if (input.connection && input.connection.targetConnection) {
|
|
454
|
+
var linkedBlock = input.connection.targetBlock();
|
|
455
|
+
var bBox = linkedBlock.getHeightWidth(true);
|
|
456
|
+
metrics.bayHeight = Math.max(metrics.bayHeight, bBox.height);
|
|
457
|
+
metrics.bayWidth = Math.max(metrics.bayWidth, bBox.width);
|
|
458
|
+
}
|
|
459
|
+
var linkedBlock = input.connection.targetBlock();
|
|
460
|
+
if (linkedBlock && !linkedBlock.lastConnectionInStack()) {
|
|
461
|
+
metrics.bayNotchAtRight = false;
|
|
462
|
+
} else {
|
|
463
|
+
metrics.bayWidth -= Blockly.BlockSvg.NOTCH_WIDTH;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// Find image field, input fields
|
|
468
|
+
for (var j = 0, field; field = input.fieldRow[j]; j++) {
|
|
469
|
+
if (field instanceof Blockly.FieldImage) {
|
|
470
|
+
metrics.imageField = field;
|
|
471
|
+
}
|
|
472
|
+
if (field instanceof Blockly.FieldIconMenu) {
|
|
473
|
+
metrics.iconMenu = field;
|
|
474
|
+
}
|
|
475
|
+
if (field instanceof Blockly.FieldTextInput) {
|
|
476
|
+
metrics.fieldRadius = field.getBorderRadius();
|
|
477
|
+
} else {
|
|
478
|
+
metrics.fieldRadius = Blockly.BlockSvg.FIELD_DEFAULT_CORNER_RADIUS;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// Determine whether a block is a start hat or end cap by checking connections.
|
|
484
|
+
if (this.nextConnection && !this.previousConnection) {
|
|
485
|
+
metrics.startHat = true;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// End caps have no bay, a previous, no output, and no next.
|
|
489
|
+
if (!this.nextConnection && this.previousConnection &&
|
|
490
|
+
!this.outputConnection && !metrics.statement) {
|
|
491
|
+
metrics.endCap = true;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// If this block is an icon menu shadow, attempt to set the parent's
|
|
495
|
+
// ImageField src to the one that represents the current value of the field.
|
|
496
|
+
if (metrics.iconMenu) {
|
|
497
|
+
var currentSrc = metrics.iconMenu.getSrcForValue(metrics.iconMenu.getValue());
|
|
498
|
+
if (currentSrc) {
|
|
499
|
+
metrics.iconMenu.setParentFieldImage(currentSrc);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// Always render image field at 40x40 px
|
|
504
|
+
// Normal block sizing
|
|
505
|
+
metrics.width = Blockly.BlockSvg.SEP_SPACE_X * 2 + Blockly.BlockSvg.IMAGE_FIELD_WIDTH;
|
|
506
|
+
metrics.height = Blockly.BlockSvg.SEP_SPACE_Y * 2 + Blockly.BlockSvg.IMAGE_FIELD_HEIGHT;
|
|
507
|
+
|
|
508
|
+
if (this.outputConnection) {
|
|
509
|
+
// Field shadow block
|
|
510
|
+
metrics.height = Blockly.BlockSvg.FIELD_HEIGHT;
|
|
511
|
+
metrics.width = Blockly.BlockSvg.FIELD_WIDTH;
|
|
512
|
+
}
|
|
513
|
+
if (metrics.statement) {
|
|
514
|
+
// Block with statement (e.g., repeat, forever)
|
|
515
|
+
metrics.width += metrics.bayWidth + 4 * Blockly.BlockSvg.CORNER_RADIUS + 2 * Blockly.BlockSvg.GRID_UNIT;
|
|
516
|
+
metrics.height = metrics.bayHeight + Blockly.BlockSvg.STATEMENT_BLOCK_SPACE;
|
|
517
|
+
}
|
|
518
|
+
if (metrics.startHat) {
|
|
519
|
+
// Start hats are 1 unit wider to account for optical effect of curve.
|
|
520
|
+
metrics.width += 1 * Blockly.BlockSvg.GRID_UNIT;
|
|
521
|
+
}
|
|
522
|
+
if (metrics.endCap) {
|
|
523
|
+
// End caps are 1 unit wider to account for optical effect of no notch.
|
|
524
|
+
metrics.width += 1 * Blockly.BlockSvg.GRID_UNIT;
|
|
525
|
+
}
|
|
526
|
+
return metrics;
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Draw the path of the block.
|
|
532
|
+
* Move the fields to the correct locations.
|
|
533
|
+
* @param {!Object} metrics An object containing computed measurements of the
|
|
534
|
+
* block.
|
|
535
|
+
* @private
|
|
536
|
+
*/
|
|
537
|
+
Blockly.BlockSvg.prototype.renderDraw_ = function(metrics) {
|
|
538
|
+
// Fetch the block's coordinates on the surface for use in anchoring
|
|
539
|
+
// the connections.
|
|
540
|
+
var connectionsXY = this.getRelativeToSurfaceXY();
|
|
541
|
+
// Assemble the block's path.
|
|
542
|
+
var steps = [];
|
|
543
|
+
|
|
544
|
+
this.renderDrawLeft_(steps, connectionsXY, metrics);
|
|
545
|
+
this.renderDrawBottom_(steps, connectionsXY, metrics);
|
|
546
|
+
this.renderDrawRight_(steps, connectionsXY, metrics);
|
|
547
|
+
this.renderDrawTop_(steps, connectionsXY, metrics);
|
|
548
|
+
|
|
549
|
+
var pathString = steps.join(' ');
|
|
550
|
+
this.svgPath_.setAttribute('d', pathString);
|
|
551
|
+
|
|
552
|
+
if (this.RTL) {
|
|
553
|
+
// Mirror the block's path.
|
|
554
|
+
// This is awesome.
|
|
555
|
+
this.svgPath_.setAttribute('transform', 'scale(-1 1)');
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// Horizontal blocks have a single Image Field that is specially positioned
|
|
559
|
+
if (metrics.imageField) {
|
|
560
|
+
var imageField = metrics.imageField.getSvgRoot();
|
|
561
|
+
var imageFieldSize = metrics.imageField.getSize();
|
|
562
|
+
// Image field's position is calculated relative to the "end" edge of the
|
|
563
|
+
// block.
|
|
564
|
+
var imageFieldX = metrics.width - imageFieldSize.width -
|
|
565
|
+
Blockly.BlockSvg.SEP_SPACE_X / 1.5;
|
|
566
|
+
var imageFieldY = metrics.height - imageFieldSize.height -
|
|
567
|
+
Blockly.BlockSvg.SEP_SPACE_Y;
|
|
568
|
+
if (metrics.endCap) {
|
|
569
|
+
// End-cap image is offset by a grid unit to account for optical effect of no notch.
|
|
570
|
+
imageFieldX -= Blockly.BlockSvg.GRID_UNIT;
|
|
571
|
+
}
|
|
572
|
+
var imageFieldScale = "scale(1 1)";
|
|
573
|
+
if (this.RTL) {
|
|
574
|
+
// Do we want to mirror the Image Field left-to-right?
|
|
575
|
+
if (metrics.imageField.getFlipRTL()) {
|
|
576
|
+
imageFieldScale = "scale(-1 1)";
|
|
577
|
+
imageFieldX = -metrics.width + imageFieldSize.width +
|
|
578
|
+
Blockly.BlockSvg.SEP_SPACE_X / 1.5;
|
|
579
|
+
} else {
|
|
580
|
+
// If not, don't offset by imageFieldSize.width
|
|
581
|
+
imageFieldX = -metrics.width + Blockly.BlockSvg.SEP_SPACE_X / 1.5;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (imageField) {
|
|
585
|
+
// Fields are invisible on insertion marker.
|
|
586
|
+
if (this.isInsertionMarker()) {
|
|
587
|
+
imageField.setAttribute('display', 'none');
|
|
588
|
+
}
|
|
589
|
+
imageField.setAttribute('transform',
|
|
590
|
+
'translate(' + imageFieldX + ',' + imageFieldY + ') ' +
|
|
591
|
+
imageFieldScale);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// Position value input
|
|
596
|
+
if (this.getFieldShadowBlock_()) {
|
|
597
|
+
var input = this.getFieldShadowBlock_().getSvgRoot();
|
|
598
|
+
var valueX = (Blockly.BlockSvg.NOTCH_WIDTH +
|
|
599
|
+
(metrics.bayWidth ? 2 * Blockly.BlockSvg.GRID_UNIT +
|
|
600
|
+
Blockly.BlockSvg.NOTCH_WIDTH * 2 : 0) + metrics.bayWidth);
|
|
601
|
+
if (metrics.startHat) {
|
|
602
|
+
// Start hats add some left margin to field for visual balance
|
|
603
|
+
valueX += Blockly.BlockSvg.GRID_UNIT * 2;
|
|
604
|
+
}
|
|
605
|
+
if (this.RTL) {
|
|
606
|
+
valueX = -valueX;
|
|
607
|
+
}
|
|
608
|
+
var valueY = (metrics.height + Blockly.BlockSvg.FIELD_Y_OFFSET);
|
|
609
|
+
var transformation = 'translate(' + valueX + ',' + valueY + ')';
|
|
610
|
+
input.setAttribute('transform', transformation);
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Give the block an attribute 'data-shapes' that lists its shape[s], and an
|
|
616
|
+
* attribute 'data-category' with its category.
|
|
617
|
+
* @param {!Object} metrics An object containing computed measurements of the
|
|
618
|
+
* block.
|
|
619
|
+
* @private
|
|
620
|
+
*/
|
|
621
|
+
Blockly.BlockSvg.prototype.renderClassify_ = function(metrics) {
|
|
622
|
+
var shapes = [];
|
|
623
|
+
|
|
624
|
+
if (this.isShadow_) {
|
|
625
|
+
shapes.push('argument');
|
|
626
|
+
} else {
|
|
627
|
+
if(metrics.statement) {
|
|
628
|
+
shapes.push('c-block');
|
|
629
|
+
}
|
|
630
|
+
if (metrics.startHat) {
|
|
631
|
+
shapes.push('hat'); // c-block+hats are possible (e.x. reprter procedures)
|
|
632
|
+
} else if (!metrics.statement) {
|
|
633
|
+
shapes.push('stack'); //only call it "stack" if it's not a c-block
|
|
634
|
+
}
|
|
635
|
+
if (!this.nextConnection) {
|
|
636
|
+
shapes.push('end');
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
this.svgGroup_.setAttribute('data-shapes', shapes.join(' '));
|
|
641
|
+
|
|
642
|
+
if (this.getCategory()) {
|
|
643
|
+
this.svgGroup_.setAttribute('data-category', this.getCategory());
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Render the left edge of the block.
|
|
649
|
+
* @param {!Array.<string>} steps Path of block outline.
|
|
650
|
+
* @param {!Object} connectionsXY Location of block.
|
|
651
|
+
* @param {!Object} metrics An object containing computed measurements of the
|
|
652
|
+
* block.
|
|
653
|
+
* @private
|
|
654
|
+
*/
|
|
655
|
+
Blockly.BlockSvg.prototype.renderDrawLeft_ = function(steps, connectionsXY, metrics) {
|
|
656
|
+
// Top edge.
|
|
657
|
+
if (metrics.startHat) {
|
|
658
|
+
// Hat block
|
|
659
|
+
// Position the cursor at the top-left starting point.
|
|
660
|
+
steps.push(Blockly.BlockSvg.HAT_TOP_LEFT_CORNER_START);
|
|
661
|
+
// Top-left rounded corner.
|
|
662
|
+
steps.push(Blockly.BlockSvg.HAT_TOP_LEFT_CORNER);
|
|
663
|
+
} else if (this.previousConnection) {
|
|
664
|
+
// Regular block
|
|
665
|
+
// Position the cursor at the top-left starting point.
|
|
666
|
+
steps.push(Blockly.BlockSvg.TOP_LEFT_CORNER_START);
|
|
667
|
+
// Top-left rounded corner.
|
|
668
|
+
steps.push(Blockly.BlockSvg.TOP_LEFT_CORNER);
|
|
669
|
+
var cursorY = metrics.height - Blockly.BlockSvg.CORNER_RADIUS -
|
|
670
|
+
Blockly.BlockSvg.SEP_SPACE_Y - Blockly.BlockSvg.NOTCH_HEIGHT;
|
|
671
|
+
steps.push('V', cursorY);
|
|
672
|
+
steps.push(Blockly.BlockSvg.NOTCH_PATH_DOWN);
|
|
673
|
+
// Create previous block connection.
|
|
674
|
+
var connectionX = connectionsXY.x;
|
|
675
|
+
var connectionY = connectionsXY.y + metrics.height -
|
|
676
|
+
Blockly.BlockSvg.CORNER_RADIUS * 2;
|
|
677
|
+
this.previousConnection.moveTo(connectionX, connectionY);
|
|
678
|
+
// This connection will be tightened when the parent renders.
|
|
679
|
+
steps.push('V', metrics.height - Blockly.BlockSvg.CORNER_RADIUS);
|
|
680
|
+
} else {
|
|
681
|
+
// Input
|
|
682
|
+
// Position the cursor at the top-left starting point.
|
|
683
|
+
steps.push('m', metrics.fieldRadius + ',0');
|
|
684
|
+
// Top-left rounded corner.
|
|
685
|
+
steps.push(
|
|
686
|
+
'A', metrics.fieldRadius + ',' + metrics.fieldRadius,
|
|
687
|
+
'0', '0,0', '0,' + metrics.fieldRadius);
|
|
688
|
+
steps.push(
|
|
689
|
+
'V', metrics.height - metrics.fieldRadius);
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Render the bottom edge of the block.
|
|
695
|
+
* @param {!Array.<string>} steps Path of block outline.
|
|
696
|
+
* @param {!Object} connectionsXY Location of block.
|
|
697
|
+
* @param {!Object} metrics An object containing computed measurements of the
|
|
698
|
+
* block.
|
|
699
|
+
* @private
|
|
700
|
+
*/
|
|
701
|
+
Blockly.BlockSvg.prototype.renderDrawBottom_ = function(steps,
|
|
702
|
+
connectionsXY, metrics) {
|
|
703
|
+
|
|
704
|
+
if (metrics.startHat) {
|
|
705
|
+
steps.push('a', Blockly.BlockSvg.HAT_CORNER_RADIUS + ',' +
|
|
706
|
+
Blockly.BlockSvg.HAT_CORNER_RADIUS + ' 0 0,0 ' +
|
|
707
|
+
Blockly.BlockSvg.HAT_CORNER_RADIUS + ',' +
|
|
708
|
+
Blockly.BlockSvg.HAT_CORNER_RADIUS);
|
|
709
|
+
} else if (this.previousConnection) {
|
|
710
|
+
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
711
|
+
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 ' +
|
|
712
|
+
Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
713
|
+
Blockly.BlockSvg.CORNER_RADIUS);
|
|
714
|
+
} else {
|
|
715
|
+
// Input
|
|
716
|
+
steps.push(
|
|
717
|
+
'a', metrics.fieldRadius + ',' + metrics.fieldRadius,
|
|
718
|
+
'0', '0,0', metrics.fieldRadius + ',' + metrics.fieldRadius);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
// Has statement
|
|
722
|
+
if (metrics.statement) {
|
|
723
|
+
steps.push('h', 4 * Blockly.BlockSvg.GRID_UNIT);
|
|
724
|
+
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
725
|
+
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 ' +
|
|
726
|
+
Blockly.BlockSvg.CORNER_RADIUS + ',-' +
|
|
727
|
+
Blockly.BlockSvg.CORNER_RADIUS);
|
|
728
|
+
steps.push('v', -2.5 * Blockly.BlockSvg.GRID_UNIT);
|
|
729
|
+
steps.push(Blockly.BlockSvg.NOTCH_PATH_UP);
|
|
730
|
+
// @todo Why 3?
|
|
731
|
+
steps.push('v', -metrics.bayHeight + (Blockly.BlockSvg.CORNER_RADIUS * 3) +
|
|
732
|
+
Blockly.BlockSvg.NOTCH_HEIGHT + 2 * Blockly.BlockSvg.GRID_UNIT);
|
|
733
|
+
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
734
|
+
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,1 ' +
|
|
735
|
+
Blockly.BlockSvg.CORNER_RADIUS + ',-' +
|
|
736
|
+
Blockly.BlockSvg.CORNER_RADIUS);
|
|
737
|
+
steps.push('h', metrics.bayWidth - (Blockly.BlockSvg.CORNER_RADIUS * 2));
|
|
738
|
+
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
739
|
+
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,1 ' +
|
|
740
|
+
Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
741
|
+
Blockly.BlockSvg.CORNER_RADIUS);
|
|
742
|
+
if (metrics.bayNotchAtRight) {
|
|
743
|
+
steps.push('v', metrics.bayHeight - (Blockly.BlockSvg.CORNER_RADIUS * 3) -
|
|
744
|
+
Blockly.BlockSvg.NOTCH_HEIGHT - 2 * Blockly.BlockSvg.GRID_UNIT);
|
|
745
|
+
steps.push(Blockly.BlockSvg.NOTCH_PATH_DOWN);
|
|
746
|
+
}
|
|
747
|
+
steps.push('V', metrics.bayHeight + 2 * Blockly.BlockSvg.GRID_UNIT);
|
|
748
|
+
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
749
|
+
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 ' +
|
|
750
|
+
Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
751
|
+
Blockly.BlockSvg.CORNER_RADIUS);
|
|
752
|
+
|
|
753
|
+
// Create statement connection.
|
|
754
|
+
var connectionX = connectionsXY.x + Blockly.BlockSvg.CORNER_RADIUS * 2 +
|
|
755
|
+
4 * Blockly.BlockSvg.GRID_UNIT;
|
|
756
|
+
if (this.RTL) {
|
|
757
|
+
connectionX = connectionsXY.x - Blockly.BlockSvg.CORNER_RADIUS * 2 -
|
|
758
|
+
4 * Blockly.BlockSvg.GRID_UNIT;
|
|
759
|
+
}
|
|
760
|
+
var connectionY = connectionsXY.y + metrics.height -
|
|
761
|
+
Blockly.BlockSvg.CORNER_RADIUS * 2;
|
|
762
|
+
metrics.statement.connection.moveTo(connectionX, connectionY);
|
|
763
|
+
if (metrics.statement.connection.targetConnection) {
|
|
764
|
+
metrics.statement.connection.tighten_();
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
if (!this.isShadow()) {
|
|
769
|
+
steps.push('H', metrics.width - Blockly.BlockSvg.CORNER_RADIUS);
|
|
770
|
+
} else {
|
|
771
|
+
// input
|
|
772
|
+
steps.push('H', metrics.width - metrics.fieldRadius);
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Render the right edge of the block.
|
|
778
|
+
* @param {!Array.<string>} steps Path of block outline.
|
|
779
|
+
* @param {!Object} connectionsXY Location of block.
|
|
780
|
+
* @param {!Object} metrics An object containing computed measurements of the
|
|
781
|
+
* block.
|
|
782
|
+
* @private
|
|
783
|
+
*/
|
|
784
|
+
Blockly.BlockSvg.prototype.renderDrawRight_ = function(steps, connectionsXY, metrics) {
|
|
785
|
+
if (!this.isShadow()) {
|
|
786
|
+
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
787
|
+
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 ' +
|
|
788
|
+
Blockly.BlockSvg.CORNER_RADIUS + ',-' +
|
|
789
|
+
Blockly.BlockSvg.CORNER_RADIUS);
|
|
790
|
+
steps.push('v', -2.5 * Blockly.BlockSvg.GRID_UNIT);
|
|
791
|
+
} else {
|
|
792
|
+
// Input
|
|
793
|
+
steps.push(
|
|
794
|
+
'a', metrics.fieldRadius + ',' + metrics.fieldRadius,
|
|
795
|
+
'0', '0,0', metrics.fieldRadius + ',' + -1 * metrics.fieldRadius);
|
|
796
|
+
steps.push('v', -1 * (metrics.height - metrics.fieldRadius * 2));
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
if (this.nextConnection) {
|
|
800
|
+
steps.push(Blockly.BlockSvg.NOTCH_PATH_UP);
|
|
801
|
+
|
|
802
|
+
// Include width of notch in block width.
|
|
803
|
+
this.width += Blockly.BlockSvg.NOTCH_WIDTH;
|
|
804
|
+
|
|
805
|
+
// Create next block connection.
|
|
806
|
+
var connectionX;
|
|
807
|
+
if (this.RTL) {
|
|
808
|
+
connectionX = connectionsXY.x - metrics.width;
|
|
809
|
+
} else {
|
|
810
|
+
connectionX = connectionsXY.x + metrics.width;
|
|
811
|
+
}
|
|
812
|
+
var connectionY = connectionsXY.y + metrics.height -
|
|
813
|
+
Blockly.BlockSvg.CORNER_RADIUS * 2;
|
|
814
|
+
this.nextConnection.moveTo(connectionX, connectionY);
|
|
815
|
+
if (this.nextConnection.targetConnection) {
|
|
816
|
+
this.nextConnection.tighten_();
|
|
817
|
+
}
|
|
818
|
+
steps.push('V', Blockly.BlockSvg.CORNER_RADIUS);
|
|
819
|
+
} else if (!this.isShadow()) {
|
|
820
|
+
steps.push('V', Blockly.BlockSvg.CORNER_RADIUS);
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* Render the top edge of the block.
|
|
826
|
+
* @param {!Array.<string>} steps Path of block outline.
|
|
827
|
+
* @param {!Object} connectionsXY Location of block.
|
|
828
|
+
* @param {!Object} metrics An object containing computed measurements of the
|
|
829
|
+
* block.
|
|
830
|
+
* @private
|
|
831
|
+
*/
|
|
832
|
+
Blockly.BlockSvg.prototype.renderDrawTop_ = function(steps, connectionsXY, metrics) {
|
|
833
|
+
if (!this.isShadow()) {
|
|
834
|
+
steps.push('a', Blockly.BlockSvg.CORNER_RADIUS + ',' +
|
|
835
|
+
Blockly.BlockSvg.CORNER_RADIUS + ' 0 0,0 -' +
|
|
836
|
+
Blockly.BlockSvg.CORNER_RADIUS + ',-' +
|
|
837
|
+
Blockly.BlockSvg.CORNER_RADIUS);
|
|
838
|
+
} else {
|
|
839
|
+
steps.push(
|
|
840
|
+
'a', metrics.fieldRadius + ',' + metrics.fieldRadius,
|
|
841
|
+
'0', '0,0', '-' + metrics.fieldRadius + ',-' + metrics.fieldRadius);
|
|
842
|
+
}
|
|
843
|
+
steps.push('z');
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Get the field shadow block, if this block has one.
|
|
848
|
+
* <p>This is horizontal Scratch-specific, as "fields" are implemented as inputs
|
|
849
|
+
* with shadow blocks, and there is only one per block.
|
|
850
|
+
* @return {Blockly.BlockSvg} The field shadow block, or null if not found.
|
|
851
|
+
* @private
|
|
852
|
+
*/
|
|
853
|
+
Blockly.BlockSvg.prototype.getFieldShadowBlock_ = function() {
|
|
854
|
+
for (var i = 0, child; child = this.childBlocks_[i]; i++) {
|
|
855
|
+
if (child.isShadow()) {
|
|
856
|
+
return child;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
return null;
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* Position an new block correctly, so that it doesn't move the existing block
|
|
865
|
+
* when connected to it.
|
|
866
|
+
* @param {!Blockly.Block} newBlock The block to position - either the first
|
|
867
|
+
* block in a dragged stack or an insertion marker.
|
|
868
|
+
* @param {!Blockly.Connection} newConnection The connection on the new block's
|
|
869
|
+
* stack - either a connection on newBlock, or the last NEXT_STATEMENT
|
|
870
|
+
* connection on the stack if the stack's being dropped before another
|
|
871
|
+
* block.
|
|
872
|
+
* @param {!Blockly.Connection} existingConnection The connection on the
|
|
873
|
+
* existing block, which newBlock should line up with.
|
|
874
|
+
*/
|
|
875
|
+
Blockly.BlockSvg.prototype.positionNewBlock = function(newBlock, newConnection, existingConnection) {
|
|
876
|
+
// We only need to position the new block if it's before the existing one,
|
|
877
|
+
// otherwise its position is set by the previous block.
|
|
878
|
+
if (newConnection.type == Blockly.NEXT_STATEMENT) {
|
|
879
|
+
var dx = existingConnection.x_ - newConnection.x_;
|
|
880
|
+
var dy = existingConnection.y_ - newConnection.y_;
|
|
881
|
+
|
|
882
|
+
// When putting a c-block around another c-block, the outer block must
|
|
883
|
+
// positioned above the inner block, as its connection point will stretch
|
|
884
|
+
// downwards when connected.
|
|
885
|
+
if (newConnection == newBlock.getFirstStatementConnection()) {
|
|
886
|
+
dy -= existingConnection.sourceBlock_.getHeightWidth(true).height -
|
|
887
|
+
Blockly.BlockSvg.MIN_BLOCK_Y;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
newBlock.moveBy(dx, dy);
|
|
891
|
+
}
|
|
892
|
+
};
|