Commit dcd463b5 authored by Neil Fraser's avatar Neil Fraser

Add 'startScale' and remove 'enabled' options on zoom.

parent 54ffdc59
...@@ -161,19 +161,17 @@ Blockly.parseOptions_ = function(options) { ...@@ -161,19 +161,17 @@ Blockly.parseOptions_ = function(options) {
/* TODO (fraser): Add documentation page: /* TODO (fraser): Add documentation page:
* https://developers.google.com/blockly/installation/zoom * https://developers.google.com/blockly/installation/zoom
* *
* enabled
*
* Set to `true` to allow zooming of the main workspace. Zooming is only
* possible if the workspace has scrollbars. If `false`, then the options
* below have no effect. Defaults to `false`.
*
* controls * controls
* *
* Set to `true` to show zoom-in and zoom-out buttons. Defaults to `true`. * Set to `true` to show zoom-in and zoom-out buttons. Defaults to `false`.
* *
* wheel * wheel
* *
* Set to `true` to allow the mouse wheel to zoom. Defaults to `true`. * Set to `true` to allow the mouse wheel to zoom. Defaults to `false`.
*
* startScale
*
* Initial magnification factor. Defaults to `1.0`.
* *
* maxScale * maxScale
* *
...@@ -194,36 +192,35 @@ Blockly.parseOptions_ = function(options) { ...@@ -194,36 +192,35 @@ Blockly.parseOptions_ = function(options) {
// https://developers.google.com/blockly/installation/zoom // https://developers.google.com/blockly/installation/zoom
var zoom = options['zoom'] || {}; var zoom = options['zoom'] || {};
var zoomOptions = {}; var zoomOptions = {};
zoomOptions.enabled = hasScrollbars && !!zoom['enabled']; if (zoom['controls'] === undefined) {
if (zoomOptions.enabled) {
if (zoom['controls'] === undefined) {
zoomOptions.controls = true;
} else {
zoomOptions.controls = !!zoom['controls'];
}
if (zoom['wheel'] === undefined) {
zoomOptions.wheel = true;
} else {
zoomOptions.wheel = !!zoom['wheel'];
}
if (zoom['maxScale'] === undefined) {
zoomOptions.maxScale = 3;
} else {
zoomOptions.maxScale = parseFloat(zoom['maxScale']);
}
if (zoom['minScale'] === undefined) {
zoomOptions.minScale = 0.3;
} else {
zoomOptions.minScale = parseFloat(zoom['minScale']);
}
if (zoom['scaleSpeed'] === undefined) {
zoomOptions.scaleSpeed = 1.2;
} else {
zoomOptions.scaleSpeed = parseFloat(zoom['scaleSpeed']);
}
} else {
zoomOptions.controls = false; zoomOptions.controls = false;
} else {
zoomOptions.controls = !!zoom['controls'];
}
if (zoom['wheel'] === undefined) {
zoomOptions.wheel = false; zoomOptions.wheel = false;
} else {
zoomOptions.wheel = !!zoom['wheel'];
}
if (zoom['startScale'] === undefined) {
zoomOptions.startScale = 1;
} else {
zoomOptions.startScale = parseFloat(zoom['startScale']);
}
if (zoom['maxScale'] === undefined) {
zoomOptions.maxScale = 3;
} else {
zoomOptions.maxScale = parseFloat(zoom['maxScale']);
}
if (zoom['minScale'] === undefined) {
zoomOptions.minScale = 0.3;
} else {
zoomOptions.minScale = parseFloat(zoom['minScale']);
}
if (zoom['scaleSpeed'] === undefined) {
zoomOptions.scaleSpeed = 1.2;
} else {
zoomOptions.scaleSpeed = parseFloat(zoom['scaleSpeed']);
} }
var enableRealtime = !!options['realtime']; var enableRealtime = !!options['realtime'];
...@@ -377,6 +374,7 @@ Blockly.createMainWorkspace_ = function(svg, options) { ...@@ -377,6 +374,7 @@ Blockly.createMainWorkspace_ = function(svg, options) {
options.getMetrics = Blockly.getMainWorkspaceMetrics_; options.getMetrics = Blockly.getMainWorkspaceMetrics_;
options.setMetrics = Blockly.setMainWorkspaceMetrics_; options.setMetrics = Blockly.setMainWorkspaceMetrics_;
var mainWorkspace = new Blockly.WorkspaceSvg(options); var mainWorkspace = new Blockly.WorkspaceSvg(options);
mainWorkspace.scale = options.zoomOptions.startScale;
svg.appendChild(mainWorkspace.createDom('blocklyMainBackground')); svg.appendChild(mainWorkspace.createDom('blocklyMainBackground'));
mainWorkspace.markFocused(); mainWorkspace.markFocused();
......
...@@ -384,7 +384,9 @@ Code.init = function() { ...@@ -384,7 +384,9 @@ Code.init = function() {
media: '../../media/', media: '../../media/',
rtl: rtl, rtl: rtl,
toolbox: toolbox, toolbox: toolbox,
zoom: {enabled: true} zoom:
{controls: true,
wheel: true}
}); });
// Add to reserved word list: Local variables in execution environment (runJS) // Add to reserved word list: Local variables in execution environment (runJS)
......
...@@ -84,9 +84,9 @@ function start() { ...@@ -84,9 +84,9 @@ function start() {
scrollbars: true, scrollbars: true,
toolbox: toolbox, toolbox: toolbox,
zoom: zoom:
{enabled: true, {controls: true,
controls: true,
wheel: true, wheel: true,
startScale: 2.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