Skip to content

Commit

Permalink
Can move polyline points
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveBarnegren committed Jul 5, 2020
1 parent 28718f5 commit 7d216d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
21 changes: 19 additions & 2 deletions PhysicsDemo/Input Handlers/InputHandlerEdit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class InputHandlerEdit: InputHandler {
switch self.state {
case .idle:
return
case .draggingHandle(let handle):
case .draggingHandle:
return
case .pressingButton(let button):
button.setter(!button.isEnabled)
Expand All @@ -109,7 +109,9 @@ class InputHandlerEdit: InputHandler {
// MARK: - Create handles

private func getHandles(simulation: PhysicsSimulation) -> [EditHandle] {
return getLineHandles(simulation: simulation) + getCircleHandles(simulation: simulation)
return getLineHandles(simulation: simulation)
+ getCircleHandles(simulation: simulation)
+ getPolylineHandles(simulation: simulation)
}

private func getLineHandles(simulation: PhysicsSimulation) -> [EditHandle] {
Expand Down Expand Up @@ -146,6 +148,21 @@ class InputHandlerEdit: InputHandler {
return handles
}

private func getPolylineHandles(simulation: PhysicsSimulation) -> [EditHandle] {

var handles = [EditHandle]()

for polyline in simulation.polyLines {
for (pointIndex, point) in polyline.points.enumerated() {
handles.append(
EditHandle(point: point, setter: { polyline.points[pointIndex] = $0 })
)
}
}

return handles
}

private func getBoundaryToggleButtons(simSize: Vector2D) -> [EditButton] {
var buttons = [EditButton]()

Expand Down
1 change: 0 additions & 1 deletion PhysicsDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ class ViewController: NSViewController {
// MARK: - Key handling

private func keyDownEventReceived(event: NSEvent) {
print("view controller key down")
if let key = KeyboardKey(keyCode: event.keyCode) {
inputHandler.keyDown(key: key, simulation: self.simulation)
}
Expand Down

0 comments on commit 7d216d0

Please sign in to comment.