Double speed of workspace drag.

This commit is contained in:
Neil Fraser 2016-02-01 16:13:05 -08:00
parent bbfd883629
commit 0027d9294a
3 changed files with 33 additions and 21 deletions

View file

@ -160,10 +160,9 @@ Blockly.Block.prototype.colour_ = '#000000';
* @param {boolean} healStack If true, then try to heal any gap by connecting
* the next statement with the previous statement. Otherwise, dispose of
* all children of this block.
* @param {boolean} animate If true, show a disposal animation and sound.
*/
Blockly.Block.prototype.dispose = function(healStack, animate) {
this.unplug(healStack, false);
Blockly.Block.prototype.dispose = function(healStack) {
this.unplug(healStack);
if (Blockly.Events.isEnabled() && !this.isShadow()) {
Blockly.Events.fire(new Blockly.Events.Delete(this));
}
@ -212,10 +211,8 @@ Blockly.Block.prototype.dispose = function(healStack, animate) {
* Unplug this block from its superior block. If this block is a statement,
* optionally reconnect the block underneath with the block on top.
* @param {boolean} healStack Disconnect child statement and reconnect stack.
* @param {boolean} bump Move the unplugged block sideways a short distance.
*/
Blockly.Block.prototype.unplug = function(healStack, bump) {
bump = bump && !!this.getParent();
Blockly.Block.prototype.unplug = function(healStack) {
if (this.outputConnection) {
if (this.outputConnection.targetConnection) {
// Disconnect from any superior block.
@ -240,12 +237,6 @@ Blockly.Block.prototype.unplug = function(healStack, bump) {
}
}
}
if (bump) {
// Bump the block sideways.
var dx = Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1);
var dy = Blockly.SNAP_RADIUS * 2;
this.moveBy(dx, dy);
}
};
/**

View file

@ -499,12 +499,8 @@ Blockly.BlockSvg.prototype.onMouseUp_ = function(e) {
if (this.rendered) {
// Trigger a connection animation.
// Determine which connection is inferior (lower in the source stack).
var inferiorConnection;
if (Blockly.localConnection_.isSuperior()) {
inferiorConnection = Blockly.highlightedConnection_;
} else {
inferiorConnection = Blockly.localConnection_;
}
var inferiorConnection = Blockly.localConnection_.isSuperior() ?
Blockly.highlightedConnection_ : Blockly.localConnection_;
inferiorConnection.sourceBlock_.connectionUiEffect();
}
if (this.workspace.trashcan) {
@ -1105,7 +1101,7 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) {
}
if (animate && this.rendered) {
this.unplug(healStack, false);
this.unplug(healStack);
this.disposeUiEffect();
}
// Stop rerendering.

View file

@ -136,8 +136,33 @@ Blockly.ScrollbarPair.prototype.resize = function() {
* @param {number} y Vertical scroll value.
*/
Blockly.ScrollbarPair.prototype.set = function(x, y) {
this.hScroll.set(x);
this.vScroll.set(y);
// This function is equivalent to:
// this.hScroll.set(x);
// this.vScroll.set(y);
// However, that calls setMetrics twice. Combining them speeds up rendering.
var xyRatio = {};
var knobValue = x * this.hScroll.ratio_;
this.hScroll.svgKnob_.setAttribute('x', knobValue);
var barLength = parseFloat(this.hScroll.svgBackground_.getAttribute('width'));
var ratio = knobValue / barLength;
if (isNaN(ratio)) {
ratio = 0;
}
xyRatio.x = ratio;
var knobValue = y * this.vScroll.ratio_;
this.vScroll.svgKnob_.setAttribute('y', knobValue);
var barLength =
parseFloat(this.vScroll.svgBackground_.getAttribute('height'));
var ratio = knobValue / barLength;
if (isNaN(ratio)) {
ratio = 0;
}
xyRatio.y = ratio;
this.workspace_.setMetrics(xyRatio);
};
// --------------------------------------------------------------------