Skip to content

Commit a2bb0f3

Browse files
add CustomPathEdit and ImageMaskEdit
1 parent 911b79b commit a2bb0f3

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.smarttoolfactory.composecropper.preferences.frames.edit
2+
3+
import androidx.compose.foundation.layout.Box
4+
import androidx.compose.foundation.layout.Column
5+
import androidx.compose.foundation.layout.aspectRatio
6+
import androidx.compose.foundation.layout.fillMaxWidth
7+
import androidx.compose.material3.ExperimentalMaterial3Api
8+
import androidx.compose.material3.TextField
9+
import androidx.compose.runtime.*
10+
import androidx.compose.ui.Modifier
11+
import androidx.compose.ui.draw.clipToBounds
12+
import androidx.compose.ui.draw.drawWithCache
13+
import androidx.compose.ui.graphics.Color
14+
import androidx.compose.ui.graphics.ImageBitmap
15+
import androidx.compose.ui.graphics.Path
16+
import com.smarttoolfactory.cropper.model.AspectRatio
17+
import com.smarttoolfactory.cropper.model.CustomPathOutline
18+
import com.smarttoolfactory.cropper.util.calculateSizeAndOffsetFromAspectRatio
19+
import com.smarttoolfactory.cropper.util.drawBlockWithCheckerAndLayer
20+
import com.smarttoolfactory.cropper.util.scaleAndTranslatePath
21+
22+
@OptIn(ExperimentalMaterial3Api::class)
23+
@Composable
24+
internal fun CustomPathEdit(
25+
aspectRatio: AspectRatio,
26+
dstBitmap: ImageBitmap,
27+
customPathOutline: CustomPathOutline,
28+
onChange: (CustomPathOutline) -> Unit
29+
) {
30+
var newTitle by remember {
31+
mutableStateOf(customPathOutline.title)
32+
}
33+
34+
Column {
35+
36+
Box(
37+
modifier = Modifier
38+
.fillMaxWidth()
39+
.clipToBounds()
40+
.aspectRatio(4 / 3f)
41+
.drawWithCache {
42+
43+
val path = Path().apply {
44+
addPath(customPathOutline.path)
45+
46+
val (newSize, offset) = calculateSizeAndOffsetFromAspectRatio(
47+
aspectRatio = aspectRatio,
48+
coefficient = 1f,
49+
size = size
50+
)
51+
scaleAndTranslatePath(newSize.width, newSize.height)
52+
translate(offset)
53+
}
54+
55+
onDrawWithContent {
56+
drawBlockWithCheckerAndLayer(dstBitmap) {
57+
drawPath(path, Color.Red)
58+
59+
}
60+
}
61+
}
62+
63+
)
64+
65+
TextField(
66+
value = newTitle,
67+
onValueChange = {
68+
newTitle = it
69+
onChange(
70+
customPathOutline.copy(
71+
title = newTitle
72+
)
73+
)
74+
75+
}
76+
)
77+
}
78+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.smarttoolfactory.composecropper.preferences.frames.edit
2+
3+
import androidx.compose.foundation.Image
4+
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.foundation.layout.fillMaxWidth
7+
import androidx.compose.material3.ExperimentalMaterial3Api
8+
import androidx.compose.material3.TextField
9+
import androidx.compose.runtime.*
10+
import androidx.compose.ui.Alignment
11+
import androidx.compose.ui.Modifier
12+
import com.smarttoolfactory.cropper.model.ImageMaskOutline
13+
14+
@OptIn(ExperimentalMaterial3Api::class)
15+
@Composable
16+
internal fun ImageMaskEdit(
17+
imageMaskOutline: ImageMaskOutline,
18+
onChange: (ImageMaskOutline) -> Unit
19+
) {
20+
21+
var newTitle by remember {
22+
mutableStateOf(imageMaskOutline.title)
23+
}
24+
25+
Column {
26+
27+
Box(
28+
modifier = Modifier.fillMaxWidth(),
29+
contentAlignment = Alignment.Center
30+
) {
31+
Image(bitmap = imageMaskOutline.image, contentDescription = "ImageMask")
32+
33+
}
34+
TextField(
35+
value = newTitle,
36+
onValueChange = {
37+
newTitle = it
38+
onChange(
39+
imageMaskOutline.copy(
40+
title = newTitle
41+
)
42+
)
43+
44+
}
45+
)
46+
}
47+
}

0 commit comments

Comments
 (0)