|
|
@ -284,11 +284,13 @@ class ImageEditorCropViewController: OWSViewController {
|
|
|
|
|
|
|
|
|
|
|
|
let pinchGestureRecognizer = ImageEditorPinchGestureRecognizer(target: self, action: #selector(handlePinchGesture(_:)))
|
|
|
|
let pinchGestureRecognizer = ImageEditorPinchGestureRecognizer(target: self, action: #selector(handlePinchGesture(_:)))
|
|
|
|
pinchGestureRecognizer.referenceView = self.clipView
|
|
|
|
pinchGestureRecognizer.referenceView = self.clipView
|
|
|
|
|
|
|
|
pinchGestureRecognizer.delegate = self
|
|
|
|
view.addGestureRecognizer(pinchGestureRecognizer)
|
|
|
|
view.addGestureRecognizer(pinchGestureRecognizer)
|
|
|
|
|
|
|
|
|
|
|
|
let panGestureRecognizer = ImageEditorPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))
|
|
|
|
let panGestureRecognizer = ImageEditorPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))
|
|
|
|
panGestureRecognizer.maximumNumberOfTouches = 1
|
|
|
|
panGestureRecognizer.maximumNumberOfTouches = 1
|
|
|
|
panGestureRecognizer.referenceView = self.clipView
|
|
|
|
panGestureRecognizer.referenceView = self.clipView
|
|
|
|
|
|
|
|
panGestureRecognizer.delegate = self
|
|
|
|
view.addGestureRecognizer(panGestureRecognizer)
|
|
|
|
view.addGestureRecognizer(panGestureRecognizer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -349,7 +351,7 @@ class ImageEditorCropViewController: OWSViewController {
|
|
|
|
updateTransform(ImageEditorTransform(outputSizePixels: gestureStartTransform.outputSizePixels,
|
|
|
|
updateTransform(ImageEditorTransform(outputSizePixels: gestureStartTransform.outputSizePixels,
|
|
|
|
unitTranslation: newUnitTranslation,
|
|
|
|
unitTranslation: newUnitTranslation,
|
|
|
|
rotationRadians: newRotationRadians,
|
|
|
|
rotationRadians: newRotationRadians,
|
|
|
|
scaling: newScaling).normalize())
|
|
|
|
scaling: newScaling).normalize(srcImageSizePixels: model.srcImageSizePixels))
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -521,7 +523,7 @@ class ImageEditorCropViewController: OWSViewController {
|
|
|
|
updateTransform(ImageEditorTransform(outputSizePixels: croppedOutputSizePixels,
|
|
|
|
updateTransform(ImageEditorTransform(outputSizePixels: croppedOutputSizePixels,
|
|
|
|
unitTranslation: unitTranslation,
|
|
|
|
unitTranslation: unitTranslation,
|
|
|
|
rotationRadians: transform.rotationRadians,
|
|
|
|
rotationRadians: transform.rotationRadians,
|
|
|
|
scaling: scaling).normalize())
|
|
|
|
scaling: scaling).normalize(srcImageSizePixels: model.srcImageSizePixels))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private func handleNormalPanGesture(_ gestureRecognizer: ImageEditorPanGestureRecognizer) {
|
|
|
|
private func handleNormalPanGesture(_ gestureRecognizer: ImageEditorPanGestureRecognizer) {
|
|
|
@ -545,7 +547,7 @@ class ImageEditorCropViewController: OWSViewController {
|
|
|
|
updateTransform(ImageEditorTransform(outputSizePixels: gestureStartTransform.outputSizePixels,
|
|
|
|
updateTransform(ImageEditorTransform(outputSizePixels: gestureStartTransform.outputSizePixels,
|
|
|
|
unitTranslation: newUnitTranslation,
|
|
|
|
unitTranslation: newUnitTranslation,
|
|
|
|
rotationRadians: gestureStartTransform.rotationRadians,
|
|
|
|
rotationRadians: gestureStartTransform.rotationRadians,
|
|
|
|
scaling: gestureStartTransform.scaling).normalize())
|
|
|
|
scaling: gestureStartTransform.scaling).normalize(srcImageSizePixels: model.srcImageSizePixels))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private func cropRegion(forGestureRecognizer gestureRecognizer: ImageEditorPanGestureRecognizer) -> CropRegion? {
|
|
|
|
private func cropRegion(forGestureRecognizer gestureRecognizer: ImageEditorPanGestureRecognizer) -> CropRegion? {
|
|
|
@ -622,7 +624,7 @@ class ImageEditorCropViewController: OWSViewController {
|
|
|
|
updateTransform(ImageEditorTransform(outputSizePixels: outputSizePixels,
|
|
|
|
updateTransform(ImageEditorTransform(outputSizePixels: outputSizePixels,
|
|
|
|
unitTranslation: unitTranslation,
|
|
|
|
unitTranslation: unitTranslation,
|
|
|
|
rotationRadians: rotationRadians,
|
|
|
|
rotationRadians: rotationRadians,
|
|
|
|
scaling: scaling).normalize())
|
|
|
|
scaling: scaling).normalize(srcImageSizePixels: model.srcImageSizePixels))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@objc public func zoom2xButtonPressed() {
|
|
|
|
@objc public func zoom2xButtonPressed() {
|
|
|
@ -633,10 +635,24 @@ class ImageEditorCropViewController: OWSViewController {
|
|
|
|
updateTransform(ImageEditorTransform(outputSizePixels: outputSizePixels,
|
|
|
|
updateTransform(ImageEditorTransform(outputSizePixels: outputSizePixels,
|
|
|
|
unitTranslation: unitTranslation,
|
|
|
|
unitTranslation: unitTranslation,
|
|
|
|
rotationRadians: rotationRadians,
|
|
|
|
rotationRadians: rotationRadians,
|
|
|
|
scaling: scaling).normalize())
|
|
|
|
scaling: scaling).normalize(srcImageSizePixels: model.srcImageSizePixels))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@objc public func resetButtonPressed() {
|
|
|
|
@objc public func resetButtonPressed() {
|
|
|
|
updateTransform(ImageEditorTransform.defaultTransform(srcImageSizePixels: model.srcImageSizePixels))
|
|
|
|
updateTransform(ImageEditorTransform.defaultTransform(srcImageSizePixels: model.srcImageSizePixels))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extension ImageEditorCropViewController: UIGestureRecognizerDelegate {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@objc public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
|
|
|
|
|
|
|
|
// Until the GR recognizes, it should only see touches that start within the content.
|
|
|
|
|
|
|
|
guard gestureRecognizer.state == .possible else {
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let location = touch.location(in: clipView)
|
|
|
|
|
|
|
|
return clipView.bounds.contains(location)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|