Skip to content

Commit

Permalink
[bgw-gui] Fixed observable bug with camera pane zoom property and wid…
Browse files Browse the repository at this point in the history
…th and hei… (#392)

* Fixed observable bug with camera pane zoom property and width and height.
  • Loading branch information
abouzerda authored Aug 17, 2023
1 parent fc53c95 commit e8deb9b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ object CameraPaneBuilder {
val node =
ZoomableScrollPane(
(NodeBuilder.build(scene, container.target) as Pane).apply {
minWidth = container.target.width
minHeight = container.target.height
container.target.widthProperty.addListenerAndInvoke(container.target.width) { _, nV ->
minWidth = nV
}
container.target.heightProperty.addListenerAndInvoke(container.target.height) { _, nV
->
minHeight = nV
}
},
container)

Expand Down Expand Up @@ -109,8 +114,8 @@ object CameraPaneBuilder {
}

return node.apply {
minWidth = container.width
minHeight = container.height
container.widthProperty.addListenerAndInvoke(container.width) { _, nV -> minWidth = nV }
container.heightProperty.addListenerAndInvoke(container.height) { _, nV -> minHeight = nV }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ internal class ZoomableScrollPane(
field = value.coerceIn(0.01, 10.0)
target.scaleX = scaleValue
target.scaleY = scaleValue
cameraPane.zoomProperty.setSilent(scaleValue)
}

private val zoomIntensity = 0.02
private val zoomNode: Node
private var timeline: Timeline? = null
Expand All @@ -82,12 +84,12 @@ internal class ZoomableScrollPane(
// isFitToWidth = true //center
hvalueProperty().addListener { _, _, nV ->
if (hPanLocked && nV != hValueLocked) hvalue = hValueLocked
val viewWidth = cameraPane.width / scaleValue
val viewWidth = cameraPane.width / cameraPane.zoom
anchorPoint = Point2D(hvalue * (cameraPane.target.width - viewWidth), anchorPoint.y)
}
vvalueProperty().addListener { _, _, nV ->
if (vPanLocked && nV != vValueLocked) vvalue = vValueLocked
val viewHeight = cameraPane.height / scaleValue
val viewHeight = cameraPane.height / cameraPane.zoom
anchorPoint = Point2D(anchorPoint.x, vvalue * (cameraPane.target.height - viewHeight))
}
}
Expand All @@ -105,17 +107,17 @@ internal class ZoomableScrollPane(
fun scrollTo(point: Point2D) {
if (inTargetBounds(point)) {
anchorPoint = point
val viewWidth = cameraPane.width / scaleValue
val viewHeight = cameraPane.height / scaleValue
val viewWidth = cameraPane.width / cameraPane.zoom
val viewHeight = cameraPane.height / cameraPane.zoom
hvalue = point.x / (cameraPane.target.width - viewWidth)
vvalue = point.y / (cameraPane.target.height - viewHeight)
}
}

fun smoothScrollTo(point: Point2D) {
if (inTargetBounds(point)) {
val viewWidth = cameraPane.width / scaleValue
val viewHeight = cameraPane.height / scaleValue
val viewWidth = cameraPane.width / cameraPane.zoom
val viewHeight = cameraPane.height / cameraPane.zoom
val newHValue = point.x / (cameraPane.target.width - viewWidth)
val newVValue = point.y / (cameraPane.target.height - viewHeight)
val clampedHValue = newHValue.coerceIn(0.0, 1.0)
Expand Down

0 comments on commit e8deb9b

Please sign in to comment.