From ab3839f602273b745aa25301d9abdf41aa5962f5 Mon Sep 17 00:00:00 2001 From: Hiroshi Kimura Date: Mon, 10 Jun 2024 16:26:13 +0900 Subject: [PATCH] clean up (#250) --- .../BrightroomEngine/Core/EditingCrop.swift | 16 +-------- .../BrightroomEngine/Library/EngineLog.swift | 9 ++++- .../Shared/Components/Crop/CropView.swift | 22 +++---------- .../ImageViews/ImagePreviewView.swift | 2 +- .../Components/ImageViews/_ImageView.swift | 2 +- .../BrightroomUI/Shared/Utils/EditorLog.swift | 33 +++++-------------- 6 files changed, 24 insertions(+), 60 deletions(-) diff --git a/Sources/BrightroomEngine/Core/EditingCrop.swift b/Sources/BrightroomEngine/Core/EditingCrop.swift index 680eaf71..04763d05 100644 --- a/Sources/BrightroomEngine/Core/EditingCrop.swift +++ b/Sources/BrightroomEngine/Core/EditingCrop.swift @@ -241,23 +241,9 @@ public struct EditingCrop: Equatable { ) } - /// Updates cropExtent with new specified rect and normalizing value using aspectRatio(optional). - /// cropExtent would be rounded in order to drop floating point value for fitting pixel. - /// With specifing `respectingAspectRatio`, it fixes cropExtent's size. - /// - /// - Parameters: - /// - cropExtent: - /// - respectingAspectRatio: public mutating func updateCropExtent( - _ cropExtent: CGRect, - respectingAspectRatio: PixelAspectRatio? + _ cropExtent: CGRect ) { -// self.cropExtent = Self.fittingRect( -// rect: cropExtent, -// in: imageSize, -// respectingAspectRatio: respectingAspectRatio -// ) - self.cropExtent = cropExtent } diff --git a/Sources/BrightroomEngine/Library/EngineLog.swift b/Sources/BrightroomEngine/Library/EngineLog.swift index 42153526..c1c0d3c7 100644 --- a/Sources/BrightroomEngine/Library/EngineLog.swift +++ b/Sources/BrightroomEngine/Library/EngineLog.swift @@ -49,7 +49,14 @@ enum EngineLog { extension OSLog { - static let renderer = OSLog.init(subsystem: "BrightroomEngine", category: "🎨 Renderer") + static let renderer: OSLog = { +#if false + return OSLog.init(subsystem: "BrightroomEngine", category: "🎨 Renderer") +#else + return .disabled +#endif + }() + static let stack = OSLog.init(subsystem: "BrightroomEngine", category: "🥞 Stack") } diff --git a/Sources/BrightroomUI/Shared/Components/Crop/CropView.swift b/Sources/BrightroomUI/Shared/Components/Crop/CropView.swift index 6060c527..e4ca4d02 100644 --- a/Sources/BrightroomUI/Shared/Components/Crop/CropView.swift +++ b/Sources/BrightroomUI/Shared/Components/Crop/CropView.swift @@ -483,7 +483,7 @@ public final class CropView: UIView, UIScrollViewDelegate { */ public func applyEditingStack() { guard let crop = store.state.proposedCrop else { - EditorLog.warn("EditingStack has not completed loading.") + EditorLog.error(.cropView, "EditingStack has not completed loading.") return } editingStack.crop(crop) @@ -515,8 +515,7 @@ public final class CropView: UIView, UIScrollViewDelegate { if let crop = $0.proposedCrop { $0.proposedCrop?.updateCropExtent( - crop.cropExtent.rotated((crop.rotation.angle - rotation.angle).radians), - respectingAspectRatio: nil + crop.cropExtent.rotated((crop.rotation.angle - rotation.angle).radians) ) $0.proposedCrop?.rotation = rotation @@ -986,11 +985,8 @@ extension CropView { rect: guideRectInImageView ) - // TODO: Might cause wrong cropping if set the invalid size or origin. For example, setting width:0, height: 0 by too zoomed in. - let preferredAspectRatio = state.preferredAspectRatio state.proposedCrop?.updateCropExtent( - resolvedRect, - respectingAspectRatio: preferredAspectRatio + resolvedRect ) } } @@ -1100,8 +1096,6 @@ extension CropView { let scale = Geometry.diagonalRatio(to: guideView.bounds.size, from: guideViewRectInPlatter.size) - print(scale) - let outbound = imagePlatterView.bounds let value = UIEdgeInsets( @@ -1135,8 +1129,6 @@ extension CropView { patternAngleDegree -= 360 } - print(patternAngleDegree) - var resolvedInsets: UIEdgeInsets { switch patternAngleDegree { @@ -1319,9 +1311,7 @@ extension UIScrollView { setContentOffset(targetContentOffset, animated: false) - #if DEBUG - print( - """ + EditorLog.debug(.cropView, """ [Zoom] input: \(rect), bound: \(boundSize), @@ -1329,9 +1319,7 @@ extension UIScrollView { targetContentOffset: \(targetContentOffset), minContentOffset: \(minContentOffset) maxContentOffset: \(maxContentOffset) - """ - ) - #endif + """) } if animated { diff --git a/Sources/BrightroomUI/Shared/Components/ImageViews/ImagePreviewView.swift b/Sources/BrightroomUI/Shared/Components/ImageViews/ImagePreviewView.swift index 2ec2d510..6ad29b0f 100644 --- a/Sources/BrightroomUI/Shared/Components/ImageViews/ImagePreviewView.swift +++ b/Sources/BrightroomUI/Shared/Components/ImageViews/ImagePreviewView.swift @@ -241,7 +241,7 @@ final class _PreviewImageView: UIImageView, CIImageDisplaying { return } - EditorLog.debug("[ImageImageView] Update") + EditorLog.debug(.imageView, "Update") let uiImage: UIImage diff --git a/Sources/BrightroomUI/Shared/Components/ImageViews/_ImageView.swift b/Sources/BrightroomUI/Shared/Components/ImageViews/_ImageView.swift index e57d68e8..def49fd2 100644 --- a/Sources/BrightroomUI/Shared/Components/ImageViews/_ImageView.swift +++ b/Sources/BrightroomUI/Shared/Components/ImageViews/_ImageView.swift @@ -51,7 +51,7 @@ final class _ImageView: UIImageView, CIImageDisplaying { return } - EditorLog.debug("[_ImageView] Update") + EditorLog.debug(.imageView, "Update") let uiImage: UIImage diff --git a/Sources/BrightroomUI/Shared/Utils/EditorLog.swift b/Sources/BrightroomUI/Shared/Utils/EditorLog.swift index 714b5ac1..eb2778f0 100644 --- a/Sources/BrightroomUI/Shared/Utils/EditorLog.swift +++ b/Sources/BrightroomUI/Shared/Utils/EditorLog.swift @@ -25,31 +25,6 @@ import os.log enum EditorLog { - private static let osLog = OSLog.init(subsystem: "PixelEditor", category: "Editor") - private static let queue = DispatchQueue.init(label: "me.muukii.PixelEditor.Log") - - static func debug(_ object: Any...) { - - queue.async { - if #available(iOS 12.0, *) { - os_log(.debug, log: osLog, "%@", object.map { "\($0)" }.joined(separator: " ")) - } else { - os_log("%@", log: osLog, type: .debug, object.map { "\($0)" }.joined(separator: " ")) - } - } - } - - static func warn(_ object: Any...) { - - queue.async { - if #available(iOS 12.0, *) { - os_log(.error, log: osLog, "%@", object.map { "\($0)" }.joined(separator: " ")) - } else { - os_log("%@", log: osLog, type: .error, object.map { "\($0)" }.joined(separator: " ")) - } - } - } - static func debug(_ log: OSLog, _ object: Any...) { os_log(.debug, log: log, "%@", object.map { "\($0)" }.joined(separator: " ")) } @@ -69,4 +44,12 @@ extension OSLog { #endif }() + static let cropView: OSLog = { + #if false + return OSLog.init(subsystem: "BrightroomUI", category: "CropView") + #else + return .disabled + #endif + }() + }