Separate overlapping emboss filter and disabled pattern across multiple Blockly instances. Issue 184.

This commit is contained in:
Neil Fraser
2015-09-28 12:17:54 -07:00
parent abd8833dbc
commit 8ecfab014f
7 changed files with 35 additions and 33 deletions

View File

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

View File

@@ -23,7 +23,7 @@
* @author spertus@google.com (Ellen Spertus)
*/
'use strict';
goog.require('goog.asserts');
/**
* Name space for the Blocks singleton.

View File

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

View File

@@ -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"
@@ -307,43 +307,39 @@ 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" />
@@ -351,7 +347,7 @@ Blockly.createDom_ = function(container, options) {
</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',

View File

@@ -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%',