From 20bec74282950642b1f9ebb69422d499eedd2d16 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 25 Jul 2019 14:59:11 -0700 Subject: [PATCH 1/9] Move all references to PUZZLE_TAB.height and width into measurables --- .../block_render_draw.js | 33 ++++++----- .../block_render_draw_highlight.js | 57 ++++++++----------- .../block_render_info.js | 8 ++- .../block_rendering_constants.js | 7 ++- .../block_rendering_rewrite/measurables.js | 23 ++++++++ 5 files changed, 77 insertions(+), 51 deletions(-) diff --git a/core/renderers/block_rendering_rewrite/block_render_draw.js b/core/renderers/block_rendering_rewrite/block_render_draw.js index 92a3942e3..a9d477b42 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw.js @@ -144,11 +144,11 @@ Blockly.blockRendering.Drawer.prototype.drawTop_ = function() { * @private */ Blockly.blockRendering.Drawer.prototype.drawValueInput_ = function(row) { + var input = row.getLastInput(); this.highlighter_.drawValueInput(row); this.steps_.push('H', row.width); this.steps_.push(Blockly.blockRendering.constants.PUZZLE_TAB.pathDown); - this.steps_.push('v', - row.height - Blockly.blockRendering.constants.PUZZLE_TAB.height); + this.steps_.push('v', row.height - input.connectionHeight); this.positionExternalValueConnection_(row); }; @@ -217,11 +217,12 @@ Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() { Blockly.blockRendering.Drawer.prototype.drawLeft_ = function() { this.highlighter_.drawLeft(); + var outputConnection = this.info_.outputConnection; this.positionOutputConnection_(); - if (this.info_.hasOutputConnection) { + if (outputConnection) { // Draw a line up to the bottom of the tab. - this.steps_.push('V', Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP + - Blockly.blockRendering.constants.PUZZLE_TAB.height); + this.steps_.push('V', + outputConnection.connectionOffsetY + outputConnection.height); this.steps_.push(Blockly.blockRendering.constants.PUZZLE_TAB.pathUp); } // Close off the path. This draws a vertical line up to the start of the @@ -315,12 +316,16 @@ Blockly.blockRendering.Drawer.prototype.drawInlineInput_ = function(input) { var height = input.height; var yPos = input.centerline - height / 2; - this.inlineSteps_.push('M', (input.xPos + Blockly.blockRendering.constants.PUZZLE_TAB.width) + ',' + yPos); - this.inlineSteps_.push('v ', Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP); + var connectionTop = input.connectionOffsetY; + var connectionBottom = input.connectionHeight + connectionTop; + var connectionRight = input.xPos + input.connectionWidth; + + + this.inlineSteps_.push('M', connectionRight + ',' + yPos); + this.inlineSteps_.push('v ', connectionTop); this.inlineSteps_.push(Blockly.blockRendering.constants.PUZZLE_TAB.pathDown); - this.inlineSteps_.push('v', height - Blockly.blockRendering.constants.PUZZLE_TAB.height - - Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP); - this.inlineSteps_.push('h', width - Blockly.blockRendering.constants.PUZZLE_TAB.width); + this.inlineSteps_.push('v', height - connectionBottom); + this.inlineSteps_.push('h', width - input.connectionWidth); this.inlineSteps_.push('v', -height); this.inlineSteps_.push('z'); @@ -340,13 +345,13 @@ Blockly.blockRendering.Drawer.prototype.positionInlineInputConnection_ = functio var yPos = input.centerline - input.height / 2; // Move the connection. if (input.connection) { - var connX = input.xPos + Blockly.blockRendering.constants.PUZZLE_TAB.width + + var connX = input.xPos + input.connectionWidth + Blockly.blockRendering.constants.DARK_PATH_OFFSET; if (this.info_.RTL) { connX *= -1; } input.connection.setOffsetInBlock( - connX, yPos + Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP + + connX, yPos + input.connectionOffsetY + Blockly.blockRendering.constants.DARK_PATH_OFFSET); } }; @@ -425,8 +430,8 @@ Blockly.blockRendering.Drawer.prototype.positionNextConnection_ = function() { * @private */ Blockly.blockRendering.Drawer.prototype.positionOutputConnection_ = function() { - if (this.info_.hasOutputConnection) { + if (this.info_.outputConnection) { this.block_.outputConnection.setOffsetInBlock(0, - Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP); + this.info_.outputConnection.connectionOffsetY); } }; diff --git a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js index b4b61d2f7..c45083862 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js @@ -52,6 +52,8 @@ Blockly.blockRendering.Highlighter = function(info, pathObject) { this.pathObject_ = pathObject; this.highlightSteps_ = this.pathObject_.highlightSteps; this.highlightInlineSteps_ = this.pathObject_.highlightInlineSteps; + + this.highlightOffset_ = Blockly.blockRendering.constants.HIGHLIGHT_OFFSET; }; Blockly.blockRendering.Highlighter.prototype.drawTopCorner = function(row) { @@ -69,19 +71,20 @@ Blockly.blockRendering.Highlighter.prototype.drawTopCorner = function(row) { this.highlightSteps_.push( Blockly.blockRendering.constants.START_HAT.highlight(this.info_.RTL)); } else if (elem.isSpacer()) { - this.highlightSteps_.push('h', elem.width - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET); + this.highlightSteps_.push('h', elem.width - this.highlightOffset_); } } - this.highlightSteps_.push('H', row.width - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET); + this.highlightSteps_.push('H', row.width - this.highlightOffset_); }; Blockly.blockRendering.Highlighter.prototype.drawValueInput = function(row) { + var input = row.getLastInput(); if (this.info_.RTL) { - var aboveTabHeight = -Blockly.blockRendering.constants.HIGHLIGHT_OFFSET; + var aboveTabHeight = -this.highlightOffset_; var belowTabHeight = row.height - - Blockly.blockRendering.constants.PUZZLE_TAB.height + - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET; + input.connectionHeight + + this.highlightOffset_; // Edge above tab. this.highlightSteps_.push('v', aboveTabHeight); // Highlight around back of tab. @@ -122,7 +125,7 @@ Blockly.blockRendering.Highlighter.prototype.drawRightSideRow = function(row) { this.highlightSteps_.push('H', row.width); } if (this.info_.RTL) { - this.highlightSteps_.push('H', row.width - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET); + this.highlightSteps_.push('H', row.width - this.highlightOffset_); this.highlightSteps_.push('v', row.height); } }; @@ -140,8 +143,8 @@ Blockly.blockRendering.Highlighter.prototype.drawBottomCorner = function(_row) { if (elem.type === 'square corner') { if (!this.info_.RTL) { this.highlightSteps_.push('M', - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET + ',' + - (height - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET)); + this.highlightOffset_ + ',' + + (height - this.highlightOffset_)); } } else if (elem.type === 'round corner') { if (!this.info_.RTL) { @@ -156,14 +159,14 @@ Blockly.blockRendering.Highlighter.prototype.drawBottomCorner = function(_row) { }; Blockly.blockRendering.Highlighter.prototype.drawLeft = function() { - if (this.info_.hasOutputConnection) { + if (this.info_.outputConnection) { this.highlightSteps_.push( Blockly.blockRendering.constants.PUZZLE_TAB_HIGHLIGHT.pathUp(this.info_.RTL)); } if (!this.info_.RTL) { if (this.info_.topRow.elements[0].isSquareCorner()) { - this.highlightSteps_.push('V', Blockly.blockRendering.constants.HIGHLIGHT_OFFSET); + this.highlightSteps_.push('V', this.highlightOffset_); } else { this.highlightSteps_.push('V', Blockly.blockRendering.constants.CORNER_RADIUS); } @@ -171,30 +174,21 @@ Blockly.blockRendering.Highlighter.prototype.drawLeft = function() { }; Blockly.blockRendering.Highlighter.prototype.drawInlineInput = function(input) { - var offset = Blockly.blockRendering.constants.HIGHLIGHT_OFFSET; + var offset = this.highlightOffset_; - var inputWidth = input.width; - var height = input.height; - var x = input.xPos; - var yPos = input.centerline - height / 2; - var bottomHighlightWidth = inputWidth - Blockly.blockRendering.constants.PUZZLE_TAB.width; + // Relative to the block's left. + var connectionRight = input.xPos + input.connectionWidth; + var yPos = input.centerline - input.height / 2; + var bottomHighlightWidth = input.width - input.connectionWidth; + var startY = yPos + offset; if (this.info_.RTL) { // TODO: Check if this is different when the inline input is populated. - - var aboveTabHeight = - Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP - - offset; - + var aboveTabHeight = input.connectionOffsetY - offset; var belowTabHeight = - height - - (Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP + - Blockly.blockRendering.constants.PUZZLE_TAB.height) + - offset; + input.height - (input.connectionOffsetY + input.connectionHeight) + offset; - var startX = x + Blockly.blockRendering.constants.PUZZLE_TAB.width - - offset; - var startY = yPos + offset; + var startX = connectionRight - offset; // Highlight right edge, around back of tab, and bottom. this.highlightInlineSteps_.push('M', startX + ',' + startY); @@ -210,14 +204,13 @@ Blockly.blockRendering.Highlighter.prototype.drawInlineInput = function(input) { } else { // Go to top right corner. this.highlightInlineSteps_.push( - Blockly.utils.svgPaths.moveTo(x + inputWidth + offset, yPos + offset)); + Blockly.utils.svgPaths.moveTo(input.xPos + input.width + offset, startY)); // Highlight right edge, bottom. - this.highlightInlineSteps_.push('v', height); + this.highlightInlineSteps_.push('v', input.height); this.highlightInlineSteps_.push('h ', -bottomHighlightWidth); // Go to top of tab. this.highlightSteps_.push(Blockly.utils.svgPaths.moveTo( - x + Blockly.blockRendering.constants.PUZZLE_TAB.width, - yPos + Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP)); + connectionRight, yPos + input.connectionOffsetY)); // Short highlight glint at bottom of tab. this.highlightSteps_.push( Blockly.blockRendering.constants.PUZZLE_TAB_HIGHLIGHT.pathDown(this.info_.RTL)); diff --git a/core/renderers/block_rendering_rewrite/block_render_info.js b/core/renderers/block_rendering_rewrite/block_render_info.js index 450479d6c..98368e290 100644 --- a/core/renderers/block_rendering_rewrite/block_render_info.js +++ b/core/renderers/block_rendering_rewrite/block_render_info.js @@ -45,10 +45,12 @@ Blockly.blockRendering.RenderInfo = function(block) { this.block_ = block; /** - * Whether the block has an output connection. - * @type {boolean} + * A measurable representing the output connection if the block has one. + * Otherwise null. + * @type {Blockly.blockRendering.OutputConnection} */ - this.hasOutputConnection = !!block.outputConnection; + this.outputConnection = !block.outputConnection ? null : + new Blockly.blockRendering.OutputConnection(); /** * Whether the block should be rendered as a single line, either because it's diff --git a/core/renderers/block_rendering_rewrite/block_rendering_constants.js b/core/renderers/block_rendering_rewrite/block_rendering_constants.js index 05e2bd1bb..7bf9637ce 100644 --- a/core/renderers/block_rendering_rewrite/block_rendering_constants.js +++ b/core/renderers/block_rendering_rewrite/block_rendering_constants.js @@ -112,9 +112,11 @@ Blockly.blockRendering.constants.SPACER_DEFAULT_HEIGHT = 15; Blockly.blockRendering.constants.MIN_BLOCK_HEIGHT = 24; -Blockly.blockRendering.constants.EMPTY_INLINE_INPUT_WIDTH = 22.5; +Blockly.blockRendering.constants.EMPTY_INLINE_INPUT_WIDTH = + Blockly.blockRendering.constants.TAB_WIDTH + 14.5; -Blockly.blockRendering.constants.EMPTY_INLINE_INPUT_HEIGHT = 26; +Blockly.blockRendering.constants.EMPTY_INLINE_INPUT_HEIGHT = + Blockly.blockRendering.constants.TAB_HEIGHT + 11; Blockly.blockRendering.constants.EXTERNAL_VALUE_INPUT_WIDTH = 10; @@ -420,6 +422,7 @@ Blockly.blockRendering.constants.PUZZLE_TAB_HIGHLIGHT = (function() { Blockly.utils.svgPaths.lineOnAxis('v', verticalOverlap); var highlightLtrUp = + // TODO: Move this 'V' out. Blockly.utils.svgPaths.lineOnAxis('V', height + Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP - 1.5) + Blockly.utils.svgPaths.moveBy(width * -0.92, -0.5) + diff --git a/core/renderers/block_rendering_rewrite/measurables.js b/core/renderers/block_rendering_rewrite/measurables.js index 2ae3c3a02..eac19bf70 100644 --- a/core/renderers/block_rendering_rewrite/measurables.js +++ b/core/renderers/block_rendering_rewrite/measurables.js @@ -222,6 +222,10 @@ Blockly.blockRendering.InlineInput = function(input) { Blockly.blockRendering.constants.DARK_PATH_OFFSET; this.height = this.connectedBlockHeight + Blockly.blockRendering.constants.DARK_PATH_OFFSET; } + + this.connectionOffsetY = Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP; + this.connectionHeight = Blockly.blockRendering.constants.PUZZLE_TAB.height; + this.connectionWidth = Blockly.blockRendering.constants.PUZZLE_TAB.width; }; goog.inherits(Blockly.blockRendering.InlineInput, Blockly.blockRendering.Input); @@ -271,10 +275,29 @@ Blockly.blockRendering.ExternalValueInput = function(input) { this.connectedBlockHeight - 2 * Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP; } this.width = Blockly.blockRendering.constants.EXTERNAL_VALUE_INPUT_WIDTH; + + this.connectionOffsetY = Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP; + this.connectionHeight = Blockly.blockRendering.constants.PUZZLE_TAB.height; + this.connectionWidth = Blockly.blockRendering.constants.PUZZLE_TAB.width; }; goog.inherits(Blockly.blockRendering.ExternalValueInput, Blockly.blockRendering.Input); +/** + * An object containing information about the space an output connection takes + * up during rendering. + * @package + * @constructor + */ +Blockly.blockRendering.OutputConnection = function() { + Blockly.blockRendering.OutputConnection.superClass_.constructor.call(this); + this.type = 'output connection'; + this.height = Blockly.blockRendering.constants.PUZZLE_TAB.height; + this.width = Blockly.blockRendering.constants.PUZZLE_TAB.width; + this.connectionOffsetY = Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP; +}; +goog.inherits(Blockly.blockRendering.OutputConnection, Blockly.blockRendering.Measurable); + /** * An object containing information about the space a previous connection takes * up during rendering. From b54ec1e2dbf8eaeb7bd931e490ca67421bcfcc35 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 26 Jul 2019 15:17:25 -0700 Subject: [PATCH 2/9] Corners and notches --- .../block_render_draw.js | 33 +- .../block_render_draw_highlight.js | 27 +- .../block_render_info.js | 8 +- .../block_rendering_constants.js | 321 +++++++++--------- .../block_rendering_rewrite/measurables.js | 36 +- 5 files changed, 236 insertions(+), 189 deletions(-) diff --git a/core/renderers/block_rendering_rewrite/block_render_draw.js b/core/renderers/block_rendering_rewrite/block_render_draw.js index a9d477b42..97de0086b 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw.js @@ -123,9 +123,9 @@ Blockly.blockRendering.Drawer.prototype.drawTop_ = function() { this.steps_.push(Blockly.blockRendering.constants.START_POINT); } else if (elem.type === 'round corner') { this.steps_.push(Blockly.blockRendering.constants.TOP_LEFT_CORNER_START, - Blockly.blockRendering.constants.TOP_LEFT_CORNER); + Blockly.blockRendering.constants.OUTSIDE_CORNERS.topLeft); } else if (elem.type === 'previous connection') { - this.steps_.push(Blockly.blockRendering.constants.NOTCH_PATH_LEFT); + this.steps_.push(Blockly.blockRendering.constants.NOTCH.pathLeft); } else if (elem.type === 'hat') { this.steps_.push(Blockly.blockRendering.constants.START_HAT.path); } else if (elem.isSpacer()) { @@ -161,11 +161,21 @@ Blockly.blockRendering.Drawer.prototype.drawValueInput_ = function(row) { */ Blockly.blockRendering.Drawer.prototype.drawStatementInput_ = function(row) { this.highlighter_.drawStatementInput(row); - var x = row.statementEdge + Blockly.blockRendering.constants.NOTCH_OFFSET_RIGHT; + // Where to start drawing the notch, which is on the right side in LTR. + var x = row.statementEdge + Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT + + Blockly.blockRendering.constants.NOTCH.width; + this.steps_.push('H', x); - this.steps_.push(Blockly.blockRendering.constants.INNER_TOP_LEFT_CORNER); - this.steps_.push('v', row.height - 2 * Blockly.blockRendering.constants.CORNER_RADIUS); - this.steps_.push(Blockly.blockRendering.constants.INNER_BOTTOM_LEFT_CORNER); + + var innerTopLeftCorner = + Blockly.blockRendering.constants.NOTCH.pathRight + ' h -' + + (Blockly.blockRendering.constants.NOTCH_WIDTH - + Blockly.blockRendering.constants.CORNER_RADIUS) + + Blockly.blockRendering.constants.INSIDE_CORNERS.pathTop; + this.steps_.push(innerTopLeftCorner); + this.steps_.push('v', + row.height - (2 * Blockly.blockRendering.constants.INSIDE_CORNERS.height)); + this.steps_.push(Blockly.blockRendering.constants.INSIDE_CORNERS.pathBottom); this.positionStatementInputConnection_(row); }; @@ -198,11 +208,13 @@ Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() { for (var i = elems.length - 1; i >= 0; i--) { var elem = elems[i]; if (elem.type === 'next connection') { - this.steps_.push(Blockly.blockRendering.constants.NOTCH_PATH_RIGHT); + this.steps_.push('h', (this.RTL ? 0.5 : - 0.5)); + this.steps_.push(Blockly.blockRendering.constants.NOTCH.pathRight); + this.steps_.push('h', (this.RTL ? -0.5 : 0.5)); } else if (elem.type === 'square corner') { this.steps_.push('H 0'); } else if (elem.type === 'round corner') { - this.steps_.push(Blockly.blockRendering.constants.BOTTOM_LEFT_CORNER); + this.steps_.push(Blockly.blockRendering.constants.OUTSIDE_CORNERS.bottomLeft); } else if (elem.isSpacer()) { this.steps_.push('h', elem.width * -1); } @@ -416,9 +428,8 @@ Blockly.blockRendering.Drawer.prototype.positionNextConnection_ = function() { var bottomRow = this.info_.bottomRow; if (bottomRow.hasNextConnection) { - var connX = - this.info_.RTL ? -Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT : - Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT; + var connInfo = bottomRow.getNextConnection(); + var connX = this.info_.RTL ? -connInfo.xPos : connInfo.xPos; bottomRow.connection.setOffsetInBlock( connX, this.info_.height + Blockly.blockRendering.constants.DARK_PATH_OFFSET); } diff --git a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js index c45083862..216263a73 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js @@ -61,12 +61,18 @@ Blockly.blockRendering.Highlighter.prototype.drawTopCorner = function(row) { if (elem.type === 'square corner') { this.highlightSteps_.push(Blockly.blockRendering.constants.START_POINT_HIGHLIGHT); } else if (elem.type === 'round corner') { - this.highlightSteps_.push(this.info_.RTL ? - Blockly.blockRendering.constants.TOP_LEFT_CORNER_START_HIGHLIGHT_RTL : - Blockly.blockRendering.constants.TOP_LEFT_CORNER_START_HIGHLIGHT_LTR); - this.highlightSteps_.push(Blockly.blockRendering.constants.TOP_LEFT_CORNER_HIGHLIGHT); + this.highlightSteps_.push( + Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS.topLeftStart( + this.info_.RTL)); + // this.highlightSteps_.push(this.info_.RTL ? + // Blockly.blockRendering.constants.TOP_LEFT_CORNER_START_HIGHLIGHT_RTL : + // Blockly.blockRendering.constants.TOP_LEFT_CORNER_START_HIGHLIGHT_LTR); + this.highlightSteps_.push( + Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS.topLeft); } else if (elem.type === 'previous connection') { - this.highlightSteps_.push(Blockly.blockRendering.constants.NOTCH_PATH_LEFT_HIGHLIGHT); + this.highlightSteps_.push('h', (this.RTL ? 0.5 : - 0.5)); + this.highlightSteps_.push(Blockly.blockRendering.constants.NOTCH.pathLeftHighlight); + this.highlightSteps_.push('h', (this.RTL ? -0.5 : 0.5)); } else if (elem.type === 'hat') { this.highlightSteps_.push( Blockly.blockRendering.constants.START_HAT.highlight(this.info_.RTL)); @@ -106,17 +112,17 @@ Blockly.blockRendering.Highlighter.prototype.drawStatementInput = function(row) (x + Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE) + ',' + (row.yPos + Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE)); this.highlightSteps_.push( - Blockly.blockRendering.constants.INNER_TOP_LEFT_CORNER_HIGHLIGHT_RTL); + Blockly.blockRendering.constants.INSIDE_CORNER_HIGHLIGHTS.pathTop(this.info_.RTL)); this.highlightSteps_.push('v', row.height - 2 * Blockly.blockRendering.constants.CORNER_RADIUS); this.highlightSteps_.push( - Blockly.blockRendering.constants.INNER_BOTTOM_LEFT_CORNER_HIGHLIGHT_RTL); + Blockly.blockRendering.constants.INSIDE_CORNER_HIGHLIGHTS.pathBottom(this.info_.RTL)); } else { this.highlightSteps_.push('M', (x + Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE) + ',' + (row.yPos + row.height - Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE)); this.highlightSteps_.push( - Blockly.blockRendering.constants.INNER_BOTTOM_LEFT_CORNER_HIGHLIGHT_LTR); + Blockly.blockRendering.constants.INSIDE_CORNER_HIGHLIGHTS.pathBottom(this.info_.RTL)); } }; @@ -149,10 +155,7 @@ Blockly.blockRendering.Highlighter.prototype.drawBottomCorner = function(_row) { } else if (elem.type === 'round corner') { if (!this.info_.RTL) { this.highlightSteps_.push( - Blockly.blockRendering.constants.BOTTOM_LEFT_CORNER_HIGHLIGHT_START + - (height - Blockly.BlockSvg.DISTANCE_45_INSIDE) + - Blockly.blockRendering.constants.BOTTOM_LEFT_CORNER_HIGHLIGHT_MID + - (height - Blockly.BlockSvg.CORNER_RADIUS)); + Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS.bottomLeft(height)); } } } diff --git a/core/renderers/block_rendering_rewrite/block_render_info.js b/core/renderers/block_rendering_rewrite/block_render_info.js index 98368e290..f99e7e55d 100644 --- a/core/renderers/block_rendering_rewrite/block_render_info.js +++ b/core/renderers/block_rendering_rewrite/block_render_info.js @@ -407,7 +407,7 @@ Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne } else if (next.isNextConnection()) { // Next connections are shifted slightly to the left (in both LTR and RTL) // to make the dark path under the previous connection show through. - return Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT + (this.RTL ? 0.5 : - 0.5); + return Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT;//+ (this.RTL ? 0.5 : - 0.5); } } @@ -418,8 +418,8 @@ Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne } else if (next.isNextConnection()) { // Next connections are shifted slightly to the left (in both LTR and RTL) // to make the dark path under the previous connection show through. - return Blockly.blockRendering.constants.NOTCH_OFFSET_ROUNDED_CORNER_PREV + - (this.RTL ? 0.5 : - 0.5); + return Blockly.blockRendering.constants.NOTCH_OFFSET_ROUNDED_CORNER_PREV;//+ + //(this.RTL ? 0.5 : - 0.5); } } @@ -462,7 +462,7 @@ Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { if (widestStatementRowFields) { this.width = Math.max(blockWidth, - widestStatementRowFields + Blockly.blockRendering.constants.NOTCH_WIDTH * 2); + widestStatementRowFields + Blockly.blockRendering.constants.NOTCH.width * 2); } else { this.width = blockWidth; } diff --git a/core/renderers/block_rendering_rewrite/block_rendering_constants.js b/core/renderers/block_rendering_rewrite/block_rendering_constants.js index 7bf9637ce..af1c0c350 100644 --- a/core/renderers/block_rendering_rewrite/block_rendering_constants.js +++ b/core/renderers/block_rendering_rewrite/block_rendering_constants.js @@ -74,12 +74,6 @@ Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT = // connection starts. Blockly.blockRendering.constants.NOTCH_OFFSET_ROUNDED_CORNER_PREV = 7; -// This is the offset from the vertical part of a statement input -// to where to start the notch, which is on the right side in LTR. -Blockly.blockRendering.constants.NOTCH_OFFSET_RIGHT = - Blockly.blockRendering.constants.NOTCH_OFFSET_LEFT + - Blockly.blockRendering.constants.NOTCH_WIDTH; - Blockly.blockRendering.constants.STATEMENT_BOTTOM_SPACER = 5; Blockly.blockRendering.constants.STATEMENT_INPUT_PADDING_LEFT = 20; Blockly.blockRendering.constants.BETWEEN_STATEMENT_PADDING_Y = 4; @@ -143,16 +137,6 @@ Blockly.blockRendering.constants.START_POINT_HIGHLIGHT = Blockly.blockRendering.constants.HIGHLIGHT_OFFSET, Blockly.blockRendering.constants.HIGHLIGHT_OFFSET); -/** - * Distance from shape edge to intersect with a curved corner at 45 degrees. - * Applies to highlighting on around the inside of a curve. - * @const - */ -Blockly.blockRendering.constants.DISTANCE_45_INSIDE = (1 - Math.SQRT1_2) * - (Blockly.blockRendering.constants.CORNER_RADIUS - - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET) + - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET; - /** * Distance from shape edge to intersect with a curved corner at 45 degrees. * Applies to highlighting on around the outside of a curve. @@ -163,96 +147,6 @@ Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE = (1 - Math.SQRT1_2) * Blockly.blockRendering.constants.HIGHLIGHT_OFFSET) - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET; -/** - * SVG path for drawing next/previous notch from left to right. - * @const - */ -Blockly.blockRendering.constants.NOTCH_PATH_LEFT = 'l 6,4 3,0 6,-4'; - -/** - * SVG path for drawing next/previous notch from left to right with - * highlighting. - * @const - */ -Blockly.blockRendering.constants.NOTCH_PATH_LEFT_HIGHLIGHT = - 'h ' + Blockly.blockRendering.constants.HIGHLIGHT_OFFSET + ' ' + Blockly.blockRendering.constants.NOTCH_PATH_LEFT; - -/** - * SVG path for drawing next/previous notch from right to left. - * @const - */ -Blockly.blockRendering.constants.NOTCH_PATH_RIGHT = 'l -6,4 -3,0 -6,-4'; - -/** - * SVG path for drawing the top-left corner of a statement input. - * Includes the top notch, a horizontal space, and the rounded inside corner. - * @const - */ -Blockly.blockRendering.constants.INNER_TOP_LEFT_CORNER = - Blockly.blockRendering.constants.NOTCH_PATH_RIGHT + ' h -' + - (Blockly.blockRendering.constants.NOTCH_WIDTH - - Blockly.blockRendering.constants.CORNER_RADIUS) + - ' a ' + Blockly.blockRendering.constants.CORNER_RADIUS + ',' + - Blockly.blockRendering.constants.CORNER_RADIUS + ' 0 0,0 -' + - Blockly.blockRendering.constants.CORNER_RADIUS + ',' + - Blockly.blockRendering.constants.CORNER_RADIUS; - -/** - * SVG path for drawing the bottom-left corner of a statement input. - * Includes the rounded inside corner. - * @const - */ -Blockly.blockRendering.constants.INNER_BOTTOM_LEFT_CORNER = - Blockly.utils.svgPaths.arc('a', '0 0,0', - Blockly.blockRendering.constants.CORNER_RADIUS, - Blockly.utils.svgPaths.point(Blockly.blockRendering.constants.CORNER_RADIUS, - Blockly.blockRendering.constants.CORNER_RADIUS)); - - -/** - * SVG path for drawing highlight on the top-left corner of a statement - * input in RTL. - * @const - */ -Blockly.blockRendering.constants.INNER_TOP_LEFT_CORNER_HIGHLIGHT_RTL = - Blockly.utils.svgPaths.arc('a', '0 0,0', - Blockly.blockRendering.constants.CORNER_RADIUS, - Blockly.utils.svgPaths.point( - -Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE - - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET, - Blockly.blockRendering.constants.CORNER_RADIUS - - Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE)); - -/** - * SVG path for drawing highlight on the bottom-left corner of a statement - * input in RTL. - * @const - */ -Blockly.blockRendering.constants.INNER_BOTTOM_LEFT_CORNER_HIGHLIGHT_RTL = - Blockly.utils.svgPaths.arc('a', '0 0,0', - Blockly.blockRendering.constants.CORNER_RADIUS + - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET, - Blockly.utils.svgPaths.point( - Blockly.blockRendering.constants.CORNER_RADIUS + - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET, - Blockly.blockRendering.constants.CORNER_RADIUS + - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET)); - -/** - * SVG path for drawing highlight on the bottom-left corner of a statement - * input in LTR. - * @const - */ -Blockly.blockRendering.constants.INNER_BOTTOM_LEFT_CORNER_HIGHLIGHT_LTR = - Blockly.utils.svgPaths.arc('a', '0 0,0', - Blockly.blockRendering.constants.CORNER_RADIUS + - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET, - Blockly.utils.svgPaths.point( - Blockly.blockRendering.constants.CORNER_RADIUS - - Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE, - Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE + - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET)); - /** * SVG start point for drawing the top-left corner. * @const @@ -260,52 +154,6 @@ Blockly.blockRendering.constants.INNER_BOTTOM_LEFT_CORNER_HIGHLIGHT_LTR = Blockly.blockRendering.constants.TOP_LEFT_CORNER_START = 'm 0,' + Blockly.blockRendering.constants.CORNER_RADIUS; -/** - * SVG path for drawing the rounded top-left corner. - * @const - */ -Blockly.blockRendering.constants.TOP_LEFT_CORNER = - 'A ' + Blockly.blockRendering.constants.CORNER_RADIUS + ',' + - Blockly.blockRendering.constants.CORNER_RADIUS + ' 0 0,1 ' + - Blockly.blockRendering.constants.CORNER_RADIUS + ',0'; - -Blockly.blockRendering.constants.BOTTOM_LEFT_CORNER = 'a' + Blockly.blockRendering.constants.CORNER_RADIUS + ',' + - Blockly.blockRendering.constants.CORNER_RADIUS + ' 0 0,1 -' + - Blockly.blockRendering.constants.CORNER_RADIUS + ',-' + - Blockly.blockRendering.constants.CORNER_RADIUS; - -Blockly.blockRendering.constants.BOTTOM_LEFT_CORNER_HIGHLIGHT_START = - 'M ' + Blockly.blockRendering.constants.DISTANCE_45_INSIDE + ', '; // follow with y pos - distance 45 inside - -Blockly.blockRendering.constants.BOTTOM_LEFT_CORNER_HIGHLIGHT_MID = - 'A ' + (Blockly.blockRendering.constants.CORNER_RADIUS - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET) + - ',' + (Blockly.blockRendering.constants.CORNER_RADIUS - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET) + - ' 0 0,1 ' + Blockly.blockRendering.constants.HIGHLIGHT_OFFSET + ','; // follow with y pos - corner radius - -/** - * SVG start point for drawing the top-left corner's highlight in RTL. - * @const - */ -Blockly.blockRendering.constants.TOP_LEFT_CORNER_START_HIGHLIGHT_RTL = - 'm ' + Blockly.blockRendering.constants.DISTANCE_45_INSIDE + ',' + - Blockly.blockRendering.constants.DISTANCE_45_INSIDE; - -/** - * SVG start point for drawing the top-left corner's highlight in LTR. - * @const - */ -Blockly.blockRendering.constants.TOP_LEFT_CORNER_START_HIGHLIGHT_LTR = - 'm 0.5,' + (Blockly.blockRendering.constants.CORNER_RADIUS - 0.5); - -/** - * SVG path for drawing the highlight on the rounded top-left corner. - * @const - */ -Blockly.blockRendering.constants.TOP_LEFT_CORNER_HIGHLIGHT = - 'A ' + (Blockly.blockRendering.constants.CORNER_RADIUS - 0.5) + ',' + - (Blockly.blockRendering.constants.CORNER_RADIUS - 0.5) + ' 0 0,1 ' + - Blockly.blockRendering.constants.CORNER_RADIUS + ',0.5'; - /** * Information about the hat on a start block. */ @@ -450,3 +298,172 @@ Blockly.blockRendering.constants.PUZZLE_TAB_HIGHLIGHT = (function() { } }; })(); + +Blockly.blockRendering.constants.NOTCH = (function() { + var width = Blockly.blockRendering.constants.NOTCH_WIDTH; + var height = Blockly.blockRendering.constants.NOTCH_HEIGHT; + var innerWidth = 3; + var outerWidth = (width - innerWidth) / 2; + function makeMainPath(dir) { + return Blockly.utils.svgPaths.line( + [ + Blockly.utils.svgPaths.point(dir * outerWidth, height), + Blockly.utils.svgPaths.point(dir * innerWidth, 0), + Blockly.utils.svgPaths.point(dir * outerWidth, -height) + ]); + } + // TODO: Find a relationship between width and path + var pathLeft = makeMainPath(1); + var pathRight = makeMainPath(-1); + + var pathLeftHighlight = Blockly.utils.svgPaths.lineOnAxis('h', Blockly.blockRendering.constants.HIGHLIGHT_OFFSET) + pathLeft; + return { + width: width, + height: height, + pathLeft: pathLeft, + pathLeftHighlight: pathLeftHighlight, + pathRight: pathRight + }; +})(); + + +Blockly.blockRendering.constants.INSIDE_CORNERS = (function() { + var radius = Blockly.blockRendering.constants.CORNER_RADIUS; + + var innerTopLeftCorner = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, + Blockly.utils.svgPaths.point(-radius, radius)); + + var innerBottomLeftCorner = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, + Blockly.utils.svgPaths.point(radius, radius)); + + return { + //width: width, + height: radius, + pathTop: innerTopLeftCorner, + pathBottom: innerBottomLeftCorner + }; +})(); + +/** + * Highlight paths for drawing the inside corners of a statement input. + */ +Blockly.blockRendering.constants.INSIDE_CORNER_HIGHLIGHTS = (function() { + var radius = Blockly.blockRendering.constants.CORNER_RADIUS; + var offset = Blockly.blockRendering.constants.HIGHLIGHT_OFFSET; + + /** + * Distance from shape edge to intersect with a curved corner at 45 degrees. + * Applies to highlighting on around the outside of a curve. + * @const + */ + var distance45outside = (1 - Math.SQRT1_2) * (radius + offset) - offset; + + /** + * Distance from shape edge to intersect with a curved corner at 45 degrees. + * Applies to highlighting on around the inside of a curve. + * @const + */ + var distance45inside = (1 - Math.SQRT1_2) * (radius - offset) + offset; + + + var pathTopRtl = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, + Blockly.utils.svgPaths.point( + -distance45outside - offset, + radius - distance45outside)); + + var pathBottomRtl = Blockly.utils.svgPaths.arc('a', '0 0,0', radius + offset, + Blockly.utils.svgPaths.point(radius + offset, radius + offset)); + + var pathBottomLtr = Blockly.utils.svgPaths.arc('a', '0 0,0', radius + offset, + Blockly.utils.svgPaths.point( + radius - distance45outside, + distance45outside + offset)); + + return { + // width: width, + // height: height, + pathTop: function(rtl) { + return rtl ? pathTopRtl : ''; + }, + pathBottom: function(rtl) { + return rtl ? pathBottomRtl : pathBottomLtr; + }, + }; +})(); + +Blockly.blockRendering.constants.OUTSIDE_CORNERS = (function() { + var radius = Blockly.blockRendering.constants.CORNER_RADIUS; + /** + * SVG path for drawing the rounded top-left corner. + * @const + */ + var topLeft = Blockly.utils.svgPaths.arc('A', '0 0,1', radius, + Blockly.utils.svgPaths.point(radius, 0)); + + var bottomLeft = Blockly.utils.svgPaths.arc('a', '0 0,1', radius, + Blockly.utils.svgPaths.point(-radius, -radius)); + + return { + // width: width, + // height: height, + topLeft: topLeft, + bottomLeft: bottomLeft + }; +})(); + +Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS = (function() { + var radius = Blockly.blockRendering.constants.CORNER_RADIUS; + var offset = Blockly.blockRendering.constants.HIGHLIGHT_OFFSET; + + /** + * Distance from shape edge to intersect with a curved corner at 45 degrees. + * Applies to highlighting on around the inside of a curve. + * @const + */ + var distance45inside = (1 - Math.SQRT1_2) * (radius - offset) + offset; + + /** + * SVG start point for drawing the top-left corner's highlight in RTL. + * @const + */ + var topLeftCornerStartRtl = + 'm ' + distance45inside + ',' + + distance45inside; + + /** + * SVG start point for drawing the top-left corner's highlight in LTR. + * @const + */ + var topLeftCornerStartLtr = + 'm 0.5,' + (radius - offset); + + /** + * SVG path for drawing the highlight on the rounded top-left corner. + * @const + */ + var topLeftCornerHighlight = + 'A ' + (radius - offset) + ',' + + (radius - offset) + ' 0 0,1 ' + + radius + ',0.5'; + + + var bottomLeftCornerStart = + 'M ' + distance45inside + ', '; // follow with y pos - distance 45 inside + + var bottomLeftCornerMid = + 'A ' + (radius - offset) + + ',' + (radius - offset) + + ' 0 0,1 ' + offset + ','; // follow with y pos - corner radius + + + return { + topLeft: topLeftCornerHighlight, + topLeftStart: function(rtl) { + return rtl ? topLeftCornerStartRtl : topLeftCornerStartLtr; + }, + bottomLeft: function(yPos) { + return bottomLeftCornerStart + (yPos - distance45inside) + + bottomLeftCornerMid + (yPos - radius); + } + }; +})(); diff --git a/core/renderers/block_rendering_rewrite/measurables.js b/core/renderers/block_rendering_rewrite/measurables.js index eac19bf70..95f32c899 100644 --- a/core/renderers/block_rendering_rewrite/measurables.js +++ b/core/renderers/block_rendering_rewrite/measurables.js @@ -249,7 +249,7 @@ Blockly.blockRendering.StatementInput = function(input) { this.height = this.connectedBlockHeight + Blockly.blockRendering.constants.STATEMENT_BOTTOM_SPACER; if (this.connectedBlock.nextConnection) { - this.height -= Blockly.blockRendering.constants.NOTCH_HEIGHT; + this.height -= Blockly.blockRendering.constants.NOTCH.height; } } }; @@ -307,8 +307,8 @@ goog.inherits(Blockly.blockRendering.OutputConnection, Blockly.blockRendering.Me Blockly.blockRendering.PreviousConnection = function() { Blockly.blockRendering.PreviousConnection.superClass_.constructor.call(this); this.type = 'previous connection'; - this.height = Blockly.blockRendering.constants.NOTCH_HEIGHT; - this.width = Blockly.blockRendering.constants.NOTCH_WIDTH; + this.height = Blockly.blockRendering.constants.NOTCH.height; + this.width = Blockly.blockRendering.constants.NOTCH.width; }; goog.inherits(Blockly.blockRendering.PreviousConnection, Blockly.blockRendering.Measurable); @@ -322,8 +322,8 @@ goog.inherits(Blockly.blockRendering.PreviousConnection, Blockly.blockRendering. Blockly.blockRendering.NextConnection = function() { Blockly.blockRendering.NextConnection.superClass_.constructor.call(this); this.type = 'next connection'; - this.height = Blockly.blockRendering.constants.NOTCH_HEIGHT; - this.width = Blockly.blockRendering.constants.NOTCH_WIDTH; + this.height = Blockly.blockRendering.constants.NOTCH.height; + this.width = Blockly.blockRendering.constants.NOTCH.width; }; goog.inherits(Blockly.blockRendering.NextConnection, Blockly.blockRendering.Measurable); @@ -351,7 +351,8 @@ goog.inherits(Blockly.blockRendering.Hat, Blockly.blockRendering.Measurable); Blockly.blockRendering.SquareCorner = function() { Blockly.blockRendering.SquareCorner.superClass_.constructor.call(this); this.type = 'square corner'; - this.height = Blockly.blockRendering.constants.NOTCH_HEIGHT; + // TODO: Is this the right height? + this.height = Blockly.blockRendering.constants.NOTCH.height; this.width = Blockly.blockRendering.constants.NO_PADDING; }; @@ -369,7 +370,8 @@ Blockly.blockRendering.RoundCorner = function() { this.width = Blockly.blockRendering.constants.CORNER_RADIUS; // The rounded corner extends into the next row by 4 so we only take the // height that is aligned with this row. - this.height = Blockly.blockRendering.constants.NOTCH_HEIGHT; + // TODO: Investigate. + this.height = Blockly.blockRendering.constants.NOTCH.height; }; goog.inherits(Blockly.blockRendering.RoundCorner, Blockly.blockRendering.Measurable); @@ -476,6 +478,14 @@ Blockly.blockRendering.TopRow = function(block) { }; goog.inherits(Blockly.blockRendering.TopRow, Blockly.blockRendering.Row); + +Blockly.blockRendering.TopRow.prototype.getPreviousConnection = function() { + if (this.hasPreviousConnection) { + return this.elements[2]; + } + return null; +}; + Blockly.blockRendering.BottomRow = function(block) { Blockly.blockRendering.BottomRow.superClass_.constructor.call(this); this.type = 'bottom row'; @@ -487,14 +497,20 @@ Blockly.blockRendering.BottomRow = function(block) { block.inputList[block.inputList.length - 1].type == Blockly.NEXT_STATEMENT; this.hasFixedWidth = followsStatement && block.getInputsInline(); - // This is the minimum height for the row. If one of it's elements has a greater + // This is the minimum height for the row. If one of its elements has a greater // height it will be overwritten in the compute pass. if (followsStatement) { this.height = Blockly.blockRendering.constants.LARGE_PADDING; } else { - this.height = Blockly.blockRendering.constants.NOTCH_HEIGHT; + this.height = Blockly.blockRendering.constants.NOTCH.height; } - }; goog.inherits(Blockly.blockRendering.BottomRow, Blockly.blockRendering.Row); + +Blockly.blockRendering.BottomRow.prototype.getNextConnection = function() { + if (this.hasNextConnection) { + return this.elements[2]; + } + return null; +}; From dbea4615e8cac6d59f8c4e0b2704a89d239928fa Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 26 Jul 2019 16:10:03 -0700 Subject: [PATCH 3/9] More corner work --- .../block_render_draw_highlight.js | 3 --- .../block_rendering_constants.js | 18 ++++-------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js index 216263a73..7485af378 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js @@ -64,9 +64,6 @@ Blockly.blockRendering.Highlighter.prototype.drawTopCorner = function(row) { this.highlightSteps_.push( Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS.topLeftStart( this.info_.RTL)); - // this.highlightSteps_.push(this.info_.RTL ? - // Blockly.blockRendering.constants.TOP_LEFT_CORNER_START_HIGHLIGHT_RTL : - // Blockly.blockRendering.constants.TOP_LEFT_CORNER_START_HIGHLIGHT_LTR); this.highlightSteps_.push( Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS.topLeft); } else if (elem.type === 'previous connection') { diff --git a/core/renderers/block_rendering_rewrite/block_rendering_constants.js b/core/renderers/block_rendering_rewrite/block_rendering_constants.js index af1c0c350..6d3008096 100644 --- a/core/renderers/block_rendering_rewrite/block_rendering_constants.js +++ b/core/renderers/block_rendering_rewrite/block_rendering_constants.js @@ -358,14 +358,6 @@ Blockly.blockRendering.constants.INSIDE_CORNER_HIGHLIGHTS = (function() { */ var distance45outside = (1 - Math.SQRT1_2) * (radius + offset) - offset; - /** - * Distance from shape edge to intersect with a curved corner at 45 degrees. - * Applies to highlighting on around the inside of a curve. - * @const - */ - var distance45inside = (1 - Math.SQRT1_2) * (radius - offset) + offset; - - var pathTopRtl = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, Blockly.utils.svgPaths.point( -distance45outside - offset, @@ -427,24 +419,22 @@ Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS = (function() { * @const */ var topLeftCornerStartRtl = - 'm ' + distance45inside + ',' + - distance45inside; + Blockly.utils.svgPaths.moveBy(distance45inside, distance45inside); /** * SVG start point for drawing the top-left corner's highlight in LTR. * @const */ var topLeftCornerStartLtr = - 'm 0.5,' + (radius - offset); + Blockly.utils.svgPaths.moveBy(offset, radius - offset); /** * SVG path for drawing the highlight on the rounded top-left corner. * @const */ var topLeftCornerHighlight = - 'A ' + (radius - offset) + ',' + - (radius - offset) + ' 0 0,1 ' + - radius + ',0.5'; + Blockly.utils.svgPaths.arc('A', '0 0,1', radius - offset, + Blockly.utils.svgPaths.point(radius, offset)); var bottomLeftCornerStart = From 64cc3c5de670f5b80df790ac24bd0a64d997724c Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 26 Jul 2019 16:41:06 -0700 Subject: [PATCH 4/9] Reduce number of direct references to the constants file --- .../block_render_draw.js | 4 +-- .../block_render_draw_highlight.js | 32 ++++++++----------- .../block_rendering_constants.js | 22 ++++--------- 3 files changed, 23 insertions(+), 35 deletions(-) diff --git a/core/renderers/block_rendering_rewrite/block_render_draw.js b/core/renderers/block_rendering_rewrite/block_render_draw.js index 97de0086b..2298cb266 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw.js @@ -208,9 +208,9 @@ Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() { for (var i = elems.length - 1; i >= 0; i--) { var elem = elems[i]; if (elem.type === 'next connection') { - this.steps_.push('h', (this.RTL ? 0.5 : - 0.5)); + //this.steps_.push('h', (this.RTL ? 0.5 : - 0.5)); this.steps_.push(Blockly.blockRendering.constants.NOTCH.pathRight); - this.steps_.push('h', (this.RTL ? -0.5 : 0.5)); + //this.steps_.push('h', (this.RTL ? -0.5 : 0.5)); } else if (elem.type === 'square corner') { this.steps_.push('H 0'); } else if (elem.type === 'round corner') { diff --git a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js index 7485af378..a3cc2457f 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js @@ -54,6 +54,10 @@ Blockly.blockRendering.Highlighter = function(info, pathObject) { this.highlightInlineSteps_ = this.pathObject_.highlightInlineSteps; this.highlightOffset_ = Blockly.blockRendering.constants.HIGHLIGHT_OFFSET; + + this.outsideCornerPaths_ = Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS; + this.insideCornerPaths_ = Blockly.blockRendering.constants.INSIDE_CORNER_HIGHLIGHTS; + this.puzzleTabPaths_ = Blockly.blockRendering.constants.PUZZLE_TAB_HIGHLIGHT; }; Blockly.blockRendering.Highlighter.prototype.drawTopCorner = function(row) { @@ -62,10 +66,7 @@ Blockly.blockRendering.Highlighter.prototype.drawTopCorner = function(row) { this.highlightSteps_.push(Blockly.blockRendering.constants.START_POINT_HIGHLIGHT); } else if (elem.type === 'round corner') { this.highlightSteps_.push( - Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS.topLeftStart( - this.info_.RTL)); - this.highlightSteps_.push( - Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS.topLeft); + this.outsideCornerPaths_.topLeft(this.info_.RTL)); } else if (elem.type === 'previous connection') { this.highlightSteps_.push('h', (this.RTL ? 0.5 : - 0.5)); this.highlightSteps_.push(Blockly.blockRendering.constants.NOTCH.pathLeftHighlight); @@ -91,14 +92,13 @@ Blockly.blockRendering.Highlighter.prototype.drawValueInput = function(row) { // Edge above tab. this.highlightSteps_.push('v', aboveTabHeight); // Highlight around back of tab. - this.highlightSteps_.push( - Blockly.blockRendering.constants.PUZZLE_TAB_HIGHLIGHT.pathDown(this.info_.RTL)); + this.highlightSteps_.push(this.puzzleTabPaths_.pathDown(this.info_.RTL)); // Edge below tab. this.highlightSteps_.push('v', belowTabHeight); } else { this.highlightSteps_.push(Blockly.utils.svgPaths.moveTo(row.width, row.yPos)); this.highlightSteps_.push( - Blockly.blockRendering.constants.PUZZLE_TAB_HIGHLIGHT.pathDown(this.info_.RTL)); + this.puzzleTabPaths_.pathDown(this.info_.RTL)); } }; @@ -108,18 +108,15 @@ Blockly.blockRendering.Highlighter.prototype.drawStatementInput = function(row) this.highlightSteps_.push('M', (x + Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE) + ',' + (row.yPos + Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE)); - this.highlightSteps_.push( - Blockly.blockRendering.constants.INSIDE_CORNER_HIGHLIGHTS.pathTop(this.info_.RTL)); + this.highlightSteps_.push(this.insideCornerPaths_.pathTop(this.info_.RTL)); this.highlightSteps_.push('v', row.height - 2 * Blockly.blockRendering.constants.CORNER_RADIUS); - this.highlightSteps_.push( - Blockly.blockRendering.constants.INSIDE_CORNER_HIGHLIGHTS.pathBottom(this.info_.RTL)); + this.highlightSteps_.push(this.insideCornerPaths_.pathBottom(this.info_.RTL)); } else { this.highlightSteps_.push('M', (x + Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE) + ',' + (row.yPos + row.height - Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE)); - this.highlightSteps_.push( - Blockly.blockRendering.constants.INSIDE_CORNER_HIGHLIGHTS.pathBottom(this.info_.RTL)); + this.highlightSteps_.push(this.insideCornerPaths_.pathBottom(this.info_.RTL)); } }; @@ -151,8 +148,7 @@ Blockly.blockRendering.Highlighter.prototype.drawBottomCorner = function(_row) { } } else if (elem.type === 'round corner') { if (!this.info_.RTL) { - this.highlightSteps_.push( - Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS.bottomLeft(height)); + this.highlightSteps_.push(this.outsideCornerPaths_.bottomLeft(height)); } } } @@ -161,7 +157,7 @@ Blockly.blockRendering.Highlighter.prototype.drawBottomCorner = function(_row) { Blockly.blockRendering.Highlighter.prototype.drawLeft = function() { if (this.info_.outputConnection) { this.highlightSteps_.push( - Blockly.blockRendering.constants.PUZZLE_TAB_HIGHLIGHT.pathUp(this.info_.RTL)); + this.puzzleTabPaths_.pathUp(this.info_.RTL)); } if (!this.info_.RTL) { @@ -196,7 +192,7 @@ Blockly.blockRendering.Highlighter.prototype.drawInlineInput = function(input) { this.highlightInlineSteps_.push('v', aboveTabHeight); // Back of tab. this.highlightInlineSteps_.push( - Blockly.blockRendering.constants.PUZZLE_TAB_HIGHLIGHT.pathDown(this.info_.RTL)); + this.puzzleTabPaths_.pathDown(this.info_.RTL)); // Right edge below tab. this.highlightInlineSteps_.push('v', belowTabHeight); // Bottom (horizontal). @@ -213,6 +209,6 @@ Blockly.blockRendering.Highlighter.prototype.drawInlineInput = function(input) { connectionRight, yPos + input.connectionOffsetY)); // Short highlight glint at bottom of tab. this.highlightSteps_.push( - Blockly.blockRendering.constants.PUZZLE_TAB_HIGHLIGHT.pathDown(this.info_.RTL)); + this.puzzleTabPaths_.pathDown(this.info_.RTL)); } }; diff --git a/core/renderers/block_rendering_rewrite/block_rendering_constants.js b/core/renderers/block_rendering_rewrite/block_rendering_constants.js index 6d3008096..74dedc92e 100644 --- a/core/renderers/block_rendering_rewrite/block_rendering_constants.js +++ b/core/renderers/block_rendering_rewrite/block_rendering_constants.js @@ -436,24 +436,16 @@ Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS = (function() { Blockly.utils.svgPaths.arc('A', '0 0,1', radius - offset, Blockly.utils.svgPaths.point(radius, offset)); - - var bottomLeftCornerStart = - 'M ' + distance45inside + ', '; // follow with y pos - distance 45 inside - - var bottomLeftCornerMid = - 'A ' + (radius - offset) + - ',' + (radius - offset) + - ' 0 0,1 ' + offset + ','; // follow with y pos - corner radius - - return { - topLeft: topLeftCornerHighlight, - topLeftStart: function(rtl) { - return rtl ? topLeftCornerStartRtl : topLeftCornerStartLtr; + topLeft: function(rtl) { + var start = rtl ? topLeftCornerStartRtl : topLeftCornerStartLtr; + return start + topLeftCornerHighlight; }, bottomLeft: function(yPos) { - return bottomLeftCornerStart + (yPos - distance45inside) + - bottomLeftCornerMid + (yPos - radius); + return Blockly.utils.svgPaths.moveTo( + distance45inside,yPos - distance45inside) + + Blockly.utils.svgPaths.arc('A', '0 0,1', radius - offset, + Blockly.utils.svgPaths.point(offset, yPos - radius)); } }; })(); From 36b4b184921c7628aa3df9009f8e3f9587b87e7a Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 26 Jul 2019 17:33:10 -0700 Subject: [PATCH 5/9] Quarantine highlights. --- blockly_compressed.js | 146 ++++++------ blockly_uncompressed.js | 8 +- .../block_render_draw_highlight.js | 32 +-- .../block_rendering_constants.js | 177 +------------- .../highlight_constants.js | 224 ++++++++++++++++++ 5 files changed, 318 insertions(+), 269 deletions(-) create mode 100644 core/renderers/block_rendering_rewrite/highlight_constants.js diff --git a/blockly_compressed.js b/blockly_compressed.js index 6512de9e6..b7721c6f6 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -913,7 +913,9 @@ Blockly.Touch.isMouseOrTouchEvent=function(a){return Blockly.utils.string.starts Blockly.Touch.splitEventByTouches=function(a){var b=[];if(a.changedTouches)for(var c=0;cc)){var d=b.getSvgXY(a.getSvgRoot());a.outputConnection?(d.x+=(a.RTL?3:-3)*c,d.y+=13*c):a.previousConnection&&(d.x+=(a.RTL?-23:23)*c,d.y+=3*c);a=Blockly.utils.dom.createSvgElement("circle",{cx:d.x,cy:d.y,r:0,fill:"none",stroke:"#888","stroke-width":10},b.getParentSvg());Blockly.blockAnimations.connectionUiStep_(a,new Date,c)}}; Blockly.blockAnimations.connectionUiStep_=function(a,b,c){var d=(new Date-b)/150;1=this.height_||0>=this.width_)throw Error("Height and width values of an image field must be greater than 0.");this.size_=new goog.math.Size(this.width_,this.height_+2*Blockly.BlockSvg.INLINE_PADDING_Y);this.flipRtl_=f;this.text_=d||"";this.setValue(a||"");"function"==typeof e&&(this.clickHandler_= -e)};goog.inherits(Blockly.FieldImage,Blockly.Field);Blockly.FieldImage.fromJson=function(a){var b=Blockly.utils.replaceMessageReferences(a.src),c=Number(Blockly.utils.replaceMessageReferences(a.width)),d=Number(Blockly.utils.replaceMessageReferences(a.height)),e=Blockly.utils.replaceMessageReferences(a.alt);return new Blockly.FieldImage(b,c,d,e,null,!!a.flipRtl)};Blockly.FieldImage.prototype.EDITABLE=!1;Blockly.FieldImage.prototype.isDirty_=!1; -Blockly.FieldImage.prototype.initView=function(){this.imageElement_=Blockly.utils.dom.createSvgElement("image",{height:this.height_+"px",width:this.width_+"px",alt:this.text_},this.fieldGroup_);this.imageElement_.setAttributeNS(Blockly.utils.dom.XLINK_NS,"xlink:href",this.value_)};Blockly.FieldImage.prototype.doClassValidation_=function(a){return"string"!=typeof a?null:a}; +Blockly.Field.register("field_label_serializable",Blockly.FieldLabelSerializable);Blockly.FieldImage=function(a,b,c,d,e,f){this.sourceBlock_=null;if(!a)throw Error("Src value of an image field is required");if(isNaN(c)||isNaN(b))throw Error("Height and width values of an image field must cast to numbers.");this.height_=Number(c);this.width_=Number(b);if(0>=this.height_||0>=this.width_)throw Error("Height and width values of an image field must be greater than 0.");this.size_=new goog.math.Size(this.width_,this.height_+2*Blockly.BlockSvg.INLINE_PADDING_Y);this.flipRtl_=f;this.text_= +d||"";this.setValue(a||"");"function"==typeof e&&(this.clickHandler_=e)};goog.inherits(Blockly.FieldImage,Blockly.Field);Blockly.FieldImage.fromJson=function(a){var b=Blockly.utils.replaceMessageReferences(a.src),c=Number(Blockly.utils.replaceMessageReferences(a.width)),d=Number(Blockly.utils.replaceMessageReferences(a.height)),e=Blockly.utils.replaceMessageReferences(a.alt);return new Blockly.FieldImage(b,c,d,e,null,!!a.flipRtl)};Blockly.FieldImage.prototype.EDITABLE=!1; +Blockly.FieldImage.prototype.isDirty_=!1;Blockly.FieldImage.prototype.initView=function(){this.imageElement_=Blockly.utils.dom.createSvgElement("image",{height:this.height_+"px",width:this.width_+"px",alt:this.text_},this.fieldGroup_);this.imageElement_.setAttributeNS(Blockly.utils.dom.XLINK_NS,"xlink:href",this.value_)};Blockly.FieldImage.prototype.doClassValidation_=function(a){return"string"!=typeof a?null:a}; Blockly.FieldImage.prototype.doValueUpdate_=function(a){this.value_=a;this.imageElement_&&this.imageElement_.setAttributeNS(Blockly.utils.dom.XLINK_NS,"xlink:href",this.value_||"")};Blockly.FieldImage.prototype.getFlipRtl=function(){return this.flipRtl_};Blockly.FieldImage.prototype.setText=function(a){null!==a&&(this.text_=a,this.imageElement_&&this.imageElement_.setAttribute("alt",a||""))};Blockly.FieldImage.prototype.showEditor_=function(){this.clickHandler_&&this.clickHandler_(this)}; Blockly.FieldImage.prototype.setOnClickHandler=function(a){this.clickHandler_=a};Blockly.FieldImage.prototype.getCorrectedSize=function(){this.getSize();return new goog.math.Size(this.size_.width,this.height_+1)};Blockly.Field.register("field_image",Blockly.FieldImage);Blockly.FieldNumber=function(a,b,c,d,e){this.setConstraints(b,c,d);a=this.doClassValidation_(a);null===a&&(a=0);Blockly.FieldNumber.superClass_.constructor.call(this,a,e)};goog.inherits(Blockly.FieldNumber,Blockly.FieldTextInput);Blockly.FieldNumber.fromJson=function(a){return new Blockly.FieldNumber(a.value,a.min,a.max,a.precision)};Blockly.FieldNumber.prototype.SERIALIZABLE=!0; Blockly.FieldNumber.prototype.setConstraints=function(a,b,c){c=parseFloat(c);this.precision_=isNaN(c)?0:c;c=this.precision_.toString();var d=c.indexOf(".");this.fractionalDigits_=-1==d?-1:c.length-(d+1);a=parseFloat(a);this.min_=isNaN(a)?-Infinity:a;b=parseFloat(b);this.max_=isNaN(b)?Infinity:b;this.setValue(this.getValue())}; diff --git a/blockly_uncompressed.js b/blockly_uncompressed.js index 465385681..dc627c3a3 100644 --- a/blockly_uncompressed.js +++ b/blockly_uncompressed.js @@ -92,10 +92,11 @@ goog.addDependency("../../../" + dir + "/core/procedures.js", ['Blockly.Procedur goog.addDependency("../../../" + dir + "/core/rendered_connection.js", ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.Events', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_render_draw.js", ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Highlighter', 'Blockly.blockRendering.Measurable']); goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_render_draw_debug.js", ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Highlighter', 'Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable']); -goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js", ['Blockly.blockRendering.Highlighter'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Measurable']); +goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js", ['Blockly.blockRendering.Highlighter'], ['Blockly.blockRendering.highlightConstants', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Measurable']); goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_render_info.js", ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable']); goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_rendering.js", ['Blockly.blockRendering'], ['Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.RenderInfo']); goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_rendering_constants.js", ['Blockly.blockRendering.constants'], ['Blockly.utils.svgPaths']); +goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/highlight_constants.js", ['Blockly.blockRendering.highlightConstants'], ['Blockly.blockRendering.constants', 'Blockly.utils.svgPaths']); goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/measurables.js", ['Blockly.blockRendering.Measurable'], ['Blockly.blockRendering.constants']); goog.addDependency("../../../" + dir + "/core/scrollbar.js", ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Touch', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency("../../../" + dir + "/core/theme.js", ['Blockly.Theme'], []); @@ -126,7 +127,7 @@ goog.addDependency("../../../" + dir + "/core/variables.js", ['Blockly.Variables goog.addDependency("../../../" + dir + "/core/variables_dynamic.js", ['Blockly.VariablesDynamic'], ['Blockly.Variables', 'Blockly.Blocks', 'Blockly.Msg', 'Blockly.utils.xml', 'Blockly.VariableModel', 'Blockly.Xml']); goog.addDependency("../../../" + dir + "/core/warning.js", ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.Ui', 'Blockly.Icon', 'Blockly.utils.dom']); goog.addDependency("../../../" + dir + "/core/widgetdiv.js", ['Blockly.WidgetDiv'], ['Blockly.Css', 'goog.style']); -goog.addDependency("../../../" + dir + "/core/workspace.js", ['Blockly.Workspace'], ['Blockly.Events', 'Blockly.utils', 'Blockly.utils.math', 'Blockly.VariableMap', 'Blockly.WorkspaceComment', 'Blockly.Cursor', 'Blockly.Themes.Classic']); +goog.addDependency("../../../" + dir + "/core/workspace.js", ['Blockly.Workspace'], ['Blockly.Cursor', 'Blockly.Events', 'Blockly.Themes.Classic', 'Blockly.utils', 'Blockly.utils.math', 'Blockly.VariableMap', 'Blockly.WorkspaceComment']); goog.addDependency("../../../" + dir + "/core/workspace_audio.js", ['Blockly.WorkspaceAudio'], ['Blockly.utils', 'Blockly.utils.userAgent']); goog.addDependency("../../../" + dir + "/core/workspace_comment.js", ['Blockly.WorkspaceComment'], ['Blockly.Events', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.xml']); goog.addDependency("../../../" + dir + "/core/workspace_comment_render_svg.js", ['Blockly.WorkspaceCommentSvg.render'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.dom', 'Blockly.WorkspaceCommentSvg']); @@ -701,10 +702,8 @@ goog.addDependency("html/sanitizer/csssanitizer.js", ['goog.html.sanitizer.CssSa goog.addDependency("html/sanitizer/csssanitizer_test.js", [], []); goog.addDependency("html/sanitizer/elementweakmap.js", [], []); goog.addDependency("html/sanitizer/elementweakmap_test.js", [], []); -goog.addDependency("html/sanitizer/html_test_vectors.js", ['goog.html.htmlTestVectors'], []); goog.addDependency("html/sanitizer/htmlsanitizer.js", ['goog.html.sanitizer.HtmlSanitizer', 'goog.html.sanitizer.HtmlSanitizer.Builder', 'goog.html.sanitizer.HtmlSanitizerAttributePolicy', 'goog.html.sanitizer.HtmlSanitizerPolicy', 'goog.html.sanitizer.HtmlSanitizerPolicyContext', 'goog.html.sanitizer.HtmlSanitizerPolicyHints', 'goog.html.sanitizer.HtmlSanitizerUrlPolicy'], ['goog.array', 'goog.asserts', 'goog.dom', 'goog.dom.TagName', 'goog.functions', 'goog.html.SafeHtml', 'goog.html.SafeStyle', 'goog.html.SafeStyleSheet', 'goog.html.SafeUrl', 'goog.html.sanitizer.AttributeSanitizedWhitelist', 'goog.html.sanitizer.AttributeWhitelist', 'goog.html.sanitizer.CssSanitizer', 'goog.html.sanitizer.SafeDomTreeProcessor', 'goog.html.sanitizer.TagBlacklist', 'goog.html.sanitizer.TagWhitelist', 'goog.html.sanitizer.noclobber', 'goog.html.uncheckedconversions', 'goog.object', 'goog.string', 'goog.string.Const']); goog.addDependency("html/sanitizer/htmlsanitizer_test.js", [], []); -goog.addDependency("html/sanitizer/htmlsanitizer_unified_test.js", [], []); goog.addDependency("html/sanitizer/noclobber.js", [], []); goog.addDependency("html/sanitizer/noclobber_test.js", [], []); goog.addDependency("html/sanitizer/safedomtreeprocessor.js", [], []); @@ -1885,6 +1884,7 @@ goog.require('Blockly.blockRendering.Highlighter'); goog.require('Blockly.blockRendering.Measurable'); goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.constants'); +goog.require('Blockly.blockRendering.highlightConstants'); goog.require('Blockly.constants'); goog.require('Blockly.inject'); goog.require('Blockly.utils'); diff --git a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js index a3cc2457f..b863c865c 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js @@ -26,7 +26,7 @@ 'use strict'; goog.provide('Blockly.blockRendering.Highlighter'); -goog.require('Blockly.blockRendering.constants'); +goog.require('Blockly.blockRendering.highlightConstants'); goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.Measurable'); @@ -53,27 +53,30 @@ Blockly.blockRendering.Highlighter = function(info, pathObject) { this.highlightSteps_ = this.pathObject_.highlightSteps; this.highlightInlineSteps_ = this.pathObject_.highlightInlineSteps; - this.highlightOffset_ = Blockly.blockRendering.constants.HIGHLIGHT_OFFSET; + this.highlightOffset_ = Blockly.blockRendering.highlightConstants.OFFSET; - this.outsideCornerPaths_ = Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS; - this.insideCornerPaths_ = Blockly.blockRendering.constants.INSIDE_CORNER_HIGHLIGHTS; - this.puzzleTabPaths_ = Blockly.blockRendering.constants.PUZZLE_TAB_HIGHLIGHT; + this.outsideCornerPaths_ = Blockly.blockRendering.highlightConstants.OUTSIDE_CORNER; + this.insideCornerPaths_ = Blockly.blockRendering.highlightConstants.INSIDE_CORNER; + this.puzzleTabPaths_ = Blockly.blockRendering.highlightConstants.PUZZLE_TAB; + this.notchPaths_ = Blockly.blockRendering.highlightConstants.NOTCH; + this.startPaths_ = Blockly.blockRendering.highlightConstants.START_HAT; }; Blockly.blockRendering.Highlighter.prototype.drawTopCorner = function(row) { for (var i = 0, elem; elem = row.elements[i]; i++) { if (elem.type === 'square corner') { - this.highlightSteps_.push(Blockly.blockRendering.constants.START_POINT_HIGHLIGHT); + this.highlightSteps_.push(Blockly.blockRendering.highlightConstants.START_POINT); } else if (elem.type === 'round corner') { this.highlightSteps_.push( this.outsideCornerPaths_.topLeft(this.info_.RTL)); } else if (elem.type === 'previous connection') { + // TODO: move the offsets into the definition of the notch highlight, maybe. this.highlightSteps_.push('h', (this.RTL ? 0.5 : - 0.5)); - this.highlightSteps_.push(Blockly.blockRendering.constants.NOTCH.pathLeftHighlight); + this.highlightSteps_.push(this.notchPaths_.pathLeft); this.highlightSteps_.push('h', (this.RTL ? -0.5 : 0.5)); } else if (elem.type === 'hat') { this.highlightSteps_.push( - Blockly.blockRendering.constants.START_HAT.highlight(this.info_.RTL)); + this.startPaths_.path(this.info_.RTL)); } else if (elem.isSpacer()) { this.highlightSteps_.push('h', elem.width - this.highlightOffset_); } @@ -104,18 +107,19 @@ Blockly.blockRendering.Highlighter.prototype.drawValueInput = function(row) { Blockly.blockRendering.Highlighter.prototype.drawStatementInput = function(row) { var x = row.statementEdge; + var distance45outside = Blockly.blockRendering.highlightConstants.DISTANCE_45_OUTSIDE; if (this.info_.RTL) { this.highlightSteps_.push('M', - (x + Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE) + - ',' + (row.yPos + Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE)); + (x + distance45outside) + + ',' + (row.yPos + distance45outside)); this.highlightSteps_.push(this.insideCornerPaths_.pathTop(this.info_.RTL)); this.highlightSteps_.push('v', - row.height - 2 * Blockly.blockRendering.constants.CORNER_RADIUS); + row.height - 2 * this.insideCornerPaths_.height); this.highlightSteps_.push(this.insideCornerPaths_.pathBottom(this.info_.RTL)); } else { this.highlightSteps_.push('M', - (x + Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE) + ',' + - (row.yPos + row.height - Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE)); + (x + distance45outside) + ',' + + (row.yPos + row.height - distance45outside)); this.highlightSteps_.push(this.insideCornerPaths_.pathBottom(this.info_.RTL)); } }; @@ -164,7 +168,7 @@ Blockly.blockRendering.Highlighter.prototype.drawLeft = function() { if (this.info_.topRow.elements[0].isSquareCorner()) { this.highlightSteps_.push('V', this.highlightOffset_); } else { - this.highlightSteps_.push('V', Blockly.blockRendering.constants.CORNER_RADIUS); + this.highlightSteps_.push('V', this.outsideCornerPaths_.height); } } }; diff --git a/core/renderers/block_rendering_rewrite/block_rendering_constants.js b/core/renderers/block_rendering_rewrite/block_rendering_constants.js index 74dedc92e..ac921db75 100644 --- a/core/renderers/block_rendering_rewrite/block_rendering_constants.js +++ b/core/renderers/block_rendering_rewrite/block_rendering_constants.js @@ -41,7 +41,6 @@ Blockly.blockRendering.constants.LARGE_PADDING = 10; Blockly.blockRendering.constants.TALL_INPUT_FIELD_OFFSET_Y = Blockly.blockRendering.constants.MEDIUM_PADDING; -Blockly.blockRendering.constants.HIGHLIGHT_OFFSET = 0.5; // The dark/shadow path in classic rendering is the same as the normal block // path, but translated down one and right one. @@ -132,21 +131,6 @@ Blockly.blockRendering.constants.POPULATED_STATEMENT_INPUT_WIDTH = 25; Blockly.blockRendering.constants.START_POINT = Blockly.utils.svgPaths.moveBy(0, 0); -Blockly.blockRendering.constants.START_POINT_HIGHLIGHT = - Blockly.utils.svgPaths.moveBy( - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET, - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET); - -/** - * Distance from shape edge to intersect with a curved corner at 45 degrees. - * Applies to highlighting on around the outside of a curve. - * @const - */ -Blockly.blockRendering.constants.DISTANCE_45_OUTSIDE = (1 - Math.SQRT1_2) * - (Blockly.blockRendering.constants.CORNER_RADIUS + - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET) - - Blockly.blockRendering.constants.HIGHLIGHT_OFFSET; - /** * SVG start point for drawing the top-left corner. * @const @@ -161,23 +145,6 @@ Blockly.blockRendering.constants.START_HAT = (function() { // It's really minus 15, which is super unfortunate. var height = Blockly.blockRendering.constants.START_HAT_HEIGHT; var width = Blockly.blockRendering.constants.START_HAT_WIDTH; - var highlightRtlPath = - Blockly.utils.svgPaths.moveBy(25, -8.7) + - Blockly.utils.svgPaths.curve('c', - [ - Blockly.utils.svgPaths.point(29.7, -6.2), - Blockly.utils.svgPaths.point(57.2, -0.5), - Blockly.utils.svgPaths.point(75, 8.7) - ]); - - var highlightLtrPath = - Blockly.utils.svgPaths.curve('c', - [ - Blockly.utils.svgPaths.point(17.8, -9.2), - Blockly.utils.svgPaths.point(45.3, -14.9), - Blockly.utils.svgPaths.point(75, -8.7) - ]) + - Blockly.utils.svgPaths.moveTo(100.5, 0.5); var mainPath = Blockly.utils.svgPaths.curve('c', @@ -189,10 +156,7 @@ Blockly.blockRendering.constants.START_HAT = (function() { return { height: height, width: width, - path: mainPath, - highlight: function(rtl) { - return rtl ? highlightRtlPath : highlightLtrPath; - } + path: mainPath }; })(); @@ -244,60 +208,6 @@ Blockly.blockRendering.constants.PUZZLE_TAB = (function() { }; })(); -Blockly.blockRendering.constants.PUZZLE_TAB_HIGHLIGHT = (function() { - var width = Blockly.blockRendering.constants.TAB_WIDTH; - var height = Blockly.blockRendering.constants.TAB_HEIGHT; - - // This is how much of the vertical block edge is actually drawn by the puzzle - // tab. - var verticalOverlap = 2.5; - - // The highlight paths are not simple offsets of the main paths. Changing - // them is fiddly work. - var highlightRtlUp = - Blockly.utils.svgPaths.moveTo(width * -0.25, 8.4) + - Blockly.utils.svgPaths.lineTo(width * -0.45, -2.1); - - var highlightRtlDown = - Blockly.utils.svgPaths.lineOnAxis('v', verticalOverlap) + - Blockly.utils.svgPaths.moveBy(-width * 0.97, 2.5) + - Blockly.utils.svgPaths.curve('q', - [ - Blockly.utils.svgPaths.point(-width * 0.05, 10), - Blockly.utils.svgPaths.point(width * 0.3, 9.5) - ]) + - Blockly.utils.svgPaths.moveBy(width * 0.67, -1.9) + - Blockly.utils.svgPaths.lineOnAxis('v', verticalOverlap); - - var highlightLtrUp = - // TODO: Move this 'V' out. - Blockly.utils.svgPaths.lineOnAxis('V', - height + Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP - 1.5) + - Blockly.utils.svgPaths.moveBy(width * -0.92, -0.5) + - Blockly.utils.svgPaths.curve('q', - [ - Blockly.utils.svgPaths.point(width * -0.19, -5.5), - Blockly.utils.svgPaths.point(0,-11) - ]) + - Blockly.utils.svgPaths.moveBy(width * 0.92, 1) + - Blockly.utils.svgPaths.lineOnAxis('V', 0.5) + - Blockly.utils.svgPaths.lineOnAxis('H', 1); - - var highlightLtrDown = - Blockly.utils.svgPaths.moveBy(-5, height - 0.7) + - Blockly.utils.svgPaths.lineTo(width * 0.46, -2.1); - - return { - width: width, - height: height, - pathUp: function(rtl) { - return rtl ? highlightRtlUp : highlightLtrUp; - }, - pathDown: function(rtl) { - return rtl ? highlightRtlDown : highlightLtrDown; - } - }; -})(); Blockly.blockRendering.constants.NOTCH = (function() { var width = Blockly.blockRendering.constants.NOTCH_WIDTH; @@ -316,12 +226,10 @@ Blockly.blockRendering.constants.NOTCH = (function() { var pathLeft = makeMainPath(1); var pathRight = makeMainPath(-1); - var pathLeftHighlight = Blockly.utils.svgPaths.lineOnAxis('h', Blockly.blockRendering.constants.HIGHLIGHT_OFFSET) + pathLeft; return { width: width, height: height, pathLeft: pathLeft, - pathLeftHighlight: pathLeftHighlight, pathRight: pathRight }; })(); @@ -344,44 +252,7 @@ Blockly.blockRendering.constants.INSIDE_CORNERS = (function() { }; })(); -/** - * Highlight paths for drawing the inside corners of a statement input. - */ -Blockly.blockRendering.constants.INSIDE_CORNER_HIGHLIGHTS = (function() { - var radius = Blockly.blockRendering.constants.CORNER_RADIUS; - var offset = Blockly.blockRendering.constants.HIGHLIGHT_OFFSET; - /** - * Distance from shape edge to intersect with a curved corner at 45 degrees. - * Applies to highlighting on around the outside of a curve. - * @const - */ - var distance45outside = (1 - Math.SQRT1_2) * (radius + offset) - offset; - - var pathTopRtl = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, - Blockly.utils.svgPaths.point( - -distance45outside - offset, - radius - distance45outside)); - - var pathBottomRtl = Blockly.utils.svgPaths.arc('a', '0 0,0', radius + offset, - Blockly.utils.svgPaths.point(radius + offset, radius + offset)); - - var pathBottomLtr = Blockly.utils.svgPaths.arc('a', '0 0,0', radius + offset, - Blockly.utils.svgPaths.point( - radius - distance45outside, - distance45outside + offset)); - - return { - // width: width, - // height: height, - pathTop: function(rtl) { - return rtl ? pathTopRtl : ''; - }, - pathBottom: function(rtl) { - return rtl ? pathBottomRtl : pathBottomLtr; - }, - }; -})(); Blockly.blockRendering.constants.OUTSIDE_CORNERS = (function() { var radius = Blockly.blockRendering.constants.CORNER_RADIUS; @@ -403,49 +274,3 @@ Blockly.blockRendering.constants.OUTSIDE_CORNERS = (function() { }; })(); -Blockly.blockRendering.constants.OUTSIDE_CORNER_HIGHLIGHTS = (function() { - var radius = Blockly.blockRendering.constants.CORNER_RADIUS; - var offset = Blockly.blockRendering.constants.HIGHLIGHT_OFFSET; - - /** - * Distance from shape edge to intersect with a curved corner at 45 degrees. - * Applies to highlighting on around the inside of a curve. - * @const - */ - var distance45inside = (1 - Math.SQRT1_2) * (radius - offset) + offset; - - /** - * SVG start point for drawing the top-left corner's highlight in RTL. - * @const - */ - var topLeftCornerStartRtl = - Blockly.utils.svgPaths.moveBy(distance45inside, distance45inside); - - /** - * SVG start point for drawing the top-left corner's highlight in LTR. - * @const - */ - var topLeftCornerStartLtr = - Blockly.utils.svgPaths.moveBy(offset, radius - offset); - - /** - * SVG path for drawing the highlight on the rounded top-left corner. - * @const - */ - var topLeftCornerHighlight = - Blockly.utils.svgPaths.arc('A', '0 0,1', radius - offset, - Blockly.utils.svgPaths.point(radius, offset)); - - return { - topLeft: function(rtl) { - var start = rtl ? topLeftCornerStartRtl : topLeftCornerStartLtr; - return start + topLeftCornerHighlight; - }, - bottomLeft: function(yPos) { - return Blockly.utils.svgPaths.moveTo( - distance45inside,yPos - distance45inside) + - Blockly.utils.svgPaths.arc('A', '0 0,1', radius - offset, - Blockly.utils.svgPaths.point(offset, yPos - radius)); - } - }; -})(); diff --git a/core/renderers/block_rendering_rewrite/highlight_constants.js b/core/renderers/block_rendering_rewrite/highlight_constants.js new file mode 100644 index 000000000..aed02338f --- /dev/null +++ b/core/renderers/block_rendering_rewrite/highlight_constants.js @@ -0,0 +1,224 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2019 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 fenichel@google.com (Rachel Fenichel) + */ + +'use strict'; +goog.provide('Blockly.blockRendering.highlightConstants'); + +goog.require('Blockly.blockRendering.constants'); +goog.require('Blockly.utils.svgPaths'); + + +Blockly.blockRendering.highlightConstants.OFFSET = 0.5; + +Blockly.blockRendering.highlightConstants.START_POINT = + Blockly.utils.svgPaths.moveBy( + Blockly.blockRendering.highlightConstants.OFFSET, + Blockly.blockRendering.highlightConstants.OFFSET); + +/** + * Distance from shape edge to intersect with a curved corner at 45 degrees. + * Applies to highlighting on around the outside of a curve. + * @const + */ +Blockly.blockRendering.highlightConstants.DISTANCE_45_OUTSIDE = (1 - Math.SQRT1_2) * + (Blockly.blockRendering.constants.CORNER_RADIUS + + Blockly.blockRendering.highlightConstants.OFFSET) - + Blockly.blockRendering.highlightConstants.OFFSET; + +/** + * Highlight paths for drawing the inside corners of a statement input. + */ +Blockly.blockRendering.highlightConstants.INSIDE_CORNER = (function() { + var radius = Blockly.blockRendering.constants.CORNER_RADIUS; + var offset = Blockly.blockRendering.highlightConstants.OFFSET; + + /** + * Distance from shape edge to intersect with a curved corner at 45 degrees. + * Applies to highlighting on around the outside of a curve. + * @const + */ + var distance45outside = (1 - Math.SQRT1_2) * (radius + offset) - offset; + + var pathTopRtl = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, + Blockly.utils.svgPaths.point( + -distance45outside - offset, + radius - distance45outside)); + + var pathBottomRtl = Blockly.utils.svgPaths.arc('a', '0 0,0', radius + offset, + Blockly.utils.svgPaths.point(radius + offset, radius + offset)); + + var pathBottomLtr = Blockly.utils.svgPaths.arc('a', '0 0,0', radius + offset, + Blockly.utils.svgPaths.point( + radius - distance45outside, + distance45outside + offset)); + + return { + // width: width, + height: radius, + pathTop: function(rtl) { + return rtl ? pathTopRtl : ''; + }, + pathBottom: function(rtl) { + return rtl ? pathBottomRtl : pathBottomLtr; + }, + }; +})(); + +Blockly.blockRendering.highlightConstants.OUTSIDE_CORNER = (function() { + var radius = Blockly.blockRendering.constants.CORNER_RADIUS; + var offset = Blockly.blockRendering.highlightConstants.OFFSET; + + /** + * Distance from shape edge to intersect with a curved corner at 45 degrees. + * Applies to highlighting on around the inside of a curve. + * @const + */ + var distance45inside = (1 - Math.SQRT1_2) * (radius - offset) + offset; + + /** + * SVG start point for drawing the top-left corner's highlight in RTL. + * @const + */ + var topLeftCornerStartRtl = + Blockly.utils.svgPaths.moveBy(distance45inside, distance45inside); + + /** + * SVG start point for drawing the top-left corner's highlight in LTR. + * @const + */ + var topLeftCornerStartLtr = + Blockly.utils.svgPaths.moveBy(offset, radius - offset); + + /** + * SVG path for drawing the highlight on the rounded top-left corner. + * @const + */ + var topLeftCornerHighlight = + Blockly.utils.svgPaths.arc('A', '0 0,1', radius - offset, + Blockly.utils.svgPaths.point(radius, offset)); + + return { + height: radius, + topLeft: function(rtl) { + var start = rtl ? topLeftCornerStartRtl : topLeftCornerStartLtr; + return start + topLeftCornerHighlight; + }, + bottomLeft: function(yPos) { + return Blockly.utils.svgPaths.moveTo( + distance45inside,yPos - distance45inside) + + Blockly.utils.svgPaths.arc('A', '0 0,1', radius - offset, + Blockly.utils.svgPaths.point(offset, yPos - radius)); + } + }; +})(); + + +Blockly.blockRendering.highlightConstants.PUZZLE_TAB = (function() { + var width = Blockly.blockRendering.constants.TAB_WIDTH; + var height = Blockly.blockRendering.constants.TAB_HEIGHT; + + // This is how much of the vertical block edge is actually drawn by the puzzle + // tab. + var verticalOverlap = 2.5; + + var highlightRtlUp = + Blockly.utils.svgPaths.moveTo(width * -0.25, 8.4) + + Blockly.utils.svgPaths.lineTo(width * -0.45, -2.1); + + var highlightRtlDown = + Blockly.utils.svgPaths.lineOnAxis('v', verticalOverlap) + + Blockly.utils.svgPaths.moveBy(-width * 0.97, 2.5) + + Blockly.utils.svgPaths.curve('q', + [ + Blockly.utils.svgPaths.point(-width * 0.05, 10), + Blockly.utils.svgPaths.point(width * 0.3, 9.5) + ]) + + Blockly.utils.svgPaths.moveBy(width * 0.67, -1.9) + + Blockly.utils.svgPaths.lineOnAxis('v', verticalOverlap); + + var highlightLtrUp = + // TODO: Move this 'V' out. + Blockly.utils.svgPaths.lineOnAxis('V', + height + Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP - 1.5) + + Blockly.utils.svgPaths.moveBy(width * -0.92, -0.5) + + Blockly.utils.svgPaths.curve('q', + [ + Blockly.utils.svgPaths.point(width * -0.19, -5.5), + Blockly.utils.svgPaths.point(0,-11) + ]) + + Blockly.utils.svgPaths.moveBy(width * 0.92, 1) + + Blockly.utils.svgPaths.lineOnAxis('V', 0.5) + + Blockly.utils.svgPaths.lineOnAxis('H', 1); + + var highlightLtrDown = + Blockly.utils.svgPaths.moveBy(-5, height - 0.7) + + Blockly.utils.svgPaths.lineTo(width * 0.46, -2.1); + + return { + width: width, + height: height, + pathUp: function(rtl) { + return rtl ? highlightRtlUp : highlightLtrUp; + }, + pathDown: function(rtl) { + return rtl ? highlightRtlDown : highlightLtrDown; + } + }; +})(); + +Blockly.blockRendering.highlightConstants.NOTCH = (function() { + var pathLeft = + Blockly.utils.svgPaths.lineOnAxis( + 'h', Blockly.blockRendering.highlightConstants.OFFSET) + + Blockly.blockRendering.constants.NOTCH.pathLeft; + return { + pathLeft: pathLeft + }; +})(); + +Blockly.blockRendering.highlightConstants.START_HAT = (function() { + var pathRtl = + Blockly.utils.svgPaths.moveBy(25, -8.7) + + Blockly.utils.svgPaths.curve('c', + [ + Blockly.utils.svgPaths.point(29.7, -6.2), + Blockly.utils.svgPaths.point(57.2, -0.5), + Blockly.utils.svgPaths.point(75, 8.7) + ]); + + var pathLtr = + Blockly.utils.svgPaths.curve('c', + [ + Blockly.utils.svgPaths.point(17.8, -9.2), + Blockly.utils.svgPaths.point(45.3, -14.9), + Blockly.utils.svgPaths.point(75, -8.7) + ]) + + Blockly.utils.svgPaths.moveTo(100.5, 0.5); + return { + path: function(rtl) { + return rtl ? pathRtl : pathLtr; + } + }; +})(); From 9ce8282568136b7e74b2d90335a8562ddd66eea5 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 29 Jul 2019 14:58:51 -0700 Subject: [PATCH 6/9] Remove references to distance45outside --- .../block_render_draw_highlight.js | 165 +++++++++--------- .../highlight_constants.js | 48 ++--- 2 files changed, 114 insertions(+), 99 deletions(-) diff --git a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js index b863c865c..e093c05d7 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js @@ -50,9 +50,16 @@ goog.require('Blockly.blockRendering.Measurable'); Blockly.blockRendering.Highlighter = function(info, pathObject) { this.info_ = info; this.pathObject_ = pathObject; - this.highlightSteps_ = this.pathObject_.highlightSteps; - this.highlightInlineSteps_ = this.pathObject_.highlightInlineSteps; + this.steps_ = this.pathObject_.highlightSteps; + this.inlineSteps_ = this.pathObject_.highlightInlineSteps; + this.RTL_ = this.info_.RTL; + + /** + * The offset between the block's main path and highlight path. + * @type {number} + * @private + */ this.highlightOffset_ = Blockly.blockRendering.highlightConstants.OFFSET; this.outsideCornerPaths_ = Blockly.blockRendering.highlightConstants.OUTSIDE_CORNER; @@ -65,72 +72,72 @@ Blockly.blockRendering.Highlighter = function(info, pathObject) { Blockly.blockRendering.Highlighter.prototype.drawTopCorner = function(row) { for (var i = 0, elem; elem = row.elements[i]; i++) { if (elem.type === 'square corner') { - this.highlightSteps_.push(Blockly.blockRendering.highlightConstants.START_POINT); + this.steps_.push(Blockly.blockRendering.highlightConstants.START_POINT); } else if (elem.type === 'round corner') { - this.highlightSteps_.push( - this.outsideCornerPaths_.topLeft(this.info_.RTL)); + this.steps_.push( + this.outsideCornerPaths_.topLeft(this.RTL_)); } else if (elem.type === 'previous connection') { // TODO: move the offsets into the definition of the notch highlight, maybe. - this.highlightSteps_.push('h', (this.RTL ? 0.5 : - 0.5)); - this.highlightSteps_.push(this.notchPaths_.pathLeft); - this.highlightSteps_.push('h', (this.RTL ? -0.5 : 0.5)); + this.steps_.push('h', (this.RTL_ ? 0.5 : - 0.5)); + this.steps_.push(this.notchPaths_.pathLeft); + this.steps_.push('h', (this.RTL_ ? -0.5 : 0.5)); } else if (elem.type === 'hat') { - this.highlightSteps_.push( - this.startPaths_.path(this.info_.RTL)); + this.steps_.push( + this.startPaths_.path(this.RTL_)); } else if (elem.isSpacer()) { - this.highlightSteps_.push('h', elem.width - this.highlightOffset_); + this.steps_.push('h', elem.width - this.highlightOffset_); } } - this.highlightSteps_.push('H', row.width - this.highlightOffset_); + this.steps_.push('H', row.width - this.highlightOffset_); }; Blockly.blockRendering.Highlighter.prototype.drawValueInput = function(row) { var input = row.getLastInput(); - if (this.info_.RTL) { + var pathString = ''; + if (this.RTL_) { var aboveTabHeight = -this.highlightOffset_; - var belowTabHeight = row.height - - input.connectionHeight + - this.highlightOffset_; - // Edge above tab. - this.highlightSteps_.push('v', aboveTabHeight); - // Highlight around back of tab. - this.highlightSteps_.push(this.puzzleTabPaths_.pathDown(this.info_.RTL)); - // Edge below tab. - this.highlightSteps_.push('v', belowTabHeight); + var belowTabHeight = + row.height - input.connectionHeight + this.highlightOffset_; + + pathString = + Blockly.utils.svgPaths.lineOnAxis('v', aboveTabHeight) + + this.puzzleTabPaths_.pathDown(this.RTL_) + + Blockly.utils.svgPaths.lineOnAxis('v', belowTabHeight); } else { - this.highlightSteps_.push(Blockly.utils.svgPaths.moveTo(row.width, row.yPos)); - this.highlightSteps_.push( - this.puzzleTabPaths_.pathDown(this.info_.RTL)); + pathString = + Blockly.utils.svgPaths.moveTo(row.width, row.yPos) + + this.puzzleTabPaths_.pathDown(this.RTL_); } + + this.steps_.push(pathString); }; Blockly.blockRendering.Highlighter.prototype.drawStatementInput = function(row) { - var x = row.statementEdge; - var distance45outside = Blockly.blockRendering.highlightConstants.DISTANCE_45_OUTSIDE; - if (this.info_.RTL) { - this.highlightSteps_.push('M', - (x + distance45outside) + - ',' + (row.yPos + distance45outside)); - this.highlightSteps_.push(this.insideCornerPaths_.pathTop(this.info_.RTL)); - this.highlightSteps_.push('v', - row.height - 2 * this.insideCornerPaths_.height); - this.highlightSteps_.push(this.insideCornerPaths_.pathBottom(this.info_.RTL)); + if (this.RTL_) { + var innerHeight = row.height - (2 * this.insideCornerPaths_.height); + var steps = + Blockly.utils.svgPaths.moveTo(row.statementEdge, row.yPos) + + this.insideCornerPaths_.pathTop(this.RTL_) + + Blockly.utils.svgPaths.lineOnAxis('v', innerHeight) + + this.insideCornerPaths_.pathBottom(this.RTL_); + this.steps_.push(steps); } else { - this.highlightSteps_.push('M', - (x + distance45outside) + ',' + - (row.yPos + row.height - distance45outside)); - this.highlightSteps_.push(this.insideCornerPaths_.pathBottom(this.info_.RTL)); + var steps = + Blockly.utils.svgPaths.moveTo(row.statementEdge, row.yPos + row.height) + + this.insideCornerPaths_.pathBottom(this.RTL_); + + this.steps_.push(steps); } }; Blockly.blockRendering.Highlighter.prototype.drawRightSideRow = function(row) { if (row.followsStatement) { - this.highlightSteps_.push('H', row.width); + this.steps_.push('H', row.width); } - if (this.info_.RTL) { - this.highlightSteps_.push('H', row.width - this.highlightOffset_); - this.highlightSteps_.push('v', row.height); + if (this.RTL_) { + this.steps_.push('H', row.width - this.highlightOffset_); + this.steps_.push('v', row.height); } }; @@ -138,21 +145,21 @@ Blockly.blockRendering.Highlighter.prototype.drawBottomCorner = function(_row) { var height = this.info_.height; var elems = this.info_.bottomRow.elements; - if (this.info_.RTL) { - this.highlightSteps_.push('V', height); + if (this.RTL_) { + this.steps_.push('V', height); } for (var i = elems.length - 1; i >= 0; i--) { var elem = elems[i]; if (elem.type === 'square corner') { - if (!this.info_.RTL) { - this.highlightSteps_.push('M', + if (!this.RTL_) { + this.steps_.push('M', this.highlightOffset_ + ',' + (height - this.highlightOffset_)); } } else if (elem.type === 'round corner') { - if (!this.info_.RTL) { - this.highlightSteps_.push(this.outsideCornerPaths_.bottomLeft(height)); + if (!this.RTL_) { + this.steps_.push(this.outsideCornerPaths_.bottomLeft(height)); } } } @@ -160,15 +167,15 @@ Blockly.blockRendering.Highlighter.prototype.drawBottomCorner = function(_row) { Blockly.blockRendering.Highlighter.prototype.drawLeft = function() { if (this.info_.outputConnection) { - this.highlightSteps_.push( - this.puzzleTabPaths_.pathUp(this.info_.RTL)); + this.steps_.push( + this.puzzleTabPaths_.pathUp(this.RTL_)); } - if (!this.info_.RTL) { + if (!this.RTL_) { if (this.info_.topRow.elements[0].isSquareCorner()) { - this.highlightSteps_.push('V', this.highlightOffset_); + this.steps_.push('V', this.highlightOffset_); } else { - this.highlightSteps_.push('V', this.outsideCornerPaths_.height); + this.steps_.push('V', this.outsideCornerPaths_.height); } } }; @@ -182,7 +189,7 @@ Blockly.blockRendering.Highlighter.prototype.drawInlineInput = function(input) { var bottomHighlightWidth = input.width - input.connectionWidth; var startY = yPos + offset; - if (this.info_.RTL) { + if (this.RTL_) { // TODO: Check if this is different when the inline input is populated. var aboveTabHeight = input.connectionOffsetY - offset; var belowTabHeight = @@ -190,29 +197,31 @@ Blockly.blockRendering.Highlighter.prototype.drawInlineInput = function(input) { var startX = connectionRight - offset; - // Highlight right edge, around back of tab, and bottom. - this.highlightInlineSteps_.push('M', startX + ',' + startY); - // Right edge above tab. - this.highlightInlineSteps_.push('v', aboveTabHeight); - // Back of tab. - this.highlightInlineSteps_.push( - this.puzzleTabPaths_.pathDown(this.info_.RTL)); - // Right edge below tab. - this.highlightInlineSteps_.push('v', belowTabHeight); - // Bottom (horizontal). - this.highlightInlineSteps_.push('h', bottomHighlightWidth); + var steps = Blockly.utils.svgPaths.moveTo(startX, startY) + + // Right edge above tab. + Blockly.utils.svgPaths.lineOnAxis('v', aboveTabHeight) + + // Back of tab. + this.puzzleTabPaths_.pathDown(this.RTL_) + + // Right edge below tab. + Blockly.utils.svgPaths.lineOnAxis('v', belowTabHeight) + + // Bottom. + Blockly.utils.svgPaths.lineOnAxis('h', bottomHighlightWidth); + + this.inlineSteps_.push(steps); + } else { - // Go to top right corner. - this.highlightInlineSteps_.push( - Blockly.utils.svgPaths.moveTo(input.xPos + input.width + offset, startY)); - // Highlight right edge, bottom. - this.highlightInlineSteps_.push('v', input.height); - this.highlightInlineSteps_.push('h ', -bottomHighlightWidth); - // Go to top of tab. - this.highlightSteps_.push(Blockly.utils.svgPaths.moveTo( - connectionRight, yPos + input.connectionOffsetY)); - // Short highlight glint at bottom of tab. - this.highlightSteps_.push( - this.puzzleTabPaths_.pathDown(this.info_.RTL)); + + var steps = + // Go to top right corner. + Blockly.utils.svgPaths.moveTo(input.xPos + input.width + offset, startY) + + // Highlight right edge, bottom. + Blockly.utils.svgPaths.lineOnAxis('v', input.height) + + Blockly.utils.svgPaths.lineOnAxis('h', -bottomHighlightWidth) + + // Go to top of tab. + Blockly.utils.svgPaths.moveTo(connectionRight, yPos + input.connectionOffsetY) + + // Short highlight glint at bottom of tab. + this.puzzleTabPaths_.pathDown(this.RTL_); + + this.inlineSteps_.push(steps); } }; diff --git a/core/renderers/block_rendering_rewrite/highlight_constants.js b/core/renderers/block_rendering_rewrite/highlight_constants.js index aed02338f..b134b6661 100644 --- a/core/renderers/block_rendering_rewrite/highlight_constants.js +++ b/core/renderers/block_rendering_rewrite/highlight_constants.js @@ -29,7 +29,17 @@ goog.provide('Blockly.blockRendering.highlightConstants'); goog.require('Blockly.blockRendering.constants'); goog.require('Blockly.utils.svgPaths'); +/** + * Some highlights are simple offsets of the parent paths and can be generated + * programmatically. Others, especially on curves, are just made out of piles + * of constants and are hard to tweak. + */ +/** + * The offset between the block's main path and highlight path. + * @type {number} + * @package + */ Blockly.blockRendering.highlightConstants.OFFSET = 0.5; Blockly.blockRendering.highlightConstants.START_POINT = @@ -37,18 +47,10 @@ Blockly.blockRendering.highlightConstants.START_POINT = Blockly.blockRendering.highlightConstants.OFFSET, Blockly.blockRendering.highlightConstants.OFFSET); -/** - * Distance from shape edge to intersect with a curved corner at 45 degrees. - * Applies to highlighting on around the outside of a curve. - * @const - */ -Blockly.blockRendering.highlightConstants.DISTANCE_45_OUTSIDE = (1 - Math.SQRT1_2) * - (Blockly.blockRendering.constants.CORNER_RADIUS + - Blockly.blockRendering.highlightConstants.OFFSET) - - Blockly.blockRendering.highlightConstants.OFFSET; - /** * Highlight paths for drawing the inside corners of a statement input. + * RTL and LTR refer to the rendering of the block as a whole. However, the top + * of the statement input is drawn from right to left in LTR mode. */ Blockly.blockRendering.highlightConstants.INSIDE_CORNER = (function() { var radius = Blockly.blockRendering.constants.CORNER_RADIUS; @@ -61,21 +63,25 @@ Blockly.blockRendering.highlightConstants.INSIDE_CORNER = (function() { */ var distance45outside = (1 - Math.SQRT1_2) * (radius + offset) - offset; - var pathTopRtl = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, - Blockly.utils.svgPaths.point( - -distance45outside - offset, - radius - distance45outside)); + var pathTopRtl = + Blockly.utils.svgPaths.moveBy(distance45outside, distance45outside) + + Blockly.utils.svgPaths.arc('a', '0 0,0', radius, + Blockly.utils.svgPaths.point( + -distance45outside - offset, + radius - distance45outside)); - var pathBottomRtl = Blockly.utils.svgPaths.arc('a', '0 0,0', radius + offset, - Blockly.utils.svgPaths.point(radius + offset, radius + offset)); + var pathBottomRtl = + Blockly.utils.svgPaths.arc('a', '0 0,0', radius + offset, + Blockly.utils.svgPaths.point(radius + offset, radius + offset)); - var pathBottomLtr = Blockly.utils.svgPaths.arc('a', '0 0,0', radius + offset, - Blockly.utils.svgPaths.point( - radius - distance45outside, - distance45outside + offset)); + var pathBottomLtr = + Blockly.utils.svgPaths.moveBy(distance45outside, - distance45outside) + + Blockly.utils.svgPaths.arc('a', '0 0,0', radius + offset, + Blockly.utils.svgPaths.point( + radius - distance45outside, + distance45outside + offset)); return { - // width: width, height: radius, pathTop: function(rtl) { return rtl ? pathTopRtl : ''; From bed30dfa68d44d0d7f66076c8fa2223b0a83f919 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 29 Jul 2019 15:26:53 -0700 Subject: [PATCH 7/9] Cleanup --- .../block_rendering_rewrite/block_render_draw_highlight.js | 4 +--- .../block_rendering_rewrite/block_rendering_constants.js | 3 --- core/renderers/block_rendering_rewrite/highlight_constants.js | 2 +- core/renderers/block_rendering_rewrite/measurables.js | 2 -- 4 files changed, 2 insertions(+), 9 deletions(-) diff --git a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js index e093c05d7..efe8d7826 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js @@ -82,8 +82,7 @@ Blockly.blockRendering.Highlighter.prototype.drawTopCorner = function(row) { this.steps_.push(this.notchPaths_.pathLeft); this.steps_.push('h', (this.RTL_ ? -0.5 : 0.5)); } else if (elem.type === 'hat') { - this.steps_.push( - this.startPaths_.path(this.RTL_)); + this.steps_.push(this.startPaths_.path(this.RTL_)); } else if (elem.isSpacer()) { this.steps_.push('h', elem.width - this.highlightOffset_); } @@ -126,7 +125,6 @@ Blockly.blockRendering.Highlighter.prototype.drawStatementInput = function(row) var steps = Blockly.utils.svgPaths.moveTo(row.statementEdge, row.yPos + row.height) + this.insideCornerPaths_.pathBottom(this.RTL_); - this.steps_.push(steps); } }; diff --git a/core/renderers/block_rendering_rewrite/block_rendering_constants.js b/core/renderers/block_rendering_rewrite/block_rendering_constants.js index ac921db75..0142fb5a5 100644 --- a/core/renderers/block_rendering_rewrite/block_rendering_constants.js +++ b/core/renderers/block_rendering_rewrite/block_rendering_constants.js @@ -245,7 +245,6 @@ Blockly.blockRendering.constants.INSIDE_CORNERS = (function() { Blockly.utils.svgPaths.point(radius, radius)); return { - //width: width, height: radius, pathTop: innerTopLeftCorner, pathBottom: innerBottomLeftCorner @@ -267,8 +266,6 @@ Blockly.blockRendering.constants.OUTSIDE_CORNERS = (function() { Blockly.utils.svgPaths.point(-radius, -radius)); return { - // width: width, - // height: height, topLeft: topLeft, bottomLeft: bottomLeft }; diff --git a/core/renderers/block_rendering_rewrite/highlight_constants.js b/core/renderers/block_rendering_rewrite/highlight_constants.js index b134b6661..59a222dbd 100644 --- a/core/renderers/block_rendering_rewrite/highlight_constants.js +++ b/core/renderers/block_rendering_rewrite/highlight_constants.js @@ -19,7 +19,7 @@ */ /** - * @fileoverview Methods for graphically rendering a block as SVG. + * @fileoverview Objects for rendering highlights on blocks. * @author fenichel@google.com (Rachel Fenichel) */ diff --git a/core/renderers/block_rendering_rewrite/measurables.js b/core/renderers/block_rendering_rewrite/measurables.js index 95f32c899..be247d114 100644 --- a/core/renderers/block_rendering_rewrite/measurables.js +++ b/core/renderers/block_rendering_rewrite/measurables.js @@ -351,7 +351,6 @@ goog.inherits(Blockly.blockRendering.Hat, Blockly.blockRendering.Measurable); Blockly.blockRendering.SquareCorner = function() { Blockly.blockRendering.SquareCorner.superClass_.constructor.call(this); this.type = 'square corner'; - // TODO: Is this the right height? this.height = Blockly.blockRendering.constants.NOTCH.height; this.width = Blockly.blockRendering.constants.NO_PADDING; @@ -370,7 +369,6 @@ Blockly.blockRendering.RoundCorner = function() { this.width = Blockly.blockRendering.constants.CORNER_RADIUS; // The rounded corner extends into the next row by 4 so we only take the // height that is aligned with this row. - // TODO: Investigate. this.height = Blockly.blockRendering.constants.NOTCH.height; }; From fd398ce75a822f5a6537d5ede1acbc8e6dd7a42e Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 29 Jul 2019 16:04:44 -0700 Subject: [PATCH 8/9] Review cleanup --- .../block_render_draw.js | 2 +- .../block_render_draw_highlight.js | 43 ++++++++----------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/core/renderers/block_rendering_rewrite/block_render_draw.js b/core/renderers/block_rendering_rewrite/block_render_draw.js index 2298cb266..8085c76bd 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw.js @@ -202,7 +202,7 @@ Blockly.blockRendering.Drawer.prototype.drawRightSideRow_ = function(row) { Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() { var bottomRow = this.info_.bottomRow; var elems = bottomRow.elements; - this.highlighter_.drawBottomCorner(bottomRow); + this.highlighter_.drawBottomRow(bottomRow); this.positionNextConnection_(); this.steps_.push('v', bottomRow.height); for (var i = elems.length - 1; i >= 0; i--) { diff --git a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js index efe8d7826..4290edcd6 100644 --- a/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js +++ b/core/renderers/block_rendering_rewrite/block_render_draw_highlight.js @@ -93,40 +93,40 @@ Blockly.blockRendering.Highlighter.prototype.drawTopCorner = function(row) { Blockly.blockRendering.Highlighter.prototype.drawValueInput = function(row) { var input = row.getLastInput(); - var pathString = ''; + var steps = ''; if (this.RTL_) { var aboveTabHeight = -this.highlightOffset_; var belowTabHeight = row.height - input.connectionHeight + this.highlightOffset_; - pathString = + steps = Blockly.utils.svgPaths.lineOnAxis('v', aboveTabHeight) + this.puzzleTabPaths_.pathDown(this.RTL_) + Blockly.utils.svgPaths.lineOnAxis('v', belowTabHeight); } else { - pathString = + steps = Blockly.utils.svgPaths.moveTo(row.width, row.yPos) + this.puzzleTabPaths_.pathDown(this.RTL_); } - this.steps_.push(pathString); + this.steps_.push(steps); }; Blockly.blockRendering.Highlighter.prototype.drawStatementInput = function(row) { + var steps = ''; if (this.RTL_) { var innerHeight = row.height - (2 * this.insideCornerPaths_.height); - var steps = + steps = Blockly.utils.svgPaths.moveTo(row.statementEdge, row.yPos) + this.insideCornerPaths_.pathTop(this.RTL_) + Blockly.utils.svgPaths.lineOnAxis('v', innerHeight) + this.insideCornerPaths_.pathBottom(this.RTL_); - this.steps_.push(steps); } else { - var steps = + steps = Blockly.utils.svgPaths.moveTo(row.statementEdge, row.yPos + row.height) + this.insideCornerPaths_.pathBottom(this.RTL_); - this.steps_.push(steps); } + this.steps_.push(steps); }; Blockly.blockRendering.Highlighter.prototype.drawRightSideRow = function(row) { @@ -139,26 +139,21 @@ Blockly.blockRendering.Highlighter.prototype.drawRightSideRow = function(row) { } }; -Blockly.blockRendering.Highlighter.prototype.drawBottomCorner = function(_row) { +Blockly.blockRendering.Highlighter.prototype.drawBottomRow = function(_row) { var height = this.info_.height; - var elems = this.info_.bottomRow.elements; + // Highlight the vertical edge of the bottom row on the input side. + // Highlighting is always from the top left, both in LTR and RTL. if (this.RTL_) { this.steps_.push('V', height); - } - - for (var i = elems.length - 1; i >= 0; i--) { - var elem = elems[i]; - if (elem.type === 'square corner') { - if (!this.RTL_) { - this.steps_.push('M', - this.highlightOffset_ + ',' + - (height - this.highlightOffset_)); - } - } else if (elem.type === 'round corner') { - if (!this.RTL_) { - this.steps_.push(this.outsideCornerPaths_.bottomLeft(height)); - } + } else { + var cornerElem = this.info_.bottomRow.elements[0]; + if (cornerElem.type === 'square corner') { + this.steps_.push( + Blockly.utils.svgPaths.moveTo( + this.highlightOffset_, height - this.highlightOffset_)); + } else if (cornerElem.type === 'round corner') { + this.steps_.push(this.outsideCornerPaths_.bottomLeft(height)); } } }; From b74fe2a6ccc540b88d965d4f10be98d8853387f3 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 29 Jul 2019 16:09:03 -0700 Subject: [PATCH 9/9] lint --- core/renderers/block_rendering_rewrite/block_render_info.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/renderers/block_rendering_rewrite/block_render_info.js b/core/renderers/block_rendering_rewrite/block_render_info.js index f99e7e55d..af0a1e0f9 100644 --- a/core/renderers/block_rendering_rewrite/block_render_info.js +++ b/core/renderers/block_rendering_rewrite/block_render_info.js @@ -419,7 +419,7 @@ Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne // Next connections are shifted slightly to the left (in both LTR and RTL) // to make the dark path under the previous connection show through. return Blockly.blockRendering.constants.NOTCH_OFFSET_ROUNDED_CORNER_PREV;//+ - //(this.RTL ? 0.5 : - 0.5); + //(this.RTL ? 0.5 : - 0.5); } }