Skip to content

Commit 864948f

Browse files
change EnhancedZoomData visible section to IntRect to match Bitmap
1 parent 5f4f93d commit 864948f

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

image/src/main/java/com/smarttoolfactory/image/util/RectUtil.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package com.smarttoolfactory.image.util
22

33
import androidx.compose.ui.geometry.Offset
44
import androidx.compose.ui.geometry.Rect
5-
import androidx.compose.ui.geometry.Size
5+
import androidx.compose.ui.unit.IntOffset
6+
import androidx.compose.ui.unit.IntRect
7+
import androidx.compose.ui.unit.IntSize
68

79
/**
810
* Get rectangle of current transformation of [pan], [zoom] and current bounds of the Composable's
@@ -27,20 +29,20 @@ fun getCropRect(
2729
pan: Offset,
2830
zoom: Float,
2931
rectSelection: Rect
30-
): Rect {
32+
): IntRect {
3133
val widthRatio = bitmapWidth / containerWidth
3234
val heightRatio = bitmapHeight / containerHeight
3335

3436
val width = (widthRatio * rectSelection.width / zoom).coerceIn(0f, bitmapWidth.toFloat())
3537
val height = (heightRatio * rectSelection.height / zoom).coerceIn(0f, bitmapHeight.toFloat())
3638

3739
val offsetXInBitmap = (widthRatio * (pan.x + rectSelection.left / zoom))
38-
.coerceIn(0f, bitmapWidth - width)
39-
val offsetYInBitmap = heightRatio * (pan.y + rectSelection.top / zoom)
40-
.coerceIn(0f, bitmapHeight - height)
40+
.coerceIn(0f, bitmapWidth - width).toInt()
41+
val offsetYInBitmap = (heightRatio * (pan.y + rectSelection.top / zoom))
42+
.coerceIn(0f, bitmapHeight - height).toInt()
4143

42-
return Rect(
43-
offset = Offset(offsetXInBitmap, offsetYInBitmap),
44-
size = Size(width, height)
44+
return IntRect(
45+
offset = IntOffset(offsetXInBitmap, offsetYInBitmap),
46+
size = IntSize(width.toInt(), height.toInt())
4547
)
4648
}

image/src/main/java/com/smarttoolfactory/image/zoom/AnimatedZoomModifier.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ fun Modifier.animatedZoom(
7979
mainPointer = mainPointer,
8080
changes = pointerList
8181
)
82+
}
8283

83-
if (gestureEnabled) {
84-
mainPointer.consume()
85-
}
84+
if (gestureEnabled) {
85+
mainPointer.consume()
8686
}
8787
}
8888
)
@@ -189,10 +189,10 @@ fun Modifier.animatedZoom(
189189
mainPointer = mainPointer,
190190
changes = pointerList
191191
)
192+
}
192193

193-
if (gestureEnabled) {
194-
mainPointer.consume()
195-
}
194+
if (gestureEnabled) {
195+
mainPointer.consume()
196196
}
197197
}
198198
)

image/src/main/java/com/smarttoolfactory/image/zoom/EnhancedZoomModifier.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ fun Modifier.enhancedZoom(
412412
}
413413
)
414414

415-
internal val DefaultEnabled = { _: Float, _: Offset, _: Float ->
415+
internal val DefaultEnabled = { zoom: Float, pan: Offset, rotation: Float ->
416416
true
417417
}
418418

image/src/main/java/com/smarttoolfactory/image/zoom/EnhancedZoomStateImpl.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.compose.ui.geometry.Rect
77
import androidx.compose.ui.geometry.Size
88
import androidx.compose.ui.input.pointer.PointerInputChange
99
import androidx.compose.ui.input.pointer.util.VelocityTracker
10+
import androidx.compose.ui.unit.IntRect
1011
import androidx.compose.ui.unit.IntSize
1112
import com.smarttoolfactory.image.util.coerceIn
1213
import com.smarttoolfactory.image.util.getCropRect
@@ -79,7 +80,7 @@ open class EnhancedZoomState constructor(
7980
visibleRegion = calculateRectBounds()
8081
)
8182

82-
private fun calculateRectBounds(): Rect {
83+
private fun calculateRectBounds(): IntRect {
8384

8485
val width = size.width
8586
val height = size.height

image/src/main/java/com/smarttoolfactory/image/zoom/ZoomData.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.smarttoolfactory.image.zoom
33
import androidx.compose.runtime.Immutable
44
import androidx.compose.ui.geometry.Offset
55
import androidx.compose.ui.geometry.Rect
6+
import androidx.compose.ui.unit.IntRect
67

78
/**
89
* class that contains current zoom, pan and rotation information
@@ -24,5 +25,5 @@ data class EnhancedZoomData(
2425
val pan: Offset = Offset.Zero,
2526
val rotation: Float = 0f,
2627
val imageRegion: Rect,
27-
val visibleRegion: Rect
28+
val visibleRegion: IntRect
2829
)

0 commit comments

Comments
 (0)