mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 01:10:09 +00:00
Disable drawing animations when energy saving
This commit is contained in:
parent
1ab3cff8fa
commit
c341b1c449
@ -140,7 +140,7 @@ final class PenTool: DrawingElement {
|
||||
self.start = newStart
|
||||
}
|
||||
|
||||
if !element.isEraser && !element.isBlur {
|
||||
if element.hasAnimations {
|
||||
let count = CGFloat(element.segments.count - self.segmentsCount)
|
||||
if count > 0 {
|
||||
let dryingPath = CGMutablePath()
|
||||
@ -193,7 +193,7 @@ final class PenTool: DrawingElement {
|
||||
return
|
||||
}
|
||||
|
||||
if !element.isEraser && !element.isBlur {
|
||||
if element.hasAnimations {
|
||||
let dryingPath = CGMutablePath()
|
||||
for segment in element.activeSegments {
|
||||
let segmentPath = element.pathForSegment(segment)
|
||||
@ -216,7 +216,7 @@ final class PenTool: DrawingElement {
|
||||
context.scaleBy(x: 1.0 / parent.drawScale.width, y: 1.0 / parent.drawScale.height)
|
||||
element.drawSegments(in: context, from: parent.start, to: parent.segmentsCount)
|
||||
|
||||
if !element.isEraser && !element.isBlur {
|
||||
if element.hasAnimations {
|
||||
element.drawActiveSegments(in: context, strokeWidth: !parent.isActiveDrying ? element.renderLineWidth * parent.dryingFactor : nil)
|
||||
} else {
|
||||
element.drawActiveSegments(in: context, strokeWidth: nil)
|
||||
@ -266,6 +266,12 @@ final class PenTool: DrawingElement {
|
||||
private var segmentPaths: [Int: CGPath] = [:]
|
||||
|
||||
private var useCubicBezier = true
|
||||
|
||||
private let animationsEnabled: Bool
|
||||
|
||||
var hasAnimations: Bool {
|
||||
return self.animationsEnabled && !self.isEraser && !self.isBlur
|
||||
}
|
||||
|
||||
var isValid: Bool {
|
||||
if self.hasArrow {
|
||||
@ -284,7 +290,7 @@ final class PenTool: DrawingElement {
|
||||
return normalizeDrawingRect(combinedBounds, drawingSize: self.drawingSize)
|
||||
}
|
||||
|
||||
required init(drawingSize: CGSize, color: DrawingColor, lineWidth: CGFloat, hasArrow: Bool, isEraser: Bool, isBlur: Bool, blurredImage: UIImage?) {
|
||||
required init(drawingSize: CGSize, color: DrawingColor, lineWidth: CGFloat, hasArrow: Bool, isEraser: Bool, isBlur: Bool, blurredImage: UIImage?, animationsEnabled: Bool) {
|
||||
self.uuid = UUID()
|
||||
self.drawingSize = drawingSize
|
||||
self.color = isEraser || isBlur ? DrawingColor(rgb: 0x000000) : color
|
||||
@ -292,6 +298,7 @@ final class PenTool: DrawingElement {
|
||||
self.isEraser = isEraser
|
||||
self.isBlur = isBlur
|
||||
self.blurredImage = blurredImage
|
||||
self.animationsEnabled = animationsEnabled
|
||||
|
||||
let minLineWidth = max(1.0, max(drawingSize.width, drawingSize.height) * 0.002)
|
||||
let maxLineWidth = max(10.0, max(drawingSize.width, drawingSize.height) * 0.07)
|
||||
|
||||
@ -1994,6 +1994,7 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController, U
|
||||
var drawingView: DrawingView {
|
||||
if self._drawingView == nil, let controller = self.controller {
|
||||
self._drawingView = DrawingView(size: controller.size)
|
||||
self._drawingView?.animationsEnabled = self.context.sharedContext.energyUsageSettings.fullTranslucency
|
||||
self._drawingView?.shouldBegin = { [weak self] _ in
|
||||
if let strongSelf = self {
|
||||
if strongSelf._entitiesView?.hasSelection == true {
|
||||
|
||||
@ -103,6 +103,8 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, UIPencilInt
|
||||
private var isDrawing = false
|
||||
private var drawingGestureStartTimestamp: Double?
|
||||
|
||||
var animationsEnabled = true
|
||||
|
||||
private func loadTemplates() {
|
||||
func load(_ name: String) {
|
||||
if let url = getAppBundle().url(forResource: name, withExtension: "json"),
|
||||
@ -920,7 +922,8 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, UIPencilInt
|
||||
hasArrow: false,
|
||||
isEraser: false,
|
||||
isBlur: false,
|
||||
blurredImage: nil
|
||||
blurredImage: nil,
|
||||
animationsEnabled: self.animationsEnabled
|
||||
)
|
||||
element = penTool
|
||||
case .arrow:
|
||||
@ -931,7 +934,8 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, UIPencilInt
|
||||
hasArrow: true,
|
||||
isEraser: false,
|
||||
isBlur: false,
|
||||
blurredImage: nil
|
||||
blurredImage: nil,
|
||||
animationsEnabled: self.animationsEnabled
|
||||
)
|
||||
element = penTool
|
||||
case .marker:
|
||||
@ -956,7 +960,8 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, UIPencilInt
|
||||
hasArrow: false,
|
||||
isEraser: false,
|
||||
isBlur: true,
|
||||
blurredImage: self.preparedBlurredImage
|
||||
blurredImage: self.preparedBlurredImage,
|
||||
animationsEnabled: self.animationsEnabled
|
||||
)
|
||||
element = penTool
|
||||
case .eraser:
|
||||
@ -967,7 +972,8 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, UIPencilInt
|
||||
hasArrow: false,
|
||||
isEraser: true,
|
||||
isBlur: false,
|
||||
blurredImage: nil
|
||||
blurredImage: nil,
|
||||
animationsEnabled: self.animationsEnabled
|
||||
)
|
||||
element = penTool
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user