From 4f5d1445ae56f4e3306f64ee31560bfeaf79c91a Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 3 Mar 2023 14:30:08 +0400 Subject: [PATCH] Tune outgoing bubble highlight color --- .../Sources/ChatMessageBackground.swift | 7 ++-- submodules/Display/Source/UIKitUtils.swift | 38 +++++++++++++++++++ .../Sources/PremiumIntroScreen.swift | 2 +- .../DefaultDarkPresentationTheme.swift | 14 ++++++- .../Sources/DefaultDayPresentationTheme.swift | 15 ++++++-- 5 files changed, 67 insertions(+), 9 deletions(-) diff --git a/submodules/ChatMessageBackground/Sources/ChatMessageBackground.swift b/submodules/ChatMessageBackground/Sources/ChatMessageBackground.swift index 37d8b8cab5..317488e118 100644 --- a/submodules/ChatMessageBackground/Sources/ChatMessageBackground.swift +++ b/submodules/ChatMessageBackground/Sources/ChatMessageBackground.swift @@ -218,12 +218,13 @@ public class ChatMessageBackground: ASDisplayNode { } let outlineImage: UIImage? - + var isIncoming = false if hasWallpaper { switch type { case .none: outlineImage = nil case let .incoming(mergeType): + isIncoming = true switch mergeType { case .None: outlineImage = graphics.chatMessageBackgroundIncomingOutlineImage @@ -305,9 +306,9 @@ public class ChatMessageBackground: ASDisplayNode { } } } - + self.imageNode.image = image - if highlighted && maskMode, let backdropNode = self.backdropNode, backdropNode.hasImage { + if highlighted && maskMode, let backdropNode = self.backdropNode, backdropNode.hasImage && isIncoming { self.imageNode.layer.compositingFilter = "overlayBlendMode" self.imageNode.alpha = 1.0 diff --git a/submodules/Display/Source/UIKitUtils.swift b/submodules/Display/Source/UIKitUtils.swift index 1f81855572..ef9d40ef51 100644 --- a/submodules/Display/Source/UIKitUtils.swift +++ b/submodules/Display/Source/UIKitUtils.swift @@ -158,6 +158,24 @@ public extension UIColor { } } + var brightness: CGFloat { + var hue: CGFloat = 0.0 + var saturation: CGFloat = 0.0 + var brightness: CGFloat = 0.0 + var alpha: CGFloat = 0.0 + self.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha) + return brightness + } + + var saturation: CGFloat { + var hue: CGFloat = 0.0 + var saturation: CGFloat = 0.0 + var brightness: CGFloat = 0.0 + var alpha: CGFloat = 0.0 + self.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha) + return saturation + } + func withMultipliedBrightnessBy(_ factor: CGFloat) -> UIColor { var hue: CGFloat = 0.0 var saturation: CGFloat = 0.0 @@ -202,6 +220,26 @@ public extension UIColor { return self } + func multipliedWith(_ other: UIColor) -> UIColor { + var r1: CGFloat = 0.0 + var r2: CGFloat = 0.0 + var g1: CGFloat = 0.0 + var g2: CGFloat = 0.0 + var b1: CGFloat = 0.0 + var b2: CGFloat = 0.0 + var a1: CGFloat = 0.0 + var a2: CGFloat = 0.0 + if self.getRed(&r1, green: &g1, blue: &b1, alpha: &a1) && + other.getRed(&r2, green: &g2, blue: &b2, alpha: &a2) + { + let r = r1 * r2 + let g = g1 * g2 + let b = b1 * b2 + return UIColor(red: r, green: g, blue: b, alpha: 1.0) + } + return self + } + func blitOver(_ other: UIColor, alpha: CGFloat) -> UIColor { let alpha = min(1.0, max(0.0, alpha)) diff --git a/submodules/PremiumUI/Sources/PremiumIntroScreen.swift b/submodules/PremiumUI/Sources/PremiumIntroScreen.swift index d485e3e8bb..9b97fa4b27 100644 --- a/submodules/PremiumUI/Sources/PremiumIntroScreen.swift +++ b/submodules/PremiumUI/Sources/PremiumIntroScreen.swift @@ -2726,7 +2726,7 @@ public final class PremiumIntroScreen: ViewControllerComponentContainer { let presentationData = context.sharedContext.currentPresentationData.with { $0 } if modal { - let cancelItem = UIBarButtonItem(title: presentationData.strings.Common_Cancel, style: .plain, target: self, action: #selector(self.cancelPressed)) + let cancelItem = UIBarButtonItem(title: presentationData.strings.Common_Close, style: .plain, target: self, action: #selector(self.cancelPressed)) self.navigationItem.setLeftBarButton(cancelItem, animated: false) self.navigationPresentation = .modal } else { diff --git a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift index 06ab683f5e..09ed616499 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift @@ -174,6 +174,16 @@ public func customizeDefaultDarkPresentationTheme(theme: PresentationTheme, edit } } + var highlightedBubbleFillColor: UIColor? + if let outgoingBubbleFillColors { + let middleBubbleFillColor = outgoingBubbleFillColors[Int(floor(Float(outgoingBubbleFillColors.count) / 2))] + if middleBubbleFillColor.brightness > 0.98 { + highlightedBubbleFillColor = middleBubbleFillColor.withMultiplied(hue: 1.0, saturation: 0.87, brightness: 1.0) + } else { + highlightedBubbleFillColor = middleBubbleFillColor.withMultiplied(hue: 1.0, saturation: 1.1, brightness: 1.121) + } + } + chat = chat.withUpdated( defaultWallpaper: defaultWallpaper, animateMessageColors: animateBubbleColors, @@ -223,7 +233,7 @@ public func customizeDefaultDarkPresentationTheme(theme: PresentationTheme, edit bubble: chat.message.outgoing.bubble.withUpdated( withWallpaper: chat.message.outgoing.bubble.withWallpaper.withUpdated( fill: outgoingBubbleFillColors, - highlightedFill: outgoingBubbleFillColors?.first?.withMultipliedBrightnessBy(1.421), + highlightedFill: highlightedBubbleFillColor, stroke: .clear, reactionInactiveBackground: UIColor(rgb: 0xffffff, alpha: 0.12), reactionInactiveForeground: UIColor(rgb: 0xffffff), @@ -234,7 +244,7 @@ public func customizeDefaultDarkPresentationTheme(theme: PresentationTheme, edit ), withoutWallpaper: chat.message.outgoing.bubble.withoutWallpaper.withUpdated( fill: outgoingBubbleFillColors, - highlightedFill: outgoingBubbleFillColors?.first?.withMultipliedBrightnessBy(1.421), + highlightedFill: highlightedBubbleFillColor, stroke: .clear, reactionInactiveBackground: UIColor(rgb: 0xffffff, alpha: 0.12), reactionInactiveForeground: UIColor(rgb: 0xffffff), diff --git a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift index b9b957bcff..547edd2235 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift @@ -168,7 +168,16 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, editing: Bool, ti outgoingBubbleStrokeColor = .clear } - outgoingBubbleHighlightedFill = outgoingBubbleFillColors?.first?.withMultiplied(hue: 1.00, saturation: 1.589, brightness: 0.96) + if let outgoingBubbleFillColors { + let middleBubbleFillColor = outgoingBubbleFillColors[Int(floor(Float(outgoingBubbleFillColors.count - 1) / 2))] + if middleBubbleFillColor.lightness < 0.85 { + outgoingBubbleHighlightedFill = middleBubbleFillColor.multipliedWith(middleBubbleFillColor).withMultiplied(hue: 1.0, saturation: 0.6, brightness: 1.0) + } else if middleBubbleFillColor.lightness > 0.97 { + outgoingBubbleHighlightedFill = middleBubbleFillColor.withMultiplied(hue: 1.00, saturation: 2.359, brightness: 0.99) + } else { + outgoingBubbleHighlightedFill = middleBubbleFillColor.withMultiplied(hue: 1.00, saturation: 1.589, brightness: 0.99) + } + } let lightnessColor = UIColor.average(of: bubbleColors.map(UIColor.init(rgb:))) if lightnessColor.lightness > 0.705 { @@ -622,7 +631,7 @@ public func makeDefaultDayPresentationTheme(extendingThemeReference: Presentatio bubble: PresentationThemeBubbleColor( withWallpaper: PresentationThemeBubbleColorComponents( fill: [UIColor(rgb: 0xe1ffc7)], - highlightedFill: UIColor(rgb: 0xc8ffa6), + highlightedFill: UIColor(rgb: 0xbaff93), stroke: bubbleStrokeColor, shadow: nil, reactionInactiveBackground: UIColor(rgb: 0x2DA32F).withMultipliedAlpha(0.12), @@ -634,7 +643,7 @@ public func makeDefaultDayPresentationTheme(extendingThemeReference: Presentatio ), withoutWallpaper: PresentationThemeBubbleColorComponents( fill: [UIColor(rgb: 0xe1ffc7)], - highlightedFill: UIColor(rgb: 0xc8ffa6), + highlightedFill: UIColor(rgb: 0xbaff93), stroke: bubbleStrokeColor, shadow: nil, reactionInactiveBackground: UIColor(rgb: 0x2DA32F).withMultipliedAlpha(0.12),