Skip to content

Commit

Permalink
fix: re-expose HSV_VALUE and HSV_SATURATION as settable properties on…
Browse files Browse the repository at this point in the history
… Blockly (google#5821)
  • Loading branch information
rachel-fenichel authored and alschmiedt committed Dec 15, 2021
1 parent b8cc983 commit 0e5f3ce
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 28 deletions.
32 changes: 30 additions & 2 deletions core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,36 @@ Object.defineProperties(exports, {
common.setSelected(newSelection);
},
},
/**
* The richness of block colours, regardless of the hue.
* Must be in the range of 0 (inclusive) to 1 (exclusive).
* @name Blockly.HSV_SATURATION
* @type {number}
* @suppress {checkTypes}
*/
HSV_SATURATION: {
get: function() {
return utils.colour.getHsvSaturation();
},
set: function(newValue) {
utils.colour.setHsvSaturation(newValue);
},
},
/**
* The intensity of block colours, regardless of the hue.
* Must be in the range of 0 (inclusive) to 1 (exclusive).
* @name Blockly.HSV_VALUE
* @type {number}
* @suppress {checkTypes}
*/
HSV_VALUE: {
get: function() {
return utils.colour.getHsvValue();
},
set: function(newValue) {
utils.colour.setHsvValue(newValue);
},
},
});

/**
Expand Down Expand Up @@ -639,8 +669,6 @@ exports.COLLAPSE_CHARS = internalConstants.COLLAPSE_CHARS;
exports.LONGPRESS = internalConstants.LONGPRESS;
exports.SOUND_LIMIT = internalConstants.SOUND_LIMIT;
exports.DRAG_STACK = internalConstants.DRAG_STACK;
exports.HSV_SATURATION = internalConstants.HSV_SATURATION;
exports.HSV_VALUE = internalConstants.HSV_VALUE;
exports.SPRITE = internalConstants.SPRITE;
exports.DRAG_NONE = internalConstants.DRAG_NONE;
exports.DRAG_STICKY = internalConstants.DRAG_STICKY;
Expand Down
16 changes: 0 additions & 16 deletions core/internal_constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,6 @@ exports.SOUND_LIMIT = SOUND_LIMIT;
const DRAG_STACK = true;
exports.DRAG_STACK = DRAG_STACK;

/**
* The richness of block colours, regardless of the hue.
* Must be in the range of 0 (inclusive) to 1 (exclusive).
* @alias Blockly.internalConstants.HSV_SATURATION
*/
const HSV_SATURATION = 0.45;
exports.HSV_SATURATION = HSV_SATURATION;

/**
* The intensity of block colours, regardless of the hue.
* Must be in the range of 0 (inclusive) to 1 (exclusive).
* @alias Blockly.internalConstants.HSV_VALUE
*/
const HSV_VALUE = 0.65;
exports.HSV_VALUE = HSV_VALUE;

/**
* Sprited icons and images.
* @alias Blockly.internalConstants.SPRITE
Expand Down
68 changes: 61 additions & 7 deletions core/utils/colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,76 @@

/**
* @fileoverview Utility methods for colour manipulation.
* These methods are not specific to Blockly, and could be factored out into
* a JavaScript framework such as Closure.
*/
'use strict';

/**
* Utility methods for colour manipulation.
* These methods are not specific to Blockly, and could be factored out into
* a JavaScript framework such as Closure.
* @namespace Blockly.utils.colour
*/
goog.module('Blockly.utils.colour');

const internalConstants = goog.require('Blockly.internalConstants');
/**
* The richness of block colours, regardless of the hue.
* Must be in the range of 0 (inclusive) to 1 (exclusive).
* @alias Blockly.utils.colour.hsvSaturation
* @package
*/
let hsvSaturation = 0.45;

/**
* Get the richness of block colours, regardless of the hue.
* @alias Blockly.utils.colour.getHsvSaturation
* @return {number} The current richness.
* @package
*/
const getHsvSaturation = function() {
return hsvSaturation;
};
exports.getHsvSaturation = getHsvSaturation;

/**
* Set the richness of block colours, regardless of the hue.
* @param {number} newSaturation The new richness, in the range of 0
* (inclusive) to 1 (exclusive)
* @alias Blockly.utils.colour.setHsvSaturation
* @package
*/
const setHsvSaturation = function(newSaturation) {
hsvSaturation = newSaturation;
};
exports.setHsvSaturation = setHsvSaturation;

/**
* The intensity of block colours, regardless of the hue.
* Must be in the range of 0 (inclusive) to 1 (exclusive).
* @alias Blockly.utils.colour.hsvValue
* @package
*/
let hsvValue = 0.65;

/**
* Get the intensity of block colours, regardless of the hue.
* @alias Blockly.utils.colour.getHsvValue
* @return {number} The current intensity.
* @package
*/
const getHsvValue = function() {
return hsvValue;
};
exports.getHsvValue = getHsvValue;

/**
* Set the intensity of block colours, regardless of the hue.
* @param {number} newValue The new intensity, in the range of 0
* (inclusive) to 1 (exclusive)
* @alias Blockly.utils.colour.setHsvValue
* @package
*/
const setHsvValue = function(newValue) {
hsvValue = newValue;
};
exports.setHsvValue = setHsvValue;

/**
* Parses a colour from a string.
Expand Down Expand Up @@ -228,7 +283,6 @@ exports.names = names;
* @alias Blockly.utils.colour.hueToHex
*/
const hueToHex = function(hue) {
return hsvToHex(
hue, internalConstants.HSV_SATURATION, internalConstants.HSV_VALUE * 255);
return hsvToHex(hue, hsvSaturation, hsvValue * 255);
};
exports.hueToHex = hueToHex;
4 changes: 1 addition & 3 deletions core/utils/parsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
goog.module('Blockly.utils.parsing');

const colourUtils = goog.require('Blockly.utils.colour');
const internalConstants = goog.require('Blockly.internalConstants');
const stringUtils = goog.require('Blockly.utils.string');
const {Msg} = goog.require('Blockly.Msg');

Expand Down Expand Up @@ -243,8 +242,7 @@ const parseBlockColour = function(colour) {
return {
hue: hue,
hex: colourUtils.hsvToHex(
hue, internalConstants.HSV_SATURATION,
internalConstants.HSV_VALUE * 255),
hue, colourUtils.getHsvSaturation(), colourUtils.getHsvValue() * 255),
};
} else {
const hex = colourUtils.parse(dereferenced);
Expand Down

0 comments on commit 0e5f3ce

Please sign in to comment.