mirror of
https://github.com/google/blockly.git
synced 2026-01-11 02:47:09 +01:00
Creating cursordrawer in renderer.
This commit is contained in:
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user