Various fixes

This commit is contained in:
Ilya Laktyushin 2022-12-18 11:36:53 +04:00
parent 2d5df7debc
commit c6a3e1a932
6 changed files with 116 additions and 75 deletions

View File

@ -157,9 +157,22 @@ final class DrawingBubbleEntityView: DrawingEntityView {
return self.shapeLayer.lineWidth
}
private var maxLineWidth: CGFloat {
return max(10.0, min(self.bubbleEntity.referenceDrawingSize.width, self.bubbleEntity.referenceDrawingSize.height) * 0.1)
}
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
let lineWidth = self.maxLineWidth * 0.5
let expandedBounds = self.bounds.insetBy(dx: -lineWidth, dy: -lineWidth)
if expandedBounds.contains(point) {
return true
}
return false
}
override func precisePoint(inside point: CGPoint) -> Bool {
if case .stroke = self.bubbleEntity.drawType, var path = self.shapeLayer.path {
path = path.copy(strokingWithWidth: 20.0, lineCap: .square, lineJoin: .bevel, miterLimit: 0.0)
path = path.copy(strokingWithWidth: maxLineWidth * 0.8, lineCap: .square, lineJoin: .bevel, miterLimit: 0.0)
if path.contains(point) {
return true
} else {

View File

@ -411,6 +411,9 @@ private class Brush {
}
self.bezier.finish()
guard points.count >= 2 else {
return
}
for i in 1 ..< points.count {
let p = points[i]
if (i == points.count - 1) || pointStep <= 1 || (pointStep > 1 && previousPoint.distance(to: p) >= pointStep) {
@ -624,40 +627,40 @@ final class Texture {
self.height = height
self.bytesPerRow = bytesPerRow
if #available(iOS 12.0, *) {
#if targetEnvironment(simulator)
self.buffer = nil
let textureDescriptor = MTLTextureDescriptor()
textureDescriptor.textureType = .type2D
textureDescriptor.pixelFormat = .bgra8Unorm
textureDescriptor.width = width
textureDescriptor.height = height
textureDescriptor.usage = [.renderTarget, .shaderRead]
textureDescriptor.storageMode = .shared
guard let texture = device.makeTexture(descriptor: textureDescriptor) else {
return nil
}
#else
guard let buffer = device.makeBuffer(length: bytesPerRow * height, options: MTLResourceOptions.storageModeShared) else {
return nil
}
self.buffer = buffer
let textureDescriptor = MTLTextureDescriptor()
textureDescriptor.textureType = .type2D
textureDescriptor.pixelFormat = .bgra8Unorm
textureDescriptor.width = width
textureDescriptor.height = height
textureDescriptor.usage = [.renderTarget, .shaderRead]
textureDescriptor.storageMode = buffer.storageMode
guard let texture = buffer.makeTexture(descriptor: textureDescriptor, offset: 0, bytesPerRow: bytesPerRow) else {
return nil
}
#endif
self.texture = texture
} else {
// if #available(iOS 12.0, *) {
//#if targetEnvironment(simulator)
// self.buffer = nil
// let textureDescriptor = MTLTextureDescriptor()
// textureDescriptor.textureType = .type2D
// textureDescriptor.pixelFormat = .bgra8Unorm
// textureDescriptor.width = width
// textureDescriptor.height = height
// textureDescriptor.usage = [.renderTarget, .shaderRead]
// textureDescriptor.storageMode = .shared
//
// guard let texture = device.makeTexture(descriptor: textureDescriptor) else {
// return nil
// }
//#else
// guard let buffer = device.makeBuffer(length: bytesPerRow * height, options: MTLResourceOptions.storageModeShared) else {
// return nil
// }
// self.buffer = buffer
//
// let textureDescriptor = MTLTextureDescriptor()
// textureDescriptor.textureType = .type2D
// textureDescriptor.pixelFormat = .bgra8Unorm
// textureDescriptor.width = width
// textureDescriptor.height = height
// textureDescriptor.usage = [.renderTarget, .shaderRead]
// textureDescriptor.storageMode = buffer.storageMode
//
// guard let texture = buffer.makeTexture(descriptor: textureDescriptor, offset: 0, bytesPerRow: bytesPerRow) else {
// return nil
// }
//#endif
// self.texture = texture
// } else {
self.buffer = nil
let textureDescriptor = MTLTextureDescriptor()
@ -673,7 +676,7 @@ final class Texture {
}
self.texture = texture
}
// }
self.clear()
}

View File

@ -167,9 +167,22 @@ final class DrawingSimpleShapeEntityView: DrawingEntityView {
return self.shapeLayer.lineWidth
}
private var maxLineWidth: CGFloat {
return max(10.0, min(self.shapeEntity.referenceDrawingSize.width, self.shapeEntity.referenceDrawingSize.height) * 0.1)
}
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
let lineWidth = self.maxLineWidth * 0.5
let expandedBounds = self.bounds.insetBy(dx: -lineWidth, dy: -lineWidth)
if expandedBounds.contains(point) {
return true
}
return false
}
override func precisePoint(inside point: CGPoint) -> Bool {
if case .stroke = self.shapeEntity.drawType, var path = self.shapeLayer.path {
path = path.copy(strokingWithWidth: 20.0, lineCap: .square, lineJoin: .bevel, miterLimit: 0.0)
path = path.copy(strokingWithWidth: self.maxLineWidth * 0.8, lineCap: .square, lineJoin: .bevel, miterLimit: 0.0)
if path.contains(point) {
return true
} else {

View File

@ -134,6 +134,10 @@ final class DrawingVectorEntityView: DrawingEntityView {
return self.shapeLayer.path?.boundingBox ?? self.bounds
}
private var maxLineWidth: CGFloat {
return max(10.0, min(self.vectorEntity.referenceDrawingSize.width, self.vectorEntity.referenceDrawingSize.height) * 0.1)
}
override func update(animated: Bool) {
self.center = CGPoint(x: self.vectorEntity.drawingSize.width * 0.5, y: self.vectorEntity.drawingSize.height * 0.5)
self.bounds = CGRect(origin: .zero, size: self.vectorEntity.drawingSize)
@ -174,7 +178,15 @@ final class DrawingVectorEntityView: DrawingEntityView {
if path.contains(point) {
return true
} else {
return false
let expandedPath = CGPath.curve(
start: self.vectorEntity.start,
end: self.vectorEntity.end,
mid: self.vectorEntity.midPoint,
lineWidth: self.maxLineWidth * 0.8,
arrowSize: nil,
twoSided: false
)
return expandedPath.contains(point)
}
} else {
return super.precisePoint(inside: point)

View File

@ -475,7 +475,7 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, TGPhotoDraw
private let queue = Queue()
private var skipDrawing = Set<UUID>()
private func commit(reset: Bool = false, interactive: Bool = false, synchronous: Bool = false, completion: @escaping () -> Void = {}) {
private func commit(reset: Bool = false, interactive: Bool = false, synchronous: Bool = true, completion: @escaping () -> Void = {}) {
let currentImage = self.drawingImage
let uncommitedElement = self.uncommitedElement
let imageSize = self.imageSize

View File

@ -946,42 +946,42 @@ func selectivePrivacySettingsController(
}
}
let controller = selectivePrivacyPeersController(context: context, title: title, initialPeers: updatedPeerIds, updated: { updatedPeerIds in
updateState { state in
if enable {
switch target {
case .main:
var disableFor = state.disableFor
for (key, _) in updatedPeerIds {
disableFor.removeValue(forKey: key)
}
return state.withUpdatedEnableFor(updatedPeerIds).withUpdatedDisableFor(disableFor)
case .callP2P:
var callP2PDisableFor = state.callP2PDisableFor ?? [:]
for (key, _) in updatedPeerIds {
callP2PDisableFor.removeValue(forKey: key)
}
return state.withUpdatedCallP2PEnableFor(updatedPeerIds).withUpdatedCallP2PDisableFor(callP2PDisableFor)
}
} else {
switch target {
case .main:
var enableFor = state.enableFor
for (key, _) in updatedPeerIds {
enableFor.removeValue(forKey: key)
}
return state.withUpdatedDisableFor(updatedPeerIds).withUpdatedEnableFor(enableFor)
case .callP2P:
var callP2PEnableFor = state.callP2PEnableFor ?? [:]
for (key, _) in updatedPeerIds {
callP2PEnableFor.removeValue(forKey: key)
}
return state.withUpdatedCallP2PDisableFor(updatedPeerIds).withUpdatedCallP2PEnableFor(callP2PEnableFor)
}
}
}
})
pushControllerImpl?(controller, false)
// let controller = selectivePrivacyPeersController(context: context, title: title, initialPeers: updatedPeerIds, updated: { updatedPeerIds in
// updateState { state in
// if enable {
// switch target {
// case .main:
// var disableFor = state.disableFor
// for (key, _) in updatedPeerIds {
// disableFor.removeValue(forKey: key)
// }
// return state.withUpdatedEnableFor(updatedPeerIds).withUpdatedDisableFor(disableFor)
// case .callP2P:
// var callP2PDisableFor = state.callP2PDisableFor ?? [:]
// for (key, _) in updatedPeerIds {
// callP2PDisableFor.removeValue(forKey: key)
// }
// return state.withUpdatedCallP2PEnableFor(updatedPeerIds).withUpdatedCallP2PDisableFor(callP2PDisableFor)
// }
// } else {
// switch target {
// case .main:
// var enableFor = state.enableFor
// for (key, _) in updatedPeerIds {
// enableFor.removeValue(forKey: key)
// }
// return state.withUpdatedDisableFor(updatedPeerIds).withUpdatedEnableFor(enableFor)
// case .callP2P:
// var callP2PEnableFor = state.callP2PEnableFor ?? [:]
// for (key, _) in updatedPeerIds {
// callP2PEnableFor.removeValue(forKey: key)
// }
// return state.withUpdatedCallP2PDisableFor(updatedPeerIds).withUpdatedCallP2PEnableFor(callP2PEnableFor)
// }
// }
// }
// })
// pushControllerImpl?(controller, false)
})
}))
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))