From c45ea439c77d70720956ac4dc2c582d8a2b7f235 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 11 Aug 2023 14:23:26 +0200 Subject: [PATCH] Colored location stickers --- .../Sources/DrawingLocationEntity.swift | 13 ++++++++++++ .../Drawing/DrawingLocationEntity.swift | 20 ++++++++++++++++++- .../Sources/MediaEditorValues.swift | 16 +++++++++++---- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/submodules/DrawingUI/Sources/DrawingLocationEntity.swift b/submodules/DrawingUI/Sources/DrawingLocationEntity.swift index ba245c6303..0ff37e65fb 100644 --- a/submodules/DrawingUI/Sources/DrawingLocationEntity.swift +++ b/submodules/DrawingUI/Sources/DrawingLocationEntity.swift @@ -171,6 +171,12 @@ public final class DrawingLocationEntityView: DrawingEntityView, UITextViewDeleg case .black: updatedStyle = .transparent case .transparent: + if self.locationEntity.hasCustomColor { + updatedStyle = .custom + } else { + updatedStyle = .white + } + case .custom: updatedStyle = .white case .blur: updatedStyle = .white @@ -217,6 +223,8 @@ public final class DrawingLocationEntityView: DrawingEntityView, UITextViewDeleg textColor = .black case .black, .transparent, .blur: textColor = .white + case .custom: + textColor = .white } text.addAttribute(.foregroundColor, value: textColor, range: range) @@ -247,6 +255,11 @@ public final class DrawingLocationEntityView: DrawingEntityView, UITextViewDeleg self.backgroundView.backgroundColor = UIColor(rgb: 0x000000, alpha: 0.2) self.backgroundView.isHidden = false self.blurredBackgroundView.isHidden = true + case .custom: + self.textView.textColor = .white + self.backgroundView.backgroundColor = self.locationEntity.color.toUIColor() + self.backgroundView.isHidden = false + self.blurredBackgroundView.isHidden = true case .blur: self.textView.textColor = .white self.backgroundView.isHidden = true diff --git a/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingLocationEntity.swift b/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingLocationEntity.swift index 028925d55f..657ee72620 100644 --- a/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingLocationEntity.swift +++ b/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingLocationEntity.swift @@ -11,6 +11,8 @@ public final class DrawingLocationEntity: DrawingEntity, Codable { case uuid case title case style + case color + case hasCustomColor case location case icon case queryId @@ -27,6 +29,7 @@ public final class DrawingLocationEntity: DrawingEntity, Codable { case white case black case transparent + case custom case blur } @@ -42,7 +45,18 @@ public final class DrawingLocationEntity: DrawingEntity, Codable { public var icon: TelegramMediaFile? public var queryId: Int64? public var resultId: String? - public var color: DrawingColor = .clear + public var color: DrawingColor = DrawingColor(color: .white) { + didSet { + if self.color.toUIColor().argb == UIColor.white.argb { + self.style = .white + self.hasCustomColor = false + } else { + self.style = .custom + self.hasCustomColor = true + } + } + } + public var hasCustomColor = false public var lineWidth: CGFloat = 0.0 public var referenceDrawingSize: CGSize @@ -88,6 +102,8 @@ public final class DrawingLocationEntity: DrawingEntity, Codable { self.uuid = try container.decode(UUID.self, forKey: .uuid) self.title = try container.decode(String.self, forKey: .title) self.style = try container.decode(Style.self, forKey: .style) + self.color = try container.decodeIfPresent(DrawingColor.self, forKey: .color) ?? DrawingColor(color: .white) + self.hasCustomColor = try container.decodeIfPresent(Bool.self, forKey: .hasCustomColor) ?? false if let locationData = try container.decodeIfPresent(Data.self, forKey: .location) { self.location = PostboxDecoder(buffer: MemoryBuffer(data: locationData)).decodeRootObject() as! TelegramMediaMap @@ -117,6 +133,8 @@ public final class DrawingLocationEntity: DrawingEntity, Codable { try container.encode(self.uuid, forKey: .uuid) try container.encode(self.title, forKey: .title) try container.encode(self.style, forKey: .style) + try container.encode(self.color, forKey: .color) + try container.encode(self.hasCustomColor, forKey: .hasCustomColor) var encoder = PostboxEncoder() encoder.encodeRootObject(self.location) diff --git a/submodules/TelegramUI/Components/MediaEditor/Sources/MediaEditorValues.swift b/submodules/TelegramUI/Components/MediaEditor/Sources/MediaEditorValues.swift index a12727b141..bb5a1ac369 100644 --- a/submodules/TelegramUI/Components/MediaEditor/Sources/MediaEditorValues.swift +++ b/submodules/TelegramUI/Components/MediaEditor/Sources/MediaEditorValues.swift @@ -116,16 +116,24 @@ public final class MediaEditorValues: Codable, Equatable { return false } if let lhsToolValue = lhsToolValue as? Float, let rhsToolValue = rhsToolValue as? Float { - return lhsToolValue != rhsToolValue + if lhsToolValue != rhsToolValue { + return false + } } if let lhsToolValue = lhsToolValue as? BlurValue, let rhsToolValue = rhsToolValue as? BlurValue { - return lhsToolValue != rhsToolValue + if lhsToolValue != rhsToolValue { + return false + } } if let lhsToolValue = lhsToolValue as? TintValue, let rhsToolValue = rhsToolValue as? TintValue { - return lhsToolValue != rhsToolValue + if lhsToolValue != rhsToolValue { + return false + } } if let lhsToolValue = lhsToolValue as? CurvesValue, let rhsToolValue = rhsToolValue as? CurvesValue { - return lhsToolValue != rhsToolValue + if lhsToolValue != rhsToolValue { + return false + } } }