From ca1e49bf8ead42976ecc3e392c526828a6dc9e68 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 28 Oct 2019 17:34:15 -0700 Subject: [PATCH] Fields now go through blockSvg for colours. --- core/block.js | 4 ---- core/block_svg.js | 18 +++++++++++++++++- core/field_angle.js | 5 ++--- core/field_date.js | 4 ++-- core/field_dropdown.js | 4 ++-- core/renderers/common/path_object.js | 4 ++-- core/renderers/geras/path_object.js | 1 + core/renderers/geras/renderer.js | 1 - core/utils/colour.js | 3 ++- 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/core/block.js b/core/block.js index b896ac84b..65e054b31 100644 --- a/core/block.js +++ b/core/block.js @@ -889,7 +889,6 @@ Blockly.Block.prototype.setTooltip = function(newTip) { * @return {string} #RRGGBB string. */ Blockly.Block.prototype.getColour = function() { - // TODO: Can we remove this? return this.colour_; }; @@ -915,9 +914,6 @@ Blockly.Block.prototype.getHue = function() { * or a message reference string pointing to one of those two values. */ Blockly.Block.prototype.setColour = function(colour) { - // Set colour just stores these as properties on the block, but never uses - // them again. - // TODO: see if we can just get rid of these properties on the block. var parsed = Blockly.utils.colour.parseBlockColour(colour); this.hue_ = parsed.hue; this.colour_ = parsed.hex; diff --git a/core/block_svg.js b/core/block_svg.js index 364e8808b..523f771d2 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -1289,9 +1289,9 @@ Blockly.BlockSvg.prototype.setDeleteStyle = function(enable) { } }; + // Overrides of functions on Blockly.Block that take into account whether the // block has been rendered. - /** * Get the colour of a block. * @return {string} #RRGGBB string. @@ -1300,6 +1300,22 @@ Blockly.BlockSvg.prototype.getColour = function() { return this.pathObject.primaryColour; }; +/** + * Get the secondary colour of a block. + * @return {string} #RRGGBB string. + */ +Blockly.BlockSvg.prototype.getSecondaryColour = function() { + return this.pathObject.primaryColour; +}; + +/** + * Get the tertiary colour of a block. + * @return {string} #RRGGBB string. + */ +Blockly.BlockSvg.prototype.getTertiaryColour = function() { + return this.pathObject.primaryColour; +}; + /** * Change the colour of a block. * @param {number|string} colour HSV hue value, or #RRGGBB string. diff --git a/core/field_angle.js b/core/field_angle.js index dafed3810..7076d5760 100644 --- a/core/field_angle.js +++ b/core/field_angle.js @@ -269,9 +269,8 @@ Blockly.FieldAngle.prototype.showEditor_ = function() { var editor = this.dropdownCreate_(); Blockly.DropDownDiv.getContentDiv().appendChild(editor); - var pathObject = this.sourceBlock_.pathObject; - Blockly.DropDownDiv.setColour(pathObject.primaryColour, - pathObject.tertiaryColour); + Blockly.DropDownDiv.setColour(this.sourceBlock_.getColour(), + this.sourceBlock_.getTertiaryColour()); Blockly.DropDownDiv.showPositionedByField( this, this.dropdownDispose_.bind(this)); diff --git a/core/field_date.js b/core/field_date.js index b6fff8f2c..e22c9a6f0 100644 --- a/core/field_date.js +++ b/core/field_date.js @@ -130,8 +130,8 @@ Blockly.FieldDate.prototype.render_ = function() { * @package */ Blockly.FieldDate.prototype.applyColour = function() { - this.todayColour_ = this.sourceBlock_.pathObject.primaryColour; - this.selectedColour_ = this.sourceBlock_.pathObject.secondaryColour; + this.todayColour_ = this.sourceBlock_.getColour(); + this.selectedColour_ = this.sourceBlock_.getSecondaryColour(); this.updateEditor_(); }; diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 179f98e23..fe5866de1 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -472,9 +472,9 @@ Blockly.FieldDropdown.prototype.applyColour = function() { // Update arrow's colour. if (this.sourceBlock_ && this.arrow_) { if (this.sourceBlock_.isShadow()) { - this.arrow_.style.fill = this.sourceBlock_.pathObject.secondaryColour; + this.arrow_.style.fill = this.sourceBlock_.getSecondaryColour(); } else { - this.arrow_.style.fill = this.sourceBlock_.pathObject.primaryColour; + this.arrow_.style.fill = this.sourceBlock_.getColour(); } } }; diff --git a/core/renderers/common/path_object.js b/core/renderers/common/path_object.js index 015e2af52..64eede105 100644 --- a/core/renderers/common/path_object.js +++ b/core/renderers/common/path_object.js @@ -129,9 +129,9 @@ Blockly.blockRendering.PathObject.prototype.applyColour = function(isShadow) { /** * Update colour properties based on a triplet of colours. * @param {string} primary The primary colour. - * @param {string} secondary The secondary colour, or null to have the colourer + * @param {?string} secondary The secondary colour, or null to have the colourer * generate it. - * @param {string} tertiary The tertiary colour, or null to have the colourer + * @param {?string} tertiary The tertiary colour, or null to have the colourer * generate it. * @protected */ diff --git a/core/renderers/geras/path_object.js b/core/renderers/geras/path_object.js index e1e90b51f..134b52999 100644 --- a/core/renderers/geras/path_object.js +++ b/core/renderers/geras/path_object.js @@ -26,6 +26,7 @@ goog.provide('Blockly.geras.PathObject'); goog.require('Blockly.blockRendering.IPathObject'); goog.require('Blockly.utils.dom'); +goog.require('Blockly.utils.object'); /** diff --git a/core/renderers/geras/renderer.js b/core/renderers/geras/renderer.js index b01597ffd..fcd5e516d 100644 --- a/core/renderers/geras/renderer.js +++ b/core/renderers/geras/renderer.js @@ -106,7 +106,6 @@ Blockly.geras.Renderer.prototype.makePathObject = function(root) { return new Blockly.geras.PathObject(root); }; - /** * Create a new instance of the renderer's highlight constant provider. * @return {!Blockly.geras.HighlightConstantProvider} The highlight constant diff --git a/core/utils/colour.js b/core/utils/colour.js index 08aeae89b..1a0f50dd0 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -217,8 +217,9 @@ Blockly.utils.colour.names = { * definition. * @param {number|string} colour HSV hue value (0 to 360), #RRGGBB string, * or a message reference string pointing to one of those two values. - * @return {{hue: ?number, colour: string}} An object containing the colour as + * @return {{hue: ?number, hex: string}} An object containing the colour as * a #RRGGBB string, and the hue if the input was an HSV hue value. + * @throws {Error} If If the colour cannot be parsed. */ Blockly.utils.colour.parseBlockColour = function(colour) { var dereferenced = (typeof colour == 'string') ?