Skip to content

Commit

Permalink
ImageDisplay: add an option to flip image in X or Z axis #35
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsacha committed Aug 9, 2024
1 parent 254309a commit 479dd7e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand All @@ -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()

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 479dd7e

Please sign in to comment.