From e0993404a6d513e6b8f55488d0482dff123703a8 Mon Sep 17 00:00:00 2001 From: LeeWyatt Date: Fri, 15 Sep 2023 19:24:23 +0900 Subject: [PATCH] Fix FlipView blur bug --- .../components/skins/FlipViewSkin.java | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/components/src/main/java/com/dlsc/jfxcentral2/components/skins/FlipViewSkin.java b/components/src/main/java/com/dlsc/jfxcentral2/components/skins/FlipViewSkin.java index c3674122..ba7c0f2c 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/components/skins/FlipViewSkin.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/components/skins/FlipViewSkin.java @@ -7,6 +7,7 @@ import javafx.animation.Timeline; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.value.ChangeListener; import javafx.scene.Node; import javafx.scene.control.SkinBase; import javafx.scene.effect.PerspectiveTransform; @@ -22,8 +23,6 @@ * Modified on: 2023-04-25 */ public class FlipViewSkin extends SkinBase { - - private static final Double PIE = Math.PI; private static final Double HALF_PIE = Math.PI / 2; private final SimpleDoubleProperty angle = new SimpleDoubleProperty(HALF_PIE); @@ -43,10 +42,12 @@ public FlipViewSkin(FlipView control) { super(control); this.control = control; - angle.addListener((ob, ov, nv) -> recalculateTransformation(nv.doubleValue())); + ChangeListener numberChangeListener = (ob, ov, nv) -> recalculateTransformation(angle.doubleValue()); + flipPane.getStyleClass().add("content-pane"); - flipPane.widthProperty().addListener((ob, ov, nv) -> recalculateTransformation(angle.doubleValue())); - flipPane.heightProperty().addListener((ob, ov, nv) -> recalculateTransformation(angle.doubleValue())); + angle.addListener(numberChangeListener); + flipPane.widthProperty().addListener(numberChangeListener); + flipPane.heightProperty().addListener(numberChangeListener); getChildren().add(flipPane); control.frontNodeSupplierProperty().addListener((ob, ov, nv) -> { @@ -73,10 +74,10 @@ public FlipViewSkin(FlipView control) { control.animateOnFlipProperty().addListener((ob, ov, nv) -> { if (frontNode != null) { - frontNode.setEffect(nv ? transform : null); + frontNode.setEffect(null); } if (backNode != null) { - backNode.setEffect(nv ? transform : null); + backNode.setEffect(null); } if (!nv && flipAnimation != null && flipAnimation.getStatus() == Timeline.Status.RUNNING) { flipAnimation.jumpTo(flipAnimation.getTotalDuration()); @@ -120,23 +121,39 @@ private void recalculateTransformation(double angle) { private Timeline createAnimation() { Duration flipTime = control.getFlipTime(); return new Timeline( - new KeyFrame(Duration.millis(0), new KeyValue(angle, HALF_PIE)), - new KeyFrame(flipTime.divide(2), new KeyValue(angle, 0, Interpolator.EASE_IN)), - new KeyFrame(flipTime.divide(2), evt -> flippedProperty.set(flippedProperty.not().get())), - new KeyFrame(flipTime.divide(2), new KeyValue(angle, PIE)), - new KeyFrame(flipTime, new KeyValue(angle, HALF_PIE, Interpolator.EASE_OUT)) + new KeyFrame(Duration.millis(0), + event -> { + frontNode.setEffect(transform); + backNode.setEffect(transform); + }, + new KeyValue(angle, HALF_PIE) + ), + new KeyFrame(flipTime.divide(2), + evt -> flippedProperty.set(!flippedProperty.get()), + new KeyValue(angle, 0d, Interpolator.EASE_IN) + ), + new KeyFrame(flipTime.divide(2).add(Duration.millis(1)), + new KeyValue(angle, Math.PI, Interpolator.EASE_OUT) + ), + new KeyFrame(flipTime, + event -> { + frontNode.setEffect(null); + backNode.setEffect(null); + }, + new KeyValue(angle, HALF_PIE, Interpolator.EASE_OUT) + ) ); + } private void initBackNode() { - if (control.getBackNodeSupplier() == null ) { + if (control.getBackNodeSupplier() == null) { return; } if (backNode == null || isBackNodeSupplierChanged) { backNode = control.getBackNodeSupplier().get(); backNode.getStyleClass().add("back-node"); backNode.visibleProperty().bind(flippedProperty.not()); - backNode.setEffect(control.getAnimateOnFlip() ? transform : null); isBackNodeSupplierChanged = false; } } @@ -149,7 +166,6 @@ private void initFrontNode() { frontNode = control.getFrontNodeSupplier().get(); frontNode.getStyleClass().add("front-node"); frontNode.visibleProperty().bind(flippedProperty); - frontNode.setEffect(control.getAnimateOnFlip() ? transform : null); isFrontNodeSupplierChanged = false; } } @@ -179,7 +195,7 @@ private void flip(boolean isToBack) { flipAnimation = createAnimation(); } flipAnimation.setRate(isToBack ? 1 : -1); - flipAnimation.play(); + flipAnimation.playFromStart(); } else { flippedProperty.set(!isToBack); }