mirror of
https://github.com/google/blockly.git
synced 2026-01-14 04:17:10 +01:00
Setting cursor and marker directly in Workspace and adding check to setCursor/setDrawer.
This commit is contained in:
@@ -68,8 +68,7 @@ Blockly.CursorSvg = function(workspace, opt_marker) {
|
||||
* @type {Blockly.blockRendering.ConstantProvider}
|
||||
* @private
|
||||
*/
|
||||
this.constants_ = new Blockly.blockRendering.ConstantProvider();
|
||||
this.constants_.init();
|
||||
this.constants_ = workspace.getRenderer().getConstants();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -122,24 +122,20 @@ Blockly.Workspace = function(opt_options) {
|
||||
* @type {Blockly.Cursor}
|
||||
* @protected
|
||||
*/
|
||||
this.cursor_ = null;
|
||||
this.cursor_ = new Blockly.Cursor();
|
||||
|
||||
/**
|
||||
* The marker used to mark a location for keyboard navigation.
|
||||
* @type {Blockly.MarkerCursor}
|
||||
* @protected
|
||||
*/
|
||||
this.marker_ = null;
|
||||
this.marker_ = new Blockly.MarkerCursor();
|
||||
|
||||
// Set the default theme. This is for headless workspaces. This will get
|
||||
// overwritten by the theme passed into the inject call for rendered workspaces.
|
||||
if (!Blockly.getTheme()) {
|
||||
Blockly.setTheme(Blockly.Themes.Classic);
|
||||
}
|
||||
|
||||
this.setCursor(new Blockly.Cursor());
|
||||
|
||||
this.setMarker(new Blockly.MarkerCursor());
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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,20 +419,17 @@ 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_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the cursor for use with keyboard navigation.
|
||||
*
|
||||
* @param {Blockly.Cursor} cursor The cursor used to move around this workspace.
|
||||
* @override
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.setCursor = function(cursor) {
|
||||
if (this.cursor_) {
|
||||
if (this.cursor_ && this.cursor_.getDrawer()) {
|
||||
this.cursor_.getDrawer().dispose();
|
||||
}
|
||||
this.cursor_ = cursor;
|
||||
@@ -449,7 +446,7 @@ Blockly.WorkspaceSvg.prototype.setCursor = function(cursor) {
|
||||
* @override
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.setMarker = function(marker) {
|
||||
if (this.marker_) {
|
||||
if (this.marker_ && this.marker_.getDrawer()) {
|
||||
this.marker_.getDrawer().dispose();
|
||||
}
|
||||
this.marker_ = marker;
|
||||
@@ -666,9 +663,11 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) {
|
||||
}
|
||||
this.recordDeleteAreas();
|
||||
|
||||
this.cursor_.setDrawer(this.getRenderer().makeCursorDrawer(this, false));
|
||||
var svgCursor = this.cursor_.getDrawer().createDom();
|
||||
this.svgGroup_.appendChild(svgCursor);
|
||||
|
||||
this.marker_.setDrawer(this.getRenderer().makeCursorDrawer(this, true));
|
||||
var svgMarker = this.marker_.getDrawer().createDom();
|
||||
this.svgGroup_.appendChild(svgMarker);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user