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