Skip to content

Commit 2220214

Browse files
committed
Rewrite it to work in Safari and improve color accuracy
1 parent c490f08 commit 2220214

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

core/field_angle.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,22 @@ Blockly.FieldAngle.RADIUS = Blockly.FieldAngle.HALF
137137
Blockly.FieldAngle.CENTER_RADIUS = 2;
138138

139139
/**
140-
* Path to the arrow svg icon.
140+
* SVG path data for arrow icon.
141141
*/
142-
Blockly.FieldAngle.ARROW_SVG_PATH = 'icons/arrow.svg';
142+
Blockly.FieldAngle.ARROW_SVG_PATH_DATA =
143+
'M 0.0189 -1.3178' +
144+
' L -4.4901 -0.5663' +
145+
' C -4.7532 -0.5224 -4.9811 -0.2606 -4.9811 0.0156' +
146+
' C -4.9811 0.2836 -4.7613 0.5522 -4.4901 0.5974' +
147+
' L 0.0189 1.3489' +
148+
' L 0.0189 3.0185' +
149+
' C 0.0189 3.5625 0.3833 3.752 0.8327 3.4269' +
150+
' L 4.641 0.6721' +
151+
' C 5.0982 0.3414 5.0957 -0.1853 4.6527 -0.5168' +
152+
' L 0.821 -3.3842' +
153+
' C 0.3756 -3.7175 0.0189 -3.5381 0.0189 -2.9874' +
154+
' L 0.0189 -1.3178' +
155+
' Z';
143156

144157
/**
145158
* Clean up this FieldAngle, as well as the inherited FieldTextInput.
@@ -234,27 +247,17 @@ Blockly.FieldAngle.prototype.showEditor_ = function() {
234247
'r': Blockly.FieldAngle.HANDLE_RADIUS,
235248
'class': 'blocklyAngleDragHandle'
236249
}, this.handle_);
237-
this.arrowSvg_ = Blockly.utils.createSvgElement('image',
250+
this.arrowSvg_ = Blockly.utils.createSvgElement('path',
238251
{
239252
'width': Blockly.FieldAngle.ARROW_WIDTH,
240253
'height': Blockly.FieldAngle.ARROW_WIDTH,
241254
'x': -Blockly.FieldAngle.ARROW_WIDTH / 2,
242255
'y': -Blockly.FieldAngle.ARROW_WIDTH / 2,
243-
'class': 'blocklyAngleDragArrow'
256+
'class': 'blocklyAngleDragArrow',
257+
'fill': parentBlock.getColour(),
258+
'd': Blockly.FieldAngle.ARROW_SVG_PATH_DATA
244259
},
245260
this.handle_);
246-
this.arrowSvg_.setAttributeNS(
247-
'http://www.w3.org/1999/xlink',
248-
'xlink:href',
249-
Blockly.mainWorkspace.options.pathToMedia + Blockly.FieldAngle.ARROW_SVG_PATH
250-
);
251-
var blockHSL = goog.color.hexToHsl(parentBlock.getColour());
252-
// -214.86 stems from the blue hue in 'Blockly.FieldAngle.ARROW_SVG_PATH'
253-
this.arrowSvg_.setAttribute(
254-
'filter',
255-
'hue-rotate(' + (-214.86 + blockHSL[0]) + 'deg) saturate(' +
256-
blockHSL[1] + ') brightness(' + (blockHSL[2] * 1.8) + ')'
257-
);
258261

259262
Blockly.DropDownDiv.setColour(parentBlock.getColour(), this.sourceBlock_.getColourTertiary());
260263
Blockly.DropDownDiv.setCategory(parentBlock.getCategory());

0 commit comments

Comments
 (0)