receivedPointerSignal method
Handle mousewheel and web trackpad scroll events.
Implementation
@protected
void receivedPointerSignal(PointerSignalEvent event) {
final double scaleChange;
if (event is PointerScrollEvent) {
if (!_ctrlPressed) {
// Normal scroll, so treat it as a pan.
if (!gestureIsSupported(GestureType.pan)) {
return;
}
Offset scrollDelta = event.scrollDelta;
//TODO add axis alignement
if (event.kind == PointerDeviceKind.trackpad) {
if (scrollDelta.dx != 0) {
scrollbarController?.onScrollStartHorizontal();
}
if (scrollDelta.dy != 0) {
scrollbarController?.onScrollStartVertical();
}
} else {
//Shift pressed, so scroll horizontally with the mousewheel
if (_shiftPressed) {
scrollDelta = Offset(scrollDelta.dy, scrollDelta.dx);
scrollbarController?.onScrollStartHorizontal();
} else {
scrollbarController?.onScrollStartVertical();
}
}
final Offset localDelta = PointerEvent.transformDeltaViaPositions(
untransformedEndPosition: event.position + scrollDelta,
untransformedDelta: scrollDelta,
transform: event.transform,
);
final Offset focalPointScene = transformationController!.toScene(
event.localPosition,
);
final Offset newFocalPointScene = transformationController!.toScene(
event.localPosition - localDelta,
);
transformationController!.value = matrixTranslate(
transformationController!.value,
newFocalPointScene - focalPointScene);
scrollbarController?.onScrollEnd();
return;
}
// Ignore left and right mouse wheel scroll.
if (event.scrollDelta.dy == 0.0) {
return;
}
scaleChange = math.exp(-event.scrollDelta.dy / widget.scaleFactor);
} else if (event is PointerScaleEvent) {
scaleChange = event.scale;
} else {
return;
}
if (!gestureIsSupported(GestureType.scale)) {
return;
}
scrollbarController?.onScrollStart();
final Offset focalPointScene = transformationController!.toScene(
event.localPosition,
);
transformationController!.value = matrixScale(
transformationController!.value,
scaleChange,
);
// After scaling, translate such that the event's position is at the
// same scene point before and after the scale.
final Offset focalPointSceneScaled = transformationController!.toScene(
event.localPosition,
);
transformationController!.value = matrixTranslate(
transformationController!.value,
focalPointSceneScaled - focalPointScene,
);
afterZoom();
scrollbarController?.onScrollEnd();
}