mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-01 07:57:01 +00:00
Improve drawing entities snapping
This commit is contained in:
parent
3e4cf69560
commit
f83b6e7c7a
@ -308,7 +308,7 @@ class DrawingEntitySnapTool {
|
|||||||
func maybeSkipFromStart(entityView: DrawingEntityView, rotation: CGFloat) {
|
func maybeSkipFromStart(entityView: DrawingEntityView, rotation: CGFloat) {
|
||||||
self.rotationState = nil
|
self.rotationState = nil
|
||||||
|
|
||||||
let snapDelta: CGFloat = 0.25
|
let snapDelta: CGFloat = 0.01
|
||||||
for snapRotation in self.snapRotations {
|
for snapRotation in self.snapRotations {
|
||||||
let snapRotation = snapRotation * .pi
|
let snapRotation = snapRotation * .pi
|
||||||
if rotation > snapRotation - snapDelta && rotation < snapRotation + snapDelta {
|
if rotation > snapRotation - snapDelta && rotation < snapRotation + snapDelta {
|
||||||
@ -318,7 +318,7 @@ class DrawingEntitySnapTool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(entityView: DrawingEntityView, velocity: CGFloat, delta: CGFloat, updatedRotation: CGFloat) -> CGFloat {
|
func update(entityView: DrawingEntityView, velocity: CGFloat, delta: CGFloat, updatedRotation: CGFloat, skipMultiplier: CGFloat = 1.0) -> CGFloat {
|
||||||
var updatedRotation = updatedRotation
|
var updatedRotation = updatedRotation
|
||||||
if updatedRotation < 0.0 {
|
if updatedRotation < 0.0 {
|
||||||
updatedRotation = 2.0 * .pi + updatedRotation
|
updatedRotation = 2.0 * .pi + updatedRotation
|
||||||
@ -332,7 +332,7 @@ class DrawingEntitySnapTool {
|
|||||||
|
|
||||||
let snapDelta: CGFloat = 0.01
|
let snapDelta: CGFloat = 0.01
|
||||||
let snapVelocity: CGFloat = snapDelta * 35.0
|
let snapVelocity: CGFloat = snapDelta * 35.0
|
||||||
let snapSkipRotation: CGFloat = snapDelta * 40.0
|
let snapSkipRotation: CGFloat = snapDelta * 45.0 * skipMultiplier
|
||||||
|
|
||||||
if abs(velocity) < snapVelocity || self.rotationState?.waitForLeave == true {
|
if abs(velocity) < snapVelocity || self.rotationState?.waitForLeave == true {
|
||||||
if let (snapRotation, skipped, waitForLeave) = self.rotationState {
|
if let (snapRotation, skipped, waitForLeave) = self.rotationState {
|
||||||
|
@ -547,9 +547,12 @@ final class DrawingStickerEntititySelectionView: DrawingEntitySelectionView {
|
|||||||
} else {
|
} else {
|
||||||
newAngle = atan2(parentLocation.y - self.center.y, parentLocation.x - self.center.x)
|
newAngle = atan2(parentLocation.y - self.center.y, parentLocation.x - self.center.x)
|
||||||
}
|
}
|
||||||
|
var delta = newAngle - updatedRotation
|
||||||
// let delta = newAngle - updatedRotation
|
if delta < -.pi {
|
||||||
updatedRotation = newAngle// self.snapTool.update(entityView: entityView, velocity: 0.0, delta: delta, updatedRotation: newAngle)
|
delta = 2.0 * .pi + delta
|
||||||
|
}
|
||||||
|
let velocityValue = sqrt(velocity.x * velocity.x + velocity.y * velocity.y) / 1000.0
|
||||||
|
updatedRotation = self.snapTool.update(entityView: entityView, velocity: velocityValue, delta: delta, updatedRotation: newAngle, skipMultiplier: 1.0)
|
||||||
} else if self.currentHandle === self.layer {
|
} else if self.currentHandle === self.layer {
|
||||||
updatedPosition.x += delta.x
|
updatedPosition.x += delta.x
|
||||||
updatedPosition.y += delta.y
|
updatedPosition.y += delta.y
|
||||||
|
@ -869,9 +869,12 @@ final class DrawingTextEntititySelectionView: DrawingEntitySelectionView {
|
|||||||
} else {
|
} else {
|
||||||
newAngle = atan2(parentLocation.y - self.center.y, parentLocation.x - self.center.x)
|
newAngle = atan2(parentLocation.y - self.center.y, parentLocation.x - self.center.x)
|
||||||
}
|
}
|
||||||
|
var delta = newAngle - updatedRotation
|
||||||
//let delta = newAngle - updatedRotation
|
if delta < -.pi {
|
||||||
updatedRotation = newAngle //" self.snapTool.update(entityView: entityView, velocity: 0.0, delta: delta, updatedRotation: newAngle)
|
delta = 2.0 * .pi + delta
|
||||||
|
}
|
||||||
|
let velocityValue = sqrt(velocity.x * velocity.x + velocity.y * velocity.y) / 1000.0
|
||||||
|
updatedRotation = self.snapTool.update(entityView: entityView, velocity: velocityValue, delta: delta, updatedRotation: newAngle, skipMultiplier: 1.0)
|
||||||
} else if self.currentHandle === self.layer {
|
} else if self.currentHandle === self.layer {
|
||||||
updatedPosition.x += delta.x
|
updatedPosition.x += delta.x
|
||||||
updatedPosition.y += delta.y
|
updatedPosition.y += delta.y
|
||||||
|
Loading…
x
Reference in New Issue
Block a user