-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] 화이트보드에 그림 추가 기능 구현(2차) #87
Changes from 9 commits
be92e37
a43485b
291c03e
be9286f
1849996
cca5296
b408841
ec952cf
d4a5a0d
570a31e
e8e129b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,14 +20,17 @@ public protocol ManageWhiteboardObjectUseCaseInterface { | |
/// 화이트보드 객체를 추가하는 메서드 | ||
/// - Parameter whiteboardObject: 추가할 화이트보드 객체 | ||
/// - Returns: 추가 성공 여부 | ||
@discardableResult | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 코멘트 영향으로 @discardableResult를 붙인건가용 ?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 우선은 실패 처리를 위해 Bool 타입을 반환하도록 설계했습니다. 다만 아직 실패했을 때에 대한 정책이 정해진 것이 없어 반환값을 사용하는 곳이 없습니다. (테스트 코드 제외) 따라서 일단 discardableResult를 붙여놓았습니다! |
||
func addObject(whiteboardObject: WhiteboardObject) -> Bool | ||
|
||
/// 화이트보드 객체를 수정하는 메서드 | ||
/// - Parameter whiteboardObject: 수정할 화이트보드 객체 | ||
/// - Returns: 추가 성공 여부 | ||
@discardableResult | ||
func updateObject(whiteboardObject: WhiteboardObject) -> Bool | ||
|
||
/// 화이트보드를 제거하는 메서드 | ||
/// - Returns: 추가 성공 여부 | ||
@discardableResult | ||
func removeObject(whiteboardObject: WhiteboardObject) -> Bool | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,18 @@ import Foundation | |
|
||
public final class DrawObjectUseCase: DrawObjectUseCaseInterface { | ||
public private(set) var points: [CGPoint] | ||
public private(set) var origin: CGPoint? | ||
public private(set) var lineWidth: CGFloat | ||
|
||
public init() { | ||
points = [] | ||
lineWidth = 5 | ||
} | ||
|
||
public func setLineWidth(width: CGFloat) { | ||
lineWidth = width | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 수정까지 미리 만들어 주셨군요!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앗 요 부분은 수정을 염두에 두고 한 것은 아닙니다.!.! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앗 그렇네요..??ㅋㅋㅋ |
||
|
||
public func startDrawing(at point: CGPoint) { | ||
origin = point | ||
points = [point] | ||
} | ||
|
||
|
@@ -32,29 +36,29 @@ public final class DrawObjectUseCase: DrawObjectUseCaseInterface { | |
} | ||
|
||
guard | ||
let origin, | ||
let minX = xPoints.min(), | ||
let maxX = xPoints.max(), | ||
let minY = yPoints.min(), | ||
let maxY = yPoints.max() | ||
else { return nil } | ||
|
||
let size = CGSize(width: maxX - minX, height: maxY - minY) | ||
let padding = lineWidth / 2 | ||
let origin = CGPoint(x: minX - padding, y: minY - padding) | ||
let size = CGSize(width: maxX - minX + padding * 2, height: maxY - minY + padding * 2) | ||
let adjustedPoints = points.map { | ||
CGPoint(x: $0.x - minX, y: $0.y - minY) | ||
CGPoint(x: $0.x - minX + padding, y: $0.y - minY + padding) | ||
} | ||
|
||
let drawingObject = DrawingObject( | ||
id: UUID(), | ||
position: origin, | ||
size: size, | ||
points: adjustedPoints) | ||
points: adjustedPoints, | ||
lineWidth: lineWidth) | ||
|
||
return drawingObject | ||
} | ||
|
||
private func reset() { | ||
origin = nil | ||
points.removeAll() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,7 +21,12 @@ public final class ManageWhiteboardToolUseCase: ManageWhiteboardToolUseCaseInter | |||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
public func selectTool(tool: WhiteboardTool) { | ||||||||||||||||||
currentToolSubject.send(tool) | ||||||||||||||||||
let previousTool = currentToolSubject.value | ||||||||||||||||||
if previousTool == tool { | ||||||||||||||||||
currentToolSubject.send(nil) | ||||||||||||||||||
} else { | ||||||||||||||||||
currentToolSubject.send(tool) | ||||||||||||||||||
} | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. send(nil)을 통해 nil값에 따라 처리가 필요한 거 겠죠!?
삼항 연산자는 어떻게 생각하시나요??
Suggested change
이런 느낌으로!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 깔끔해서 좋은 것 같습니다! 동~ |
||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
public func finishUsingTool() { | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// DrawingView.swift | ||
// Presentation | ||
// | ||
// Created by 이동현 on 11/16/24. | ||
// | ||
|
||
import UIKit | ||
|
||
protocol DrawingViewDelegate: AnyObject { | ||
func drawingView(_ sender: DrawingView, at point: CGPoint) | ||
func drawingViewDidStartDrawing(_ sender: DrawingView, at point: CGPoint) | ||
func drawingViewDidEndDrawing(_ sender: DrawingView) | ||
} | ||
|
||
final class DrawingView: UIView { | ||
private var drawingLayer = CAShapeLayer() | ||
private var drawingPath = UIBezierPath() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위 프로퍼티들이 재할당되는 부분이 보이지 않는데 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아닙니다! let으로 바꾸겠습니다 |
||
private var previousPoint: CGPoint? | ||
weak var delegate: DrawingViewDelegate? | ||
|
||
init() { | ||
super.init(frame: .zero) | ||
configureAttributes() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
configureAttributes() | ||
} | ||
|
||
func reset() { | ||
drawingLayer.path = nil | ||
drawingPath.removeAllPoints() | ||
previousPoint = nil | ||
} | ||
|
||
private func configureAttributes() { | ||
backgroundColor = .clear | ||
drawingLayer.strokeColor = UIColor.black.cgColor | ||
drawingLayer.lineWidth = 5 | ||
drawingLayer.lineCap = .round | ||
layer.addSublayer(drawingLayer) | ||
|
||
let drawingGesture = UIPanGestureRecognizer(target: self, action: #selector(handleDrawingGesture(sender:))) | ||
drawingGesture.minimumNumberOfTouches = 1 | ||
drawingGesture.maximumNumberOfTouches = 1 | ||
self.addGestureRecognizer(drawingGesture) | ||
} | ||
|
||
@objc private func handleDrawingGesture(sender: UIPanGestureRecognizer) { | ||
let point = sender.location(in: self) | ||
|
||
switch sender.state { | ||
case .began: | ||
previousPoint = point | ||
delegate?.drawingViewDidStartDrawing(self, at: point) | ||
drawLine(to: point) | ||
case .changed: | ||
delegate?.drawingView(self, at: point) | ||
drawLine(to: point) | ||
case .ended: | ||
delegate?.drawingViewDidEndDrawing(self) | ||
previousPoint = nil | ||
default: | ||
break | ||
} | ||
} | ||
Comment on lines
+51
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 스프린트 때 PanGesture를 사용해 봤었는데, 이런 드래그 이벤트같은 것들은 UIKit에서는 거의 PanGesture로 처리가 가능하군요?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 그렇습니다!!! |
||
|
||
private func drawLine(to point: CGPoint) { | ||
guard let previousPoint else { return } | ||
|
||
drawingPath.move(to: previousPoint) | ||
drawingPath.addLine(to: point) | ||
drawingLayer.path = drawingPath.cgPath | ||
self.previousPoint = point | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저희 코드 컨벤션 정할 때 함수명에 get, set 지양하기로 하지 않았었나용 ? 🥺
만약
lineWidth = 5
처럼 선 굵기에 대한 초기값이 정해져있는데 업데이트를 위해 set 함수가 필요한 것이라면 update 혹은 configure, apply 라는 메서드명은 어떠신지요 ??There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 그렇네요..!
말씀해주신 것처럼 초기값이 정해져 있으니 update라는 네이밍이 괜찮아보입니다. 수정하겠습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
조이의 코멘트를 보고 추천 남깁니다~