Ensure brush strokes include the entire gesture.

pull/2/head
Matthew Chen 6 years ago
parent 65ee1dbd75
commit 919e886eb7

@ -127,7 +127,7 @@ public class ImageEditorBrushViewController: OWSViewController {
private var currentStrokeSamples = [ImageEditorStrokeItem.StrokeSample]()
@objc
public func handleBrushGesture(_ gestureRecognizer: UIGestureRecognizer) {
public func handleBrushGesture(_ gestureRecognizer: ImageEditorPanGestureRecognizer) {
AssertIsOnMainThread()
let removeCurrentStroke = {
@ -137,10 +137,9 @@ public class ImageEditorBrushViewController: OWSViewController {
self.currentStroke = nil
self.currentStrokeSamples.removeAll()
}
let tryToAppendStrokeSample = {
let tryToAppendStrokeSample = { (locationInView: CGPoint) in
let view = self.canvasView.gestureReferenceView
let viewBounds = view.bounds
let locationInView = gestureRecognizer.location(in: view)
let newSample = ImageEditorCanvasView.locationImageUnit(forLocationInView: locationInView,
viewBounds: viewBounds,
model: self.model,
@ -162,14 +161,22 @@ public class ImageEditorBrushViewController: OWSViewController {
case .began:
removeCurrentStroke()
tryToAppendStrokeSample()
// Apply the location history of the gesture so that the stroke reflects
// the touch's movement before the gesture recognized.
for location in gestureRecognizer.locations {
tryToAppendStrokeSample(location)
}
let locationInView = gestureRecognizer.location(in: canvasView.gestureReferenceView)
tryToAppendStrokeSample(locationInView)
let stroke = ImageEditorStrokeItem(color: strokeColor, unitSamples: currentStrokeSamples, unitStrokeWidth: unitStrokeWidth)
model.append(item: stroke)
currentStroke = stroke
case .changed, .ended:
tryToAppendStrokeSample()
let locationInView = gestureRecognizer.location(in: canvasView.gestureReferenceView)
tryToAppendStrokeSample(locationInView)
guard let lastStroke = self.currentStroke else {
owsFailDebug("Missing last stroke.")

@ -13,7 +13,12 @@ public class ImageEditorPanGestureRecognizer: UIPanGestureRecognizer {
public weak var referenceView: UIView?
public var locationStart: CGPoint?
// Capture the location history of this gesture.
public var locations = [CGPoint]()
public var locationStart: CGPoint? {
return locations.first
}
// MARK: - Touch Handling
@ -25,12 +30,23 @@ public class ImageEditorPanGestureRecognizer: UIPanGestureRecognizer {
owsFailDebug("Missing view")
return
}
locationStart = self.location(in: referenceView)
locations.append(location(in: referenceView))
}
@objc
public override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesMoved(touches, with: event)
guard let referenceView = referenceView else {
owsFailDebug("Missing view")
return
}
locations.append(location(in: referenceView))
}
public override func reset() {
super.reset()
locationStart = nil
locations.removeAll()
}
}

Loading…
Cancel
Save