Skip to content

Commit

Permalink
PAINTROID-396 Multiline tool with movable intermediate points
Browse files Browse the repository at this point in the history
refactor
  • Loading branch information
Lenkomotive committed Sep 4, 2023
1 parent a25b3c2 commit 5a6b7fa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,28 @@ class DefaultCommandManager(
return false
}
undoCommandList.addFirst(command)
val vertexStackCommands: Deque<DynamicPathCommand> = createDynamicPathsSequence()
command.setupVertexStackAfterUndo(mainActivity, vertexStackCommands)
switchToDynamicLineTool()
setupVertexStackAfterUndo()
return true
}

private fun setupVertexStackAfterUndo() {
mainActivity ?: return
val vertexStackCommands: Deque<DynamicPathCommand> = createDynamicPathsSequence()
mainActivity.runOnUiThread {
var tool = mainActivity.defaultToolController.currentTool as DynamicLineTool
tool.createSourceAndDestinationVertices(
vertexStackCommands.first.startPoint,
vertexStackCommands.first.endPoint,
vertexStackCommands.first)
vertexStackCommands.removeFirst()
for (command in vertexStackCommands) {
tool.createDestinationVertex(command.endPoint, command)
}
mainActivity.commandManager.executeAllCommands()
}
}

private fun createDynamicPathsSequence(): Deque<DynamicPathCommand> {
val vertexStackCommands: Deque<DynamicPathCommand> = ArrayDeque()
for (command in undoCommandList) {
Expand Down Expand Up @@ -255,45 +272,30 @@ class DefaultCommandManager(
}
}

// private fun handleRedoForDynamicLineTool(command: Command) {
// var currentTool = mainActivity.defaultToolController.currentTool
// if (currentTool is DynamicLineTool && command !is DynamicPathCommand) {
// currentTool.clear()
// }
// if (command is DynamicPathCommand) {
// if (currentTool !is DynamicLineTool) {
// command.switchToDynamicLineTool(mainActivity)
// }
// while (mainActivity.defaultToolController.currentTool !is DynamicLineTool)
// currentTool = mainActivity.defaultToolController.currentTool
// if (command.isSourcePath) {
// (currentTool as DynamicLineTool).clear()
// }
// (currentTool as DynamicLineTool).updateVertexStackAfterRedo(command)
// }
// }
private fun handleRedoForDynamicLineTool(command: Command) {
if (mainActivity == null) return
mainActivity ?: return
var currentTool = mainActivity.defaultToolController.currentTool
if (command is DynamicPathCommand) {
switchToDynamicLineToolIfNeeded(currentTool, command)
switchToDynamicLineTool()
currentTool = mainActivity.defaultToolController.currentTool
if (command.isSourcePath) {
(currentTool as DynamicLineTool).clear()
}
currentTool as DynamicLineTool
currentTool.updateVertexStackAfterRedo(command)
currentTool.setToolPaint(command) // here
currentTool.setToolPaint(command)
mainActivity.presenter.setBottomNavigationColor(command.paint.color)
} else if (currentTool is DynamicLineTool) {
currentTool.clear()
}
}

private fun switchToDynamicLineToolIfNeeded(currentTool: Tool?, command: DynamicPathCommand) {
if (mainActivity == null) return
if (currentTool !is DynamicLineTool) {
command.switchToDynamicLineTool(mainActivity)
private fun switchToDynamicLineTool() {
mainActivity ?: return
if (mainActivity.defaultToolController.currentTool !is DynamicLineTool) {
mainActivity.runOnUiThread {
mainActivity.presenter.switchToDynamicLineTool()
}
while (mainActivity.defaultToolController.currentTool !is DynamicLineTool) {
// do nothing
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,4 @@ class DynamicPathCommand(var paint: Paint, path: Path, startPoint: PointF, endPo
this.startPoint = startPoint
this.endPoint = endPoint
}

fun setupVertexStackAfterUndo(mainActivity: MainActivity, dynamicPathCommands: Deque<DynamicPathCommand>) {
mainActivity.runOnUiThread {
mainActivity.presenter.switchToDynamicLineTool()
if (mainActivity.defaultToolController.currentTool !is DynamicLineTool) return@runOnUiThread
var tool = mainActivity.defaultToolController.currentTool as DynamicLineTool
tool.createSourceAndDestinationVertices(
dynamicPathCommands.first.startPoint,
dynamicPathCommands.first.endPoint,
dynamicPathCommands.first)
dynamicPathCommands.removeFirst()
for (command in dynamicPathCommands) {
tool.createDestinationVertex(command.endPoint, command)
}
mainActivity.commandManager.executeAllCommands()
}
}

fun switchToDynamicLineTool(mainActivity: MainActivity) {
mainActivity.runOnUiThread {
mainActivity.presenter.switchToDynamicLineTool()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,6 @@ open class MainActivityPresenter(
override fun switchToDynamicLineTool() {
if (toolController.toolType == ToolType.DYNAMICLINE) return
idlingResource.increment()
// bottomBarViewHolder.hide()
checkForImplicitToolApplication()
switchTool(ToolType.DYNAMICLINE)
idlingResource.decrement()
Expand Down

0 comments on commit 5a6b7fa

Please sign in to comment.