Skip to content

Commit

Permalink
PAINTROID-396 Multiline tool with movable intermediate points
Browse files Browse the repository at this point in the history
CR
  • Loading branch information
Lenkomotive committed Sep 11, 2023
1 parent 9daa735 commit 50cfc22
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ class DynamicLineToolIntegrationTest {
val currentTool = launchActivityRule.activity.defaultToolController.currentTool as DynamicLineTool
Assert.assertEquals(7, currentTool.vertexStack.size)

var uriFile = saveImage()
val uriFile = saveImage()

newImage()
Assert.assertEquals(0, currentTool.vertexStack.size)
Expand All @@ -898,7 +898,7 @@ class DynamicLineToolIntegrationTest {
}

private fun loadImage(uriFile: Uri) {
var fileContent = CommandSerializer(activity, activity.commandManager, activity.model).readFromFile(uriFile!!)
val fileContent = CommandSerializer(activity, activity.commandManager, activity.model).readFromFile(uriFile)
for (command in fileContent.commandModel.commands) {
activity.commandManager.addCommand(command)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class DynamicLineToolTest {
fun testTwoVerticesCreatedAfterFirstClick() {
Assert.assertEquals(0, tool.vertexStack.size)

var firstClickCoordinate = PointF(5f, 5f)
val firstClickCoordinate = PointF(5f, 5f)
tool.handleDown(firstClickCoordinate)
tool.handleUp(firstClickCoordinate)

Expand All @@ -124,18 +124,18 @@ class DynamicLineToolTest {
@Test
@UiThreadTest
fun testLastVertexCenterChangesAfterClick() {
var firstClickCoordinate = PointF(5f, 5f)
val firstClickCoordinate = PointF(5f, 5f)
tool.handleDown(firstClickCoordinate)
tool.handleUp(firstClickCoordinate)

var secondClickCoordinate = PointF(100f, 100f)
val secondClickCoordinate = PointF(100f, 100f)
tool.handleDown(secondClickCoordinate)
tool.handleUp(secondClickCoordinate)

Assert.assertEquals(2, tool.vertexStack.size)
Assert.assertEquals(secondClickCoordinate, tool.vertexStack.last.vertexCenter)

var thirdClickCoordinate = PointF(200f, 200f)
val thirdClickCoordinate = PointF(200f, 200f)
tool.handleDown(thirdClickCoordinate)
tool.handleUp(thirdClickCoordinate)

Expand All @@ -146,11 +146,11 @@ class DynamicLineToolTest {
@Test
@UiThreadTest
fun testLastVertexCenterChangesAfterMove() {
var firstClickCoordinate = PointF(5f, 5f)
val firstClickCoordinate = PointF(5f, 5f)
tool.handleDown(firstClickCoordinate)
tool.handleUp(firstClickCoordinate)

var secondClickCoordinate = PointF(100f, 100f)
val secondClickCoordinate = PointF(100f, 100f)
tool.handleDown(secondClickCoordinate)
tool.handleUp(secondClickCoordinate)

Expand All @@ -159,7 +159,7 @@ class DynamicLineToolTest {

tool.handleDown(secondClickCoordinate)

var movingCoordinate = PointF(200f, 200f)
val movingCoordinate = PointF(200f, 200f)
tool.handleMove(movingCoordinate)
tool.handleUp(movingCoordinate)

Expand All @@ -170,11 +170,11 @@ class DynamicLineToolTest {
@Test
@UiThreadTest
fun testFirstVertexCenterChangesAfterMove() {
var firstClickCoordinate = PointF(5f, 5f)
val firstClickCoordinate = PointF(5f, 5f)
tool.handleDown(firstClickCoordinate)
tool.handleUp(firstClickCoordinate)

var secondClickCoordinate = PointF(100f, 100f)
val secondClickCoordinate = PointF(100f, 100f)
tool.handleDown(secondClickCoordinate)
tool.handleUp(secondClickCoordinate)

Expand All @@ -183,7 +183,7 @@ class DynamicLineToolTest {

tool.handleDown(firstClickCoordinate)

var movingCoordinate = PointF(200f, 200f)
val movingCoordinate = PointF(200f, 200f)
tool.handleMove(movingCoordinate)
tool.handleUp(movingCoordinate)

Expand All @@ -197,8 +197,8 @@ class DynamicLineToolTest {
var plusButtonVisibility = DynamicLineTool.topBarViewHolder?.plusButton?.visibility
Assert.assertEquals(plusButtonVisibility, View.GONE)

var tapDownCoordinate = PointF(5f, 5f)
var tapUpCoordinate = PointF(10f, 10f)
val tapDownCoordinate = PointF(5f, 5f)
val tapUpCoordinate = PointF(10f, 10f)
tool.handleDown(tapDownCoordinate)
tool.handleUp(tapUpCoordinate)

Expand All @@ -211,11 +211,11 @@ class DynamicLineToolTest {
fun testAddPathIsSetAfterClickingPlus() {
Assert.assertEquals(false, tool.addNewPath)

var firstClickCoordinate = PointF(5f, 5f)
val firstClickCoordinate = PointF(5f, 5f)
tool.handleDown(firstClickCoordinate)
tool.handleUp(firstClickCoordinate)

var secondClickCoordinate = PointF(100f, 100f)
val secondClickCoordinate = PointF(100f, 100f)
tool.handleDown(secondClickCoordinate)
tool.handleUp(secondClickCoordinate)

Expand All @@ -229,17 +229,17 @@ class DynamicLineToolTest {
fun testThreeVerticesCreatedAfterClickingPlus() {
Assert.assertEquals(0, tool.vertexStack.size)

var firstClickCoordinate = PointF(5f, 5f)
val firstClickCoordinate = PointF(5f, 5f)
tool.handleDown(firstClickCoordinate)
tool.handleUp(firstClickCoordinate)

var secondClickCoordinate = PointF(100f, 100f)
val secondClickCoordinate = PointF(100f, 100f)
tool.handleDown(secondClickCoordinate)
tool.handleUp(secondClickCoordinate)

tool.onClickOnPlus()

var thirdClickCoordinate = PointF(200f, 200f)
val thirdClickCoordinate = PointF(200f, 200f)
tool.handleDown(thirdClickCoordinate)
tool.handleUp(thirdClickCoordinate)

Expand All @@ -252,8 +252,8 @@ class DynamicLineToolTest {
var plusButtonVisibility = DynamicLineTool.topBarViewHolder?.plusButton?.visibility
Assert.assertEquals(plusButtonVisibility, View.GONE)

var tapDownCoordinate = PointF(5f, 5f)
var tapUpCoordinate = PointF(10f, 10f)
val tapDownCoordinate = PointF(5f, 5f)
val tapUpCoordinate = PointF(10f, 10f)
tool.handleDown(tapDownCoordinate)
tool.handleUp(tapUpCoordinate)

Expand Down Expand Up @@ -315,8 +315,8 @@ class DynamicLineToolTest {
fun testVertexStackIsClearedAfterCheckmark() {
Assert.assertEquals(0, tool.vertexStack.size)

var tapDownCoordinate = PointF(5f, 5f)
var tapUpCoordinate = PointF(10f, 10f)
val tapDownCoordinate = PointF(5f, 5f)
val tapUpCoordinate = PointF(10f, 10f)
tool.handleDown(tapDownCoordinate)
tool.handleUp(tapUpCoordinate)

Expand All @@ -332,17 +332,17 @@ class DynamicLineToolTest {
Assert.assertEquals(null, tool.movingVertex)
Assert.assertEquals(null, tool.successorVertex)

var firstVertexCoordinate = PointF(5f, 5f)
val firstVertexCoordinate = PointF(5f, 5f)
tool.handleDown(firstVertexCoordinate)
tool.handleUp(firstVertexCoordinate)

var middleVertexCoordinate = PointF(100f, 100f)
val middleVertexCoordinate = PointF(100f, 100f)
tool.handleDown(middleVertexCoordinate)
tool.handleUp(middleVertexCoordinate)

tool.onClickOnPlus()

var lastVertexCoordinate = PointF(200f, 200f)
val lastVertexCoordinate = PointF(200f, 200f)
tool.handleDown(lastVertexCoordinate)
tool.handleUp(lastVertexCoordinate)

Expand All @@ -360,17 +360,17 @@ class DynamicLineToolTest {
Assert.assertEquals(null, tool.movingVertex)
Assert.assertEquals(null, tool.successorVertex)

var firstVertexCoordinate = PointF(5f, 5f)
val firstVertexCoordinate = PointF(5f, 5f)
tool.handleDown(firstVertexCoordinate)
tool.handleUp(firstVertexCoordinate)

var middleVertexCoordinate = PointF(100f, 100f)
val middleVertexCoordinate = PointF(100f, 100f)
tool.handleDown(middleVertexCoordinate)
tool.handleUp(middleVertexCoordinate)

tool.onClickOnPlus()

var lastVertexCoordinate = PointF(200f, 200f)
val lastVertexCoordinate = PointF(200f, 200f)
tool.handleDown(lastVertexCoordinate)
tool.handleUp(lastVertexCoordinate)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class DefaultCommandManager(
val command = undoCommandList.pop()

if (command is DynamicPathCommand) {
var switchedTool = handleUndoForDynamicLineTool(command)
val switchedTool = handleUndoForDynamicLineTool(command)
if (switchedTool) return
}
redoCommandList.addFirst(command)
Expand All @@ -126,7 +126,7 @@ class DefaultCommandManager(

private fun handleUndoForDynamicLineTool(command: DynamicPathCommand): Boolean {
if (mainActivity == null) return false
var currentTool = mainActivity.defaultToolController.currentTool
val currentTool = mainActivity.defaultToolController.currentTool
if (currentTool is DynamicLineTool && currentTool.vertexStack.isNotEmpty()) {
currentTool.updateVertexStackAfterUndo()
currentTool.setToolPaint(command)
Expand Down Expand Up @@ -255,23 +255,6 @@ 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
var currentTool = mainActivity.defaultToolController.currentTool
Expand Down Expand Up @@ -314,13 +297,11 @@ class DefaultCommandManager(

override fun shutdown() = Unit

// LINETOOL_ONLY
override fun undoIgnoringColorChanges() {
addAndExecuteCommands(separateColorCommandsAndUndo())
notifyCommandExecuted()
}

// LINETOOL_ONLY
override fun undoIgnoringColorChangesAndAddCommand(command: Command) {
val colorCommandList = separateColorCommandsAndUndo()
undoCommandList.addFirst(command)
Expand All @@ -330,7 +311,6 @@ class DefaultCommandManager(
notifyCommandExecuted()
}

// LINETOOL_ONLY
private fun separateColorCommandsAndUndo(): Deque<Command> {
val colorCommandList = removeColorCommands()
if (undoCommandList.isNotEmpty() && undoCommandList.first != null) {
Expand All @@ -341,7 +321,6 @@ class DefaultCommandManager(
return colorCommandList
}

// LINETOOL_ONLY
override fun undoInConnectedLinesMode() {
val colorCommandList = removeColorCommands()
if (undoCommandList.isNotEmpty()) {
Expand All @@ -364,7 +343,6 @@ class DefaultCommandManager(
}
}

// LINETOOL_ONLY
private fun recolorLastLine(colorCommandList: Deque<Command>) {
if (undoCommandList.isNotEmpty() && undoCommandList.first !is ColorChangedCommand) {
val firstNonColorCommand = undoCommandList.pop()
Expand Down Expand Up @@ -401,7 +379,6 @@ class DefaultCommandManager(
notifyCommandExecuted()
}

// LINETOOL_ONLY
override fun redoInConnectedLinesMode() {
if (isRedoAvailable) {
val command = redoCommandList.pop()
Expand Down Expand Up @@ -522,7 +499,6 @@ class DefaultCommandManager(
}
}

// LINETOOL_ONLY
private fun removeColorCommands(): Deque<Command> {
val colorCommandList: Deque<Command> = ArrayDeque()
while (undoCommandList.isNotEmpty() && undoCommandList.first is ColorChangedCommand) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class DynamicPathCommand(var paint: Paint, path: Path, startPoint: PointF, endPo
mainActivity.runOnUiThread {
mainActivity.presenter.switchToDynamicLineTool()
if (mainActivity.defaultToolController.currentTool !is DynamicLineTool) return@runOnUiThread
var tool = mainActivity.defaultToolController.currentTool as DynamicLineTool
val tool = mainActivity.defaultToolController.currentTool as DynamicLineTool
tool.createSourceAndDestinationVertices(
dynamicPathCommands.first.startPoint,
dynamicPathCommands.first.endPoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,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
Loading

0 comments on commit 50cfc22

Please sign in to comment.