@@ -152,41 +152,37 @@ class Viewport
152
152
boundY = Bindings.`when`(by.greaterThan(maxY.subtract(zoomedHeight))).then(maxY.subtract(zoomedHeight)).otherwise(boundY)
153
153
}
154
154
155
-
// fun bindToFit(xMargin: Double, yMargin: Double, vararg entities: Entity) {
156
-
// val minBindingX = entities.filter { it.hasComponent(BoundingBoxComponent::class.java) }
157
-
// .map { it.getComponent(BoundingBoxComponent::class.java) }
158
-
// .map { it.minXWorldProperty() }
159
-
// .fold(Bindings.min(SimpleIntegerProperty(Int.MAX_VALUE), Integer.MAX_VALUE), { min, x -> Bindings.min(min, x) })
160
-
// .subtract(xMargin)
161
-
//
162
-
// val minBindingY = entities.filter { it.hasComponent(BoundingBoxComponent::class.java) }
163
-
// .map { it.getComponent(BoundingBoxComponent::class.java) }
164
-
// .map { it.minYWorldProperty() }
165
-
// .fold(Bindings.min(SimpleIntegerProperty(Int.MAX_VALUE), Integer.MAX_VALUE), { min, y -> Bindings.min(min, y) })
166
-
// .subtract(yMargin)
167
-
//
168
-
// val maxBindingX = entities.filter { it.hasComponent(BoundingBoxComponent::class.java) }
169
-
// .map { it.getComponent(BoundingBoxComponent::class.java) }
170
-
// .map { it.maxXWorldProperty() }
171
-
// .fold(Bindings.max(SimpleIntegerProperty(Int.MIN_VALUE), Integer.MIN_VALUE), { max, x -> Bindings.max(max, x) })
172
-
// .add(xMargin)
173
-
//
174
-
// val maxBindingY = entities.filter { it.hasComponent(BoundingBoxComponent::class.java) }
175
-
// .map { it.getComponent(BoundingBoxComponent::class.java) }
176
-
// .map { it.maxYWorldProperty() }
177
-
// .fold(Bindings.max(SimpleIntegerProperty(Int.MIN_VALUE), Integer.MIN_VALUE), { max, y -> Bindings.max(max, y) })
178
-
// .add(yMargin)
179
-
//
180
-
// val widthBinding = maxBindingX.subtract(minBindingX)
181
-
// val heightBinding = maxBindingY.subtract(minBindingY)
182
-
//
183
-
// val ratio = Bindings.min(Bindings.divide(width, widthBinding), Bindings.divide(height, heightBinding))
184
-
//
185
-
// x.bind(minBindingX)
186
-
// y.bind(minBindingY)
187
-
//
188
-
// zoom.bind(ratio)
189
-
// }
155
+
@JvmOverloads fun bindToFit(xMargin: Double = 0.0, yMargin: Double = 0.0, vararg entities: Entity) {
156
+
val minBindingX = entities
157
+
.map { it.boundingBoxComponent.minXWorldProperty() }
158
+
.fold(Bindings.min(SimpleIntegerProperty(Int.MAX_VALUE), Integer.MAX_VALUE)) { min, x -> Bindings.min(min, x) }
159
+
.subtract(xMargin)
160
+
161
+
val minBindingY = entities
162
+
.map { it.boundingBoxComponent.minYWorldProperty() }
163
+
.fold(Bindings.min(SimpleIntegerProperty(Int.MAX_VALUE), Integer.MAX_VALUE)) { min, y -> Bindings.min(min, y) }
164
+
.subtract(yMargin)
165
+
166
+
val maxBindingX = entities
167
+
.map { it.boundingBoxComponent.maxXWorldProperty() }
168
+
.fold(Bindings.max(SimpleIntegerProperty(Int.MIN_VALUE), Integer.MIN_VALUE)) { max, x -> Bindings.max(max, x) }
169
+
.add(xMargin)
170
+
171
+
val maxBindingY = entities
172
+
.map { it.boundingBoxComponent.maxYWorldProperty() }
173
+
.fold(Bindings.max(SimpleIntegerProperty(Int.MIN_VALUE), Integer.MIN_VALUE)) { max, y -> Bindings.max(max, y) }
174
+
.add(yMargin)
175
+
176
+
val widthBinding = maxBindingX.subtract(minBindingX)
177
+
val heightBinding = maxBindingY.subtract(minBindingY)
178
+
179
+
val ratio = Bindings.min(Bindings.divide(width, widthBinding), Bindings.divide(height, heightBinding))
180
+
181
+
boundX = minBindingX
182
+
boundY = minBindingY
183
+
184
+
zoom.bind(ratio)
185
+
}
190
186
191
187
/**
192
188
* Unbind viewport.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4