Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5397b224 authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Xiaoqian (Daisy) Dai
Browse files

screen capture: add resize handlers

From spec, add 4 resize handlers on the 4 corners of the region box and
hide the resize handlers during moving or resizing the region box.

Bug: 439660708, 423963391
Test: Manual
Flag: com.android.systemui.large_screen_screencapture

Change-Id: Ie203d2199a9741e4d528df48c56032543f5c7a13
parent 1aa2d4fb
Loading
Loading
Loading
Loading
+74 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
@@ -37,6 +38,10 @@ import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.StrokeJoin
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.PointerEvent
import androidx.compose.ui.input.pointer.PointerEventPass
@@ -51,6 +56,8 @@ import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import com.android.systemui.common.shared.model.Icon
@@ -675,11 +682,78 @@ fun RegionBox(
                        captureButtonPlaceable.placeRelative(0, 0)
                    }
                }

                // Draw the 4 resize knobs at the 4 corners of the region box.
                val handleSize = 20.dp
                val handleSizePx = with(density) { handleSize.toPx() }.roundToInt()
                if (state.dragMode != DragMode.MOVING && state.dragMode != DragMode.RESIZING) {
                    Box {
                        ResizeHandle(
                            modifier = Modifier.offset { IntOffset(x = 0, y = 0) },
                            rotation = 0f,
                            size = handleSize,
                        )
                        ResizeHandle(
                            modifier =
                                Modifier.offset {
                                    IntOffset(
                                        x = currentRect.width.roundToInt() - handleSizePx,
                                        y = 0,
                                    )
                                },
                            rotation = 90f,
                            size = handleSize,
                        )
                        ResizeHandle(
                            modifier =
                                Modifier.offset {
                                    IntOffset(
                                        x = 0,
                                        y = currentRect.height.roundToInt() - handleSizePx,
                                    )
                                },
                            rotation = 270f,
                            size = handleSize,
                        )
                        ResizeHandle(
                            modifier =
                                Modifier.offset {
                                    IntOffset(
                                        x = currentRect.width.roundToInt() - handleSizePx,
                                        y = currentRect.height.roundToInt() - handleSizePx,
                                    )
                                },
                            rotation = 180f,
                            size = handleSize,
                        )
                    }
                }
            }
        }
    }
}

@Composable
private fun ResizeHandle(rotation: Float, size: Dp, modifier: Modifier = Modifier) {
    val handleColor = MaterialTheme.colorScheme.primary
    Canvas(modifier = modifier.size(size).graphicsLayer { rotationZ = rotation }) {
        val strokeWidth = 6.dp.toPx()
        val canvasSize = this.size.width
        val path =
            Path().apply {
                moveTo(canvasSize - strokeWidth / 2, strokeWidth / 2)
                lineTo(strokeWidth / 2, strokeWidth / 2)
                lineTo(strokeWidth / 2, canvasSize - strokeWidth / 2)
            }

        drawPath(
            path = path,
            color = handleColor,
            style = Stroke(width = strokeWidth, join = StrokeJoin.Round, cap = StrokeCap.Round),
        )
    }
}

/**
 * Remembers the appropriate [PointerIcon] based on the current interaction state.
 *