Skip to content

Commit b8c8f16

Browse files
update util functions
1 parent edd5095 commit b8c8f16

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,48 @@ private fun getCornerTouchRegion(
7979
}
8080
}
8181

82+
/**
83+
* Returns how far user touched to corner or center of sides of the screen. [TouchRegion]
84+
* where user exactly has touched is already passed to this function. For instance user
85+
* touched top left then this function returns distance to top left from user's position so
86+
* we can add an offset to not jump edge to position user touched.
87+
*/
88+
internal fun getDistanceToEdgeFromTouch(
89+
touchRegion: TouchRegion,
90+
rect: Rect,
91+
touchPosition: Offset
92+
) = when (touchRegion) {
93+
// Corners
94+
TouchRegion.TopLeft -> {
95+
rect.topLeft - touchPosition
96+
}
97+
TouchRegion.TopRight -> {
98+
rect.topRight - touchPosition
99+
}
100+
TouchRegion.BottomLeft -> {
101+
rect.bottomLeft - touchPosition
102+
}
103+
TouchRegion.BottomRight -> {
104+
rect.bottomRight - touchPosition
105+
}
106+
// Sides
107+
TouchRegion.CenterLeft -> {
108+
rect.centerLeft - touchPosition
109+
}
110+
TouchRegion.TopCenter -> {
111+
rect.topCenter - touchPosition
112+
}
113+
TouchRegion.CenterRight -> {
114+
rect.centerRight - touchPosition
115+
}
116+
TouchRegion.BottomCenter -> {
117+
rect.bottomCenter - touchPosition
118+
}
119+
else -> {
120+
Offset.Zero
121+
}
122+
}
123+
82124
private fun getSideTouchRegion(
83125
position: Offset,
84126
rect: Rect,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,3 @@ internal fun GraphicsLayerScope.update(zoomState: ZoomState) {
5454
// Set rotation
5555
this.rotationZ = zoomState.rotation
5656
}
57-

0 commit comments

Comments
 (0)