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