From a5ec62d87425914c2613fb93accc7df14bf3243b Mon Sep 17 00:00:00 2001 From: p-x9 <50244599+p-x9@users.noreply.github.com> Date: Fri, 14 Apr 2023 03:18:44 +0900 Subject: [PATCH 1/2] add `TouchPointStyle` --- .../TouchTracker/Cocoa/TouchPointUIView.swift | 16 +++---- .../Cocoa/TouchTrackingUIView.swift | 15 ++++++ .../TouchTracker/Model/TouchPointStyle.swift | 46 +++++++++++++++++++ Sources/TouchTracker/TouchTracker.swift | 13 ++++++ Sources/TouchTracker/TrackPointView.swift | 16 +++---- 5 files changed, 90 insertions(+), 16 deletions(-) create mode 100644 Sources/TouchTracker/Model/TouchPointStyle.swift diff --git a/Sources/TouchTracker/Cocoa/TouchPointUIView.swift b/Sources/TouchTracker/Cocoa/TouchPointUIView.swift index c4d81d1..0d62745 100644 --- a/Sources/TouchTracker/Cocoa/TouchPointUIView.swift +++ b/Sources/TouchTracker/Cocoa/TouchPointUIView.swift @@ -19,19 +19,19 @@ class TouchPointUIView: UIWindow { } var radius: CGFloat - var color: UIColor = .red + var color: UIColor - var isBordered: Bool = true - var borderColor: UIColor = .black - var borderWidth: CGFloat = 1 + var isBordered: Bool + var borderColor: UIColor + var borderWidth: CGFloat - var isDropShadow: Bool = true - var shadowColor: UIColor = .black - var shadowRadius: CGFloat = 3 + var isDropShadow: Bool + var shadowColor: UIColor + var shadowRadius: CGFloat var image: UIImage? - var isShowLocation: Bool = false + var isShowLocation: Bool lazy var imageView: UIImageView = { let view = UIImageView() diff --git a/Sources/TouchTracker/Cocoa/TouchTrackingUIView.swift b/Sources/TouchTracker/Cocoa/TouchTrackingUIView.swift index 30cdbae..4df5351 100644 --- a/Sources/TouchTracker/Cocoa/TouchTrackingUIView.swift +++ b/Sources/TouchTracker/Cocoa/TouchTrackingUIView.swift @@ -66,6 +66,21 @@ public class TouchTrackingUIView: UIView { UIWindow.hook() } + @available(iOS 14.0, *) + public convenience init(style: TouchPointStyle) { + self.init( + radius: style.radius, + color: UIColor(style.color), + isBordered: style.isBordered, + borderColor: UIColor(style.borderColor), + borderWidth: style.borderWidth, + isDropShadow: style.isDropShadow, + shadowColor: UIColor(style.shadowColor), + shadowRadius: style.shadowRadius, + isShowLocation: style.isShowLocation + ) + } + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } diff --git a/Sources/TouchTracker/Model/TouchPointStyle.swift b/Sources/TouchTracker/Model/TouchPointStyle.swift new file mode 100644 index 0000000..e87d2e9 --- /dev/null +++ b/Sources/TouchTracker/Model/TouchPointStyle.swift @@ -0,0 +1,46 @@ +// +// TouchPointStyle.swift +// +// +// Created by p-x9 on 2023/04/14. +// +// + +import SwiftUI + +public struct TouchPointStyle: Equatable { + public var radius: CGFloat + public var color: Color + + public var isBordered: Bool + public var borderColor: Color + public var borderWidth: CGFloat + + public var isDropShadow: Bool + public var shadowColor: Color + public var shadowRadius: CGFloat + + public var isShowLocation: Bool + + public init( + radius: CGFloat = 20, + color: Color = .red, + isBordered: Bool = false, + borderColor: Color = .black, + borderWidth: CGFloat = 1, + isDropShadow: Bool = true, + shadowColor: Color = .black, + shadowRadius: CGFloat = 3, + isShowLocation: Bool = false + ) { + self.radius = radius + self.color = color + self.isBordered = isBordered + self.borderColor = borderColor + self.borderWidth = borderWidth + self.isDropShadow = isDropShadow + self.shadowColor = shadowColor + self.shadowRadius = shadowRadius + self.isShowLocation = isShowLocation + } +} diff --git a/Sources/TouchTracker/TouchTracker.swift b/Sources/TouchTracker/TouchTracker.swift index 5393f67..05dbf62 100644 --- a/Sources/TouchTracker/TouchTracker.swift +++ b/Sources/TouchTracker/TouchTracker.swift @@ -105,6 +105,19 @@ extension TouchTrackingView { set(enabled, for: \.isShowLocation) } + public func setTouchPointStyle(_ style: TouchPointStyle) -> Self { + self + .set(style.radius, for: \.radius) + .set(style.color, for: \.color) + .set(style.isBordered, for: \.isBordered) + .set(style.borderColor, for: \.borderColor) + .set(style.borderWidth, for: \.borderWidth) + .set(style.isDropShadow, for: \.isDropShadow) + .set(style.shadowColor, for: \.shadowColor) + .set(style.shadowRadius, for: \.shadowRadius) + .set(style.isShowLocation, for: \.isShowLocation) + } + private func set(_ value: T, for keyPath: WritableKeyPath) -> Self { var new = self new[keyPath: keyPath] = value diff --git a/Sources/TouchTracker/TrackPointView.swift b/Sources/TouchTracker/TrackPointView.swift index c881973..ca06683 100644 --- a/Sources/TouchTracker/TrackPointView.swift +++ b/Sources/TouchTracker/TrackPointView.swift @@ -12,19 +12,19 @@ struct TouchPointView: View { let location: CGPoint let radius: CGFloat - var color: Color = .red + var color: Color - var isBordered: Bool = true - var borderColor: Color = .black - var borderWidth: CGFloat = 1 + var isBordered: Bool + var borderColor: Color + var borderWidth: CGFloat - var isDropShadow: Bool = true - var shadowColor: Color = .black - var shadowRadius: CGFloat = 3 + var isDropShadow: Bool + var shadowColor: Color + var shadowRadius: CGFloat var image: Image? - var isShowLocation: Bool = false + var isShowLocation: Bool var locationText: some View { let x = String(format: "%.1f", location.x) From 367e4cd16ff91e109f31ce41851006d0b6e0d201 Mon Sep 17 00:00:00 2001 From: p-x9 <50244599+p-x9@users.noreply.github.com> Date: Fri, 14 Apr 2023 14:44:14 +0900 Subject: [PATCH 2/2] add doc comments --- Sources/TouchTracker/Model/TouchPointStyle.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/TouchTracker/Model/TouchPointStyle.swift b/Sources/TouchTracker/Model/TouchPointStyle.swift index e87d2e9..e38deb6 100644 --- a/Sources/TouchTracker/Model/TouchPointStyle.swift +++ b/Sources/TouchTracker/Model/TouchPointStyle.swift @@ -9,17 +9,26 @@ import SwiftUI public struct TouchPointStyle: Equatable { + /// radius of mark on touched point public var radius: CGFloat + /// color of mark on touched point public var color: Color + /// add a border to the mark of the touched point, or public var isBordered: Bool + /// border color of mark on touched point public var borderColor: Color + /// border width of mark on touched point public var borderWidth: CGFloat + /// add shadow to the mark of the touched point, or public var isDropShadow: Bool + /// shadow color of mark on touched point public var shadowColor: Color + /// shadow radius of mark on touched point public var shadowRadius: CGFloat + /// show coordinates label or not public var isShowLocation: Bool public init(