Commit bdc4795f authored by Neil Fraser's avatar Neil Fraser

Simplify workspace construction.

parent 0d6a3bf9
This diff is collapsed.
......@@ -715,12 +715,9 @@ Blockly.setMainWorkspaceMetrics_ = function(xyRatio) {
Blockly.mainWorkspace.scrollY = -metrics.contentHeight * xyRatio.y -
metrics.contentTop;
}
var translation = 'translate(' +
(Blockly.mainWorkspace.scrollX + metrics.absoluteLeft) + ',' +
(Blockly.mainWorkspace.scrollY + metrics.absoluteTop) + ')';
Blockly.mainWorkspace.getCanvas().setAttribute('transform', translation);
Blockly.mainWorkspace.getBubbleCanvas().setAttribute('transform',
translation);
Blockly.mainWorkspace.translate(
Blockly.mainWorkspace.scrollX + metrics.absoluteLeft,
Blockly.mainWorkspace.scrollY + metrics.absoluteTop);
};
/**
......
......@@ -191,9 +191,7 @@ Blockly.Flyout.prototype.setMetrics_ = function(yRatio) {
this.workspace_.scrollY =
-metrics.contentHeight * yRatio.y - metrics.contentTop;
}
var y = this.workspace_.scrollY + metrics.absoluteTop;
this.workspace_.getCanvas().setAttribute('transform',
'translate(0,' + y + ')');
this.workspace_.translate(0, this.workspace_.scrollY + metrics.absoluteTop);
};
/**
......
......@@ -268,6 +268,7 @@ Blockly.createDom_ = function(container) {
{'width': 10, 'height': 10, 'fill': '#aaa'}, pattern);
Blockly.createSvgElement('path',
{'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, pattern);
Blockly.mainWorkspace = new Blockly.WorkspaceSvg(
Blockly.getMainWorkspaceMetrics_,
Blockly.setMainWorkspaceMetrics_);
......@@ -280,16 +281,7 @@ Blockly.createDom_ = function(container) {
if (Blockly.hasCategories) {
Blockly.mainWorkspace.toolbox_ = new Blockly.Toolbox(svg, container);
} else if (Blockly.languageTree) {
/**
* @type {!Blockly.Flyout}
* @private
*/
Blockly.mainWorkspace.flyout_ = new Blockly.Flyout();
var flyout = Blockly.mainWorkspace.flyout_;
var flyoutSvg = flyout.createDom();
flyout.autoClose = false;
// Insert the flyout behind the workspace so that blocks appear on top.
goog.dom.insertSiblingBefore(flyoutSvg, Blockly.mainWorkspace.svgGroup_);
Blockly.mainWorkspace.addFlyout();
}
if (!Blockly.hasScrollbars) {
var workspaceChanged = function() {
......
......@@ -107,7 +107,6 @@ Blockly.Mutator.prototype.createEditor_ = function() {
/* Create the editor. Here's the markup that will be generated:
<svg>
<rect class="blocklyMutatorBackground" />
[Flyout]
[Workspace]
</svg>
*/
......@@ -120,10 +119,8 @@ Blockly.Mutator.prototype.createEditor_ = function() {
var mutator = this;
this.workspace_ = new Blockly.WorkspaceSvg(
function() {return mutator.getFlyoutMetrics_();}, null);
this.workspace_.flyout_ = new Blockly.Flyout();
this.workspace_.flyout_.autoClose = false;
this.svgDialog_.appendChild(this.workspace_.flyout_.createDom());
this.svgDialog_.appendChild(this.workspace_.createDom());
this.workspace_.addFlyout();
return this.svgDialog_;
};
......
......@@ -102,7 +102,7 @@ Blockly.WorkspaceSvg.prototype.scrollbar = null;
Blockly.WorkspaceSvg.prototype.createDom = function() {
/*
<g>
[Trashcan may go here]
[Trashcan and/or flyout may go here]
<g></g> // Block canvas
<g></g> // Bubble canvas
[Scrollbars may go here]
......@@ -151,6 +151,16 @@ Blockly.WorkspaceSvg.prototype.addTrashcan = function() {
}
};
/**
* Add a flyout.
*/
Blockly.WorkspaceSvg.prototype.addFlyout = function() {
this.flyout_ = new Blockly.Flyout();
this.flyout_.autoClose = false;
var svgFlyout = this.flyout_.createDom();
this.svgGroup_.insertBefore(svgFlyout, this.svgBlockCanvas_);
};
/**
* Get the SVG element that forms the drawing surface.
* @return {!Element} SVG element.
......@@ -167,6 +177,17 @@ Blockly.WorkspaceSvg.prototype.getBubbleCanvas = function() {
return this.svgBubbleCanvas_;
};
/**
* Translate this workspace to new coordinates.
* @param {number} x Horizontal translation.
* @param {number} y Vertical translation.
*/
Blockly.WorkspaceSvg.prototype.translate = function(x, y) {
var translation = 'translate(' + x + ',' + y + ')';
this.svgBlockCanvas_.setAttribute('transform', translation);
this.svgBubbleCanvas_.setAttribute('transform', translation);
};
/**
* Add a block to the list of top blocks.
* @param {!Blockly.Block} block Block to remove.
......
......@@ -89,7 +89,7 @@ Blockly.JavaScript.text_getSubstring=function(a){var b=Blockly.JavaScript.valueT
" function getAt(where, at) {"," if (where == 'FROM_START') {"," at--;"," } else if (where == 'FROM_END') {"," at = text.length - at;"," } else if (where == 'FIRST') {"," at = 0;"," } else if (where == 'LAST') {"," at = text.length - 1;"," } else {"," throw 'Unhandled option (text_getSubstring).';"," }"," return at;"," }"," at1 = getAt(where1, at1);"," at2 = getAt(where2, at2) + 1;"," return text.slice(at1, at2);","}"])+"("+b+", '"+c+"', "+e+", '"+
d+"', "+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.text_changeCase=function(a){var b={UPPERCASE:".toUpperCase()",LOWERCASE:".toLowerCase()",TITLECASE:null}[a.getFieldValue("CASE")];b?(a=Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_MEMBER)||"''",a+=b):(b=Blockly.JavaScript.provideFunction_("text_toTitleCase",["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"(str) {"," return str.replace(/\\S+/g,"," function(txt) {return txt[0].toUpperCase() + txt.substring(1).toLowerCase();});","}"]),a=Blockly.JavaScript.valueToCode(a,
"TEXT",Blockly.JavaScript.ORDER_NONE)||"''",a=b+"("+a+")");return[a,Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.text_trim=function(a){var b={LEFT:".trimLeft()",RIGHT:".trimRight()",BOTH:".trim()"}[a.getFieldValue("MODE")];return[(Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_MEMBER)||"''")+b,Blockly.JavaScript.ORDER_FUNCTION_CALL]};
"TEXT",Blockly.JavaScript.ORDER_NONE)||"''",a=b+"("+a+")");return[a,Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.text_trim=function(a){var b={LEFT:".replace(/^[\\s\\xa0]+/, '')",RIGHT:".replace(/[\\s\\xa0]+$/, '')",BOTH:".trim()"}[a.getFieldValue("MODE")];return[(Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_MEMBER)||"''")+b,Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.text_print=function(a){return"window.alert("+(Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_NONE)||"''")+");\n"};Blockly.JavaScript.text_prompt=function(a){var b="window.prompt("+Blockly.JavaScript.quote_(a.getFieldValue("TEXT"))+")";"NUMBER"==a.getFieldValue("TYPE")&&(b="parseFloat("+b+")");return[b,Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.text_prompt_ext=function(a){var b="window.prompt("+(Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_NONE)||"''")+")";"NUMBER"==a.getFieldValue("TYPE")&&(b="parseFloat("+b+")");return[b,Blockly.JavaScript.ORDER_FUNCTION_CALL]};
// Copyright 2012 Google Inc. Apache License 2.0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment