mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Scrol workspace on mouse wheel and pinch-zoom
Distinguish pinch-zoom in Chrome using e.ctrlKey. If a mouse wheel event is not a zoom event, scroll the workspace. #51
This commit is contained in:
parent
4c52b30a15
commit
473cb0abce
1 changed files with 21 additions and 4 deletions
|
@ -668,10 +668,27 @@ Blockly.WorkspaceSvg.prototype.moveDrag = function(e) {
|
|||
*/
|
||||
Blockly.WorkspaceSvg.prototype.onMouseWheel_ = function(e) {
|
||||
// TODO: Remove terminateDrag and compensate for coordinate skew during zoom.
|
||||
Blockly.terminateDrag_();
|
||||
var delta = e.deltaY > 0 ? -1 : 1;
|
||||
var position = Blockly.mouseToSvg(e, this.getParentSvg());
|
||||
this.zoom(position.x, position.y, delta);
|
||||
if (e.ctrlKey) {
|
||||
// Pinch-to-zoom in Chrome only
|
||||
Blockly.terminateDrag_();
|
||||
var delta = e.deltaY > 0 ? -1 : 1;
|
||||
var position = Blockly.mouseToSvg(e, this.getParentSvg());
|
||||
this.zoom(position.x, position.y, delta);
|
||||
} else {
|
||||
// This is a regular mouse wheel event - scroll the workspace
|
||||
var metrics = this.getMetrics();
|
||||
var x = this.scrollX - e.deltaX;
|
||||
var y = this.scrollY - e.deltaY;
|
||||
x = Math.min(x, -metrics.contentLeft);
|
||||
y = Math.min(y, -metrics.contentTop);
|
||||
x = Math.max(x, metrics.viewWidth - metrics.contentLeft -
|
||||
metrics.contentWidth);
|
||||
y = Math.max(y, metrics.viewHeight - metrics.contentTop -
|
||||
metrics.contentHeight);
|
||||
// Move the scrollbars and the page will scroll automatically.
|
||||
this.scrollbar.set(-x - metrics.contentLeft,
|
||||
-y - metrics.contentTop);
|
||||
}
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue