Skip to content

Commit

Permalink
Separate overlapping emboss filter and disabled pattern across multip…
Browse files Browse the repository at this point in the history
…le Blockly instances. Issue 184.
  • Loading branch information
NeilFraser committed Sep 28, 2015
1 parent abd8833 commit 8ecfab0
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 33 deletions.
17 changes: 9 additions & 8 deletions blockly_compressed.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion blockly_uncompressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var dir = this.BLOCKLY_DIR.match(/[^\/]+$/)[0];
goog.addDependency("../../../" + dir + "/core/block.js", ['Blockly.Block'], ['Blockly.Blocks', 'Blockly.Comment', 'Blockly.Connection', 'Blockly.Input', 'Blockly.Mutator', 'Blockly.Warning', 'Blockly.Workspace', 'Blockly.Xml', 'goog.array', 'goog.asserts', 'goog.math.Coordinate', 'goog.string']);
goog.addDependency("../../../" + dir + "/core/block_svg.js", ['Blockly.BlockSvg'], ['Blockly.Block', 'Blockly.ContextMenu', 'goog.Timer', 'goog.asserts', 'goog.dom', 'goog.math.Coordinate']);
goog.addDependency("../../../" + dir + "/core/blockly.js", ['Blockly'], ['Blockly.BlockSvg', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Generator', 'Blockly.Msg', 'Blockly.Procedures', 'Blockly.Toolbox', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.inject', 'Blockly.utils', 'goog.color', 'goog.userAgent']);
goog.addDependency("../../../" + dir + "/core/blocks.js", ['Blockly.Blocks'], ['goog.asserts']);
goog.addDependency("../../../" + dir + "/core/blocks.js", ['Blockly.Blocks'], []);
goog.addDependency("../../../" + dir + "/core/bubble.js", ['Blockly.Bubble'], ['Blockly.Workspace', 'goog.dom', 'goog.math', 'goog.userAgent']);
goog.addDependency("../../../" + dir + "/core/comment.js", ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Icon', 'goog.userAgent']);
goog.addDependency("../../../" + dir + "/core/connection.js", ['Blockly.Connection', 'Blockly.ConnectionDB'], ['goog.dom']);
Expand Down
3 changes: 2 additions & 1 deletion core/block_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,8 @@ Blockly.BlockSvg.prototype.updateDisabled = function() {
if (!hasClass) {
Blockly.addClass_(/** @type {!Element} */ (this.svgGroup_),
'blocklyDisabled');
this.svgPath_.setAttribute('fill', 'url(#blocklyDisabledPattern)');
this.svgPath_.setAttribute('fill',
'url(#' + this.workspace.options.disabledPatternId + ')');
}
} else {
if (hasClass) {
Expand Down
2 changes: 1 addition & 1 deletion core/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @author [email protected] (Ellen Spertus)
*/
'use strict';
goog.require('goog.asserts');


/**
* Name space for the Blocks singleton.
Expand Down
8 changes: 6 additions & 2 deletions core/bubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Blockly.Bubble.prototype.autoLayout_ = true;
Blockly.Bubble.prototype.createDom_ = function(content, hasResize) {
/* Create the bubble. Here's the markup that will be generated:
<g>
<g filter="url(#blocklyEmboss)">
<g filter="url(#blocklyEmbossFilter837493)">
<path d="... Z" />
<rect class="blocklyDraggable" rx="8" ry="8" width="180" height="180"/>
</g>
Expand All @@ -210,7 +210,8 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) {
</g>
*/
this.bubbleGroup_ = Blockly.createSvgElement('g', {}, null);
var filter = {'filter': 'url(#blocklyEmboss)'};
var filter =
{'filter': 'url(#' + this.workspace_.options.embossFilterId + ')'};
if (goog.userAgent.getUserAgentString().indexOf('JavaFX') != -1) {
// Multiple reports that JavaFX can't handle filters. UserAgent:
// Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.44
Expand Down Expand Up @@ -568,6 +569,9 @@ Blockly.Bubble.prototype.dispose = function() {
// Dispose of and unlink the bubble.
goog.dom.removeNode(this.bubbleGroup_);
this.bubbleGroup_ = null;
this.bubbleArrow_ = null;
this.bubbleBack_ = null;
this.resizeGroup_ = null;
this.workspace_ = null;
this.content_ = null;
this.shape_ = null;
Expand Down
34 changes: 15 additions & 19 deletions core/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ Blockly.createDom_ = function(container, options) {
</defs>
*/
var defs = Blockly.createSvgElement('defs', {}, svg);
var filter, feSpecularLighting, feMerge;
var rnd = String(Math.random()).substring(2);
/*
<filter id="blocklyEmboss">
<filter id="blocklyEmbossFilter837493">
<feGaussianBlur in="SourceAlpha" stdDeviation="1" result="blur"/>
<feSpecularLighting in="blur" surfaceScale="1" specularConstant="0.5"
specularExponent="10" lighting-color="white"
Expand All @@ -307,51 +307,47 @@ Blockly.createDom_ = function(container, options) {
k1="0" k2="1" k3="1" k4="0"/>
</filter>
*/
filter = Blockly.createSvgElement('filter', {'id': 'blocklyEmboss'}, defs);
var embossFilter = Blockly.createSvgElement('filter',
{'id': 'blocklyEmbossFilter' + rnd}, defs);
Blockly.createSvgElement('feGaussianBlur',
{'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, filter);
feSpecularLighting = Blockly.createSvgElement('feSpecularLighting',
{'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter);
var feSpecularLighting = Blockly.createSvgElement('feSpecularLighting',
{'in': 'blur', 'surfaceScale': 1, 'specularConstant': 0.5,
'specularExponent': 10, 'lighting-color': 'white', 'result': 'specOut'},
filter);
embossFilter);
Blockly.createSvgElement('fePointLight',
{'x': -5000, 'y': -10000, 'z': 20000}, feSpecularLighting);
Blockly.createSvgElement('feComposite',
{'in': 'specOut', 'in2': 'SourceAlpha', 'operator': 'in',
'result': 'specOut'}, filter);
'result': 'specOut'}, embossFilter);
Blockly.createSvgElement('feComposite',
{'in': 'SourceGraphic', 'in2': 'specOut', 'operator': 'arithmetic',
'k1': 0, 'k2': 1, 'k3': 1, 'k4': 0}, filter);
'k1': 0, 'k2': 1, 'k3': 1, 'k4': 0}, embossFilter);
options.embossFilterId = embossFilter.id;
/*
<filter id="blocklyShadowFilter">
<feGaussianBlur stdDeviation="2"/>
</filter>
*/
filter = Blockly.createSvgElement('filter',
{'id': 'blocklyShadowFilter'}, defs);
Blockly.createSvgElement('feGaussianBlur', {'stdDeviation': 2}, filter);
/*
<pattern id="blocklyDisabledPattern" patternUnits="userSpaceOnUse"
<pattern id="blocklyDisabledPattern837493" patternUnits="userSpaceOnUse"
width="10" height="10">
<rect width="10" height="10" fill="#aaa" />
<path d="M 0 0 L 10 10 M 10 0 L 0 10" stroke="#cc0" />
</pattern>
*/
var disabledPattern = Blockly.createSvgElement('pattern',
{'id': 'blocklyDisabledPattern', 'patternUnits': 'userSpaceOnUse',
{'id': 'blocklyDisabledPattern' + rnd,
'patternUnits': 'userSpaceOnUse',
'width': 10, 'height': 10}, defs);
Blockly.createSvgElement('rect',
{'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern);
Blockly.createSvgElement('path',
{'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, disabledPattern);
options.disabledPatternId = disabledPattern.id;
/*
<pattern id="blocklyGridPattern837493" patternUnits="userSpaceOnUse">
<rect stroke="#888" />
<rect stroke="#888" />
</pattern>
*/
var gridPattern = Blockly.createSvgElement('pattern',
{'id': 'blocklyGridPattern' + String(Math.random()).substring(2),
{'id': 'blocklyGridPattern' + rnd,
'patternUnits': 'userSpaceOnUse'}, defs);
if (options.gridOptions['length'] > 0 && options.gridOptions['spacing'] > 0) {
Blockly.createSvgElement('line',
Expand Down
2 changes: 1 addition & 1 deletion core/workspace_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) {
</g>
*/
this.svgGroup_ = Blockly.createSvgElement('g',
{'class': 'blocklyWorkspace'}, null);
{'class': 'blocklyWorkspace'}, null);
if (opt_backgroundClass) {
this.svgBackground_ = Blockly.createSvgElement('rect',
{'height': '100%', 'width': '100%',
Expand Down

0 comments on commit 8ecfab0

Please sign in to comment.