can draw a box in document

3
Timo Bryant 2024-01-01 13:50:50 +01:00
parent a2483c85d7
commit 8ef054baa4
1 changed files with 20 additions and 19 deletions

View File

@ -2,9 +2,7 @@ package de.itkl.documentViewer
import androidx.compose.desktop.ui.tooling.preview.Preview import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.* import androidx.compose.foundation.*
import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.gestures.transformable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.* import androidx.compose.runtime.*
@ -18,18 +16,18 @@ import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.drawscope.DrawStyle
import androidx.compose.ui.graphics.drawscope.Stroke import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.drawscope.scale
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.painter.BitmapPainter import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.input.pointer.PointerEventType import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.onPointerEvent import androidx.compose.ui.input.pointer.onPointerEvent
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.loadImageBitmap import androidx.compose.ui.res.loadImageBitmap
import androidx.compose.ui.text.drawText import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.WindowPlacement import androidx.compose.ui.window.WindowPlacement
import androidx.compose.ui.window.WindowPosition import androidx.compose.ui.window.WindowPosition
@ -37,8 +35,7 @@ import androidx.compose.ui.window.rememberWindowState
import com.github.panpf.zoomimage.ZoomImage import com.github.panpf.zoomimage.ZoomImage
import com.github.panpf.zoomimage.compose.ZoomState import com.github.panpf.zoomimage.compose.ZoomState
import com.github.panpf.zoomimage.compose.rememberZoomState import com.github.panpf.zoomimage.compose.rememberZoomState
import com.github.panpf.zoomimage.compose.zoom.ScrollBarSpec import com.github.panpf.zoomimage.compose.zoom.*
import com.github.panpf.zoomimage.compose.zoom.ZoomableState
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.pushingpixels.aurora.theming.auroraBackground import org.pushingpixels.aurora.theming.auroraBackground
@ -72,6 +69,7 @@ fun main() = auroraApplication {
} }
} }
@Composable @Composable
@Preview @Preview
fun viewImage() { fun viewImage() {
@ -165,13 +163,17 @@ data class PointConverter(
@Composable @Composable
fun shapes(zoomableState: ZoomableState) { fun shapes(zoomableState: ZoomableState) {
Box(modifier = Modifier.fillMaxSize()) { Box(modifier = Modifier.fillMaxSize()) {
val scale = zoomableState.transform.scaleX
Box( Box(
modifier = Modifier modifier = Modifier
.offset(100.dp) .offset { IntOffset(
.size(100.dp) ((zoomableState.transform.offset.x + (288 * scale)) ).toInt(),
((zoomableState.transform.offset.y + (697 * scale)) ).toInt()
) }
.scale(zoomableState.transform.scaleX)
.clip(RectangleShape) .clip(RectangleShape)
.size(100.dp)
.background(Color.Red) .background(Color.Red)
.onClick(true) { println("clicked") }
) )
} }
} }
@ -180,10 +182,10 @@ fun shapes(zoomableState: ZoomableState) {
fun canvas(zoomableState: ZoomableState) { fun canvas(zoomableState: ZoomableState) {
Canvas(modifier = Modifier Canvas(modifier = Modifier
.fillMaxSize() .fillMaxSize()
.onPointerEvent(PointerEventType.Move) { // .onPointerEvent(PointerEventType.Move) {
val position = it.changes.first().position // val position = it.changes.first().position
println(position) // println(position)
} // }
) )
{ {
val converter = PointConverter( val converter = PointConverter(
@ -210,9 +212,8 @@ fun canvas(zoomableState: ZoomableState) {
// ], // ],
drawRect( drawRect(
Color.Blue, Color.Blue,
// topLeft = Offset(converter.convertX(288), converter.convertY(697)), topLeft = zoomableState.transform.offset + (Offset(288 * zoomableState.transform.scaleX,697 * zoomableState.transform.scaleY)),
topLeft = zoomableState.transform.offset + Offset(800f,800f), size = Size( (793 - 288)* zoomableState.transform.scaleX, (741 - 697) * zoomableState.transform.scaleY),
size = Size(30f, 30f),
style = Stroke(width = 5f) style = Stroke(width = 5f)
) )
} }