Skip to content

Commit

Permalink
PAINTROID-540 Changing to spraytool sets stroke width to 5
Browse files Browse the repository at this point in the history
  • Loading branch information
bakicelebi committed Apr 1, 2023
1 parent 73096f2 commit e95b90a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,37 @@ class SprayToolIntegrationTest {
onView(withId(R.id.pocketpaint_spray_radius_seek_bar))
.check(matches(withProgress(MIN_RADIUS)))
}

@Test
fun testSprayRadiusToStrokeWidthStaysConsistent() {
ToolBarViewInteraction.onToolBarView().performSelectTool(ToolType.BRUSH)

var radius = "30"
onView(withId(R.id.pocketpaint_stroke_width_width_text))
.perform(replaceText(radius))
.check(matches(withText(radius)))
onView(withId(R.id.pocketpaint_stroke_width_seek_bar))
.check(matches(withProgress(radius.toInt())))

ToolBarViewInteraction.onToolBarView().performSelectTool(ToolType.SPRAY)
onView(withId(R.id.pocketpaint_radius_text))
.perform(replaceText(radius))
.check(matches(withText(radius)))
onView(withId(R.id.pocketpaint_spray_radius_seek_bar))
.check(matches(withProgress(radius.toInt())))

radius = "20"
onView(withId(R.id.pocketpaint_radius_text))
.perform(replaceText(radius))
.check(matches(withText(radius)))
onView(withId(R.id.pocketpaint_spray_radius_seek_bar))
.check(matches(withProgress(radius.toInt())))

ToolBarViewInteraction.onToolBarView().performSelectTool(ToolType.BRUSH)
onView(withId(R.id.pocketpaint_stroke_width_width_text))
.perform(replaceText(radius))
.check(matches(withText(radius)))
onView(withId(R.id.pocketpaint_stroke_width_seek_bar))
.check(matches(withProgress(radius.toInt())))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.catrobat.paintroid.tools.Workspace
import org.catrobat.paintroid.tools.implementation.ClippingTool
import org.catrobat.paintroid.tools.implementation.ImportTool
import org.catrobat.paintroid.tools.implementation.LineTool
import org.catrobat.paintroid.tools.implementation.SprayTool
import org.catrobat.paintroid.tools.options.ToolOptionsViewController

class DefaultToolController(
Expand Down Expand Up @@ -73,6 +74,9 @@ class DefaultToolController(
} else {
toolOptionsViewController.hideCheckmark()
}
if (toolReference.tool?.toolType == ToolType.SPRAY) {
(currentTool as SprayTool).resetRadiusToStrokeWidth()
}
val tool: Tool = toolFactory.createTool(
toolType,
toolOptionsViewController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private const val STROKE_WIDTH = 5f
private const val CONSTANT_1 = 0.5f

class SprayTool(
var stampToolOptionsView: SprayToolOptionsView,
var sprayToolOptionsView: SprayToolOptionsView,
override var contextCallback: ContextCallback,
toolOptionsViewController: ToolOptionsViewController,
toolPaint: ToolPaint,
Expand All @@ -76,15 +76,14 @@ class SprayTool(
private val previewCanvas = Canvas(previewBitmap)

init {
toolPaint.strokeWidth = STROKE_WIDTH

stampToolOptionsView.setCallback(object : SprayToolOptionsView.Callback {
sprayToolOptionsView.setCallback(object : SprayToolOptionsView.Callback {
override fun radiusChanged(radius: Int) {
sprayRadius = DEFAULT_RADIUS + radius * 2
}
})

stampToolOptionsView.setCurrentPaint(toolPaint.paint)
sprayToolOptionsView.setCurrentPaint(toolPaint.paint)
toolPaint.strokeWidth = STROKE_WIDTH
toolOptionsViewController.showDelayed()
}

Expand Down Expand Up @@ -131,7 +130,7 @@ class SprayTool(
super.onRestoreInstanceState(bundle)
bundle?.getInt(BUNDLE_RADIUS)?.let { radius ->
sprayRadius = radius
stampToolOptionsView.setRadius(radius)
sprayToolOptionsView.setRadius(radius)
}
}

Expand Down Expand Up @@ -184,4 +183,8 @@ class SprayTool(
point.y = radius * sin(theta).toFloat() + (currentCoordinate?.y ?: 0f)
return point
}

fun resetRadiusToStrokeWidth() {
toolPaint.strokeWidth = sprayToolOptionsView.getRadius()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ interface SprayToolOptionsView {

fun setCurrentPaint(paint: Paint)

fun getRadius(): Float

interface Callback {
fun radiusChanged(radius: Int)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.google.android.material.textfield.TextInputEditText
import org.catrobat.paintroid.R
import org.catrobat.paintroid.tools.helper.DefaultNumberRangeFilter
import org.catrobat.paintroid.tools.options.SprayToolOptionsView
import java.util.Locale

const val MIN_RADIUS = 1
private const val DEFAULT_RADIUS = 5
Expand Down Expand Up @@ -107,9 +108,17 @@ class DefaultSprayToolOptionsView(rootView: ViewGroup) : SprayToolOptionsView {

override fun setRadius(radius: Int) {
radiusSeekBar.progress = radius
radiusText.setText(
String.format(
Locale.getDefault(), "%d",
radius
)
)
}

override fun setCurrentPaint(paint: Paint) {
setRadius(paint.strokeWidth.toInt())
}

override fun getRadius(): Float = radiusSeekBar.progress.toFloat()
}

0 comments on commit e95b90a

Please sign in to comment.