mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Various fixes
This commit is contained in:
parent
8c57b9eef0
commit
e44ba3e7f8
@ -3,6 +3,7 @@ import UIKit
|
||||
import QuartzCore
|
||||
import MetalKit
|
||||
import Display
|
||||
import SwiftSignalKit
|
||||
import AppBundle
|
||||
|
||||
final class DrawingMetalView: MTKView {
|
||||
@ -53,10 +54,17 @@ final class DrawingMetalView: MTKView {
|
||||
self.autoResizeDrawable = false
|
||||
self.isOpaque = false
|
||||
self.contentScaleFactor = 1.0
|
||||
self.isPaused = true
|
||||
|
||||
self.setup()
|
||||
}
|
||||
|
||||
override var isHidden: Bool {
|
||||
didSet {
|
||||
self.isPaused = self.isHidden
|
||||
}
|
||||
}
|
||||
|
||||
required init(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
@ -124,7 +132,12 @@ final class DrawingMetalView: MTKView {
|
||||
|
||||
self.drawable?.clear()
|
||||
|
||||
self.markerBrush?.pushPoint(CGPoint(x: 100.0, y: 100.0), color: DrawingColor.clear, size: 0.0, isEnd: true)
|
||||
Queue.mainQueue().after(0.1) {
|
||||
self.markerBrush?.pushPoint(CGPoint(x: 100.0, y: 100.0), color: DrawingColor.clear, size: 0.0, isEnd: true)
|
||||
Queue.mainQueue().after(0.1) {
|
||||
self.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -76,11 +76,11 @@ final class NeonTool: DrawingElement {
|
||||
let renderColor: UIColor
|
||||
|
||||
private var pathStarted = false
|
||||
let path = UIBezierPath()
|
||||
var activePath: UIBezierPath?
|
||||
var addedSegments = 0
|
||||
private let path = UIBezierPath()
|
||||
private var activePath: UIBezierPath?
|
||||
private var addedPaths = 0
|
||||
|
||||
var renderPath: CGPath?
|
||||
fileprivate var renderPath: CGPath?
|
||||
|
||||
var translation: CGPoint = .zero
|
||||
|
||||
@ -128,8 +128,8 @@ final class NeonTool: DrawingElement {
|
||||
return nil
|
||||
}
|
||||
|
||||
func updatePath(_ point: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState) {
|
||||
guard self.addPoint(point, state: state) else {
|
||||
func updatePath(_ point: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState, zoomScale: CGFloat) {
|
||||
guard self.addPoint(point, state: state, zoomScale: zoomScale) || state == .ended else {
|
||||
return
|
||||
}
|
||||
|
||||
@ -144,8 +144,13 @@ final class NeonTool: DrawingElement {
|
||||
}
|
||||
}
|
||||
|
||||
if state == .ended, self.addedSegments == 0, let point = self.points.first {
|
||||
self.renderPath = CGPath(ellipseIn: CGRect(origin: CGPoint(x: point.x - self.renderLineWidth / 2.0, y: point.y - self.renderLineWidth / 2.0), size: CGSize(width: self.renderLineWidth, height: self.renderLineWidth)), transform: nil)
|
||||
if state == .ended {
|
||||
if let activePath = self.activePath {
|
||||
self.path.append(activePath)
|
||||
self.renderPath = self.path.cgPath.copy(strokingWithWidth: self.renderLineWidth, lineCap: .round, lineJoin: .round, miterLimit: 0.0)
|
||||
} else if self.addedPaths == 0, let point = self.points.first {
|
||||
self.renderPath = CGPath(ellipseIn: CGRect(origin: CGPoint(x: point.x - self.renderLineWidth / 2.0, y: point.y - self.renderLineWidth / 2.0), size: CGSize(width: self.renderLineWidth, height: self.renderLineWidth)), transform: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,8 +198,8 @@ final class NeonTool: DrawingElement {
|
||||
private var points: [CGPoint] = Array(repeating: .zero, count: 4)
|
||||
private var pointPtr = 0
|
||||
|
||||
private func addPoint(_ point: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState) -> Bool {
|
||||
let filterDistance: CGFloat = 10.0
|
||||
private func addPoint(_ point: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState, zoomScale: CGFloat) -> Bool {
|
||||
let filterDistance: CGFloat = 10.0 / zoomScale
|
||||
|
||||
if self.pointPtr == 0 {
|
||||
self.points[0] = point.location
|
||||
@ -210,6 +215,7 @@ final class NeonTool: DrawingElement {
|
||||
|
||||
if let bezierPath = self.currentBezierPath(3) {
|
||||
self.path.append(bezierPath)
|
||||
self.addedPaths += 1
|
||||
self.activePath = nil
|
||||
}
|
||||
|
||||
|
@ -229,8 +229,8 @@ final class PenTool: DrawingElement {
|
||||
return nil
|
||||
}
|
||||
|
||||
func updatePath(_ point: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState) {
|
||||
let result = self.addPoint(point, state: state)
|
||||
func updatePath(_ point: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState, zoomScale: CGFloat) {
|
||||
let result = self.addPoint(point, state: state, zoomScale: zoomScale)
|
||||
let resetActiveRect = result?.0 ?? false
|
||||
let updatedRect = result?.1
|
||||
var combinedRect = updatedRect
|
||||
@ -410,8 +410,8 @@ final class PenTool: DrawingElement {
|
||||
|
||||
private var previousRenderLineWidth: CGFloat?
|
||||
|
||||
private func addPoint(_ point: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState) -> (Bool, CGRect)? {
|
||||
let filterDistance: CGFloat = 10.0
|
||||
private func addPoint(_ point: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState, zoomScale: CGFloat) -> (Bool, CGRect)? {
|
||||
let filterDistance: CGFloat = 10.0 / zoomScale
|
||||
|
||||
var velocity = point.velocity
|
||||
if velocity.isZero {
|
||||
|
@ -65,8 +65,9 @@ final class MarkerTool: DrawingElement {
|
||||
}
|
||||
|
||||
private var didSetup = false
|
||||
func updatePath(_ point: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState) {
|
||||
if let lastPoint = self.points.last, lastPoint.isEqual(to: point.location, epsilon: 0.1) {
|
||||
func updatePath(_ point: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState, zoomScale: CGFloat) {
|
||||
let filterDistance: CGFloat = 10.0 / zoomScale
|
||||
if let lastPoint = self.points.last, lastPoint.distance(to: point.location) < filterDistance {
|
||||
} else {
|
||||
self.points.append(point.location)
|
||||
}
|
||||
@ -124,7 +125,7 @@ final class FillTool: DrawingElement {
|
||||
return nil
|
||||
}
|
||||
|
||||
func updatePath(_ path: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState) {
|
||||
func updatePath(_ path: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState, zoomScale: CGFloat) {
|
||||
}
|
||||
|
||||
func draw(in context: CGContext, size: CGSize) {
|
||||
|
@ -23,7 +23,7 @@ protocol DrawingElement: AnyObject {
|
||||
|
||||
func setupRenderView(screenSize: CGSize) -> DrawingRenderView?
|
||||
func setupRenderLayer() -> DrawingRenderLayer?
|
||||
func updatePath(_ point: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState)
|
||||
func updatePath(_ point: DrawingPoint, state: DrawingGesturePipeline.DrawingGestureState, zoomScale: CGFloat)
|
||||
|
||||
func draw(in: CGContext, size: CGSize)
|
||||
}
|
||||
@ -267,7 +267,7 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, TGPhotoDraw
|
||||
}
|
||||
strongSelf.currentDrawingLayer = renderLayer
|
||||
}
|
||||
newElement.updatePath(point, state: state)
|
||||
newElement.updatePath(point, state: state, zoomScale: strongSelf.zoomScale)
|
||||
strongSelf.uncommitedElement = newElement
|
||||
strongSelf.updateInternalState()
|
||||
case .changed:
|
||||
@ -275,7 +275,7 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, TGPhotoDraw
|
||||
return
|
||||
}
|
||||
strongSelf.previousPointTimestamp = currentTimestamp
|
||||
strongSelf.uncommitedElement?.updatePath(point, state: state)
|
||||
strongSelf.uncommitedElement?.updatePath(point, state: state, zoomScale: strongSelf.zoomScale)
|
||||
|
||||
// if case let .direct(point) = path, let lastPoint = line.points.last {
|
||||
// if let previousStrokePoint = strongSelf.previousStrokePoint, line.points.count > 10 {
|
||||
@ -343,25 +343,23 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, TGPhotoDraw
|
||||
// strongSelf.previousStrokePoint = lastPoint.location
|
||||
// }
|
||||
// }
|
||||
case .ended:
|
||||
case .ended, .cancelled:
|
||||
strongSelf.isDrawing = false
|
||||
strongSelf.strokeRecognitionTimer?.invalidate()
|
||||
strongSelf.strokeRecognitionTimer = nil
|
||||
strongSelf.uncommitedElement?.updatePath(point, state: state)
|
||||
strongSelf.uncommitedElement?.updatePath(point, state: state, zoomScale: strongSelf.zoomScale)
|
||||
|
||||
let bounds = strongSelf.uncommitedElement?.bounds
|
||||
Queue.mainQueue().after(0.05) {
|
||||
if let bounds = bounds {
|
||||
strongSelf.finishDrawing(rect: bounds, synchronous: true)
|
||||
if strongSelf.uncommitedElement?.isValid == true {
|
||||
let bounds = strongSelf.uncommitedElement?.bounds
|
||||
Queue.mainQueue().after(0.05) {
|
||||
if let bounds = bounds {
|
||||
strongSelf.finishDrawing(rect: bounds, synchronous: true)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
strongSelf.cancelDrawing()
|
||||
}
|
||||
strongSelf.updateInternalState()
|
||||
case .cancelled:
|
||||
strongSelf.isDrawing = false
|
||||
strongSelf.strokeRecognitionTimer?.invalidate()
|
||||
strongSelf.strokeRecognitionTimer = nil
|
||||
strongSelf.cancelDrawing()
|
||||
strongSelf.updateInternalState()
|
||||
}
|
||||
}
|
||||
self.drawingGesturePipeline = drawingGesturePipeline
|
||||
@ -599,6 +597,9 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, TGPhotoDraw
|
||||
}
|
||||
self.currentDrawingLayer = nil
|
||||
}
|
||||
if case .marker = self.tool {
|
||||
self.metalView?.isHidden = true
|
||||
}
|
||||
}
|
||||
|
||||
private func slice(for rect: CGRect) -> DrawingSlice? {
|
||||
|
Loading…
x
Reference in New Issue
Block a user