mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Various fixes
This commit is contained in:
@@ -157,9 +157,22 @@ final class DrawingBubbleEntityView: DrawingEntityView {
|
|||||||
return self.shapeLayer.lineWidth
|
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 {
|
override func precisePoint(inside point: CGPoint) -> Bool {
|
||||||
if case .stroke = self.bubbleEntity.drawType, var path = self.shapeLayer.path {
|
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) {
|
if path.contains(point) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -411,6 +411,9 @@ private class Brush {
|
|||||||
}
|
}
|
||||||
self.bezier.finish()
|
self.bezier.finish()
|
||||||
|
|
||||||
|
guard points.count >= 2 else {
|
||||||
|
return
|
||||||
|
}
|
||||||
for i in 1 ..< points.count {
|
for i in 1 ..< points.count {
|
||||||
let p = points[i]
|
let p = points[i]
|
||||||
if (i == points.count - 1) || pointStep <= 1 || (pointStep > 1 && previousPoint.distance(to: p) >= pointStep) {
|
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.height = height
|
||||||
self.bytesPerRow = bytesPerRow
|
self.bytesPerRow = bytesPerRow
|
||||||
|
|
||||||
if #available(iOS 12.0, *) {
|
// if #available(iOS 12.0, *) {
|
||||||
#if targetEnvironment(simulator)
|
//#if targetEnvironment(simulator)
|
||||||
self.buffer = nil
|
// self.buffer = nil
|
||||||
let textureDescriptor = MTLTextureDescriptor()
|
// let textureDescriptor = MTLTextureDescriptor()
|
||||||
textureDescriptor.textureType = .type2D
|
// textureDescriptor.textureType = .type2D
|
||||||
textureDescriptor.pixelFormat = .bgra8Unorm
|
// textureDescriptor.pixelFormat = .bgra8Unorm
|
||||||
textureDescriptor.width = width
|
// textureDescriptor.width = width
|
||||||
textureDescriptor.height = height
|
// textureDescriptor.height = height
|
||||||
textureDescriptor.usage = [.renderTarget, .shaderRead]
|
// textureDescriptor.usage = [.renderTarget, .shaderRead]
|
||||||
textureDescriptor.storageMode = .shared
|
// textureDescriptor.storageMode = .shared
|
||||||
|
//
|
||||||
guard let texture = device.makeTexture(descriptor: textureDescriptor) else {
|
// guard let texture = device.makeTexture(descriptor: textureDescriptor) else {
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
#else
|
//#else
|
||||||
guard let buffer = device.makeBuffer(length: bytesPerRow * height, options: MTLResourceOptions.storageModeShared) else {
|
// guard let buffer = device.makeBuffer(length: bytesPerRow * height, options: MTLResourceOptions.storageModeShared) else {
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
self.buffer = buffer
|
// self.buffer = buffer
|
||||||
|
//
|
||||||
let textureDescriptor = MTLTextureDescriptor()
|
// let textureDescriptor = MTLTextureDescriptor()
|
||||||
textureDescriptor.textureType = .type2D
|
// textureDescriptor.textureType = .type2D
|
||||||
textureDescriptor.pixelFormat = .bgra8Unorm
|
// textureDescriptor.pixelFormat = .bgra8Unorm
|
||||||
textureDescriptor.width = width
|
// textureDescriptor.width = width
|
||||||
textureDescriptor.height = height
|
// textureDescriptor.height = height
|
||||||
textureDescriptor.usage = [.renderTarget, .shaderRead]
|
// textureDescriptor.usage = [.renderTarget, .shaderRead]
|
||||||
textureDescriptor.storageMode = buffer.storageMode
|
// textureDescriptor.storageMode = buffer.storageMode
|
||||||
|
//
|
||||||
guard let texture = buffer.makeTexture(descriptor: textureDescriptor, offset: 0, bytesPerRow: bytesPerRow) else {
|
// guard let texture = buffer.makeTexture(descriptor: textureDescriptor, offset: 0, bytesPerRow: bytesPerRow) else {
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
#endif
|
//#endif
|
||||||
self.texture = texture
|
// self.texture = texture
|
||||||
} else {
|
// } else {
|
||||||
self.buffer = nil
|
self.buffer = nil
|
||||||
|
|
||||||
let textureDescriptor = MTLTextureDescriptor()
|
let textureDescriptor = MTLTextureDescriptor()
|
||||||
@@ -673,7 +676,7 @@ final class Texture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.texture = texture
|
self.texture = texture
|
||||||
}
|
// }
|
||||||
self.clear()
|
self.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -167,9 +167,22 @@ final class DrawingSimpleShapeEntityView: DrawingEntityView {
|
|||||||
return self.shapeLayer.lineWidth
|
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 {
|
override func precisePoint(inside point: CGPoint) -> Bool {
|
||||||
if case .stroke = self.shapeEntity.drawType, var path = self.shapeLayer.path {
|
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) {
|
if path.contains(point) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -134,6 +134,10 @@ final class DrawingVectorEntityView: DrawingEntityView {
|
|||||||
return self.shapeLayer.path?.boundingBox ?? self.bounds
|
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) {
|
override func update(animated: Bool) {
|
||||||
self.center = CGPoint(x: self.vectorEntity.drawingSize.width * 0.5, y: self.vectorEntity.drawingSize.height * 0.5)
|
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)
|
self.bounds = CGRect(origin: .zero, size: self.vectorEntity.drawingSize)
|
||||||
@@ -174,7 +178,15 @@ final class DrawingVectorEntityView: DrawingEntityView {
|
|||||||
if path.contains(point) {
|
if path.contains(point) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
return super.precisePoint(inside: point)
|
return super.precisePoint(inside: point)
|
||||||
|
|||||||
@@ -475,7 +475,7 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, TGPhotoDraw
|
|||||||
|
|
||||||
private let queue = Queue()
|
private let queue = Queue()
|
||||||
private var skipDrawing = Set<UUID>()
|
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 currentImage = self.drawingImage
|
||||||
let uncommitedElement = self.uncommitedElement
|
let uncommitedElement = self.uncommitedElement
|
||||||
let imageSize = self.imageSize
|
let imageSize = self.imageSize
|
||||||
|
|||||||
@@ -946,42 +946,42 @@ func selectivePrivacySettingsController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let controller = selectivePrivacyPeersController(context: context, title: title, initialPeers: updatedPeerIds, updated: { updatedPeerIds in
|
// let controller = selectivePrivacyPeersController(context: context, title: title, initialPeers: updatedPeerIds, updated: { updatedPeerIds in
|
||||||
updateState { state in
|
// updateState { state in
|
||||||
if enable {
|
// if enable {
|
||||||
switch target {
|
// switch target {
|
||||||
case .main:
|
// case .main:
|
||||||
var disableFor = state.disableFor
|
// var disableFor = state.disableFor
|
||||||
for (key, _) in updatedPeerIds {
|
// for (key, _) in updatedPeerIds {
|
||||||
disableFor.removeValue(forKey: key)
|
// disableFor.removeValue(forKey: key)
|
||||||
}
|
// }
|
||||||
return state.withUpdatedEnableFor(updatedPeerIds).withUpdatedDisableFor(disableFor)
|
// return state.withUpdatedEnableFor(updatedPeerIds).withUpdatedDisableFor(disableFor)
|
||||||
case .callP2P:
|
// case .callP2P:
|
||||||
var callP2PDisableFor = state.callP2PDisableFor ?? [:]
|
// var callP2PDisableFor = state.callP2PDisableFor ?? [:]
|
||||||
for (key, _) in updatedPeerIds {
|
// for (key, _) in updatedPeerIds {
|
||||||
callP2PDisableFor.removeValue(forKey: key)
|
// callP2PDisableFor.removeValue(forKey: key)
|
||||||
}
|
// }
|
||||||
return state.withUpdatedCallP2PEnableFor(updatedPeerIds).withUpdatedCallP2PDisableFor(callP2PDisableFor)
|
// return state.withUpdatedCallP2PEnableFor(updatedPeerIds).withUpdatedCallP2PDisableFor(callP2PDisableFor)
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
switch target {
|
// switch target {
|
||||||
case .main:
|
// case .main:
|
||||||
var enableFor = state.enableFor
|
// var enableFor = state.enableFor
|
||||||
for (key, _) in updatedPeerIds {
|
// for (key, _) in updatedPeerIds {
|
||||||
enableFor.removeValue(forKey: key)
|
// enableFor.removeValue(forKey: key)
|
||||||
}
|
// }
|
||||||
return state.withUpdatedDisableFor(updatedPeerIds).withUpdatedEnableFor(enableFor)
|
// return state.withUpdatedDisableFor(updatedPeerIds).withUpdatedEnableFor(enableFor)
|
||||||
case .callP2P:
|
// case .callP2P:
|
||||||
var callP2PEnableFor = state.callP2PEnableFor ?? [:]
|
// var callP2PEnableFor = state.callP2PEnableFor ?? [:]
|
||||||
for (key, _) in updatedPeerIds {
|
// for (key, _) in updatedPeerIds {
|
||||||
callP2PEnableFor.removeValue(forKey: key)
|
// callP2PEnableFor.removeValue(forKey: key)
|
||||||
}
|
// }
|
||||||
return state.withUpdatedCallP2PDisableFor(updatedPeerIds).withUpdatedCallP2PEnableFor(callP2PEnableFor)
|
// return state.withUpdatedCallP2PDisableFor(updatedPeerIds).withUpdatedCallP2PEnableFor(callP2PEnableFor)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
pushControllerImpl?(controller, false)
|
// pushControllerImpl?(controller, false)
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||||
|
|||||||
Reference in New Issue
Block a user