Tune wallpaper pattern scale on iPad

This commit is contained in:
Ilya Laktyushin 2023-03-03 12:11:34 +04:00
parent 4f5e7548d9
commit 2adf8a010d
16 changed files with 139 additions and 70 deletions

View File

@ -1070,7 +1070,7 @@ final class MediaPickerSelectedListNode: ASDisplayNode, UIScrollViewDelegate, UI
self.wallpaperBackgroundNode.update(wallpaper: wallpaper)
self.wallpaperBackgroundNode.updateBubbleTheme(bubbleTheme: theme, bubbleCorners: bubbleCorners)
transition.updateFrame(node: self.wallpaperBackgroundNode, frame: CGRect(origin: CGPoint(x: inset, y: 0.0), size: CGSize(width: size.width - inset * 2.0, height: size.height)))
self.wallpaperBackgroundNode.updateLayout(size: CGSize(width: size.width - inset * 2.0, height: size.height), tile: false, transition: transition)
self.wallpaperBackgroundNode.updateLayout(size: CGSize(width: size.width - inset * 2.0, height: size.height), displayMode: .aspectFill, transition: transition)
self.updateItems(transition: itemsTransition)

View File

@ -285,7 +285,7 @@ private final class BubbleSettingsControllerNode: ASDisplayNode, UIScrollViewDel
bottomInset = 37.0
self.chatBackgroundNode.frame = chatFrame
self.chatBackgroundNode.updateLayout(size: chatFrame.size, tile: false, transition: transition)
self.chatBackgroundNode.updateLayout(size: chatFrame.size, displayMode: .aspectFill, transition: transition)
self.messagesContainerNode.frame = chatFrame
transition.updateFrame(node: self.toolbarNode, frame: CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - toolbarHeight), size: CGSize(width: layout.size.width, height: toolbarHeight + layout.intrinsicInsets.bottom)))

View File

@ -179,29 +179,11 @@ class ForwardPrivacyChatPreviewItemNode: ListViewItemNode {
let layout = ListViewItemNodeLayout(contentSize: contentSize, insets: insets)
let layoutSize = layout.size
var authorNameCenter: CGFloat?
let attributedMeasureText = NSAttributedString(string: item.peerName, font: Font.regular(13.0), textColor: .black)
let (authorNameLayout, _) = makeTextLayout(TextNodeLayoutArguments(attributedString: attributedMeasureText, backgroundColor: nil, maximumNumberOfLines: 0, truncationType: .end, constrainedSize: CGSize(width: params.width, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, lineSpacing: 0.0, cutout: nil, insets: UIEdgeInsets()))
let forwardedString = item.strings.Message_ForwardedMessageShort("").string
var fromString: String?
if let newlineRange = forwardedString.range(of: "\n") {
let from = forwardedString[newlineRange.upperBound...]
if !from.isEmpty {
fromString = String(from)
}
}
let authorString = item.peerName
if let fromString = fromString {
var attributedMeasureText = NSAttributedString(string: fromString, font: Font.regular(13.0), textColor: .black)
let (fromTextLayout, _) = makeTextLayout(TextNodeLayoutArguments(attributedString: attributedMeasureText, backgroundColor: nil, maximumNumberOfLines: 0, truncationType: .end, constrainedSize: CGSize(width: params.width, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, lineSpacing: 0.0, cutout: nil, insets: UIEdgeInsets()))
let fromWidth = fromTextLayout.size.width
attributedMeasureText = NSAttributedString(string: authorString, font: Font.regular(13.0), textColor: .black)
let (authorNameLayout, _) = makeTextLayout(TextNodeLayoutArguments(attributedString: attributedMeasureText, backgroundColor: nil, maximumNumberOfLines: 0, truncationType: .end, constrainedSize: CGSize(width: params.width, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, lineSpacing: 0.0, cutout: nil, insets: UIEdgeInsets()))
let authorNameWidth = authorNameLayout.size.width
authorNameCenter = fromWidth + authorNameWidth / 2.0 + 3.0
}
let authorNameWidth = authorNameLayout.size.width
let authorNameCenter = authorNameWidth / 2.0 + 3.0
return (layout, { [weak self] in
if let strongSelf = self {
@ -264,11 +246,26 @@ class ForwardPrivacyChatPreviewItemNode: ListViewItemNode {
let backgroundFrame = CGRect(origin: CGPoint(x: 0.0, y: -min(insets.top, separatorHeight)), size: CGSize(width: params.width, height: contentSize.height + min(insets.top, separatorHeight) + min(insets.bottom, separatorHeight)))
let displayMode: WallpaperDisplayMode
if abs(params.availableHeight - params.width) < 100.0, params.availableHeight > 700.0 {
displayMode = .halfAspectFill
} else {
if backgroundFrame.width > backgroundFrame.height * 4.0 {
if params.availableHeight < 700.0 {
displayMode = .halfAspectFill
} else {
displayMode = .aspectFill
}
} else {
displayMode = .aspectFill
}
}
if let backgroundNode = strongSelf.backgroundNode {
backgroundNode.frame = backgroundFrame.insetBy(dx: 0.0, dy: -100.0)
backgroundNode.update(wallpaper: item.wallpaper)
backgroundNode.updateBubbleTheme(bubbleTheme: item.theme, bubbleCorners: item.chatBubbleCorners)
backgroundNode.updateLayout(size: backgroundNode.bounds.size, tile: false, transition: .immediate)
backgroundNode.updateLayout(size: backgroundNode.bounds.size, displayMode: displayMode, transition: .immediate)
}
strongSelf.maskNode.frame = backgroundFrame.insetBy(dx: params.leftInset, dy: 0.0)
@ -285,10 +282,8 @@ class ForwardPrivacyChatPreviewItemNode: ListViewItemNode {
var sourceRect: CGRect
if let messageNode = strongSelf.messageNode as? ChatMessagePreviewItemNode, let forwardInfoNode = messageNode.forwardInfoReferenceNode {
sourceRect = forwardInfoNode.convert(forwardInfoNode.bounds, to: strongSelf)
if let authorNameCenter = authorNameCenter {
sourceRect.origin = CGPoint(x: sourceRect.minX + authorNameCenter, y: sourceRect.minY)
sourceRect.size.width = 0.0
}
sourceRect.origin = CGPoint(x: sourceRect.minX + authorNameCenter, y: sourceRect.minY)
sourceRect.size.width = 0.0
} else {
sourceRect = CGRect(origin: CGPoint(x: layout.size.width / 2.0, y: layout.size.height / 2.0), size: CGSize())
}

View File

@ -389,11 +389,26 @@ class ReactionChatPreviewItemNode: ListViewItemNode {
let backgroundFrame = CGRect(origin: CGPoint(x: 0.0, y: -min(insets.top, separatorHeight)), size: CGSize(width: params.width, height: contentSize.height + min(insets.top, separatorHeight) + min(insets.bottom, separatorHeight)))
let displayMode: WallpaperDisplayMode
if abs(params.availableHeight - params.width) < 100.0, params.availableHeight > 700.0 {
displayMode = .halfAspectFill
} else {
if backgroundFrame.width > backgroundFrame.height * 4.0 {
if params.availableHeight < 700.0 {
displayMode = .halfAspectFill
} else {
displayMode = .aspectFill
}
} else {
displayMode = .aspectFill
}
}
if let backgroundNode = strongSelf.backgroundNode {
backgroundNode.frame = backgroundFrame.insetBy(dx: 0.0, dy: -100.0)
backgroundNode.update(wallpaper: item.wallpaper)
backgroundNode.updateBubbleTheme(bubbleTheme: item.theme, bubbleCorners: item.chatBubbleCorners)
backgroundNode.updateLayout(size: backgroundNode.bounds.size, tile: false, transition: .immediate)
backgroundNode.updateLayout(size: backgroundNode.bounds.size, displayMode: displayMode, transition: .immediate)
}
strongSelf.maskNode.frame = backgroundFrame.insetBy(dx: params.leftInset, dy: 0.0)

View File

@ -564,7 +564,7 @@ private final class TextSizeSelectionControllerNode: ASDisplayNode, UIScrollView
}
self.chatBackgroundNode.frame = chatFrame
self.chatBackgroundNode.updateLayout(size: chatFrame.size, tile: false, transition: transition)
self.chatBackgroundNode.updateLayout(size: chatFrame.size, displayMode: .aspectFill, transition: transition)
self.messagesContainerNode.frame = chatFrame
transition.updateFrame(node: self.toolbarNode, frame: CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - toolbarHeight), size: CGSize(width: layout.size.width, height: toolbarHeight + layout.intrinsicInsets.bottom)))

View File

@ -1198,7 +1198,7 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate
transition.updateFrame(node: self.backgroundContainerNode, frame: CGRect(origin: CGPoint(), size: backgroundSize))
transition.updateFrame(node: self.backgroundNode, frame: CGRect(origin: CGPoint(), size: layout.size))
self.backgroundNode.updateLayout(size: self.backgroundNode.bounds.size, tile: false, transition: transition)
self.backgroundNode.updateLayout(size: self.backgroundNode.bounds.size, displayMode: .aspectFill, transition: transition)
transition.updatePosition(node: self.backgroundWrapperNode, position: CGPoint(x: backgroundSize.width / 2.0, y: backgroundSize.height / 2.0))

View File

@ -712,11 +712,11 @@ final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate {
self.messagesContainerNode.frame = self.chatContainerNode.bounds
self.instantChatBackgroundNode.frame = self.chatContainerNode.bounds
self.instantChatBackgroundNode.updateLayout(size: self.instantChatBackgroundNode.bounds.size, tile: false, transition: .immediate)
self.instantChatBackgroundNode.updateLayout(size: self.instantChatBackgroundNode.bounds.size, displayMode: .aspectFill, transition: .immediate)
self.remoteChatBackgroundNode.frame = self.chatContainerNode.bounds
self.blurredNode.frame = self.chatContainerNode.bounds
self.wallpaperNode.frame = self.chatContainerNode.bounds
self.wallpaperNode.updateLayout(size: self.wallpaperNode.bounds.size, tile: false, transition: .immediate)
self.wallpaperNode.updateLayout(size: self.wallpaperNode.bounds.size, displayMode: .aspectFill, transition: .immediate)
transition.updateFrame(node: self.toolbarNode, frame: CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - toolbarHeight), size: CGSize(width: layout.size.width, height: toolbarHeight)))
self.toolbarNode.updateLayout(size: CGSize(width: layout.size.width, height: 49.0), layout: layout, transition: transition)

View File

@ -265,9 +265,25 @@ class ThemeSettingsChatPreviewItemNode: ListViewItemNode {
strongSelf.maskNode.image = hasCorners ? PresentationResourcesItemList.cornersImage(item.componentTheme, top: hasTopCorners, bottom: hasBottomCorners) : nil
let backgroundFrame = CGRect(origin: CGPoint(x: 0.0, y: -min(insets.top, separatorHeight)), size: CGSize(width: params.width, height: contentSize.height + min(insets.top, separatorHeight) + min(insets.bottom, separatorHeight)))
let displayMode: WallpaperDisplayMode
if abs(params.availableHeight - params.width) < 100.0, params.availableHeight > 700.0 {
displayMode = .halfAspectFill
} else {
if backgroundFrame.width > backgroundFrame.height * 4.0 {
if params.availableHeight < 700.0 {
displayMode = .halfAspectFill
} else {
displayMode = .aspectFill
}
} else {
displayMode = .aspectFill
}
}
if let backgroundNode = strongSelf.backgroundNode {
backgroundNode.frame = backgroundFrame.insetBy(dx: 0.0, dy: -100.0)
backgroundNode.updateLayout(size: backgroundNode.bounds.size, tile: false, transition: .immediate)
backgroundNode.updateLayout(size: backgroundNode.bounds.size, displayMode: displayMode, transition: .immediate)
}
strongSelf.maskNode.frame = backgroundFrame.insetBy(dx: params.leftInset, dy: 0.0)
strongSelf.topStripeNode.frame = CGRect(origin: CGPoint(x: 0.0, y: -min(insets.top, separatorHeight)), size: CGSize(width: layoutSize.width, height: separatorHeight))

View File

@ -1169,7 +1169,15 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
if self.cropNode.supernode == nil {
self.imageNode.frame = self.wrapperNode.bounds
self.nativeNode.frame = self.wrapperNode.bounds
self.nativeNode.updateLayout(size: self.nativeNode.bounds.size, tile: false, transition: .immediate)
let displayMode: WallpaperDisplayMode
if case .regular = layout.metrics.widthClass {
displayMode = .aspectFit
} else {
displayMode = .aspectFill
}
self.nativeNode.updateLayout(size: self.nativeNode.bounds.size, displayMode: displayMode, transition: .immediate)
self.blurredNode.frame = self.imageNode.frame
} else {
self.cropNode.frame = self.wrapperNode.bounds

View File

@ -1625,7 +1625,7 @@ final class MessageStoryRenderer {
let size = layout.size
self.containerNode.frame = CGRect(origin: CGPoint(), size: layout.size)
self.instantChatBackgroundNode.frame = CGRect(origin: CGPoint(), size: layout.size)
self.instantChatBackgroundNode.updateLayout(size: size, tile: false, transition: .immediate)
self.instantChatBackgroundNode.updateLayout(size: size, displayMode: .aspectFill, transition: .immediate)
self.messagesContainerNode.frame = CGRect(origin: CGPoint(), size: layout.size)
let addressLayout = self.addressNode.updateLayout(size)

View File

@ -1469,11 +1469,11 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
transition.updateFrame(node: self.backgroundNode, frame: contentBounds)
var shouldTile = false
var displayMode: WallpaperDisplayMode = .aspectFill
if case .regular = layout.metrics.widthClass, layout.size.height == layout.deviceMetrics.screenSize.width {
shouldTile = true
displayMode = .aspectFit
}
self.backgroundNode.updateLayout(size: contentBounds.size, tile: shouldTile, transition: transition)
self.backgroundNode.updateLayout(size: contentBounds.size, displayMode: displayMode, transition: transition)
transition.updateBounds(node: self.historyNodeContainer, bounds: contentBounds)
transition.updatePosition(node: self.historyNodeContainer, position: contentBounds.center)

View File

@ -1852,7 +1852,14 @@ private class QrContentNode: ASDisplayNode, ContentNode {
transition.updateFrame(node: self.containerNode, frame: CGRect(origin: CGPoint(), size: size))
transition.updateFrame(node: self.wallpaperBackgroundNode, frame: CGRect(origin: CGPoint(), size: size))
self.wallpaperBackgroundNode.updateLayout(size: size, tile: false, transition: transition)
let displayMode: WallpaperDisplayMode
if max(size.width, size.height) > 1000.0 {
displayMode = .aspectFit
} else {
displayMode = .aspectFill
}
self.wallpaperBackgroundNode.updateLayout(size: size, displayMode: displayMode, transition: transition)
let textLength = self.codeTextNode.attributedText?.string.count ?? 0
@ -2195,7 +2202,7 @@ private class MessageContentNode: ASDisplayNode, ContentNode {
transition.updateFrame(node: self.containerNode, frame: CGRect(origin: CGPoint(), size: size))
transition.updateFrame(node: self.wallpaperBackgroundNode, frame: CGRect(origin: CGPoint(), size: size))
self.wallpaperBackgroundNode.updateLayout(size: size, tile: false, transition: transition)
self.wallpaperBackgroundNode.updateLayout(size: size, displayMode: .aspectFill, transition: transition)
let inset: CGFloat = 24.0
let contentInset: CGFloat = 16.0

View File

@ -666,7 +666,7 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode {
let cleanInsets = layout.insets(options: [])
transition.updateFrame(node: self.backgroundNode, frame: CGRect(origin: CGPoint(), size: layout.size))
self.backgroundNode.updateLayout(size: self.backgroundNode.bounds.size, tile: false, transition: transition)
self.backgroundNode.updateLayout(size: self.backgroundNode.bounds.size, displayMode: .aspectFill, transition: transition)
let intrinsicPanelHeight: CGFloat = 47.0
let panelHeight = intrinsicPanelHeight + cleanInsets.bottom

View File

@ -138,7 +138,7 @@ final class MetalWallpaperBackgroundNode: ASDisplayNode, WallpaperBackgroundNode
}
func updateLayout(size: CGSize, tile: Bool, transition: ContainedViewLayoutTransition) {
func updateLayout(size: CGSize, displayMode: WallpaperDisplayMode, transition: ContainedViewLayoutTransition) {
if self.metalLayer.drawableSize != size {
self.metalLayer.drawableSize = size

View File

@ -54,13 +54,30 @@ public protocol WallpaperBubbleBackgroundNode: ASDisplayNode {
func offsetSpring(value: CGFloat, duration: Double, damping: CGFloat)
}
public enum WallpaperDisplayMode {
case aspectFill
case aspectFit
case halfAspectFill
var argumentsDisplayMode: PatternWallpaperArguments.DisplayMode {
switch self {
case .aspectFill:
return .aspectFill
case .aspectFit:
return .aspectFit
case .halfAspectFill:
return .halfAspectFill
}
}
}
public protocol WallpaperBackgroundNode: ASDisplayNode {
var isReady: Signal<Bool, NoError> { get }
var rotation: CGFloat { get set }
func update(wallpaper: TelegramWallpaper)
func _internalUpdateIsSettingUpWallpaper()
func updateLayout(size: CGSize, tile: Bool, transition: ContainedViewLayoutTransition)
func updateLayout(size: CGSize, displayMode: WallpaperDisplayMode, transition: ContainedViewLayoutTransition)
func updateIsLooping(_ isLooping: Bool)
func animateEvent(transition: ContainedViewLayoutTransition, extendAnimation: Bool)
func updateBubbleTheme(bubbleTheme: PresentationTheme, bubbleCorners: PresentationChatBubbleCorners)
@ -599,7 +616,7 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
private let bakedBackgroundView: UIImageView
private var validLayout: (CGSize, Bool)?
private var validLayout: (CGSize, WallpaperDisplayMode)?
private var wallpaper: TelegramWallpaper?
private var isSettingUpWallpaper: Bool = false
@ -884,8 +901,8 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
}
}
if let (size, tile) = self.validLayout {
self.updateLayout(size: size, tile: tile, transition: .immediate)
if let (size, displayMode) = self.validLayout {
self.updateLayout(size: size, displayMode: displayMode, transition: .immediate)
self.updateBubbles()
if scheduleLoopingEvent {
@ -953,7 +970,7 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
}
}
private func loadPatternForSizeIfNeeded(size: CGSize, tile: Bool, transition: ContainedViewLayoutTransition) {
private func loadPatternForSizeIfNeeded(size: CGSize, displayMode: WallpaperDisplayMode, transition: ContainedViewLayoutTransition) {
guard let wallpaper = self.wallpaper else {
return
}
@ -1024,8 +1041,8 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
strongSelf.validPatternImage = ValidPatternImage(wallpaper: wallpaper, invertPattern: invertPattern, generate: generator)
strongSelf.validPatternGeneratedImage = nil
if let (size, tile) = strongSelf.validLayout {
strongSelf.loadPatternForSizeIfNeeded(size: size, tile: tile, transition: .immediate)
if let (size, displayMode) = strongSelf.validLayout {
strongSelf.loadPatternForSizeIfNeeded(size: size, displayMode: displayMode, transition: .immediate)
} else {
strongSelf._isReady.set(true)
}
@ -1067,7 +1084,7 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
self.patternImageLayer.suspendCompositionUpdates = false
self.patternImageLayer.updateCompositionIfNeeded()
} else {
let patternArguments = TransformImageArguments(corners: ImageCorners(), imageSize: size, boundingSize: size, intrinsicInsets: UIEdgeInsets(), custom: PatternWallpaperArguments(colors: [patternBackgroundColor], rotation: nil, customPatternColor: patternColor, preview: false, tile: tile), scale: min(2.0, UIScreenScale))
let patternArguments = TransformImageArguments(corners: ImageCorners(), imageSize: size, boundingSize: size, intrinsicInsets: UIEdgeInsets(), custom: PatternWallpaperArguments(colors: [patternBackgroundColor], rotation: nil, customPatternColor: patternColor, preview: false, displayMode: displayMode.argumentsDisplayMode), scale: min(2.0, UIScreenScale))
if self.useSharedAnimationPhase || self.patternImageLayer.contents == nil {
if let drawingContext = validPatternImage.generate(patternArguments) {
if let image = drawingContext.generateImage() {
@ -1121,9 +1138,9 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
transition.updateFrame(layer: self.patternImageLayer, frame: CGRect(origin: CGPoint(), size: size))
}
func updateLayout(size: CGSize, tile: Bool, transition: ContainedViewLayoutTransition) {
func updateLayout(size: CGSize, displayMode: WallpaperDisplayMode, transition: ContainedViewLayoutTransition) {
let isFirstLayout = self.validLayout == nil
self.validLayout = (size, tile)
self.validLayout = (size, displayMode)
if let blurredBackgroundPortalSourceView = self.blurredBackgroundPortalSourceView {
transition.updateFrame(view: blurredBackgroundPortalSourceView, frame: CGRect(origin: CGPoint(), size: size))
@ -1151,7 +1168,7 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
outgoingBubbleGradientBackgroundNode.updateLayout(size: size, transition: transition, extendAnimation: false, backwards: false, completion: {})
}
self.loadPatternForSizeIfNeeded(size: size, tile: tile, transition: transition)
self.loadPatternForSizeIfNeeded(size: size, displayMode: displayMode, transition: transition)
/*for (animationNode, relativePosition) in self.inlineAnimationNodes {
let sizeNorm = CGSize(width: 1440, height: 2960)
@ -2021,7 +2038,7 @@ final class WallpaperBackgroundNodeMergedImpl: ASDisplayNode, WallpaperBackgroun
self.isSettingUpWallpaper = true
}
func updateLayout(size: CGSize, tile: Bool, transition: ContainedViewLayoutTransition) {
func updateLayout(size: CGSize, displayMode: WallpaperDisplayMode, transition: ContainedViewLayoutTransition) {
self.validLayout = size
self.staticView.frame = CGRect(origin: CGPoint(), size: size)

View File

@ -336,20 +336,25 @@ public enum PatternWallpaperDrawMode {
}
public struct PatternWallpaperArguments: TransformImageCustomArguments {
public enum DisplayMode: Int32 {
case aspectFill
case aspectFit
case halfAspectFill
}
let colors: [UIColor]
let rotation: Int32?
let preview: Bool
let customPatternColor: UIColor?
let bakePatternAlpha: CGFloat
let tile: Bool
let displayMode: DisplayMode
public init(colors: [UIColor], rotation: Int32?, customPatternColor: UIColor? = nil, preview: Bool = false, bakePatternAlpha: CGFloat = 1.0, tile: Bool = false) {
public init(colors: [UIColor], rotation: Int32?, customPatternColor: UIColor? = nil, preview: Bool = false, bakePatternAlpha: CGFloat = 1.0, displayMode: DisplayMode = .aspectFill) {
self.colors = colors
self.rotation = rotation
self.customPatternColor = customPatternColor
self.preview = preview
self.bakePatternAlpha = bakePatternAlpha
self.tile = tile
self.displayMode = displayMode
}
public func serialized() -> NSArray {
@ -361,7 +366,7 @@ public struct PatternWallpaperArguments: TransformImageCustomArguments {
}
array.add(NSNumber(value: self.preview))
array.add(NSNumber(value: Double(self.bakePatternAlpha)))
array.add(NSNumber(value: self.tile))
array.add(NSNumber(value: self.displayMode.rawValue))
return array
}
}
@ -542,13 +547,13 @@ private func patternWallpaperImageInternal(fullSizeData: Data?, fullSizeComplete
c.restoreGState()
}
let tile = customArguments.tile
let displayMode = customArguments.displayMode
let overlayImage = generateImage(arguments.drawingRect.size, rotatedContext: { size, c in
c.clear(CGRect(origin: CGPoint(), size: size))
var image: UIImage?
if let fullSizeData = fullSizeData {
if mode == .screen {
image = renderPreparedImage(fullSizeData, CGSize(width: size.width * context.scale, height: size.height * context.scale), .black, 1.0, tile)
image = renderPreparedImage(fullSizeData, CGSize(width: size.width * context.scale, height: size.height * context.scale), .black, 1.0, displayMode != .aspectFill)
} else {
image = UIImage(data: fullSizeData)
}
@ -570,10 +575,14 @@ private func patternWallpaperImageInternal(fullSizeData: Data?, fullSizeComplete
if abs(fittedSize.height - arguments.boundingSize.height).isLessThanOrEqualTo(CGFloat(1.0)) {
fittedSize.height = arguments.boundingSize.height
}
if tile {
fittedSize = fittedSize.aspectFitted(arguments.drawingRect.size)
} else {
switch displayMode {
case .aspectFill:
fittedSize = fittedSize.aspectFilled(arguments.drawingRect.size)
case .halfAspectFill:
fittedSize = fittedSize.aspectFilled(arguments.drawingRect.size)
fittedSize = CGSize(width: fittedSize.width * 0.5, height: fittedSize.height * 0.5)
case .aspectFit:
fittedSize = fittedSize.aspectFitted(arguments.drawingRect.size)
}
c.interpolationQuality = customArguments.preview ? .low : .medium
@ -611,16 +620,18 @@ private func patternWallpaperImageInternal(fullSizeData: Data?, fullSizeComplete
c.restoreGState()
}
if tile {
switch displayMode {
case .aspectFit, .halfAspectFill:
var fittedRect = CGRect(origin: CGPoint(x: drawingRect.origin.x, y: drawingRect.origin.y + (drawingRect.size.height - fittedSize.height) / 2.0), size: fittedSize)
drawTile(fittedRect)
fittedRect = fittedRect.offsetBy(dx: fittedSize.width, dy: 0.0)
drawTile(fittedRect)
} else {
while (fittedRect.maxX < size.width) {
fittedRect = fittedRect.offsetBy(dx: fittedSize.width, dy: 0.0)
drawTile(fittedRect)
}
case .aspectFill:
let fittedRect = CGRect(origin: CGPoint(x: drawingRect.origin.x + (drawingRect.size.width - fittedSize.width) / 2.0, y: drawingRect.origin.y + (drawingRect.size.height - fittedSize.height) / 2.0), size: fittedSize)
drawTile(fittedRect)
}
}
})
if let customPatternColor = customArguments.customPatternColor, customPatternColor.alpha < 1.0 {