diff --git a/submodules/DrawingUI/Sources/DrawingBubbleEntity.swift b/submodules/DrawingUI/Sources/DrawingBubbleEntity.swift index 025f6b9f18..b26a0a223b 100644 --- a/submodules/DrawingUI/Sources/DrawingBubbleEntity.swift +++ b/submodules/DrawingUI/Sources/DrawingBubbleEntity.swift @@ -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 { diff --git a/submodules/DrawingUI/Sources/DrawingMetalView.swift b/submodules/DrawingUI/Sources/DrawingMetalView.swift index 6f34ffd577..3c157783d7 100644 --- a/submodules/DrawingUI/Sources/DrawingMetalView.swift +++ b/submodules/DrawingUI/Sources/DrawingMetalView.swift @@ -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() } diff --git a/submodules/DrawingUI/Sources/DrawingSimpleShapeEntity.swift b/submodules/DrawingUI/Sources/DrawingSimpleShapeEntity.swift index 7fb7d65abb..2c662614af 100644 --- a/submodules/DrawingUI/Sources/DrawingSimpleShapeEntity.swift +++ b/submodules/DrawingUI/Sources/DrawingSimpleShapeEntity.swift @@ -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 { diff --git a/submodules/DrawingUI/Sources/DrawingVectorEntity.swift b/submodules/DrawingUI/Sources/DrawingVectorEntity.swift index ce06b50cb8..9d4a371d3c 100644 --- a/submodules/DrawingUI/Sources/DrawingVectorEntity.swift +++ b/submodules/DrawingUI/Sources/DrawingVectorEntity.swift @@ -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) diff --git a/submodules/DrawingUI/Sources/DrawingView.swift b/submodules/DrawingUI/Sources/DrawingView.swift index 39dafe2253..53442553b4 100644 --- a/submodules/DrawingUI/Sources/DrawingView.swift +++ b/submodules/DrawingUI/Sources/DrawingView.swift @@ -475,7 +475,7 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, TGPhotoDraw private let queue = Queue() private var skipDrawing = Set() - 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 diff --git a/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift index a5ae50f1f9..80912caa4f 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift @@ -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))