mirror of
https://github.com/google/blockly.git
synced 2026-01-08 17:40:09 +01:00
Merge pull request #3037 from moniika/moniika-cursorDrawerOnRenderer
Creating cursordrawer in renderer.
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();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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,20 @@ 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 +148,3 @@ Blockly.blockRendering.Renderer.prototype.render = function(block) {
|
||||
info.measure();
|
||||
this.makeDrawer_(block, info).draw();
|
||||
};
|
||||
|
||||
|
||||
@@ -119,27 +119,23 @@ Blockly.Workspace = function(opt_options) {
|
||||
|
||||
/**
|
||||
* The cursor used to navigate around the AST for keyboard navigation.
|
||||
* @type {Blockly.Cursor}
|
||||
* @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}
|
||||
* @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());
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -424,16 +424,17 @@ Blockly.WorkspaceSvg.prototype.getRenderer = function() {
|
||||
|
||||
/**
|
||||
* 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;
|
||||
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());
|
||||
}
|
||||
};
|
||||
@@ -445,12 +446,12 @@ 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;
|
||||
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());
|
||||
}
|
||||
};
|
||||
@@ -662,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