Fields now go through blockSvg for colours.

This commit is contained in:
Rachel Fenichel
2019-10-28 17:34:15 -07:00
parent f4bbeb0688
commit ca1e49bf8e
9 changed files with 28 additions and 16 deletions

View File

@@ -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;

View File

@@ -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.

View File

@@ -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));

View File

@@ -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_();
};

View File

@@ -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();
}
}
};

View File

@@ -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
*/

View File

@@ -26,6 +26,7 @@ goog.provide('Blockly.geras.PathObject');
goog.require('Blockly.blockRendering.IPathObject');
goog.require('Blockly.utils.dom');
goog.require('Blockly.utils.object');
/**

View File

@@ -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

View File

@@ -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') ?