Skip to content

ProCraft for Android: An Android native painting app written in Rust

Rust

feat(quickmenu): the full action list and its picker; layer opacity, solo and actual size

Josh6b787e0ac1b9
diff --git a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/CanvasSurfaceView.kt b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/CanvasSurfaceView.kt
index 230b7ed..4240c68 100644
--- a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/CanvasSurfaceView.kt
+++ b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/CanvasSurfaceView.kt
@@ -45,7 +45,7 @@ class CanvasSurfaceView(context: Context, private val vm: CanvasViewModel) : Sur
// IDLE: a finger that doesn't paint, waiting for a hold or more fingers; HOVER: fingers
// setting the brush while the pen hovers
- private enum class Mode { NONE, PEN, FINGER, IDLE, GESTURE, PICK, TRANSFORM, SELECT, ADJUST, PUCK, SHAPE, HOVER, TURN, POUR }
+ private enum class Mode { NONE, PEN, FINGER, IDLE, GESTURE, PICK, TRANSFORM, SELECT, ADJUST, PUCK, SHAPE, HOVER, TURN, POUR, OPACITY }
/** The pen is hovering over the canvas. */
private var penHovering = false
@@ -430,6 +430,13 @@ class CanvasSurfaceView(context: Context, private val vm: CanvasViewModel) : Sur
vm.pickAt(e.x, e.y, pickSide)
return true
}
+ if (vm.opacityLayer != null) {
+ // Layer opacity: one pen or finger drags the layer's opacity across the canvas
+ mode = Mode.OPACITY
+ lastSelectX = e.x
+ lastSelectTime = e.eventTime
+ return true
+ }
if (vm.dropBand == CanvasViewModel.DropBand.FILLING) {
// Continue filling: the touch fills where it lands; slid, it changes the threshold
pourStart = Offset(e.x, e.y)
@@ -607,6 +614,7 @@ class CanvasSurfaceView(context: Context, private val vm: CanvasViewModel) : Sur
}
// a second finger takes back the fill the first one made
if (mode == Mode.POUR) vm.pourEnd(keep = false)
+ if (mode == Mode.OPACITY) vm.liftLayerOpacity()
if (mode == Mode.FINGER || mode == Mode.IDLE || mode == Mode.TRANSFORM || mode == Mode.SELECT || mode == Mode.TURN || mode == Mode.POUR) {
gestureStart = e.eventTime
gestureScale = 1f
@@ -652,6 +660,12 @@ class CanvasSurfaceView(context: Context, private val vm: CanvasViewModel) : Sur
Mode.GESTURE -> if (fingers >= 3) scrub(e) else moveGesture(e, s)
Mode.SELECT -> select(e, done = false)
Mode.POUR -> pour(e, done = false)
+ Mode.OPACITY -> {
+ val dx = (e.x - lastSelectX) / resources.displayMetrics.density
+ vm.dragLayerOpacity(dragStep(dx, e.eventTime - lastSelectTime))
+ lastSelectX = e.x
+ lastSelectTime = e.eventTime
+ }
Mode.ADJUST -> if (vm.adjustment == Adjustment.LIQUIFY) {
vm.liquifyStroke(liquifyPoints(e), start = false)
followLiquify(e)
@@ -717,6 +731,7 @@ class CanvasSurfaceView(context: Context, private val vm: CanvasViewModel) : Sur
Mode.PUCK, Mode.SHAPE, Mode.IDLE, Mode.HOVER, Mode.TURN -> Unit
Mode.SELECT -> select(e, done = true)
Mode.POUR -> pour(e, done = true)
+ Mode.OPACITY -> vm.liftLayerOpacity()
Mode.ADJUST -> if (vm.adjustment == Adjustment.LIQUIFY) {
// still moving when it lifts, liquify carries on
if (e.eventTime - liquifyTime <= LIQUIFY_STILL_MS) vm.liquifyLifted(liquifyVelocity.x, liquifyVelocity.y)
diff --git a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/CanvasViewModel.kt b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/CanvasViewModel.kt
index 8cc29a6..a7d3ff6 100644
--- a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/CanvasViewModel.kt
+++ b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/CanvasViewModel.kt
@@ -1608,6 +1608,7 @@ class CanvasViewModel(app: Application) : AndroidViewModel(app) {
/** Saves the open artwork and goes back to the gallery. */
fun closeArtwork() {
endFilling()
+ endLayerOpacity()
endTransform(true)
endAdjustment(true)
val s = session ?: return
@@ -2091,8 +2092,11 @@ class CanvasViewModel(app: Application) : AndroidViewModel(app) {
/** Does [a], a QuickMenu button opened at window point [at]. */
fun runQuickAction(a: QuickAction, at: Offset) {
val current = layers.firstOrNull { it.current }
+ a.adjustment?.let {
+ startAdjustment(it)
+ return
+ }
when (a) {
- QuickAction.NONE -> Unit
QuickAction.NEW_LAYER -> addLayer()
QuickAction.DUPLICATE_LAYER -> current?.let(::duplicate)
QuickAction.DELETE_LAYER -> current?.let(::delete)
@@ -2102,7 +2106,10 @@ class CanvasViewModel(app: Application) : AndroidViewModel(app) {
QuickAction.SELECT_LAYER -> current?.let(::selectLayerContents)
QuickAction.ALPHA_LOCK -> current?.let(::toggleAlphaLock)
QuickAction.LAYER_VISIBILITY -> current?.let(::toggleVisible)
+ QuickAction.LAYER_OPACITY -> startLayerOpacity()
+ QuickAction.SOLO -> current?.let(::toggleSolo)
QuickAction.COPY -> copyLayer()
+ QuickAction.COPY_CANVAS -> copyCanvas()
QuickAction.CUT -> cutLayer()
QuickAction.PASTE -> paste()
QuickAction.COPY_PASTE_MENU -> copyPasteOpen = true
@@ -2115,23 +2122,127 @@ class CanvasViewModel(app: Application) : AndroidViewModel(app) {
QuickAction.ERASE -> select(ToolKind.ERASE)
QuickAction.EYEDROPPER -> pickNext = true
QuickAction.SWAP_COLORS -> swapColors()
+ QuickAction.PREVIOUS_BRUSH -> previousBrush()
QuickAction.SELECTION -> toggleSelecting()
- QuickAction.INVERT_SELECTION -> invertSelection()
QuickAction.TRANSFORM -> toggleTransform()
QuickAction.ADJUSTMENTS -> adjustmentsPressed()
+ QuickAction.LIQUIFY -> startAdjustment(Adjustment.LIQUIFY)
+ QuickAction.CLONE -> startAdjustment(Adjustment.CLONE)
QuickAction.COLORS -> toggle(Panel.COLOR)
QuickAction.LAYERS -> toggle(Panel.LAYERS)
QuickAction.BRUSHES -> toggle(Panel.BRUSHES)
- QuickAction.ACTIONS -> toggle(Panel.ACTIONS)
QuickAction.INTERFACE -> toggleBars()
QuickAction.FIT_CANVAS -> settleToFit()
+ QuickAction.ACTUAL_SIZE -> {
+ session?.settleToActualSize()
+ followView()
+ }
QuickAction.ADD_TEXT -> addText()
QuickAction.QUICKSHAPE -> quickShapeLast()
+ QuickAction.QUICKSHAPE_ON -> gestures.set(GesturePurpose.QUICKSHAPE, "DRAW_HOLD", !gestures.isOn(GesturePurpose.QUICKSHAPE, "DRAW_HOLD"))
QuickAction.LAYER_SELECT -> layerSelectAt(at)
- QuickAction.DRAWING_GUIDE -> setGuideOn(guide?.on != true)
+ QuickAction.GUIDE_2D -> toggleGuideKind(GuideType.GRID)
+ QuickAction.GUIDE_ISOMETRIC -> toggleGuideKind(GuideType.ISOMETRIC)
+ QuickAction.GUIDE_PERSPECTIVE -> toggleGuideKind(GuideType.PERSPECTIVE)
+ QuickAction.GUIDE_SYMMETRY -> toggleGuideKind(GuideType.SYMMETRY)
+ QuickAction.DRAWING_ASSIST -> guide?.let { setGuideAssisted(!it.assisted) }
+ QuickAction.ANIMATION_ASSIST -> changeAnimationAssist(!(animation != null && animation?.pages == false))
+ QuickAction.PAGE_ASSIST -> changePageAssist(animation?.pages != true)
+ QuickAction.NEXT_FRAME -> stepFrame(1)
+ QuickAction.PREVIOUS_FRAME -> stepFrame(-1)
+ QuickAction.ONION_SKIN -> toggleOnionSkin()
+ QuickAction.BRUSH_SCALING -> changeBrushScaling(!brushOnScreen)
+ QuickAction.PROJECT_CANVAS -> changeProjectCanvas(!projectCanvas)
+ QuickAction.REFERENCE -> changeReferenceOn(!referenceOn)
+ QuickAction.COMPANION_MOVE -> toggleCompanionMode(CompanionMode.MOVE)
+ QuickAction.COMPANION_ZOOM -> toggleCompanionMode(CompanionMode.ZOOM)
+ // nothing, Recolor (not built yet), and the adjustments (done above)
+ else -> Unit
+ }
+ }
+
+ /** The drawing guide on as [kind], or off if it already is that. */
+ private fun toggleGuideKind(kind: GuideType) {
+ val g = guide
+ if (g?.on == true && g.kind == kind) {
+ setGuideOn(false)
+ return
+ }
+ if (g?.on != true) setGuideOn(true)
+ chooseGuideKind(kind)
+ }
+
+ /** Animation Assist's next or previous frame drawn on ([by] frames along), staying in its frames. */
+ private fun stepFrame(by: Int) {
+ val at = currentFrame ?: return
+ val to = (at + by).coerceIn(0, animationFrames.size - 1)
+ if (to != at) tapFrame(to)
+ }
+
+ /** How many onion skin frames there were before they were last turned off. */
+ private var onionKept = 1u
+
+ /** Onion skins off, or back to as many as they were. */
+ private fun toggleOnionSkin() {
+ changeAnimation {
+ if (it.onionFrames > 0u) {
+ onionKept = it.onionFrames
+ it.copy(onionFrames = 0u)
+ } else {
+ it.copy(onionFrames = onionKept)
+ }
}
}
+ /** Layer [l] shown alone, or, already alone, every layer again; a message says which. */
+ fun toggleSolo(l: LayerInfo) {
+ val s = session ?: return
+ val on = s.solo() != l.id
+ if (!s.setSolo(if (on) l.id else null)) return
+ showNotice(if (on) "Solo visibility on" else "Solo visibility off")
+ }
+
+ // Layer opacity: a drag across the canvas changes the current layer's opacity, read in the band
+ // under the top bar
+
+ /** The layer whose opacity a drag changes, while the mode is on. */
+ var opacityLayer by mutableStateOf<LayerInfo?>(null)
+ private set
+
+ /** Its opacity as it is being dragged. */
+ var opacityValue by mutableFloatStateOf(1f)
+ private set
+
+ fun startLayerOpacity() {
+ val l = layers.firstOrNull { it.current } ?: return
+ if (l.kind != LayerType.PAINT && l.kind != LayerType.GROUP) return
+ endQuickShape()
+ endFilling()
+ if (transforming) endTransform(true)
+ endAdjustment(true)
+ closeSelecting()
+ closePanels()
+ opacityLayer = l
+ opacityValue = l.opacity
+ }
+
+ /** A step of the drag: the opacity changed by [by]. */
+ fun dragLayerOpacity(by: Float) {
+ val l = opacityLayer ?: return
+ opacityValue = (opacityValue + by).coerceIn(0f, 1f)
+ setLayerOpacity(l, opacityValue, done = false)
+ }
+
+ /** The drag let go: its change is one undo step. */
+ fun liftLayerOpacity() {
+ val l = opacityLayer ?: return
+ setLayerOpacity(l, opacityValue, done = true)
+ }
+
+ fun endLayerOpacity() {
+ opacityLayer = null
+ }
+
/** Does what a gesture set to the QuickMenu does: opens it at [at], or closes it if open. */
fun toggleQuickMenu(at: Offset) {
quickMenuAt = if (quickMenuAt == null) at else null
@@ -2977,6 +3088,7 @@ class CanvasViewModel(app: Application) : AndroidViewModel(app) {
val s = session ?: return
val before = currentBrush
if (s.selectBrush(b.set, b.index)) {
+ if (before != null && (before.set != b.set || before.index != b.index)) lastBrush = before.set to before.index
// the set left behind keeps showing the brush it had
before?.let { setChoice[it.set.toInt()] = it.index.toInt() }
currentBrush = s.currentBrush()
@@ -2986,6 +3098,23 @@ class CanvasViewModel(app: Application) : AndroidViewModel(app) {
}
}
+ /** The brush chosen before the current one (set, place in it), for Previous brush. */
+ private var lastBrush: Pair<UInt, UInt>? = null
+
+ /** Back to the brush chosen before this one (and Previous brush again comes back here). */
+ fun previousBrush() {
+ val s = session ?: return
+ val (set, index) = lastBrush ?: return
+ val now = currentBrush
+ if (s.selectBrush(set, index)) {
+ lastBrush = now?.let { it.set to it.index }
+ currentBrush = s.currentBrush()
+ setChoice[set.toInt()] = index.toInt()
+ readSliders()
+ keepChoices(s)
+ }
+ }
+
/** Each set's last chosen brush, which it shows highlighted (by place in the set). */
val setChoice = mutableStateMapOf<Int, Int>()
@@ -4428,6 +4557,11 @@ class CanvasViewModel(app: Application) : AndroidViewModel(app) {
fun adjustmentsPressed() {
endQuickShape()
endFilling()
+ // in Layer opacity, the button ends it
+ if (opacityLayer != null) {
+ endLayerOpacity()
+ return
+ }
if (adjustment != null) endAdjustment(true) else toggle(Panel.ADJUSTMENTS)
}
@@ -4437,6 +4571,7 @@ class CanvasViewModel(app: Application) : AndroidViewModel(app) {
fun toggleSelecting() {
endQuickShape()
endFilling()
+ endLayerOpacity()
if (selecting) {
closeSelecting()
return
@@ -4745,6 +4880,7 @@ class CanvasViewModel(app: Application) : AndroidViewModel(app) {
fun toggleTransform() {
endQuickShape()
endFilling()
+ endLayerOpacity()
if (transforming) {
endTransform(true)
return
diff --git a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/QuickActions.kt b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/QuickActions.kt
index 12bd802..eac79de 100644
--- a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/QuickActions.kt
+++ b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/QuickActions.kt
@@ -1,56 +1,99 @@
package io.github.artcraftandroid.procraft.canvas
-/** What a QuickMenu button can be set to do. */
-enum class QuickAction(val label: String) {
+/**
+ * What a QuickMenu button can be set to, by the name its picker lists. The adjustments are listed
+ * under Adjustments ([adjustment] says which). The names saved are the entries' names, so an
+ * entry keeps its name when its label changes.
+ */
+enum class QuickAction(val label: String, val adjustment: Adjustment? = null, val ready: Boolean = true) {
NONE("No Action"),
- NEW_LAYER("New Layer"),
- DUPLICATE_LAYER("Duplicate Layer"),
- DELETE_LAYER("Delete Layer"),
- MERGE_DOWN("Merge Down"),
- CLEAR_LAYER("Clear Layer"),
- FILL_LAYER("Fill Layer"),
- SELECT_LAYER("Select Layer"),
+ GUIDE_2D("2D Guide visibility"),
+ ACTUAL_SIZE("Actual size"),
+ ADD_TEXT("Add Text"),
ALPHA_LOCK("Alpha Lock"),
- LAYER_VISIBILITY("Layer Visibility"),
+ ANIMATION_ASSIST("Animation Assist"),
+ BRUSH_SCALING("Brush scaling"),
+ CLEAR_LAYER("Clear layer"),
+ COPY_PASTE_MENU("Clipboard"),
+ CLONE("Clone"),
COPY("Copy"),
+ COPY_CANVAS("Copy canvas"),
CUT("Cut"),
- PASTE("Paste"),
- COPY_PASTE_MENU("Copy & Paste Menu"),
- FLIP_HORIZONTAL("Flip Horizontal"),
- FLIP_VERTICAL("Flip Vertical"),
- UNDO("Undo"),
- REDO("Redo"),
- PAINT("Paint"),
- SMUDGE("Smudge"),
+ DELETE_LAYER("Delete layer"),
+ DRAWING_ASSIST("Drawing Assist"),
+ DUPLICATE_LAYER("Duplicate layer"),
ERASE("Erase"),
EYEDROPPER("Eyedropper"),
- SWAP_COLORS("Swap Colors"),
- SELECTION("Selection"),
- INVERT_SELECTION("Invert Selection"),
- TRANSFORM("Transform"),
- ADJUSTMENTS("Adjustments"),
- COLORS("Colors"),
- LAYERS("Layers"),
- BRUSHES("Brushes"),
- ACTIONS("Actions"),
- INTERFACE("Interface"),
- FIT_CANVAS("Fit Canvas"),
- ADD_TEXT("Add Text"),
- QUICKSHAPE("QuickShape"),
+ FILL_LAYER("Fill layer"),
+ FIT_CANVAS("Fit canvas"),
+ FLIP_HORIZONTAL("Flip horizontally"),
+ FLIP_VERTICAL("Flip vertically"),
+ INTERFACE("Full screen"),
+ GUIDE_ISOMETRIC("Isometric Guide visibility"),
LAYER_SELECT("Layer Select"),
- DRAWING_GUIDE("Drawing Guide"),
+ LAYER_OPACITY("Layer opacity"),
+ LAYER_VISIBILITY("Layer visibility"),
+ LIQUIFY("Liquify"),
+ MERGE_DOWN("Merge down"),
+ NEW_LAYER("New layer"),
+ NEXT_FRAME("Next frame"),
+ ONION_SKIN("Onion skin"),
+ ADJUSTMENTS("Open Adjustments"),
+ COLORS("Open Color panel"),
+ LAYERS("Open Layers panel"),
+ PAGE_ASSIST("Page Assist"),
+ PAINT("Paint"),
+ PASTE("Paste"),
+ GUIDE_PERSPECTIVE("Perspective Guide visibility"),
+ PREVIOUS_BRUSH("Previous brush"),
+ SWAP_COLORS("Previous color"),
+ PREVIOUS_FRAME("Previous frame"),
+ PROJECT_CANVAS("Project canvas"),
+ QUICKSHAPE_ON("QuickShape"),
+ QUICKSHAPE("QuickShape stroke"),
+ // not built yet: left out of the picker
+ RECOLOR("Recolor", ready = false),
+ REDO("Redo"),
+ REFERENCE("Reference"),
+ BRUSHES("Select brush"),
+ SELECT_LAYER("Select layer contents"),
+ SELECTION("Selection tool"),
+ COMPANION_MOVE("Single touch move"),
+ COMPANION_ZOOM("Single touch zoom"),
+ SMUDGE("Smudge"),
+ SOLO("Solo visibility"),
+ GUIDE_SYMMETRY("Symmetry Guide visibility"),
+ TRANSFORM("Transform tool"),
+ UNDO("Undo"),
+
+ // under Adjustments
+ BLOOM("Bloom", Adjustment.BLOOM),
+ CHROMATIC_ABERRATION("Chromatic Aberration", Adjustment.CHROMATIC_ABERRATION),
+ COLOR_BALANCE("Color Balance", Adjustment.COLOR_BALANCE),
+ CURVES("Curves", Adjustment.CURVES),
+ GAUSSIAN_BLUR("Gaussian Blur", Adjustment.GAUSSIAN_BLUR),
+ GLITCH("Glitch", Adjustment.GLITCH),
+ GRADIENT_MAP("Gradient Map", Adjustment.GRADIENT_MAP),
+ HALFTONE("Halftone", Adjustment.HALFTONE),
+ HSB("Hue, Saturation, Brightness", Adjustment.HSB),
+ MOTION_BLUR("Motion Blur", Adjustment.MOTION_BLUR),
+ NOISE("Noise", Adjustment.NOISE),
+ PERSPECTIVE_BLUR("Perspective Blur", Adjustment.PERSPECTIVE_BLUR),
+ SHARPEN("Sharpen", Adjustment.SHARPEN),
;
- /** What its button in the menu says: the name in sentence case, the flips as verbs. */
- val button: String
- get() = when (this) {
- FLIP_HORIZONTAL -> "Flip horizontally"
- FLIP_VERTICAL -> "Flip vertically"
- else -> label.take(1) + label.drop(1).lowercase()
- }
+ /** What its button in the menu says. */
+ val button: String get() = label
companion object {
/** The buttons a QuickMenu starts with, clockwise from the top. */
val DEFAULTS = listOf(NEW_LAYER, FLIP_HORIZONTAL, COPY, MERGE_DOWN, CLEAR_LAYER, FLIP_VERTICAL)
+
+ /** The picker's rows: the actions by name (as written, capitals first), null for Adjustments. */
+ val LISTED: List<QuickAction?> = (entries.filter { it.adjustment == null && it.ready }.map { it.label to it } + ("Adjustments" to null))
+ .sortedBy { it.first }.map { it.second }
+
+ /** The rows under Adjustments, by name. */
+ val ADJUSTMENTS_LISTED: List<QuickAction> = entries.filter { it.adjustment != null }.sortedBy { it.label }
}
}
diff --git a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/AdjustmentsUi.kt b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/AdjustmentsUi.kt
index 9e18b27..82ebd55 100644
--- a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/AdjustmentsUi.kt
+++ b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/AdjustmentsUi.kt
@@ -40,6 +40,8 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.graphics.drawscope.clipPath
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
@@ -63,7 +65,8 @@ import io.github.artcraftandroid.procraft.core.LiquifyKind
import kotlin.math.roundToInt
// light: the band see-through (241 over white, 228 over the surround), the panel near white
-private val ModeBar get() = if (Pc.light) Color(0xBAECECEC) else Color(0xFF5A5A5A)
+// translucent over the canvas (as measured over white and over a colour)
+private val ModeBar get() = if (Pc.light) Color(0xD6EEEEEE) else Color(0xD63B3B3B)
private val ModeText get() = if (Pc.light) Color(0xFF6A6A6A) else Color(0xFFC5C5C5)
private val HsbPanelFill get() = if (Pc.light) Color(0xF7F1F1F1) else Color(0xF71E1E1E)
private val HsbLabel get() = if (Pc.light) Color(0xFF595959) else Color(0xFF808080)
@@ -131,6 +134,46 @@ fun AdjustmentBar(vm: CanvasViewModel, modifier: Modifier = Modifier) {
}
}
+/** Layer opacity's band: its glyph, "Opacity" and the opacity, the blue line across the screen under it. */
+@Composable
+fun LayerOpacityBar(vm: CanvasViewModel, modifier: Modifier = Modifier) {
+ Column(modifier.fillMaxWidth()) {
+ Row(Modifier.fillMaxWidth().height(32.dp).background(ModeBar), horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
+ Box(Modifier.size(33.dp, 32.dp), contentAlignment = Alignment.Center) { OpacityGlyph(ModeText) }
+ Text("Opacity", color = ModeText, fontSize = 17.sp, fontWeight = FontWeight.Bold, maxLines = 1)
+ Spacer(Modifier.width(3.dp))
+ Text("${(vm.opacityValue * 100).roundToInt()}%", color = ModeText, fontSize = 14.sp, maxLines = 1)
+ }
+ Box(Modifier.fillMaxWidth(vm.opacityValue.coerceIn(0f, 1f)).height(4.dp).background(Pc.Accent))
+ }
+}
+
+/**
+ * Opacity's glyph, 14 across: a ring behind and up to the right, a disc in front, striped where
+ * it covers the ring (the stripes cut through to what is behind).
+ */
+@Composable
+private fun OpacityGlyph(ink: Color) {
+ androidx.compose.foundation.Canvas(
+ Modifier.size(14.dp).graphicsLayer { compositingStrategy = androidx.compose.ui.graphics.CompositingStrategy.Offscreen },
+ ) {
+ val u = size.width / 14f
+ val back = Offset(8.7f * u, 5.3f * u)
+ val front = Offset(5.4f * u, 8.6f * u)
+ val r = 4.9f * u
+ drawCircle(ink, r, back, style = androidx.compose.ui.graphics.drawscope.Stroke(1.1f * u))
+ drawCircle(ink, r, front)
+ // the stripes, only where the disc covers the ring's inside
+ val inside = androidx.compose.ui.graphics.Path().apply { addOval(androidx.compose.ui.geometry.Rect(back, r)) }
+ clipPath(inside) {
+ for (k in -1..1) {
+ val o = k * 2.2f * u
+ drawLine(Color.Black, Offset(front.x + o - 5f * u, front.y - o - 5f * u), Offset(front.x + o + 5f * u, front.y - o + 5f * u), 1f * u, blendMode = androidx.compose.ui.graphics.BlendMode.Clear)
+ }
+ }
+ }
+}
+
private fun Adjustment.icon() = when (this) {
Adjustment.HSB -> PcIcons.AdjustHsb
Adjustment.COLOR_BALANCE -> PcIcons.AdjustBalance
diff --git a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/AppRoot.kt b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/AppRoot.kt
index 9a64e62..dcb74cd 100644
--- a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/AppRoot.kt
+++ b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/AppRoot.kt
@@ -117,6 +117,7 @@ fun AppRoot(vm: CanvasViewModel) {
// a mode taking the screen slides it off its edge, and back when it ends
androidx.compose.animation.AnimatedVisibility(
vm.showSideBar && !vm.transforming && !vm.selecting && !vm.guideEditing && !vm.lightingStudioOpen && vm.cropRect == null && vm.textInfo == null &&
+ vm.opacityLayer == null &&
(vm.adjustment == null || vm.adjustPencil),
Modifier.align(if (vm.rightHanded) Alignment.TopEnd else Alignment.TopStart).offset(y = maxHeight * Pc.SIDE_BAR_CENTRE - Pc.SideBarHeight / 2),
enter = Motion.sideBarIn(vm.rightHanded),
@@ -228,6 +229,7 @@ fun AppRoot(vm: CanvasViewModel) {
QuickMenu(vm)
LayerChoice(vm)
if (!vm.barsHidden) QuickShapeBar(vm, Modifier.offset(y = Pc.BarHeight))
+ if (vm.opacityLayer != null && !vm.barsHidden) LayerOpacityBar(vm, Modifier.offset(y = Pc.BarHeight))
if (vm.adjustment != null && !vm.barsHidden) {
AdjustmentBar(vm, Modifier.offset(y = Pc.BarHeight))
AdjustModes(vm, Modifier.align(Alignment.TopCenter).offset(y = Pc.BarHeight + 52.dp))
diff --git a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/Chrome.kt b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/Chrome.kt
index f8fa74a..e0d395c 100644
--- a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/Chrome.kt
+++ b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/Chrome.kt
@@ -79,7 +79,7 @@ fun TopBar(vm: CanvasViewModel, modifier: Modifier = Modifier) {
Text("Gallery", color = Pc.BarText, fontSize = 18.sp, fontWeight = FontWeight.Medium, maxLines = 1, softWrap = false, modifier = Modifier.offset(y = (-1).dp))
}
ActionButton(PcIcons.Actions, "Actions", selected = vm.panel == Panel.ACTIONS) { vm.toggle(Panel.ACTIONS) }
- ActionButton(PcIcons.Adjustments, "Adjustments", selected = vm.panel == Panel.ADJUSTMENTS || vm.adjustment != null) { vm.adjustmentsPressed() }
+ ActionButton(PcIcons.Adjustments, "Adjustments", selected = vm.panel == Panel.ADJUSTMENTS || vm.adjustment != null || vm.opacityLayer != null) { vm.adjustmentsPressed() }
ActionButton(PcIcons.Selection, "Selection", selected = vm.selecting, glyph = 33.dp) { vm.toggleSelecting() }
ActionButton(PcIcons.Transform, "Transform", selected = vm.transforming, glyph = 44.dp) { vm.toggleTransform() }
}
diff --git a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/LayersPanel.kt b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/LayersPanel.kt
index 8ade55b..ddb10e0 100644
--- a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/LayersPanel.kt
+++ b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/LayersPanel.kt
@@ -9,6 +9,7 @@ import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.detectDragGesturesAfterLongPress
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
+import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.gestures.snapping.SnapPosition
import androidx.compose.foundation.gestures.snapping.rememberSnapFlingBehavior
import androidx.compose.foundation.layout.Arrangement
@@ -207,6 +208,11 @@ fun LayersPanel(vm: CanvasViewModel, arrowX: Dp, modifier: Modifier = Modifier)
translationY = if (dragging) dragOffset else 0f
alpha = if (blendAt in 0 until index) belowShown else 1f
}
+ .twoFingerTap(l.kind != LayerType.MASK) {
+ // two fingers tapped on a layer: its opacity, dragged across the canvas
+ vm.selectLayer(l.id)
+ vm.startLayerOpacity()
+ }
.pointerInput(l.id) {
if (l.kind == LayerType.MASK) return@pointerInput
detectDragGesturesAfterLongPress(
@@ -566,7 +572,7 @@ private fun GroupRow(
Box(Modifier.offset(x = 8.dp).size(44.dp, GroupHeight).clickable(onClick = onToggle), contentAlignment = Alignment.Center) {
Icon(if (l.collapsed) PcIcons.ChevronRight else PcIcons.ChevronDown, contentDescription = if (l.collapsed) "Open" else "Close", tint = ink, modifier = Modifier.size(16.dp))
}
- Box(Modifier.size(44.dp, GroupHeight).clickable { vm.toggleVisible(l) }, contentAlignment = Alignment.Center) {
+ Box(Modifier.size(44.dp, GroupHeight).visibilityTouch(vm, l), contentAlignment = Alignment.Center) {
CheckBox(l.visible, if (l.current || l.picked) Color.White else Pc.CheckFill)
}
Spacer(Modifier.width(8.dp))
@@ -643,7 +649,7 @@ private fun LayerRow(
Text(blendCode(vm, l.blend), color = letter, fontSize = 14.sp, fontWeight = FontWeight.SemiBold)
}
}
- Box(Modifier.size(44.dp, 47.dp).clickable { vm.toggleVisible(l) }, contentAlignment = Alignment.Center) {
+ Box(Modifier.size(44.dp, 47.dp).visibilityTouch(vm, l), contentAlignment = Alignment.Center) {
CheckBox(l.visible, if (selected || l.picked) Color.White else Pc.CheckFill)
}
Spacer(Modifier.width(8.dp))
@@ -984,3 +990,28 @@ private fun BackgroundRow(vm: CanvasViewModel) {
Spacer(Modifier.width(8.dp))
}
}
+
+/** A layer's visibility box: tapped, shown or hidden; held, shown alone (or every layer again). */
+private fun Modifier.visibilityTouch(vm: CanvasViewModel, l: LayerInfo): Modifier =
+ pointerInput(l) { detectTapGestures(onTap = { vm.toggleVisible(l) }, onLongPress = { vm.toggleSolo(l) }) }
+
+/** Two fingers tapping (down and up together, still) do [onTap]; the touches go on to the rest as they are. */
+private fun Modifier.twoFingerTap(enabled: Boolean, onTap: () -> Unit): Modifier = if (!enabled) this else pointerInput(Unit) {
+ awaitEachGesture {
+ val first = awaitFirstDown(requireUnconsumed = false, pass = androidx.compose.ui.input.pointer.PointerEventPass.Initial)
+ var two = false
+ var moved = false
+ while (true) {
+ val e = awaitPointerEvent(androidx.compose.ui.input.pointer.PointerEventPass.Initial)
+ if (e.changes.count { it.pressed } >= 2) two = true
+ e.changes.firstOrNull { it.id == first.id }?.let { if ((it.position - first.position).getDistance() > viewConfiguration.touchSlop) moved = true }
+ if (e.changes.none { it.pressed }) {
+ if (two && !moved && (e.changes.maxOfOrNull { it.uptimeMillis } ?: 0L) - first.uptimeMillis <= TWO_FINGER_TAP_MS) onTap()
+ break
+ }
+ }
+ }
+}
+
+/** How long two fingers may stay down and still tap, milliseconds. */
+private const val TWO_FINGER_TAP_MS = 400L
diff --git a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/QuickMenuUi.kt b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/QuickMenuUi.kt
index c2e2d34..b3148e0 100644
--- a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/QuickMenuUi.kt
+++ b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/QuickMenuUi.kt
@@ -1,6 +1,14 @@
package io.github.artcraftandroid.procraft.ui
+import androidx.compose.foundation.Canvas
import androidx.compose.foundation.ExperimentalFoundationApi
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.ui.draw.shadow
+import androidx.compose.ui.graphics.Path
+import androidx.compose.ui.unit.Dp
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
@@ -85,7 +93,8 @@ fun BoxScope.QuickMenu(vm: CanvasViewModel) {
val density = LocalDensity.current
// the button whose action is being chosen
var choosing by remember { mutableStateOf<Int?>(null) }
- BoxWithConstraints(Modifier.fillMaxSize().pointerInput(Unit) { detectTapGestures { vm.quickMenuAt = null } }) {
+ // a tap elsewhere closes the picker if it is open, else the menu
+ BoxWithConstraints(Modifier.fillMaxSize().pointerInput(Unit) { detectTapGestures { if (choosing != null) choosing = null else vm.quickMenuAt = null } }) {
// kept on the screen
val c = with(density) {
val x = at.x.toDp().coerceIn(RingReachX + RingButtonWidth / 2, maxWidth - RingReachX - RingButtonWidth / 2)
@@ -106,7 +115,7 @@ fun BoxScope.QuickMenu(vm: CanvasViewModel) {
val y = c.second + dy.dp * shown - RingButtonHeight / 2
Box(
Modifier.offset(x = x, y = y).size(RingButtonWidth, RingButtonHeight).graphicsLayer { alpha = shown.coerceIn(0f, 1f) }.clip(CircleShape)
- .background(if (choosing == i) Pc.Accent else ButtonFill).border(1.dp, ButtonEdge, CircleShape)
+ .background(ButtonFill).border(1.dp, ButtonEdge, CircleShape)
.combinedClickable(
onClick = {
vm.quickMenuAt = null
@@ -116,30 +125,83 @@ fun BoxScope.QuickMenu(vm: CanvasViewModel) {
),
contentAlignment = Alignment.Center,
) {
- Text(action.button, color = if (choosing == i) Color.White else ButtonInk, fontSize = 16.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, textAlign = TextAlign.Center)
+ Text(action.button, color = ButtonInk, fontSize = 16.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, textAlign = TextAlign.Center)
}
}
- // the actions a held button can be set to, beside the ring
+ // the actions a held button can be set to, hung from it
choosing?.let { i ->
- val right = c.first + RingReachX + RingButtonWidth / 2
- val left = (if (right + 236.dp < maxWidth) right + 16.dp else c.first - RingReachX - RingButtonWidth / 2 - 236.dp)
- .coerceIn(8.dp, (maxWidth - 228.dp).coerceAtLeast(8.dp))
- val top = (c.second - 220.dp).coerceIn(8.dp, (maxHeight - 448.dp).coerceAtLeast(8.dp))
- Column(
- Modifier.offset(x = left, y = top).width(220.dp).height(440.dp).clip(RoundedCornerShape(16.dp)).background(Pc.PopoverFill)
- .verticalScroll(rememberScrollState()).padding(vertical = 6.dp),
- ) {
- for (a in QuickAction.entries) {
- val chosen = a == slots.getOrNull(i)
- Box(
- Modifier.fillMaxWidth().height(40.dp).clickable {
- vm.setQuickSlot(i, a)
- choosing = null
- }.padding(horizontal = 16.dp),
- contentAlignment = Alignment.CenterStart,
- ) {
- Text(a.label, color = Pc.PanelTitle, fontSize = 16.sp, maxLines = 1)
- if (chosen) Icon(PcIcons.Tick, contentDescription = null, tint = Pc.Accent, modifier = Modifier.align(Alignment.CenterEnd).size(18.dp))
+ val (dx, dy) = Slots.getOrNull(i) ?: return@let
+ val centre = c.first + dx.dp
+ val top = c.second + dy.dp - RingButtonHeight / 2
+ ActionPicker(slots.getOrNull(i) ?: QuickAction.NONE, centre, top, top + RingButtonHeight, maxWidth, maxHeight) {
+ vm.setQuickSlot(i, it)
+ choosing = null
+ }
+ }
+ }
+}
+
+/**
+ * A held QuickMenu button's picker, hung from the button by an arrow (above it when there is no
+ * room below): every action by name, the button's own blue, scrolled to it; Adjustments opens
+ * their own list. A row tapped sets the button.
+ */
+@Composable
+private fun ActionPicker(current: QuickAction, centreX: Dp, buttonTop: Dp, buttonBottom: Dp, maxWidth: Dp, maxHeight: Dp, onPick: (QuickAction) -> Unit) {
+ var adjustments by remember { mutableStateOf(current.adjustment != null) }
+ val below = buttonBottom + PickerArrow + PickerHeight <= maxHeight - PickerMargin
+ val left = (centreX - PickerWidth / 2).coerceIn(PickerMargin, (maxWidth - PickerWidth - PickerMargin).coerceAtLeast(PickerMargin))
+ val top = if (below) buttonBottom + PickerArrow else buttonTop - PickerArrow - PickerHeight
+ // the arrow, its point on the button
+ Canvas(Modifier.fillMaxSize()) {
+ val x = centreX.toPx()
+ val a = PickerArrow.toPx()
+ val tip = if (below) buttonBottom.toPx() else buttonTop.toPx()
+ val base = if (below) tip + a + 1f else tip - a - 1f
+ drawPath(Path().apply { moveTo(x, tip); lineTo(x + a, base); lineTo(x - a, base); close() }, PickerFill)
+ }
+ Column(
+ Modifier.offset(x = left, y = top).size(PickerWidth, PickerHeight).shadow(24.dp, RoundedCornerShape(PickerCorner))
+ .clip(RoundedCornerShape(PickerCorner)).background(PickerFill).pointerInput(Unit) { detectTapGestures { } },
+ ) {
+ // the title; in Adjustments a way back
+ Row(
+ Modifier.fillMaxWidth().height(PickerHeader).let { if (adjustments) it.clickable { adjustments = false } else it }
+ .padding(start = if (adjustments) 13.dp else 21.dp, top = 15.dp),
+ verticalAlignment = Alignment.Top,
+ ) {
+ if (adjustments) {
+ Icon(PcIcons.ChevronLeft, contentDescription = "Back", tint = PickerTitleInk, modifier = Modifier.size(24.dp))
+ Spacer(Modifier.width(4.dp))
+ }
+ Text(if (adjustments) "Adjustments" else "Set Action", color = PickerTitleInk, fontSize = 19.3.sp, fontWeight = FontWeight.Bold, maxLines = 1)
+ }
+ val rows: List<QuickAction?> = if (adjustments) QuickAction.ADJUSTMENTS_LISTED else QuickAction.LISTED
+ // the button's own action blue (in Adjustments, the first when it is none of them)
+ val chosen = if (adjustments) rows.indexOf(current).takeIf { it >= 0 } ?: 0 else rows.indexOf(current)
+ val list = androidx.compose.foundation.lazy.rememberLazyListState()
+ val past = with(LocalDensity.current) { (PickerRowPitch * 2 - PickerChosenAt).roundToPx() }
+ androidx.compose.runtime.LaunchedEffect(adjustments) {
+ // the chosen row a little below the list's top
+ if (chosen >= 2) list.scrollToItem(chosen - 2, past) else list.scrollToItem(0)
+ }
+ androidx.compose.foundation.lazy.LazyColumn(
+ Modifier.fillMaxWidth().weight(1f),
+ state = list,
+ verticalArrangement = Arrangement.spacedBy(PickerRowGap),
+ contentPadding = PaddingValues(start = PickerInset, end = PickerInset, bottom = 6.dp),
+ ) {
+ items(rows.size) { k ->
+ val a = rows[k]
+ val on = k == chosen
+ Box(
+ Modifier.fillMaxWidth().height(PickerRowHeight).clip(CircleShape).background(if (on) Pc.Accent else PickerRowFill)
+ .clickable { if (a == null) adjustments = true else onPick(a) }.padding(horizontal = 16.dp),
+ contentAlignment = Alignment.CenterStart,
+ ) {
+ Text(a?.label ?: "Adjustments", color = if (on) Color.White else PickerRowInk, fontSize = 14.5.sp, fontWeight = if (on) FontWeight.SemiBold else FontWeight.Normal, maxLines = 1)
+ if (a == null) {
+ Icon(PcIcons.ChevronRight, contentDescription = null, tint = PickerRowInk, modifier = Modifier.align(Alignment.CenterEnd).size(18.dp))
}
}
}
@@ -147,6 +209,25 @@ fun BoxScope.QuickMenu(vm: CanvasViewModel) {
}
}
+// the picker (as measured): a dark panel 220 wide, corners 30, an arrow 14 tall; capsule rows 47
+// tall on a 50 pitch, 8.5 in from its sides, under a 55.5 tall title
+private val PickerWidth = 220.dp
+private val PickerCorner = 30.dp
+private val PickerArrow = 14.dp
+private val PickerHeader = 55.5.dp
+private val PickerRowHeight = 47.dp
+private val PickerRowGap = 3.dp
+private val PickerRowPitch = PickerRowHeight + PickerRowGap
+private val PickerInset = 8.5.dp
+private val PickerHeight = PickerHeader + PickerRowPitch * 6 - PickerRowGap + 6.dp
+private val PickerMargin = 8.dp
+/** How far below the list's top the chosen row shows. */
+private val PickerChosenAt = 89.dp
+private val PickerFill = Color(0xFF373737)
+private val PickerRowFill = Color(0xFF2E2E2E)
+private val PickerRowInk = Color(0xFFC5C5C5)
+private val PickerTitleInk = Color(0xFFC4C4C4)
+
/** Layer Select's list: the layers drawn under the point, top first, the current one blue. */
@Composable
fun BoxScope.LayerChoice(vm: CanvasViewModel) {
diff --git a/apps/procraft-android/src/layers.rs b/apps/procraft-android/src/layers.rs
index a529ded..cb13dda 100644
--- a/apps/procraft-android/src/layers.rs
+++ b/apps/procraft-android/src/layers.rs
@@ -447,6 +447,30 @@ impl CanvasSession {
.is_some()
}
+ /// Shows layer `id` alone, the others left out of the picture (solo visibility), or with
+ /// none every layer as it is set again. Not an undo step; false if `id` isn't a layer.
+ pub fn set_solo(&self, id: Option<u64>) -> bool {
+ let mut guard = self.shared.lock();
+ let st = &mut *guard;
+ let solo = id.map(LayerId);
+ if solo.is_some_and(|s| st.doc.layer(s).is_none()) {
+ return false;
+ }
+ st.doc.solo = solo;
+ if let Some(canvas) = st.canvas.as_mut() {
+ canvas.invalidate();
+ }
+ st.revision += 1;
+ self.shared.frame(st);
+ true
+ }
+
+ /// The layer shown alone, if one is.
+ pub fn solo(&self) -> Option<u64> {
+ let st = self.shared.lock();
+ st.doc.solo.filter(|s| st.doc.layer(*s).is_some()).map(|s| s.0)
+ }
+
/// Opacity 0..1; `done` ends the drag (one undo step for the whole drag).
pub fn set_layer_opacity(&self, id: u64, opacity: f32, done: bool) -> bool {
self.change_live("layer opacity", done, |d| d.set_opacity(LayerId(id), opacity))
diff --git a/apps/procraft-android/src/lib.rs b/apps/procraft-android/src/lib.rs
index 340cfd3..b6ddb3e 100644
--- a/apps/procraft-android/src/lib.rs
+++ b/apps/procraft-android/src/lib.rs
@@ -1077,6 +1077,21 @@ impl CanvasSession {
self.shared.frame(&mut st);
}
+ /// Zooms to the canvas's actual size (a canvas pixel to a window pixel) about the middle of
+ /// the window, keeping its turn, settling into place as [`CanvasSession::settle_to_fit`] does.
+ pub fn settle_to_actual_size(&self) {
+ let mut st = self.shared.lock();
+ let Some(from) = st.view else { return };
+ let middle = Vec2::new(st.window_size.0 as f32 / 2.0, st.window_size.1 as f32 / 2.0);
+ let Some(to) =
+ from.screen_to_canvas(middle).and_then(|c| View::centred(c, 1.0, from.rotation(), st.window_size))
+ else {
+ return;
+ };
+ st.view_motion = Some(ViewMotion { from, to, start: std::time::Instant::now(), curve: ViewCurve::Settle });
+ self.shared.frame(&mut st);
+ }
+
/// Fits the whole canvas in the window again, growing back into place over 0.3 s, slowing to
/// a stop (as leaving crop without cropping does).
pub fn ease_to_fit(&self) {
diff --git a/apps/procraft-android/src/tests.rs b/apps/procraft-android/src/tests.rs
index d0f5784..2c31f46 100644
--- a/apps/procraft-android/src/tests.rs
+++ b/apps/procraft-android/src/tests.rs
@@ -2663,3 +2663,33 @@ fn a_layered_psd_comes_in_as_an_artwork() {
);
let _ = std::fs::remove_dir_all(&dir);
}
+
+#[test]
+fn a_layer_shown_alone_hides_the_others_until_solo_ends() {
+ let Some(s) = session(100, 100) else { return };
+ s.set_brush_size(0.4);
+ let dot = |x: f32| {
+ s.stroke_begin(PointerKind::Finger, vec![sample(x, 50.0, 0.0)]);
+ s.stroke_end(vec![]);
+ };
+ dot(20.0);
+ let top = s.add_layer();
+ dot(80.0);
+ assert_eq!(pixel(&s, 20, 50), [0, 0, 0, 255]);
+ assert!(s.set_solo(Some(top)));
+ assert_eq!(s.solo(), Some(top));
+ assert_eq!(pixel(&s, 20, 50), [255, 255, 255, 255]);
+ assert_eq!(pixel(&s, 80, 50), [0, 0, 0, 255]);
+ // undo changes the artwork, not how it is looked at
+ s.undo();
+ assert_eq!(s.solo(), Some(top));
+ assert_eq!(pixel(&s, 20, 50), [255, 255, 255, 255]);
+ assert!(s.set_solo(None));
+ assert_eq!(pixel(&s, 20, 50), [0, 0, 0, 255]);
+ assert!(!s.set_solo(Some(999)));
+ // the layer shown alone undone away: every layer shows again
+ assert!(s.set_solo(Some(top)));
+ s.undo();
+ assert_eq!(s.solo(), None);
+ assert_eq!(pixel(&s, 20, 50), [0, 0, 0, 255]);
+}
diff --git a/crates/engine/src/document.rs b/crates/engine/src/document.rs
index b5667e3..498ed59 100644
--- a/crates/engine/src/document.rs
+++ b/crates/engine/src/document.rs
@@ -328,6 +328,9 @@ pub struct Document {
/// built-in profiles.
#[serde(default, deserialize_with = "crate::cms::lenient", skip_serializing_if = "Option::is_none")]
pub icc: Option<crate::cms::CanvasIcc>,
+ /// The layer shown alone, the others left out of the picture (solo visibility).
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub solo: Option<LayerId>,
}
/// A document's profile settings apart from it.
@@ -369,6 +372,7 @@ impl Document {
animation: None,
profile: crate::profile::Profile::Srgb,
icc: None,
+ solo: None,
};
doc.add_layer();
doc
@@ -514,6 +518,16 @@ impl Document {
true
}
+ /// Whether layer `id` is left out of the picture while another is shown alone (solo): all
+ /// but that layer, its mask and the groups it is in.
+ pub fn soloed_out(&self, id: LayerId) -> bool {
+ let Some(solo) = self.solo.filter(|s| self.layer(*s).is_some()) else { return false };
+ if id == solo || self.mask_of(solo) == Some(id) {
+ return false;
+ }
+ !(self.layer(id).is_some_and(|l| l.kind == LayerKind::Group) && self.is_inside(solo, id))
+ }
+
/// The reference layer, if one is set.
pub fn reference(&self) -> Option<LayerId> {
self.layers.iter().find(|l| l.reference).map(|l| l.id)
@@ -1287,6 +1301,9 @@ impl Document {
if self.layer(self.current).is_none() {
self.current = self.layers.last().map_or(LayerId(0), |l| l.id);
}
+ if self.solo.is_some_and(|s| self.layer(s).is_none()) {
+ self.solo = None;
+ }
let (current, ids): (LayerId, Vec<LayerId>) = (self.current, self.layers.iter().map(|l| l.id).collect());
self.picked.retain(|p| *p != current && ids.contains(p));
self
diff --git a/crates/gpu/src/canvas.rs b/crates/gpu/src/canvas.rs
index e79c2c3..3fbc963 100644
--- a/crates/gpu/src/canvas.rs
+++ b/crates/gpu/src/canvas.rs
@@ -3292,8 +3292,11 @@ impl Canvas {
}
self.dirty = self.dirty.union(s.rect);
}
+ let solo = doc.solo;
let replaced = step.doc.map(|before| Box::new(std::mem::replace(doc, *before)));
if replaced.is_some() {
+ // a layer shown alone is how the artwork is looked at, not a change to undo
+ doc.solo = solo.filter(|s| doc.layer(*s).is_some());
self.dirty = self.full();
}
let selection = step.selection.map(|before| {
@@ -3530,6 +3533,10 @@ impl Canvas {
let focus = animation.and_then(|_| self.play_frame.or_else(|| animation::current_frame(doc)));
for id in doc.members(group) {
let Some(layer) = doc.layer(id) else { continue };
+ // another layer shown alone
+ if doc.soloed_out(id) {
+ continue;
+ }
let look = match (animation, focus, frames.iter().position(|f| *f == id)) {
(Some(a), Some(c), Some(i)) => {
match animation::look(a, i, frames.len(), c, self.play_frame.is_some()) {