From 3d06e7eb33f36b741d172542f7180d297a1c4ec7 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 17 Sep 2019 11:21:16 -0700 Subject: [PATCH] Creating cursordrawer in renderer. --- core/renderers/common/renderer.js | 17 +++++++++++++++-- core/workspace_svg.js | 22 +++++++++++++--------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/core/renderers/common/renderer.js b/core/renderers/common/renderer.js index 1582d0824..db3856c62 100644 --- a/core/renderers/common/renderer.js +++ b/core/renderers/common/renderer.js @@ -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(); }; - diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 9a8a5b944..630039bd1 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -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()); } };