@@ -4,24 +4,15 @@ import androidx.compose.material3.AlertDialog
44import androidx.compose.material3.Button
55import androidx.compose.material3.Text
66import androidx.compose.runtime.*
7- import androidx.compose.ui.Modifier
8- import androidx.compose.ui.draw.drawWithCache
9- import androidx.compose.ui.geometry.Size
10- import androidx.compose.ui.graphics.Color
117import androidx.compose.ui.graphics.ImageBitmap
12- import androidx.compose.ui.graphics.Shape
13- import androidx.compose.ui.graphics.drawOutline
14- import androidx.compose.ui.graphics.drawscope.translate
158import androidx.compose.ui.res.imageResource
16- import androidx.compose.ui.unit.Density
179import com.smarttoolfactory.cropper.R
1810import com.smarttoolfactory.cropper.model.*
19- import com.smarttoolfactory.cropper.util.drawBlockWithCheckerAndLayer
2011
2112@Composable
2213fun CropFrameEditDialog (
2314 aspectRatio : AspectRatio ,
24- index : Int = 0 ,
15+ index : Int ,
2516 cropFrame : CropFrame ,
2617 onConfirm : (CropFrame ) -> Unit ,
2718 onDismiss : () -> Unit
@@ -32,7 +23,7 @@ fun CropFrameEditDialog(
3223 val outlineType = cropFrame.outlineType
3324
3425 var outline: CropOutline by remember {
35- mutableStateOf(cropFrame.cropOutlineContainer. outlines[index])
26+ mutableStateOf(cropFrame.outlines[index])
3627 }
3728
3829 AlertDialog (
@@ -96,7 +87,7 @@ fun CropFrameEditDialog(
9687 confirmButton = {
9788 Button (onClick = {
9889
99- val newOutlines: List <CropOutline > = cropFrame.cropOutlineContainer. outlines
90+ val newOutlines: List <CropOutline > = cropFrame.outlines
10091 .toMutableList()
10192 .apply {
10293 set(index, outline)
@@ -109,117 +100,13 @@ fun CropFrameEditDialog(
109100
110101 onConfirm(newCropFrame)
111102 }) {
112- Text (" Confirm " )
103+ Text (" OK " )
113104 }
114105 },
115106 dismissButton = {
116107 Button (onClick = { onDismiss() }) {
117- Text (text = " Dismiss " )
108+ Text (text = " Cancel " )
118109 }
119110 }
120111 )
121112}
122-
123- internal fun Modifier.drawOutlineWithCache (
124- aspectRatio : AspectRatio ,
125- shape : Shape ,
126- density : Density ,
127- dstBitmap : ImageBitmap
128- ) = this .then(
129- Modifier .drawWithCache {
130-
131- val coefficient = .9f
132-
133- val width = size.width
134- val height = size.height
135-
136- val value = aspectRatio.value
137-
138- val shapeSize = if (aspectRatio == AspectRatio .Unspecified ) {
139- Size (width * coefficient, height * coefficient)
140- } else if (value > 1 ) {
141- Size (
142- width = coefficient * width,
143- height = coefficient * width / value
144- )
145- } else {
146- Size (width = coefficient * height * value, height = coefficient * height)
147- }
148-
149- val left = (width - shapeSize.width) / 2
150- val top = (height - shapeSize.height) / 2
151-
152- val outline = shape.createOutline(
153- size = shapeSize,
154- layoutDirection = layoutDirection,
155- density = density
156- )
157-
158- onDrawWithContent {
159- drawBlockWithCheckerAndLayer(dstBitmap) {
160- translate(left = left, top = top) {
161- drawOutline(
162- outline = outline,
163- color = Color .Red ,
164- )
165- }
166- }
167- }
168- }
169- )
170-
171- @Suppress(" UNCHECKED_CAST" )
172- private fun getOutlineContainer (
173- outlineType : OutlineType ,
174- index : Int ,
175- outlines : List <CropOutline >
176- ): CropOutlineContainer <out CropOutline > {
177- return when (outlineType) {
178- OutlineType .RoundedRect -> {
179- RoundedRectOutlineContainer (
180- selectedIndex = index,
181- outlines = outlines as List <RoundedCornerCropShape >
182- )
183- }
184- OutlineType .CutCorner -> {
185- CutCornerRectOutlineContainer (
186- selectedIndex = index,
187- outlines = outlines as List <CutCornerCropShape >
188- )
189- }
190-
191- OutlineType .Oval -> {
192- OvalOutlineContainer (
193- selectedIndex = index,
194- outlines = outlines as List <OvalCropShape >
195- )
196- }
197-
198- OutlineType .Polygon -> {
199- PolygonOutlineContainer (
200- selectedIndex = index,
201- outlines = outlines as List <PolygonCropShape >
202- )
203- }
204-
205- OutlineType .Custom -> {
206- PolygonOutlineContainer (
207- selectedIndex = index,
208- outlines = outlines as List <PolygonCropShape >
209- )
210- }
211-
212- OutlineType .ImageMask -> {
213- ImageMaskOutlineContainer (
214- selectedIndex = index,
215- outlines = outlines as List <ImageMaskOutline >
216- )
217- }
218- else -> {
219- RectOutlineContainer (
220- selectedIndex = index,
221- outlines = outlines as List <RectCropShape >
222- )
223- }
224- }
225- }
0 commit comments