mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Various theme improvements
This commit is contained in:
@@ -11,7 +11,7 @@ import AppBundle
|
||||
|
||||
private var backgroundImageForWallpaper: (TelegramWallpaper, Bool, UIImage)?
|
||||
|
||||
public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper initialWallpaper: TelegramWallpaper, mediaBox: MediaBox, composed: Bool = true, knockoutMode: Bool) -> UIImage? {
|
||||
public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper initialWallpaper: TelegramWallpaper, mediaBox: MediaBox, composed: Bool = true, knockoutMode: Bool, cached: Bool = true) -> UIImage? {
|
||||
var wallpaper = initialWallpaper
|
||||
if knockoutMode, let theme = theme {
|
||||
switch theme.name {
|
||||
@@ -28,9 +28,10 @@ public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper i
|
||||
}
|
||||
|
||||
var backgroundImage: UIImage?
|
||||
if composed && wallpaper == backgroundImageForWallpaper?.0, (wallpaper.settings?.blur ?? false) == backgroundImageForWallpaper?.1 {
|
||||
if cached && composed && wallpaper == backgroundImageForWallpaper?.0, (wallpaper.settings?.blur ?? false) == backgroundImageForWallpaper?.1 {
|
||||
backgroundImage = backgroundImageForWallpaper?.2
|
||||
} else {
|
||||
var succeed = true
|
||||
switch wallpaper {
|
||||
case .builtin:
|
||||
if let filePath = getAppBundle().path(forResource: "ChatWallpaperBuiltin0", ofType: "jpg") {
|
||||
@@ -41,14 +42,18 @@ public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper i
|
||||
context.setFillColor(UIColor(rgb: UInt32(bitPattern: color)).withAlphaComponent(1.0).cgColor)
|
||||
context.fill(CGRect(origin: CGPoint(), size: size))
|
||||
})
|
||||
case let .gradient(topColor, bottomColor, _):
|
||||
backgroundImage = generateImage(CGSize(width: 1.0, height: 1280.0), rotatedContext: { size, context in
|
||||
case let .gradient(topColor, bottomColor, settings):
|
||||
backgroundImage = generateImage(CGSize(width: 640.0, height: 1280.0), rotatedContext: { size, context in
|
||||
let gradientColors = [UIColor(rgb: UInt32(bitPattern: topColor)).cgColor, UIColor(rgb: UInt32(bitPattern: bottomColor)).cgColor] as CFArray
|
||||
|
||||
var locations: [CGFloat] = [0.0, 1.0]
|
||||
let colorSpace = CGColorSpaceCreateDeviceRGB()
|
||||
let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)!
|
||||
|
||||
context.translateBy(x: 320.0, y: 640.0)
|
||||
context.rotate(by: CGFloat(settings.rotation ?? 0) * CGFloat.pi / 180.0)
|
||||
context.translateBy(x: -320.0, y: -640.0)
|
||||
|
||||
context.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: 0.0), end: CGPoint(x: 0.0, y: size.height), options: CGGradientDrawingOptions())
|
||||
})
|
||||
case let .image(representations, settings):
|
||||
@@ -63,13 +68,14 @@ public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper i
|
||||
backgroundImage = image
|
||||
}
|
||||
if backgroundImage == nil, let path = mediaBox.completedResourcePath(largest.resource) {
|
||||
succeed = false
|
||||
backgroundImage = UIImage(contentsOfFile: path)?.precomposed()
|
||||
}
|
||||
}
|
||||
case let .file(file):
|
||||
if file.isPattern, let color = file.settings.color, let intensity = file.settings.intensity {
|
||||
var image: UIImage?
|
||||
let _ = mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: color, intensity: intensity), complete: true, fetch: true, attemptSynchronously: true).start(next: { data in
|
||||
let _ = mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: color, bottomColor: file.settings.bottomColor, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: true).start(next: { data in
|
||||
if data.complete {
|
||||
image = UIImage(contentsOfFile: data.path)?.precomposed()
|
||||
}
|
||||
@@ -86,11 +92,12 @@ public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper i
|
||||
backgroundImage = image
|
||||
}
|
||||
if backgroundImage == nil, let path = mediaBox.completedResourcePath(file.file.resource) {
|
||||
succeed = false
|
||||
backgroundImage = UIImage(contentsOfFile: path)?.precomposed()
|
||||
}
|
||||
}
|
||||
}
|
||||
if let backgroundImage = backgroundImage, composed {
|
||||
if let backgroundImage = backgroundImage, composed && succeed {
|
||||
backgroundImageForWallpaper = (wallpaper, (wallpaper.settings?.blur ?? false), backgroundImage)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user