GenericTransformUpdateDetails.fromPointerScroll constructor

GenericTransformUpdateDetails.fromPointerScroll(
  1. PointerScrollEvent details,
  2. ScrollWheelBehavior scrollWheelBehavior, [
  3. double scrollWheelSensitivity = 1.0
])

Implementation

factory GenericTransformUpdateDetails.fromPointerScroll(
    PointerScrollEvent details, ScrollWheelBehavior scrollWheelBehavior,
    [double scrollWheelSensitivity = 1.0]) {
  Offset focalPoint = details.position;
  Offset localFocalPoint = details.localPosition;
  double rotation = 0.0;
  double scale = 1.0;

  switch (scrollWheelBehavior) {
    case ScrollWheelBehavior.translateX:
      focalPoint -= Offset(details.scrollDelta.dy / 5, 0);
      localFocalPoint -= Offset(details.scrollDelta.dy / 5, 0);
      break;
    case ScrollWheelBehavior.translateXInvert:
      focalPoint += Offset(details.scrollDelta.dy / 5, 0);
      localFocalPoint += Offset(details.scrollDelta.dy / 5, 0);
      break;
    case ScrollWheelBehavior.translateY:
      focalPoint -= details.scrollDelta / 5;
      localFocalPoint -= details.scrollDelta / 5;
      break;
    case ScrollWheelBehavior.translateYInvert:
      focalPoint += details.scrollDelta / 5;
      localFocalPoint += details.scrollDelta / 5;
      break;
    case ScrollWheelBehavior.rotateClockwise:
      rotation += details.scrollDelta.dy > 0 ? -0.1 : 0.1;
      break;
    case ScrollWheelBehavior.rotateCounterClockwise:
      rotation += details.scrollDelta.dy > 0 ? 0.1 : -0.1;
      break;
    default:
      scale += details.scrollDelta.dy > 0
          ? -scrollWheelSensitivity / 10
          : scrollWheelSensitivity / 10;
  }

  return GenericTransformUpdateDetails(
    focalPoint: focalPoint,
    localFocalPoint: localFocalPoint,
    scale: scale,
    rotation: rotation,
    kind: details.kind,
    buttons: details.buttons,
    pointerCount: 0,
  );
}