Commit 890d8d8d authored by Neil Fraser's avatar Neil Fraser

Fix zoom center button. Reverse disconnect wiggle.

parent 34f4b067
This diff is collapsed.
...@@ -706,9 +706,7 @@ Blockly.BlockSvg.prototype.onMouseMove_ = function(e) { ...@@ -706,9 +706,7 @@ Blockly.BlockSvg.prototype.onMouseMove_ = function(e) {
if (this_.parentBlock_) { if (this_.parentBlock_) {
// Push this block to the very top of the stack. // Push this block to the very top of the stack.
this_.setParent(null); this_.setParent(null);
if (workspace_.scale >= 1) { this_.disconnectUiEffect();
this_.disconnectUiEffect();
}
} }
this_.setDragging_(true); this_.setDragging_(true);
workspace_.recordDeleteAreas(); workspace_.recordDeleteAreas();
...@@ -1097,7 +1095,9 @@ Blockly.BlockSvg.disposeUiStep_ = function(clone, rtl, start, workspaceScale) { ...@@ -1097,7 +1095,9 @@ Blockly.BlockSvg.disposeUiStep_ = function(clone, rtl, start, workspaceScale) {
*/ */
Blockly.BlockSvg.prototype.connectionUiEffect = function() { Blockly.BlockSvg.prototype.connectionUiEffect = function() {
this.workspace.playAudio('click'); this.workspace.playAudio('click');
if (this.workspace.scale < 1) {
return; // Too small to care about visual effects.
}
// Determine the absolute coordinates of the inferior block. // Determine the absolute coordinates of the inferior block.
var xy = Blockly.getSvgXY_(/** @type {!Element} */ (this.svgGroup_), var xy = Blockly.getSvgXY_(/** @type {!Element} */ (this.svgGroup_),
this.workspace); this.workspace);
...@@ -1144,12 +1144,15 @@ Blockly.BlockSvg.connectionUiStep_ = function(ripple, start, workspaceScale) { ...@@ -1144,12 +1144,15 @@ Blockly.BlockSvg.connectionUiStep_ = function(ripple, start, workspaceScale) {
*/ */
Blockly.BlockSvg.prototype.disconnectUiEffect = function() { Blockly.BlockSvg.prototype.disconnectUiEffect = function() {
this.workspace.playAudio('disconnect'); this.workspace.playAudio('disconnect');
if (this.workspace.scale < 1) {
return; // Too small to care about visual effects.
}
// Horizontal distance for bottom of block to wiggle. // Horizontal distance for bottom of block to wiggle.
var DISPLACEMENT = 10; var DISPLACEMENT = 10;
// Scale magnitude of skew to height of block. // Scale magnitude of skew to height of block.
var height = this.getHeightWidth().height; var height = this.getHeightWidth().height;
var magnitude = Math.atan(DISPLACEMENT / height) / Math.PI * 180; var magnitude = Math.atan(DISPLACEMENT / height) / Math.PI * 180;
if (this.RTL) { if (!this.RTL) {
magnitude *= -1; magnitude *= -1;
} }
// Start the animation. // Start the animation.
......
...@@ -113,9 +113,10 @@ Blockly.Field.prototype.init = function(block) { ...@@ -113,9 +113,10 @@ Blockly.Field.prototype.init = function(block) {
'x': -Blockly.BlockSvg.SEP_SPACE_X / 2, 'x': -Blockly.BlockSvg.SEP_SPACE_X / 2,
'y': 0, 'y': 0,
'height': 16}, this.fieldGroup_, this.sourceBlock_.workspace); 'height': 16}, this.fieldGroup_, this.sourceBlock_.workspace);
/** @type {Element} */ /** @type {!Element} */
this.textElement_ = Blockly.createSvgElement('text', this.textElement_ = Blockly.createSvgElement('text',
{'class': 'blocklyText', 'y': this.size_.height - 12.5}, this.fieldGroup_); {'class': 'blocklyText', 'y': this.size_.height - 12.5},
this.fieldGroup_);
this.updateEditable(); this.updateEditable();
block.getSvgRoot().appendChild(this.fieldGroup_); block.getSvgRoot().appendChild(this.fieldGroup_);
......
...@@ -913,18 +913,26 @@ Blockly.WorkspaceSvg.prototype.zoomCenter = function(type) { ...@@ -913,18 +913,26 @@ Blockly.WorkspaceSvg.prototype.zoomCenter = function(type) {
/** /**
* Reset zooming and dragging. * Reset zooming and dragging.
* @param {!Event} e Mouse down event.
*/ */
Blockly.WorkspaceSvg.prototype.zoomReset = function() { Blockly.WorkspaceSvg.prototype.zoomReset = function(e) {
this.scale = 1; this.scale = 1;
this.updateGridPattern_(); this.updateGridPattern_();
var metrics = this.getMetrics();
this.scrollbar.set((metrics.contentWidth - metrics.viewWidth) / 2,
(metrics.contentHeight - metrics.viewHeight) / 2);
Blockly.hideChaff(false); Blockly.hideChaff(false);
if (this.flyout_) { if (this.flyout_) {
// No toolbox, resize flyout. // No toolbox, resize flyout.
this.flyout_.reflow(); this.flyout_.reflow();
} }
// Center the workspace once the scaling has had a chance to take effect.
var thisWorkspace = this;
var scroll = function() {
var metrics = thisWorkspace.getMetrics();
thisWorkspace.scrollbar.set((metrics.contentWidth - metrics.viewWidth) / 2,
(metrics.contentHeight - metrics.viewHeight) / 2);
};
setTimeout(scroll, 0);
// This event has been handled. No need to bubble up to the document.
e.stopPropagation();
}; };
/** /**
......
...@@ -163,11 +163,13 @@ Blockly.ZoomControls.prototype.createDom = function() { ...@@ -163,11 +163,13 @@ Blockly.ZoomControls.prototype.createDom = function() {
// Attach event listeners. // Attach event listeners.
Blockly.bindEvent_(zoomresetSvg, 'mousedown', workspace, workspace.zoomReset); Blockly.bindEvent_(zoomresetSvg, 'mousedown', workspace, workspace.zoomReset);
Blockly.bindEvent_(zoominSvg, 'mousedown', null, function() { Blockly.bindEvent_(zoominSvg, 'mousedown', null, function(e) {
workspace.zoomCenter(1); workspace.zoomCenter(1);
e.stopPropagation(); // Don't start a workspace scroll.
}); });
Blockly.bindEvent_(zoomoutSvg, 'mousedown', null, function() { Blockly.bindEvent_(zoomoutSvg, 'mousedown', null, function(e) {
workspace.zoomCenter(-1); workspace.zoomCenter(-1);
e.stopPropagation(); // Don't start a workspace scroll.
}); });
return this.svgGroup_; return this.svgGroup_;
......
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