Skip to content

Commit

Permalink
Patch
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Jun 10, 2024
1 parent d9e0039 commit 450af34
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 60 deletions.
16 changes: 1 addition & 15 deletions Sources/BrightroomEngine/Core/EditingCrop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 8 additions & 1 deletion Sources/BrightroomEngine/Library/EngineLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")

}
22 changes: 5 additions & 17 deletions Sources/BrightroomUI/Shared/Components/Crop/CropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
}
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -1135,8 +1129,6 @@ extension CropView {
patternAngleDegree -= 360
}

print(patternAngleDegree)

var resolvedInsets: UIEdgeInsets {
switch patternAngleDegree {

Expand Down Expand Up @@ -1319,19 +1311,15 @@ extension UIScrollView {

setContentOffset(targetContentOffset, animated: false)

#if DEBUG
print(
"""
EditorLog.debug(.cropView, """
[Zoom]
input: \(rect),
bound: \(boundSize),
targetScale: \(targetScale),
targetContentOffset: \(targetContentOffset),
minContentOffset: \(minContentOffset)
maxContentOffset: \(maxContentOffset)
"""
)
#endif
""")
}

if animated {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ final class _PreviewImageView: UIImageView, CIImageDisplaying {
return
}

EditorLog.debug("[ImageImageView] Update")
EditorLog.debug(.imageView, "Update")

let uiImage: UIImage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class _ImageView: UIImageView, CIImageDisplaying {
return
}

EditorLog.debug("[_ImageView] Update")
EditorLog.debug(.imageView, "Update")

let uiImage: UIImage

Expand Down
33 changes: 8 additions & 25 deletions Sources/BrightroomUI/Shared/Utils/EditorLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: " "))
}
Expand All @@ -69,4 +44,12 @@ extension OSLog {
#endif
}()

static let cropView: OSLog = {
#if false
return OSLog.init(subsystem: "BrightroomUI", category: "CropView")
#else
return .disabled
#endif
}()

}

0 comments on commit 450af34

Please sign in to comment.