Add highlighter opacity.

This commit is contained in:
Alex Hart
2026-07-29 16:20:45 -03:00
parent bb3354d4ca
commit 44334936d7
3 changed files with 12 additions and 5 deletions
@@ -191,7 +191,7 @@ class ImageController @RememberInComposition constructor(
}
fun setDrawColor(color: Int) {
imageEditorState.drawColor = color
imageEditorState.drawColor = brushTool?.applyAlpha(color) ?: color
}
fun setBrushWidthFraction(fraction: Float) {
@@ -205,7 +205,7 @@ class ImageController @RememberInComposition constructor(
imageEditorState.isBlur = mode == Mode.BLUR
imageEditorState.drawCap = if (mode == Mode.HIGHLIGHT) Paint.Cap.SQUARE else Paint.Cap.ROUND
imageEditorState.drawThickness = brushThickness
imageEditorState.drawColor = drawColorBarState.color
setDrawColor(drawColorBarState.color)
}
fun enterCropMode() {
@@ -193,7 +193,7 @@ fun MediaEditScreen(
visible = isAdjustingBrushWidth,
thickness = imageController.brushThickness,
viewMatrix = imageController.imageEditorState.viewMatrix,
color = Color(imageController.imageEditorState.drawColor),
color = Color(imageController.drawColorBarState.color),
isBlur = imageController.isUserBlurring,
modifier = Modifier.fillMaxSize()
)
@@ -11,20 +11,27 @@ import androidx.compose.runtime.annotation.RememberInComposition
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.core.graphics.ColorUtils
import kotlinx.parcelize.Parcelize
private const val OPAQUE_ALPHA = 0xFF
private const val HIGHLIGHTER_ALPHA = 0x60
/**
* The image editor tools which support a user-adjustable stroke width.
*
* Thicknesses are expressed as a fraction of the editor's coordinate space width, matching what
* [ImageEditorState.drawThickness] expects.
*/
enum class BrushTool(val minThickness: Float, val maxThickness: Float) {
enum class BrushTool(val minThickness: Float, val maxThickness: Float, val alpha: Int = OPAQUE_ALPHA) {
MARKER(0.01f, 0.05f),
HIGHLIGHTER(0.03f, 0.08f),
HIGHLIGHTER(0.03f, 0.08f, alpha = HIGHLIGHTER_ALPHA),
BLUR(0.052f, 0.092f);
fun thicknessAt(fraction: Float): Float = minThickness + (maxThickness - minThickness) * fraction
/** [color] with this tool's opacity applied. */
fun applyAlpha(color: Int): Int = ColorUtils.setAlphaComponent(color, alpha)
}
/**