Creating cursordrawer in renderer.

This commit is contained in:
kozbial
2019-09-17 11:21:16 -07:00
parent d82a0ae0b8
commit 3d06e7eb33
2 changed files with 28 additions and 11 deletions

View File

@@ -32,6 +32,7 @@ goog.require('Blockly.blockRendering.Drawer');
goog.require('Blockly.blockRendering.IPathObject');
goog.require('Blockly.blockRendering.PathObject');
goog.require('Blockly.blockRendering.RenderInfo');
goog.require('Blockly.CursorSvg');
/**
@@ -50,7 +51,7 @@ Blockly.blockRendering.Renderer = function() {
};
/**
* Initialize the renderer
* Initialize the renderer.
* @package
*/
Blockly.blockRendering.Renderer.prototype.init = function() {
@@ -98,6 +99,19 @@ Blockly.blockRendering.Renderer.prototype.makeDebugger_ = function() {
return new Blockly.blockRendering.Debug();
};
/**
* Create a new instance of the renderer's cursor drawer
* @param {!Blockly.WorkspaceSvg} workspace The workspace the cursor belongs to.
* @param {boolean=} opt_marker True if the cursor is a marker. A marker is used
* to save a location and is an immovable cursor. False or undefined if the
* cursor is not a marker.
* @return {!Blockly.CursorSvg} The cursor drawer.
* @package
*/
Blockly.blockRendering.Renderer.prototype.makeCursorDrawer = function(workspace, opt_marker) {
return new Blockly.CursorSvg(workspace, opt_marker);
};
/**
* Create a new instance of a renderer path object.
* @param {!SVGElement} root The root SVG element.
@@ -133,4 +147,3 @@ Blockly.blockRendering.Renderer.prototype.render = function(block) {
info.measure();
this.makeDrawer_(block, info).draw();
};

View File

@@ -139,16 +139,16 @@ Blockly.WorkspaceSvg = function(options,
this.registerToolboxCategoryCallback(Blockly.PROCEDURE_CATEGORY_NAME,
Blockly.Procedures.flyoutCategory);
}
/**
* The block renderer used for rendering blocks on this workspace.
* @type {!Blockly.blockRendering.Renderer}
* @private
*/
this.renderer_ = Blockly.blockRendering.init(this.options.renderer || 'geras');
};
Blockly.utils.object.inherits(Blockly.WorkspaceSvg, Blockly.Workspace);
/**
* The block renderer used for rendering blocks on this workspace.
* @type {!Blockly.blockRendering.Renderer}
* @private
*/
Blockly.WorkspaceSvg.prototype.renderer_ = undefined;
/**
* A wrapper function called when a resize event occurs.
* You can pass the result to `unbindEvent_`.
@@ -419,6 +419,10 @@ Blockly.WorkspaceSvg.prototype.inverseScreenCTMDirty_ = true;
* @return {!Blockly.blockRendering.Renderer} The renderer attached to this workspace.
*/
Blockly.WorkspaceSvg.prototype.getRenderer = function() {
if (!this.renderer_) {
this.renderer_ =
Blockly.blockRendering.init(this.options.renderer || 'geras');
}
return this.renderer_;
};
@@ -433,7 +437,7 @@ Blockly.WorkspaceSvg.prototype.setCursor = function(cursor) {
}
this.cursor_ = cursor;
if (this.cursor_) {
this.cursor_.setDrawer(new Blockly.CursorSvg(this, false));
this.cursor_.setDrawer(this.getRenderer().makeCursorDrawer(this, false));
this.setCursorSvg(this.cursor_.getDrawer().createDom());
}
};
@@ -450,7 +454,7 @@ Blockly.WorkspaceSvg.prototype.setMarker = function(marker) {
}
this.marker_ = marker;
if (this.marker_) {
this.marker_.setDrawer(new Blockly.CursorSvg(this, true));
this.marker_.setDrawer(this.getRenderer().makeCursorDrawer(this, true));
this.setMarkerSvg(this.marker_.getDrawer().createDom());
}
};