|
@@ -1,6 +1,5 @@
|
|
package com.ys.imageProcess.ui.work
|
|
package com.ys.imageProcess.ui.work
|
|
|
|
|
|
-import android.graphics.Point
|
|
|
|
import android.graphics.PointF
|
|
import android.graphics.PointF
|
|
import androidx.compose.foundation.Canvas
|
|
import androidx.compose.foundation.Canvas
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
@@ -11,11 +10,9 @@ import androidx.compose.ui.geometry.Rect
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.graphics.Path
|
|
import androidx.compose.ui.graphics.Path
|
|
import androidx.compose.ui.graphics.drawscope.DrawScope
|
|
import androidx.compose.ui.graphics.drawscope.DrawScope
|
|
-import androidx.compose.ui.graphics.drawscope.Fill
|
|
|
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
import com.ys.imageProcess.ui.theme.ImageProcTheme
|
|
import com.ys.imageProcess.ui.theme.ImageProcTheme
|
|
-import kotlin.math.abs
|
|
|
|
|
|
|
|
@Composable
|
|
@Composable
|
|
fun CanvasView(
|
|
fun CanvasView(
|
|
@@ -30,7 +27,7 @@ fun CanvasView(
|
|
Canvas(modifier.fillMaxSize()) {
|
|
Canvas(modifier.fillMaxSize()) {
|
|
val strokeWidth = 5 / scale
|
|
val strokeWidth = 5 / scale
|
|
if (state.showContour) {
|
|
if (state.showContour) {
|
|
- drawPolygon(contour, fillColor, Color.Green, strokeWidth, state.editMode)
|
|
|
|
|
|
+ drawPolygon(contour, fillColor, Color.Green, strokeWidth, state.editMode,true)
|
|
}
|
|
}
|
|
if (state.showWidth) {
|
|
if (state.showWidth) {
|
|
drawPolygon(width, fillColor, Color.Blue, strokeWidth, state.editMode)
|
|
drawPolygon(width, fillColor, Color.Blue, strokeWidth, state.editMode)
|
|
@@ -38,7 +35,6 @@ fun CanvasView(
|
|
if (state.showLength) {
|
|
if (state.showLength) {
|
|
drawPolygon(length, fillColor, Color.Red, strokeWidth, state.editMode)
|
|
drawPolygon(length, fillColor, Color.Red, strokeWidth, state.editMode)
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -66,7 +62,6 @@ private fun DrawScope.drawPolygon(
|
|
close()
|
|
close()
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
if (showAnchors) {
|
|
if (showAnchors) {
|
|
val l = strokeWidth * 5
|
|
val l = strokeWidth * 5
|
|
|
|
|
|
@@ -77,47 +72,11 @@ private fun DrawScope.drawPolygon(
|
|
moveTo(x, y)
|
|
moveTo(x, y)
|
|
val rect = Rect(Offset(x - l, y - l), Offset(x + l, y + l))
|
|
val rect = Rect(Offset(x - l, y - l), Offset(x + l, y + l))
|
|
addRect(rect)
|
|
addRect(rect)
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- // var showRect = true
|
|
|
|
- // var lastRectIndex = -1
|
|
|
|
- // val l = strokeWidth * 5
|
|
|
|
- //
|
|
|
|
- // for (i in points.indices) {
|
|
|
|
- // val x = points[i].x * d
|
|
|
|
- // val y = points[i].y * d
|
|
|
|
- // if (i > 0) {
|
|
|
|
- // if (lastRectIndex >= 0) {
|
|
|
|
- // val lastRectX = points[lastRectIndex].x * d
|
|
|
|
- // val lastRectY = points[lastRectIndex].y * d
|
|
|
|
- // showRect =
|
|
|
|
- // abs(lastRectX - x) > l * 4 || abs(lastRectY - y) > l * 4
|
|
|
|
- // showRect = true
|
|
|
|
- // }
|
|
|
|
- // if (showRect) {
|
|
|
|
- // lastRectIndex = i
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- //
|
|
|
|
- //
|
|
|
|
- // if (showRect) {
|
|
|
|
- // moveTo(x, y)
|
|
|
|
- // val rect = Rect(Offset(x - l, y - l), Offset(x + l, y + l))
|
|
|
|
- // addRect(rect)
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- // }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-// drawPath(
|
|
|
|
-// path = path,
|
|
|
|
-// color = fillColor,
|
|
|
|
-// style = Fill
|
|
|
|
-// )
|
|
|
|
-
|
|
|
|
drawPath(
|
|
drawPath(
|
|
path = path,
|
|
path = path,
|
|
color = strokeColor,
|
|
color = strokeColor,
|