calculateInteractiveButtonScaleRotate method
dynamic
calculateInteractiveButtonScaleRotate({
- required ScaleUpdateDetails details,
- required Layer activeLayer,
- required Size editorSize,
- required bool configEnabledHitVibration,
- required ThemeLayerInteraction layerTheme,
Calculates scaling and rotation based on user interactions.
Implementation
calculateInteractiveButtonScaleRotate({
required ScaleUpdateDetails details,
required Layer activeLayer,
required Size editorSize,
required bool configEnabledHitVibration,
required ThemeLayerInteraction layerTheme,
}) {
Offset layerOffset = Offset(
activeLayer.offset.dx,
activeLayer.offset.dy,
);
Size activeSize = rotateScaleLayerSizeHelper!;
Offset touchPositionFromCenter = Offset(
details.focalPoint.dx - editorSize.width / 2,
details.focalPoint.dy - editorSize.height / 2,
) -
layerOffset;
touchPositionFromCenter = Offset(
touchPositionFromCenter.dx * (activeLayer.flipX ? -1 : 1),
touchPositionFromCenter.dy * (activeLayer.flipY ? -1 : 1),
);
double newDistance = touchPositionFromCenter.distance;
double margin = layerTheme.buttonRadius + layerTheme.strokeWidth * 2;
var realSize = Offset(
activeSize.width / 2 - margin,
activeSize.height / 2 - margin,
) /
rotateScaleLayerScaleHelper!;
activeLayer.scale = newDistance / realSize.distance;
activeLayer.rotation =
touchPositionFromCenter.direction - atan(1 / activeSize.aspectRatio);
checkRotationLine(
activeLayer: activeLayer,
editorSize: editorSize,
configEnabledHitVibration: configEnabledHitVibration,
);
}