Allow zooming of non-scrolling workspaces.

This commit is contained in:
Neil Fraser 2015-10-21 14:38:39 -07:00
parent dcd463b550
commit a485e63df2
4 changed files with 18 additions and 5 deletions

View file

@ -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();

View file

@ -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) {

View file

@ -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();
};

View file

@ -86,7 +86,7 @@ function start() {
zoom:
{controls: true,
wheel: true,
startScale: 2.0,
startScale: 1.0,
maxScale: 4,
minScale: .25,
scaleSpeed: 1.1