Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.animation.PauseTransition;
import javafx.beans.InvalidationListener;
import javafx.beans.WeakInvalidationListener;
import javafx.beans.property.DoubleProperty;
Expand Down Expand Up @@ -239,28 +240,41 @@ public static void initialize(Stage stage) {

Controllers.stage = stage;

final Duration DEBOUNCE_DELAY = Duration.millis(600);
final PauseTransition debounceX = new PauseTransition(DEBOUNCE_DELAY);
final PauseTransition debounceY = new PauseTransition(DEBOUNCE_DELAY);
final PauseTransition debounceWidth = new PauseTransition(DEBOUNCE_DELAY);
final PauseTransition debounceHeight = new PauseTransition(DEBOUNCE_DELAY);

stageSizeChangeListener = o -> {
ReadOnlyDoubleProperty sourceProperty = (ReadOnlyDoubleProperty) o;
DoubleProperty targetProperty;
PauseTransition debounce;

switch (sourceProperty.getName()) {
case "x": {
targetProperty = stageX;
debounce = debounceX;
break;
}
case "y": {
targetProperty = stageY;
debounce = debounceY;
break;
}
case "width": {
targetProperty = stageWidth;
debounce = debounceWidth;
break;
}
case "height": {
targetProperty = stageHeight;
debounce = debounceHeight;
break;
}
default: {
targetProperty = null;
debounce = null;
}
}

Expand All @@ -272,6 +286,33 @@ public static void initialize(Stage stage) {
!Controllers.stage.isFullScreen() && !Controllers.stage.isMaximized())
) {
targetProperty.set(sourceProperty.get());

final String name = sourceProperty.getName();
final double value = sourceProperty.get();

if (debounce != null) {
debounce.setOnFinished(event -> {
switch (name) {
case "x": {
config().setX(value / SCREEN.getBounds().getWidth());
break;
}
case "y": {
config().setY(value / SCREEN.getBounds().getHeight());
break;
}
case "width": {
config().setWidth(value);
break;
}
case "height": {
config().setHeight(value);
break;
}
}
});
debounce.playFromStart();
}
}
};

Expand Down