Ulric 3 долоо хоног өмнө
parent
commit
84f9b6ba51

+ 1 - 42
app/src/main/java/com/ys/imageProcess/ui/work/CanvasView.kt

@@ -1,6 +1,5 @@
 package com.ys.imageProcess.ui.work
 
-import android.graphics.Point
 import android.graphics.PointF
 import androidx.compose.foundation.Canvas
 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.Path
 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.tooling.preview.Preview
 import com.ys.imageProcess.ui.theme.ImageProcTheme
-import kotlin.math.abs
 
 @Composable
 fun CanvasView(
@@ -30,7 +27,7 @@ fun CanvasView(
     Canvas(modifier.fillMaxSize()) {
         val strokeWidth = 5 / scale
         if (state.showContour) {
-            drawPolygon(contour, fillColor, Color.Green, strokeWidth, state.editMode)
+            drawPolygon(contour, fillColor, Color.Green, strokeWidth, state.editMode,true)
         }
         if (state.showWidth) {
             drawPolygon(width, fillColor, Color.Blue, strokeWidth, state.editMode)
@@ -38,7 +35,6 @@ fun CanvasView(
         if (state.showLength) {
             drawPolygon(length, fillColor, Color.Red, strokeWidth, state.editMode)
         }
-
     }
 }
 
@@ -66,7 +62,6 @@ private fun DrawScope.drawPolygon(
                 close()
             }
 
-
             if (showAnchors) {
                 val l = strokeWidth * 5
 
@@ -77,47 +72,11 @@ private fun DrawScope.drawPolygon(
                     moveTo(x, y)
                     val rect = Rect(Offset(x - l, y - l), Offset(x + l, y + l))
                     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(
         path = path,
         color = strokeColor,

+ 4 - 0
app/src/main/java/com/ys/imageProcess/ui/work/CentralImageView.kt

@@ -1,6 +1,9 @@
 package com.ys.imageProcess.ui.work
 
+import android.content.ContentValues.TAG
 import android.graphics.BitmapFactory
+import android.nfc.Tag
+import android.util.Log
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.Box
@@ -34,6 +37,7 @@ fun CentralImageView(
     viewModel: CentralImageViewModel = viewModel(),
 ) {
     LaunchedEffect(data) {
+        Log.i(TAG, "set data")
         viewModel.setData(canvasSize, data)
     }
 

+ 26 - 6
app/src/main/java/com/ys/imageProcess/ui/work/ViewToolBar.kt

@@ -3,10 +3,13 @@ package com.ys.imageProcess.ui.work
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
 import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.size
 import androidx.compose.material3.Button
 import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
@@ -83,6 +86,17 @@ fun ViewToolBar(
                 SwitchEdit -> if (state.editMode) Blue else Color.DarkGray
             }
 
+            val text: String = when (it) {
+                Back -> "退出"
+                ZoomIn -> "放大"
+                ZoomOut -> "缩小"
+                FitScreen -> "适应屏幕"
+                ShowContour -> if (state.editMode) "调整轮廓" else "显示轮廓"
+                ShowLength -> if (state.editMode) "调整长度" else "显示长度"
+                ShowWidth -> if (state.editMode) "调整宽度" else "显示宽度"
+                SwitchEdit -> if (state.editMode) "保存" else "调整"
+            }
+
             Button(
                 onClick = {
                     action(it)
@@ -93,12 +107,18 @@ fun ViewToolBar(
                     disabledContainerColor = Color.Transparent
                 ),
             ) {
-                Image(
-                    modifier = Modifier.size(35.dp),
-                    painter = painterResource(it.icon()),
-                    contentDescription = "",
-                    colorFilter = ColorFilter.tint(color)
-                )
+                Column(
+                    horizontalAlignment = Alignment.CenterHorizontally,
+                    modifier = Modifier
+                ) {
+                    Image(
+                        modifier = Modifier.size(35.dp),
+                        painter = painterResource(it.icon()),
+                        contentDescription = "",
+                        colorFilter = ColorFilter.tint(color)
+                    )
+                    Text(text = text, color = color)
+                }
             }
         }
     }

+ 2 - 2
app/src/main/java/com/ys/imageProcess/ui/work/WorkScreen.kt

@@ -86,6 +86,7 @@ fun WorkScreen(
                                 viewModel.onDrag(change.position / density)
                             }
                         }
+                        .background(Color.Red)
                 ) {
                     val canvasSize = Size(maxWidth.value, maxHeight.value)
                     LaunchedEffect(canvasSize) {
@@ -116,8 +117,7 @@ fun WorkScreen(
 
                     AnchorLayer(
                         Modifier
-                            .fillMaxSize()
-                            .background(Color(0x88888888)),
+                            .fillMaxSize(),
                         imgOffset = offset,
                         imgScale = scale
                     )

+ 3 - 0
app/src/main/java/com/ys/imageProcess/viewModel/WorkViewModel.kt

@@ -223,6 +223,9 @@ class WorkViewModel : ViewModel() {
     }
 
     fun onDrag(position: Offset) {
+
+//        Log.i(TAG, "drag $position")
+
         if (dragStartPos == null) {
             dragStartPos = position
         }