diff --git a/scalafx-extras-demos/src/main/scala/org/scalafx/extras/image/ImageDisplayDemoApp.scala b/scalafx-extras-demos/src/main/scala/org/scalafx/extras/image/ImageDisplayDemoApp.scala index 3f6f7f1..4fdf026 100644 --- a/scalafx-extras-demos/src/main/scala/org/scalafx/extras/image/ImageDisplayDemoApp.scala +++ b/scalafx-extras-demos/src/main/scala/org/scalafx/extras/image/ImageDisplayDemoApp.scala @@ -72,9 +72,14 @@ object ImageDisplayDemoApp extends JFXApp3 { new ToggleButton("Zoom to fit") { selected <==> imageDisplay.zoomToFit }, + new ToggleButton("Flip X") { + selected <==> imageDisplay.flipX + }, + new ToggleButton("Flip Y") { + selected <==> imageDisplay.flipY + }, new ChoiceBox(rotationItems) { selectionModel().selectedItem.onChange { (_, _, newValue) => - println(s"$newValue chosen in ChoiceBox") imageDisplay.rotation = newValue } selectionModel().selectFirst() diff --git a/scalafx-extras/src/main/scala/org/scalafx/extras/image/ImageDisplay.scala b/scalafx-extras/src/main/scala/org/scalafx/extras/image/ImageDisplay.scala index b274501..69737f3 100644 --- a/scalafx-extras/src/main/scala/org/scalafx/extras/image/ImageDisplay.scala +++ b/scalafx-extras/src/main/scala/org/scalafx/extras/image/ImageDisplay.scala @@ -140,6 +140,12 @@ class ImageDisplay() { */ val view: Node = scrollPane + /** Flip image on X axis, this is done before applying rotation */ + val flipX: BooleanProperty = BooleanProperty(value = false) + + /** Flip image on Y axis, this is done before applying rotation */ + val flipY: BooleanProperty = BooleanProperty(value = false) + /** * Property containing image to be displayed. If `null` the display will be blank (following JavaFX convention) */ @@ -148,7 +154,9 @@ class ImageDisplay() { initialize() /** - * Image rotation in degrees. Default value is 0 (no rotation). + * Image rotation in degrees. + * The default value is 0 (no rotation). + * This is done after applying flip operations. */ def rotation: Double = imageView.rotate() @@ -198,6 +206,16 @@ class ImageDisplay() { } } + flipX.onChange { (_, _, newValue) => + val v = math.abs(imageView.scaleX.value) + imageView.scaleX.value = if (newValue) -v else v + } + + flipY.onChange { (_, _, newValue) => + val v = math.abs(imageView.scaleY.value) + imageView.scaleY.value = if (newValue) -v else v + } + updateFit() // Update fit when zoom or control size changes