undo last move button for pressure curve tool
This commit is contained in:
1 parent
e59f3ba1ab
commit
c3358efa9d
1 file changed
+35
-1
@@ -233,6 +233,9 @@ final class PressureCurveView: UIView {
|
|||||||
let curve = PressureCurve()
|
let curve = PressureCurve()
|
||||||
|
|
||||||
private var draggingIndex: Int? = nil
|
private var draggingIndex: Int? = nil
|
||||||
|
private var latestDraggingIndex: Int? = nil
|
||||||
|
private var newPointGenerated: Bool = false
|
||||||
|
private var draggingPointPreviousLocation: CGPoint? = nil
|
||||||
private let hitRadius: CGFloat = 35
|
private let hitRadius: CGFloat = 35
|
||||||
|
|
||||||
enum PressureTestStage: UInt8 {
|
enum PressureTestStage: UInt8 {
|
||||||
@@ -342,6 +345,22 @@ final class PressureCurveView: UIView {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func undoLastMove() {
|
||||||
|
if newPointGenerated {
|
||||||
|
guard let latestDraggingIndex = latestDraggingIndex else { return }
|
||||||
|
self.latestDraggingIndex = nil
|
||||||
|
curve.polylinePoints.remove(at: latestDraggingIndex )
|
||||||
|
setNeedsDisplay()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
guard let latestDraggingIndex = latestDraggingIndex else { return }
|
||||||
|
self.latestDraggingIndex = nil
|
||||||
|
guard let draggingPointPreviousLocation = draggingPointPreviousLocation else { return }
|
||||||
|
curve.polylinePoints[latestDraggingIndex] = draggingPointPreviousLocation
|
||||||
|
setNeedsDisplay()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
guard let touch = touches.first else { return }
|
guard let touch = touches.first else { return }
|
||||||
let location = touch.location(in: self)
|
let location = touch.location(in: self)
|
||||||
@@ -355,6 +374,7 @@ final class PressureCurveView: UIView {
|
|||||||
guard
|
guard
|
||||||
let touch = touches.first
|
let touch = touches.first
|
||||||
else { return }
|
else { return }
|
||||||
|
newPointGenerated = true
|
||||||
let location = touch.location(in: self)
|
let location = touch.location(in: self)
|
||||||
var point = unmap(location)
|
var point = unmap(location)
|
||||||
|
|
||||||
@@ -372,8 +392,15 @@ final class PressureCurveView: UIView {
|
|||||||
curve.polylinePoints.insert(point, at: insertIdx)
|
curve.polylinePoints.insert(point, at: insertIdx)
|
||||||
draggingIndex = insertIdx
|
draggingIndex = insertIdx
|
||||||
}
|
}
|
||||||
|
latestDraggingIndex = draggingIndex
|
||||||
setNeedsDisplay()
|
setNeedsDisplay()
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
guard let draggingIndex = draggingIndex else { return }
|
||||||
|
latestDraggingIndex = draggingIndex
|
||||||
|
draggingPointPreviousLocation = curve.polylinePoints[draggingIndex]
|
||||||
|
newPointGenerated = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
@@ -760,12 +787,13 @@ class PressureCurveViewController: UIViewController, UIGestureRecognizerDelegate
|
|||||||
|
|
||||||
if curveView.testStage == .curveStage {
|
if curveView.testStage == .curveStage {
|
||||||
let resetButton = UIBarButtonItem(title: SwiftLocalizationHelper.localizedString(forKey: "Reset"), style: .plain, target: self, action: #selector(resetTapped))
|
let resetButton = UIBarButtonItem(title: SwiftLocalizationHelper.localizedString(forKey: "Reset"), style: .plain, target: self, action: #selector(resetTapped))
|
||||||
|
let undoButton = UIBarButtonItem(title: SwiftLocalizationHelper.localizedString(forKey: "Undo"), style: .plain, target: self, action: #selector(undoTapped))
|
||||||
let rangeTestButton = UIBarButtonItem(title: SwiftLocalizationHelper.localizedString(forKey: "Pressure-range-test"), style: .plain, target: self, action: #selector(pressureRangeTest))
|
let rangeTestButton = UIBarButtonItem(title: SwiftLocalizationHelper.localizedString(forKey: "Pressure-range-test"), style: .plain, target: self, action: #selector(pressureRangeTest))
|
||||||
// curvePhaseButton = UIBarButtonItem(title: SwiftLocalizationHelper.localizedString(forKey: "Initial-touch-curve"), style: .plain, target: self, action: #selector(curvePhaseButtonTapped))
|
// curvePhaseButton = UIBarButtonItem(title: SwiftLocalizationHelper.localizedString(forKey: "Initial-touch-curve"), style: .plain, target: self, action: #selector(curvePhaseButtonTapped))
|
||||||
curvePhase = .stroke
|
curvePhase = .stroke
|
||||||
saveButton = UIBarButtonItem(title: SwiftLocalizationHelper.localizedString(forKey: "Save"), style: .plain, target: self, action: #selector(saveTapped))
|
saveButton = UIBarButtonItem(title: SwiftLocalizationHelper.localizedString(forKey: "Save"), style: .plain, target: self, action: #selector(saveTapped))
|
||||||
// let quitButton = UIBarButtonItem(title: SwiftLocalizationHelper.localizedString(forKey: "Exit"), style: .plain, target: self, action: #selector(exitTapped))
|
// let quitButton = UIBarButtonItem(title: SwiftLocalizationHelper.localizedString(forKey: "Exit"), style: .plain, target: self, action: #selector(exitTapped))
|
||||||
navItem.leftBarButtonItems = [resetButton, rangeTestButton]
|
navItem.leftBarButtonItems = [resetButton, undoButton, rangeTestButton,]
|
||||||
navItem.rightBarButtonItems = [saveButton]
|
navItem.rightBarButtonItems = [saveButton]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -810,6 +838,12 @@ class PressureCurveViewController: UIViewController, UIGestureRecognizerDelegate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc private func undoTapped() {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.curveView.undoLastMove()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@objc private func pencilProPurchaseAborted(_ notification: Notification) {
|
@objc private func pencilProPurchaseAborted(_ notification: Notification) {
|
||||||
guard let interruption = notification.object as? PurchaseInterruption else { return }
|
guard let interruption = notification.object as? PurchaseInterruption else { return }
|
||||||
if interruption != .learnMore {
|
if interruption != .learnMore {
|
||||||
|
|||||||
Reference in new issue
Block a user