mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Add drag surface sizing and translation
This commit is contained in:
parent
cbc38698d2
commit
30d1c247cd
2 changed files with 27 additions and 0 deletions
|
@ -95,6 +95,19 @@ Blockly.DragSurfaceSvg.prototype.translateBlocks = function (x, y) {
|
|||
blocks.setAttribute('style', 'transform: translate3d(' + x + 'px,' + y + 'px, 0px)');
|
||||
};
|
||||
|
||||
/**
|
||||
* Translate and scale the entire drag surface group to keep in sync with the workspace.
|
||||
* @param {Number} x X translation
|
||||
* @param {Number} y Y translation
|
||||
* @param {Number} scale Scale of the group
|
||||
*/
|
||||
Blockly.DragSurfaceSvg.prototype.translateAndScaleGroup = function (x, y, scale) {
|
||||
// TODO: fall back to 2D translate when translate3d not supported.
|
||||
var transform = 'transform: translate3d(' + x + 'px, ' + y + 'px, 0px) ' +
|
||||
'scale3d(' + scale + ',' + scale + ',' + scale + ');';
|
||||
this.dragGroup_.setAttribute('style', transform);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear the group and hide the surface; move the blocks off onto the provided element.
|
||||
* @param {!Element} newSurface Surface the dragging blocks should be moved to
|
||||
|
|
|
@ -327,6 +327,17 @@ Blockly.WorkspaceSvg.prototype.resize = function() {
|
|||
if (this.scrollbar) {
|
||||
this.scrollbar.resize();
|
||||
}
|
||||
if (this.dragSurface_) {
|
||||
this.resizeDragSurface_();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Resize the drag surface according to new workspace metrics.
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.resizeDragSurface_ = function () {
|
||||
var bbox = this.svgGroup_.getBBox();
|
||||
this.dragSurface_.setSurfaceDimensions(bbox.width, bbox.height, -bbox.height)
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -374,6 +385,9 @@ Blockly.WorkspaceSvg.prototype.translate = function(x, y) {
|
|||
'scale(' + this.scale + ')';
|
||||
this.svgBlockCanvas_.setAttribute('transform', translation);
|
||||
this.svgBubbleCanvas_.setAttribute('transform', translation);
|
||||
if (this.dragSurface_) {
|
||||
this.dragSurface_.translateAndScaleGroup(x, y, this.scale);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue