mirror of
https://github.com/google/blockly.git
synced 2026-01-10 18:37:09 +01:00
Moved setHighlighted and setDisabled into the path object.
This commit is contained in:
@@ -76,23 +76,6 @@ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) {
|
||||
*/
|
||||
this.pathObject = workspace.getRenderer().makePathObject(this.svgGroup_);
|
||||
|
||||
// The next two paths are set only for backwards compatibility reasons.
|
||||
/**
|
||||
* The primary path of the block.
|
||||
* @type {SVGElement}
|
||||
* @private
|
||||
*/
|
||||
this.svgPath_ = this.pathObject.svgPath || null;
|
||||
|
||||
/**
|
||||
* The light path of the block.
|
||||
* @type {SVGElement}
|
||||
* @private
|
||||
*/
|
||||
this.svgPathLight_ = this.pathObject.svgPathLight || null;
|
||||
|
||||
this.svgPath_.tooltip = this;
|
||||
|
||||
/** @type {boolean} */
|
||||
this.rendered = false;
|
||||
|
||||
@@ -115,7 +98,9 @@ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) {
|
||||
this.useDragSurface_ =
|
||||
Blockly.utils.is3dSupported() && !!workspace.getBlockDragSurface();
|
||||
|
||||
Blockly.Tooltip.bindMouseEvents(this.svgPath_);
|
||||
var svgPath = this.pathObject.svgPath;
|
||||
svgPath.tooltip = this;
|
||||
Blockly.Tooltip.bindMouseEvents(svgPath);
|
||||
Blockly.BlockSvg.superClass_.constructor.call(this,
|
||||
workspace, prototypeName, opt_id);
|
||||
|
||||
@@ -1023,8 +1008,6 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) {
|
||||
blockWorkspace.resizeContents();
|
||||
// Sever JavaScript to DOM connections.
|
||||
this.svgGroup_ = null;
|
||||
this.svgPath_ = null;
|
||||
this.svgPathLight_ = null;
|
||||
Blockly.utils.dom.stopTextWidthCache();
|
||||
};
|
||||
|
||||
@@ -1060,15 +1043,13 @@ Blockly.BlockSvg.prototype.updateDisabled = function() {
|
||||
var added = Blockly.utils.dom.addClass(
|
||||
/** @type {!Element} */ (this.svgGroup_), 'blocklyDisabled');
|
||||
if (added) {
|
||||
this.svgPath_.setAttribute('fill',
|
||||
'url(#' +
|
||||
this.workspace.getRenderer().getConstants().disabledPatternId + ')');
|
||||
this.pathObject.setDisabled(true, this.isShadow());
|
||||
}
|
||||
} else {
|
||||
var removed = Blockly.utils.dom.removeClass(
|
||||
/** @type {!Element} */ (this.svgGroup_), 'blocklyDisabled');
|
||||
if (removed) {
|
||||
this.applyColour();
|
||||
this.pathObject.setDisabled(false, this.isShadow());
|
||||
}
|
||||
}
|
||||
var children = this.getChildren(false);
|
||||
@@ -1252,15 +1233,7 @@ Blockly.BlockSvg.prototype.setHighlighted = function(highlighted) {
|
||||
if (!this.rendered) {
|
||||
return;
|
||||
}
|
||||
if (highlighted) {
|
||||
this.svgPath_.setAttribute('filter',
|
||||
'url(#' +
|
||||
this.workspace.getRenderer().getConstants().embossFilterId + ')');
|
||||
this.svgPathLight_.style.display = 'none';
|
||||
} else {
|
||||
this.svgPath_.setAttribute('filter', 'none');
|
||||
this.svgPathLight_.style.display = 'inline';
|
||||
}
|
||||
this.pathObject.setHighlighted(highlighted);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -232,7 +232,8 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) {
|
||||
*/
|
||||
this.bubbleGroup_ = Blockly.utils.dom.createSvgElement('g', {}, null);
|
||||
var filter =
|
||||
{'filter': 'url(#' + this.workspace_.options.embossFilterId + ')'};
|
||||
{'filter': 'url(#' +
|
||||
this.workspace_.getRenderer().getConstants().embossFilterId + ')'};
|
||||
if (Blockly.utils.userAgent.JAVA_FX) {
|
||||
// Multiple reports that JavaFX can't handle filters.
|
||||
// https://github.com/google/blockly/issues/99
|
||||
@@ -240,7 +241,8 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) {
|
||||
}
|
||||
var bubbleEmboss = Blockly.utils.dom.createSvgElement('g',
|
||||
filter, this.bubbleGroup_);
|
||||
this.bubbleArrow_ = Blockly.utils.dom.createSvgElement('path', {}, bubbleEmboss);
|
||||
this.bubbleArrow_ = Blockly.utils.dom.createSvgElement('path', {},
|
||||
bubbleEmboss);
|
||||
this.bubbleBack_ = Blockly.utils.dom.createSvgElement('rect',
|
||||
{
|
||||
'class': 'blocklyDraggable',
|
||||
|
||||
@@ -154,7 +154,6 @@ Blockly.Mutator.prototype.createEditor_ = function() {
|
||||
// If you want to enable disabling, also remove the
|
||||
// event filter from workspaceChanged_ .
|
||||
disable: false,
|
||||
disabledPatternId: this.block_.workspace.options.disabledPatternId,
|
||||
languageTree: quarkXml,
|
||||
parentWorkspace: this.block_.workspace,
|
||||
pathToMedia: this.block_.workspace.options.pathToMedia,
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
goog.provide('Blockly.blockRendering.ConstantProvider');
|
||||
|
||||
goog.require('Blockly.utils.dom');
|
||||
goog.require('Blockly.utils.svgPaths');
|
||||
|
||||
|
||||
@@ -134,6 +135,34 @@ Blockly.blockRendering.ConstantProvider = function() {
|
||||
* @const
|
||||
*/
|
||||
this.JAGGED_TEETH_WIDTH = 6;
|
||||
|
||||
/**
|
||||
* The ID of the emboss filter, or the empty string if no filter is set.
|
||||
* @type {string}
|
||||
* @package
|
||||
*/
|
||||
this.embossFilterId = '';
|
||||
|
||||
/**
|
||||
* The <filter> element to use for highlighting, or null if not set.
|
||||
* @type {SVGElement}
|
||||
* @private
|
||||
*/
|
||||
this.embossFilter_ = null;
|
||||
|
||||
/**
|
||||
* The ID of the disabled pattern, or the empty string if no pattern is set.
|
||||
* @type {string}
|
||||
* @package
|
||||
*/
|
||||
this.disabledPatternId = '';
|
||||
|
||||
/**
|
||||
* The <pattern> element to use for disabled blocks, or null if not set.
|
||||
* @type {SVGElement}
|
||||
* @private
|
||||
*/
|
||||
this.disabledPattern_ = null;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -180,6 +209,20 @@ Blockly.blockRendering.ConstantProvider.prototype.init = function() {
|
||||
this.OUTSIDE_CORNERS = this.makeOutsideCorners();
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispose of this constants provider.
|
||||
* Delete all DOM elements that this provider created.
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.ConstantProvider.prototype.dispose = function() {
|
||||
if (this.embossFilter_) {
|
||||
Blockly.utils.dom.removeNode(this.embossFilter_);
|
||||
}
|
||||
if (this.disabledPattern_) {
|
||||
Blockly.utils.dom.removeNode(this.disabledPattern_);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {!Object} An object containing sizing and path information about
|
||||
* collapsed block indicators.
|
||||
@@ -463,6 +506,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg) {
|
||||
'k4': 0
|
||||
}, embossFilter);
|
||||
this.embossFilterId = embossFilter.id;
|
||||
this.embossFilter_ = embossFilter;
|
||||
|
||||
/*
|
||||
<pattern id="blocklyDisabledPattern837493" patternUnits="userSpaceOnUse"
|
||||
@@ -483,4 +527,5 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg) {
|
||||
Blockly.utils.dom.createSvgElement('path',
|
||||
{'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, disabledPattern);
|
||||
this.disabledPatternId = disabledPattern.id;
|
||||
this.disabledPattern_ = disabledPattern;
|
||||
};
|
||||
|
||||
@@ -25,15 +25,18 @@
|
||||
|
||||
goog.provide('Blockly.blockRendering.IPathObject');
|
||||
|
||||
goog.requireType('Blockly.blockRendering.ConstantProvider');
|
||||
goog.requireType('Blockly.Theme');
|
||||
|
||||
|
||||
/**
|
||||
* An interface for a block's path object.
|
||||
* @param {!SVGElement} _root The root SVG element.
|
||||
* @param {!Blockly.blockRendering.ConstantProvider} _constants The renderer's
|
||||
* constants.
|
||||
* @interface
|
||||
*/
|
||||
Blockly.blockRendering.IPathObject = function(_root) {};
|
||||
Blockly.blockRendering.IPathObject = function(_root, _constants) {};
|
||||
|
||||
/**
|
||||
* Apply the stored colours to the block's path, taking into account whether
|
||||
@@ -55,3 +58,17 @@ Blockly.blockRendering.IPathObject.prototype.setStyle;
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.IPathObject.prototype.flipRTL;
|
||||
|
||||
/**
|
||||
* Set whether the block shows a highlight or not. Block highlighting is
|
||||
* often used to visually mark blocks currently being executed.
|
||||
* @param {boolean} highlighted True if highlighted.
|
||||
*/
|
||||
Blockly.blockRendering.IPathObject.prototype.setHighlighted;
|
||||
|
||||
/**
|
||||
* Set whether the block shows a disable pattern or not.
|
||||
* @param {boolean} disabled True if disabled.
|
||||
* @param {boolean} isShadow True if the block is a shadow block.
|
||||
*/
|
||||
Blockly.blockRendering.IPathObject.prototype.setDisabled;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
goog.provide('Blockly.blockRendering.PathObject');
|
||||
|
||||
goog.require('Blockly.blockRendering.ConstantProvider');
|
||||
goog.require('Blockly.blockRendering.IPathObject');
|
||||
goog.require('Blockly.Theme');
|
||||
goog.require('Blockly.utils.dom');
|
||||
@@ -33,11 +34,18 @@ goog.require('Blockly.utils.dom');
|
||||
* An object that handles creating and setting each of the SVG elements
|
||||
* used by the renderer.
|
||||
* @param {!SVGElement} root The root SVG element.
|
||||
* @param {!Blockly.blockRendering.ConstantProvider} constants The renderer's
|
||||
* constants.
|
||||
* @constructor
|
||||
* @implements {Blockly.blockRendering.IPathObject}
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.PathObject = function(root) {
|
||||
Blockly.blockRendering.PathObject = function(root, constants) {
|
||||
/**
|
||||
* The renderer's constant provider.
|
||||
* @type {!Blockly.blockRendering.ConstantProvider}
|
||||
*/
|
||||
this.constants_ = constants;
|
||||
this.svgRoot = root;
|
||||
|
||||
/**
|
||||
@@ -111,3 +119,33 @@ Blockly.blockRendering.PathObject.prototype.applyColour = function(isShadow) {
|
||||
Blockly.blockRendering.PathObject.prototype.setStyle = function(blockStyle) {
|
||||
this.style = blockStyle;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set whether the block shows a highlight or not. Block highlighting is
|
||||
* often used to visually mark blocks currently being executed.
|
||||
* @param {boolean} highlighted True if highlighted.
|
||||
*/
|
||||
Blockly.blockRendering.PathObject.prototype.setHighlighted = function(
|
||||
highlighted) {
|
||||
if (highlighted) {
|
||||
this.svgPath.setAttribute('filter',
|
||||
'url(#' + this.constants_.embossFilterId + ')');
|
||||
} else {
|
||||
this.svgPath.setAttribute('filter', 'none');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set whether the block shows a disable pattern or not.
|
||||
* @param {boolean} disabled True if disabled.
|
||||
* @param {boolean} isShadow True if the block is a shadow block.
|
||||
*/
|
||||
Blockly.blockRendering.PathObject.prototype.setDisabled = function(disabled,
|
||||
isShadow) {
|
||||
if (disabled) {
|
||||
this.svgPath.setAttribute('fill',
|
||||
'url(#' + this.constants_.disabledPatternId + ')');
|
||||
} else {
|
||||
this.applyColour(isShadow);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -122,7 +122,9 @@ Blockly.blockRendering.Renderer.prototype.makeCursorDrawer = function(
|
||||
* @package
|
||||
*/
|
||||
Blockly.blockRendering.Renderer.prototype.makePathObject = function(root) {
|
||||
return new Blockly.blockRendering.PathObject(root);
|
||||
return new Blockly.blockRendering.PathObject(root,
|
||||
/** @type {!Blockly.blockRendering.ConstantProvider} */ (this.constants_));
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,9 @@
|
||||
|
||||
goog.provide('Blockly.geras.PathObject');
|
||||
|
||||
goog.require('Blockly.blockRendering.ConstantProvider');
|
||||
goog.require('Blockly.blockRendering.IPathObject');
|
||||
goog.require('Blockly.geras.ConstantProvider');
|
||||
goog.require('Blockly.Theme');
|
||||
goog.require('Blockly.utils.dom');
|
||||
goog.require('Blockly.utils.object');
|
||||
@@ -34,11 +36,19 @@ goog.require('Blockly.utils.object');
|
||||
* An object that handles creating and setting each of the SVG elements
|
||||
* used by the renderer.
|
||||
* @param {!SVGElement} root The root SVG element.
|
||||
* @param {!Blockly.blockRendering.ConstantProvider} constants The renderer's
|
||||
* constants.
|
||||
* @constructor
|
||||
* @implements {Blockly.blockRendering.IPathObject}
|
||||
* @package
|
||||
*/
|
||||
Blockly.geras.PathObject = function(root) {
|
||||
Blockly.geras.PathObject = function(root, constants) {
|
||||
/**
|
||||
* The renderer's constant provider.
|
||||
* @type {!Blockly.geras.ConstantProvider}
|
||||
*/
|
||||
this.constants_ = /** @type {!Blockly.geras.ConstantProvider} */ (constants);
|
||||
|
||||
this.svgRoot = root;
|
||||
|
||||
// The order of creation for these next three matters, because that
|
||||
@@ -140,3 +150,33 @@ Blockly.geras.PathObject.prototype.setStyle = function(blockStyle) {
|
||||
Blockly.utils.colour.blend('#000', this.style.colourPrimary, 0.2) ||
|
||||
this.colourDark;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set whether the block shows a highlight or not. Block highlighting is
|
||||
* often used to visually mark blocks currently being executed.
|
||||
* @param {boolean} highlighted True if highlighted.
|
||||
*/
|
||||
Blockly.geras.PathObject.prototype.setHighlighted = function(highlighted) {
|
||||
if (highlighted) {
|
||||
this.svgPath.setAttribute('filter',
|
||||
'url(#' + this.constants_.embossFilterId + ')');
|
||||
this.svgPathLight.style.display = 'none';
|
||||
} else {
|
||||
this.svgPath.setAttribute('filter', 'none');
|
||||
this.svgPathLight.style.display = 'inline';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set whether the block shows a disable pattern or not.
|
||||
* @param {boolean} disabled True if disabled.
|
||||
* @param {boolean} isShadow True if the block is a shadow block.
|
||||
*/
|
||||
Blockly.geras.PathObject.prototype.setDisabled = function(disabled, isShadow) {
|
||||
if (disabled) {
|
||||
this.svgPath.setAttribute('fill',
|
||||
'url(#' + this.constants_.disabledPatternId + ')');
|
||||
} else {
|
||||
this.applyColour(isShadow);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -103,7 +103,8 @@ Blockly.geras.Renderer.prototype.makeDrawer_ = function(block, info) {
|
||||
* @override
|
||||
*/
|
||||
Blockly.geras.Renderer.prototype.makePathObject = function(root) {
|
||||
return new Blockly.geras.PathObject(root);
|
||||
return new Blockly.geras.PathObject(root,
|
||||
/** @type {!Blockly.geras.ConstantProvider} */ (this.getConstants()));
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -179,7 +179,6 @@ Blockly.Toolbox.prototype.init = function() {
|
||||
Blockly.Touch.clearTouchIdentifier(); // Don't block future drags.
|
||||
}, /* opt_noCaptureIdentifier */ false, /* opt_noPreventDefault */ true);
|
||||
var workspaceOptions = /** @type {!Blockly.Options} */ ({
|
||||
disabledPatternId: workspace.options.disabledPatternId,
|
||||
parentWorkspace: workspace,
|
||||
RTL: workspace.RTL,
|
||||
oneBasedIndex: workspace.options.oneBasedIndex,
|
||||
|
||||
@@ -62,7 +62,6 @@ Blockly.Trashcan = function(workspace) {
|
||||
// Create flyout options.
|
||||
var flyoutWorkspaceOptions = /** @type {!Blockly.Options} */ ({
|
||||
scrollbars: true,
|
||||
disabledPatternId: this.workspace_.options.disabledPatternId,
|
||||
parentWorkspace: this.workspace_,
|
||||
RTL: this.workspace_.RTL,
|
||||
oneBasedIndex: this.workspace_.options.oneBasedIndex,
|
||||
|
||||
@@ -736,6 +736,8 @@ Blockly.WorkspaceSvg.prototype.dispose = function() {
|
||||
this.grid_ = null;
|
||||
}
|
||||
|
||||
this.renderer_.getConstants().dispose();
|
||||
|
||||
if (this.themeManager_) {
|
||||
this.themeManager_.unsubscribe(this.svgBackground_);
|
||||
}
|
||||
@@ -809,7 +811,6 @@ Blockly.WorkspaceSvg.prototype.addZoomControls = function() {
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.addFlyout = function(tagName) {
|
||||
var workspaceOptions = /** @type {!Blockly.Options} */ ({
|
||||
disabledPatternId: this.options.disabledPatternId,
|
||||
parentWorkspace: this,
|
||||
RTL: this.RTL,
|
||||
oneBasedIndex: this.options.oneBasedIndex,
|
||||
|
||||
Reference in New Issue
Block a user