Skip to content

Commit 479dd7e

Browse files
committed
ImageDisplay: add an option to flip image in X or Z axis #35
1 parent 254309a commit 479dd7e

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

scalafx-extras-demos/src/main/scala/org/scalafx/extras/image/ImageDisplayDemoApp.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,14 @@ object ImageDisplayDemoApp extends JFXApp3 {
7272
new ToggleButton("Zoom to fit") {
7373
selected <==> imageDisplay.zoomToFit
7474
},
75+
new ToggleButton("Flip X") {
76+
selected <==> imageDisplay.flipX
77+
},
78+
new ToggleButton("Flip Y") {
79+
selected <==> imageDisplay.flipY
80+
},
7581
new ChoiceBox(rotationItems) {
7682
selectionModel().selectedItem.onChange { (_, _, newValue) =>
77-
println(s"$newValue chosen in ChoiceBox")
7883
imageDisplay.rotation = newValue
7984
}
8085
selectionModel().selectFirst()

scalafx-extras/src/main/scala/org/scalafx/extras/image/ImageDisplay.scala

+19-1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ class ImageDisplay() {
140140
*/
141141
val view: Node = scrollPane
142142

143+
/** Flip image on X axis, this is done before applying rotation */
144+
val flipX: BooleanProperty = BooleanProperty(value = false)
145+
146+
/** Flip image on Y axis, this is done before applying rotation */
147+
val flipY: BooleanProperty = BooleanProperty(value = false)
148+
143149
/**
144150
* Property containing image to be displayed. If `null` the display will be blank (following JavaFX convention)
145151
*/
@@ -148,7 +154,9 @@ class ImageDisplay() {
148154
initialize()
149155

150156
/**
151-
* Image rotation in degrees. Default value is 0 (no rotation).
157+
* Image rotation in degrees.
158+
* The default value is 0 (no rotation).
159+
* This is done after applying flip operations.
152160
*/
153161
def rotation: Double = imageView.rotate()
154162

@@ -198,6 +206,16 @@ class ImageDisplay() {
198206
}
199207
}
200208

209+
flipX.onChange { (_, _, newValue) =>
210+
val v = math.abs(imageView.scaleX.value)
211+
imageView.scaleX.value = if (newValue) -v else v
212+
}
213+
214+
flipY.onChange { (_, _, newValue) =>
215+
val v = math.abs(imageView.scaleY.value)
216+
imageView.scaleY.value = if (newValue) -v else v
217+
}
218+
201219
updateFit()
202220

203221
// Update fit when zoom or control size changes

0 commit comments

Comments
 (0)