Skip to content

Commit

Permalink
PAINTROID-617 eraser improvements (#1307)
Browse files Browse the repository at this point in the history
color change commands had impact on eraser functionality

- when eraser is selected color changes are skipped in undo
  • Loading branch information
JulianJautz authored Oct 29, 2023
1 parent d419782 commit 505183d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,41 @@ class UndoRedoIntegrationTest {
BitmapLocationProvider.HALFWAY_TOP_MIDDLE
)
}

@Test
fun testNoColorUndoInEraserMode() {
onToolBarView()
.performSelectTool(ToolType.FILL)
onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.MIDDLE))
selectColorInDialog(0)
selectColorInDialog(1)
selectColorInDialog(2)
onToolBarView()
.performSelectTool(ToolType.ERASER)
onDrawingSurfaceView().perform(
UiInteractions.swipeAccurate(
DrawingSurfaceLocationProvider.HALFWAY_TOP_MIDDLE,
DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_MIDDLE
)
)
onTopBarView().performUndo()
onTopBarView().performUndo()
onToolBarView()
.performSelectTool(ToolType.BRUSH)
onDrawingSurfaceView().perform(
UiInteractions.swipeAccurate(
DrawingSurfaceLocationProvider.HALFWAY_TOP_MIDDLE,
DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_MIDDLE
)
)
onDrawingSurfaceView().perform(
UiInteractions.swipeAccurate(
DrawingSurfaceLocationProvider.HALFWAY_TOP_LEFT,
DrawingSurfaceLocationProvider.HALFWAY_TOP_RIGHT
)
)
onDrawingSurfaceView()
.checkPixelColor(Color.parseColor("#FF078707"), BitmapLocationProvider.HALFWAY_TOP_MIDDLE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.catrobat.paintroid.MainActivity
import org.catrobat.paintroid.command.Command
import org.catrobat.paintroid.contract.LayerContracts
import org.catrobat.paintroid.tools.ToolReference
import org.catrobat.paintroid.tools.implementation.EraserTool
import org.catrobat.paintroid.tools.implementation.LineTool

class ColorChangedCommand(toolReference: ToolReference, context: Context, color: Int) : Command {
Expand All @@ -51,8 +52,10 @@ class ColorChangedCommand(toolReference: ToolReference, context: Context, color:
firstTime = false
}
}
(context as MainActivity).runOnUiThread {
(context as MainActivity).bottomNavigationViewHolder.setColorButtonColor(color)
if (toolReference.tool !is EraserTool) {
(context as MainActivity).runOnUiThread {
(context as MainActivity).bottomNavigationViewHolder.setColorButtonColor(color)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import org.catrobat.paintroid.tools.implementation.CONSTANT_3
import org.catrobat.paintroid.tools.implementation.ClippingTool
import org.catrobat.paintroid.tools.implementation.LineTool
import org.catrobat.paintroid.tools.implementation.DefaultToolPaint
import org.catrobat.paintroid.tools.implementation.EraserTool
import org.catrobat.paintroid.ui.LayerAdapter
import java.io.File

Expand Down Expand Up @@ -591,7 +592,7 @@ open class MainActivityPresenter(
if (view.isKeyboardShown) {
view.hideKeyboard()
} else {
if (commandManager.isLastColorCommandOnTop() || commandManager.getColorCommandCount() == 0) {
if (toolController.currentTool !is EraserTool && (commandManager.isLastColorCommandOnTop() || commandManager.getColorCommandCount() == 0)) {
toolController.currentTool?.changePaintColor(Color.BLACK)
setBottomNavigationColor(Color.BLACK)
}
Expand All @@ -604,7 +605,11 @@ open class MainActivityPresenter(
if (toolController.currentTool is LineTool) {
(toolController.currentTool as LineTool).undoChangePaintColor(Color.BLACK, false)
} else {
commandManager.undo()
if (toolController.currentTool is EraserTool) {
commandManager.undoIgnoringColorChanges()
} else {
commandManager.undo()
}
}
}
}
Expand Down

0 comments on commit 505183d

Please sign in to comment.