Commit a485e63d authored by Neil Fraser's avatar Neil Fraser

Allow zooming of non-scrolling workspaces.

parent dcd463b5
......@@ -652,6 +652,9 @@ Blockly.Flyout.prototype.createBlockFunc_ = function(originBlock) {
// Scale the scroll (getSvgXY_ did not do this).
xyNew.x += workspace.scrollX / workspace.scale - workspace.scrollX;
xyNew.y += workspace.scrollY / workspace.scale - workspace.scrollY;
if (workspace.toolbox_ && !workspace.scrollbar) {
xyNew.x += workspace.toolbox_.width / workspace.scale;
}
block.moveBy(xyOld.x - xyNew.x, xyOld.y - xyNew.y);
if (flyout.autoClose) {
flyout.hide();
......
......@@ -376,6 +376,8 @@ Blockly.createMainWorkspace_ = function(svg, options) {
var mainWorkspace = new Blockly.WorkspaceSvg(options);
mainWorkspace.scale = options.zoomOptions.startScale;
svg.appendChild(mainWorkspace.createDom('blocklyMainBackground'));
// A null translation will also apply the correct initial scale.
mainWorkspace.translate(0, 0);
mainWorkspace.markFocused();
if (!options.readOnly && !options.hasScrollbars) {
......
......@@ -317,7 +317,7 @@ Blockly.WorkspaceSvg.prototype.getBubbleCanvas = function() {
* @param {number} y Vertical translation.
*/
Blockly.WorkspaceSvg.prototype.translate = function(x, y) {
var translation = 'translate(' + x + ',' + y + ')' +
var translation = 'translate(' + x + ',' + y + ') ' +
'scale(' + this.scale + ')';
this.svgBlockCanvas_.setAttribute('transform', translation);
this.svgBubbleCanvas_.setAttribute('transform', translation);
......@@ -922,7 +922,11 @@ Blockly.WorkspaceSvg.prototype.zoom = function(x, y, type) {
this.scrollX = matrix.e - metrics.absoluteLeft;
this.scrollY = matrix.f - metrics.absoluteTop;
this.updateGridPattern_();
this.scrollbar.resize();
if (this.scrollbar) {
this.scrollbar.resize();
} else {
this.translate(0, 0);
}
Blockly.hideChaff(false);
if (this.flyout_) {
// No toolbox, resize flyout.
......@@ -959,8 +963,12 @@ Blockly.WorkspaceSvg.prototype.zoomReset = function(e) {
}
// Center the workspace.
var metrics = this.getMetrics();
this.scrollbar.set((metrics.contentWidth - metrics.viewWidth) / 2,
(metrics.contentHeight - metrics.viewHeight) / 2);
if (this.scrollbar) {
this.scrollbar.set((metrics.contentWidth - metrics.viewWidth) / 2,
(metrics.contentHeight - metrics.viewHeight) / 2);
} else {
this.translate(0, 0);
}
// This event has been handled. Don't start a workspace drag.
e.stopPropagation();
};
......
......@@ -86,7 +86,7 @@ function start() {
zoom:
{controls: true,
wheel: true,
startScale: 2.0,
startScale: 1.0,
maxScale: 4,
minScale: .25,
scaleSpeed: 1.1
......
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