支持最大化和全屏模式 (#4260)
This commit is contained in:
@@ -216,7 +216,9 @@ public final class Controllers {
|
|||||||
|
|
||||||
if (targetProperty != null
|
if (targetProperty != null
|
||||||
&& Controllers.stage != null
|
&& Controllers.stage != null
|
||||||
&& !Controllers.stage.isIconified()) {
|
&& !Controllers.stage.isIconified()
|
||||||
|
&& !Controllers.stage.isFullScreen()
|
||||||
|
&& !Controllers.stage.isMaximized()) {
|
||||||
targetProperty.set(sourceProperty.get());
|
targetProperty.set(sourceProperty.get());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,10 +34,7 @@ import javafx.scene.image.Image;
|
|||||||
import javafx.scene.image.PixelReader;
|
import javafx.scene.image.PixelReader;
|
||||||
import javafx.scene.image.PixelWriter;
|
import javafx.scene.image.PixelWriter;
|
||||||
import javafx.scene.image.WritableImage;
|
import javafx.scene.image.WritableImage;
|
||||||
import javafx.scene.input.DragEvent;
|
import javafx.scene.input.*;
|
||||||
import javafx.scene.input.KeyEvent;
|
|
||||||
import javafx.scene.input.MouseButton;
|
|
||||||
import javafx.scene.input.MouseEvent;
|
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.paint.Paint;
|
import javafx.scene.paint.Paint;
|
||||||
@@ -167,6 +164,14 @@ public class DecoratorController {
|
|||||||
// press ESC to go back
|
// press ESC to go back
|
||||||
onEscPressed(navigator, this::back);
|
onEscPressed(navigator, this::back);
|
||||||
|
|
||||||
|
// press F11 to toggle full screen
|
||||||
|
navigator.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
|
||||||
|
if (e.getCode() == KeyCode.F11) {
|
||||||
|
stage.setFullScreen(!stage.isFullScreen());
|
||||||
|
e.consume();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// For JavaFX 12+
|
// For JavaFX 12+
|
||||||
MouseButton button = MouseButton.valueOf("BACK");
|
MouseButton button = MouseButton.valueOf("BACK");
|
||||||
|
|||||||
@@ -18,8 +18,11 @@
|
|||||||
package org.jackhuang.hmcl.ui.decorator;
|
package org.jackhuang.hmcl.ui.decorator;
|
||||||
|
|
||||||
import com.jfoenix.controls.JFXButton;
|
import com.jfoenix.controls.JFXButton;
|
||||||
|
import javafx.beans.InvalidationListener;
|
||||||
|
import javafx.beans.WeakInvalidationListener;
|
||||||
import javafx.beans.binding.Bindings;
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
import javafx.geometry.Bounds;
|
import javafx.geometry.Bounds;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
@@ -29,6 +32,7 @@ import javafx.scene.control.Label;
|
|||||||
import javafx.scene.control.SkinBase;
|
import javafx.scene.control.SkinBase;
|
||||||
import javafx.scene.effect.BlurType;
|
import javafx.scene.effect.BlurType;
|
||||||
import javafx.scene.effect.DropShadow;
|
import javafx.scene.effect.DropShadow;
|
||||||
|
import javafx.scene.input.MouseButton;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
@@ -50,6 +54,8 @@ public class DecoratorSkin extends SkinBase<Decorator> {
|
|||||||
private final Stage primaryStage;
|
private final Stage primaryStage;
|
||||||
private final TransitionPane navBarPane;
|
private final TransitionPane navBarPane;
|
||||||
|
|
||||||
|
private final InvalidationListener onWindowsStatusChange;
|
||||||
|
|
||||||
private double mouseInitX, mouseInitY, stageInitX, stageInitY, stageInitWidth, stageInitHeight;
|
private double mouseInitX, mouseInitY, stageInitX, stageInitY, stageInitWidth, stageInitHeight;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,9 +86,25 @@ public class DecoratorSkin extends SkinBase<Decorator> {
|
|||||||
|
|
||||||
skinnable.getSnackbar().registerSnackbarContainer(parent);
|
skinnable.getSnackbar().registerSnackbarContainer(parent);
|
||||||
|
|
||||||
root.addEventFilter(MouseEvent.MOUSE_RELEASED, this::onMouseReleased);
|
EventHandler<MouseEvent> onMouseReleased = this::onMouseReleased;
|
||||||
root.addEventFilter(MouseEvent.MOUSE_DRAGGED, this::onMouseDragged);
|
EventHandler<MouseEvent> onMouseDragged = this::onMouseDragged;
|
||||||
root.addEventFilter(MouseEvent.MOUSE_MOVED, this::onMouseMoved);
|
EventHandler<MouseEvent> onMouseMoved = this::onMouseMoved;
|
||||||
|
onWindowsStatusChange = observable -> {
|
||||||
|
if (primaryStage.isIconified() || primaryStage.isFullScreen() || primaryStage.isMaximized()) {
|
||||||
|
root.removeEventFilter(MouseEvent.MOUSE_RELEASED, onMouseReleased);
|
||||||
|
root.removeEventFilter(MouseEvent.MOUSE_DRAGGED, onMouseDragged);
|
||||||
|
root.removeEventFilter(MouseEvent.MOUSE_MOVED, onMouseMoved);
|
||||||
|
} else {
|
||||||
|
root.addEventFilter(MouseEvent.MOUSE_RELEASED, onMouseReleased);
|
||||||
|
root.addEventFilter(MouseEvent.MOUSE_DRAGGED, onMouseDragged);
|
||||||
|
root.addEventFilter(MouseEvent.MOUSE_MOVED, onMouseMoved);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
WeakInvalidationListener weakOnWindowsStatusChange = new WeakInvalidationListener(onWindowsStatusChange);
|
||||||
|
primaryStage.iconifiedProperty().addListener(weakOnWindowsStatusChange);
|
||||||
|
primaryStage.maximizedProperty().addListener(weakOnWindowsStatusChange);
|
||||||
|
primaryStage.fullScreenProperty().addListener(weakOnWindowsStatusChange);
|
||||||
|
onWindowsStatusChange.invalidated(null);
|
||||||
|
|
||||||
shadowContainer.getChildren().setAll(parent);
|
shadowContainer.getChildren().setAll(parent);
|
||||||
root.getChildren().setAll(shadowContainer);
|
root.getChildren().setAll(shadowContainer);
|
||||||
@@ -155,6 +177,12 @@ public class DecoratorSkin extends SkinBase<Decorator> {
|
|||||||
|
|
||||||
BorderPane titleBar = new BorderPane();
|
BorderPane titleBar = new BorderPane();
|
||||||
titleContainer.getChildren().add(titleBar);
|
titleContainer.getChildren().add(titleBar);
|
||||||
|
titleBar.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
|
||||||
|
if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) {
|
||||||
|
primaryStage.setMaximized(!primaryStage.isMaximized());
|
||||||
|
event.consume();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Rectangle buttonsContainerPlaceHolder = new Rectangle();
|
Rectangle buttonsContainerPlaceHolder = new Rectangle();
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user