Add fullscreen toggle (F11) with aspect-preserving 16:9 video scaling
Windowed mode still stretches the anamorphic frame to fill 480x272 like the PSP. In fullscreen the video scales to fit the screen while keeping its 16:9 display ratio, letterboxing as needed.
This commit is contained in:
@@ -43,6 +43,7 @@ public final class PlayerApp extends Application {
|
|||||||
private RcoRenderer renderer;
|
private RcoRenderer renderer;
|
||||||
private volatile Controller controller;
|
private volatile Controller controller;
|
||||||
private volatile MoviePlayer moviePlayer;
|
private volatile MoviePlayer moviePlayer;
|
||||||
|
private Stage stage;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) {
|
public void start(Stage stage) {
|
||||||
@@ -51,17 +52,30 @@ public final class PlayerApp extends Application {
|
|||||||
? null
|
? null
|
||||||
: String.join(" ", getParameters().getRaw());
|
: String.join(" ", getParameters().getRaw());
|
||||||
|
|
||||||
menuCanvas = new Canvas(WIDTH, HEIGHT);
|
this.stage = stage;
|
||||||
videoCanvas = new Canvas(WIDTH, HEIGHT);
|
|
||||||
|
menuCanvas = new Canvas();
|
||||||
|
videoCanvas = new Canvas();
|
||||||
|
|
||||||
StackPane root = new StackPane(videoCanvas, menuCanvas);
|
StackPane root = new StackPane(videoCanvas, menuCanvas);
|
||||||
|
menuCanvas.widthProperty().bind(root.widthProperty());
|
||||||
|
menuCanvas.heightProperty().bind(root.heightProperty());
|
||||||
|
videoCanvas.widthProperty().bind(root.widthProperty());
|
||||||
|
videoCanvas.heightProperty().bind(root.heightProperty());
|
||||||
|
|
||||||
Scene scene = new Scene(root, WIDTH, HEIGHT);
|
Scene scene = new Scene(root, WIDTH, HEIGHT);
|
||||||
scene.setFill(Color.BLACK);
|
scene.setFill(Color.BLACK);
|
||||||
stage.setTitle("useless-umd-player");
|
stage.setTitle("useless-umd-player");
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
stage.show();
|
stage.show();
|
||||||
|
|
||||||
scene.setOnKeyPressed(event -> handleKey(event.getCode()));
|
scene.setOnKeyPressed(event -> {
|
||||||
|
if (event.getCode() == KeyCode.F11) {
|
||||||
|
stage.setFullScreen(!stage.isFullScreen());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handleKey(event.getCode());
|
||||||
|
});
|
||||||
|
|
||||||
if (isoPath != null) {
|
if (isoPath != null) {
|
||||||
String path = isoPath;
|
String path = isoPath;
|
||||||
@@ -198,8 +212,26 @@ public final class PlayerApp extends Application {
|
|||||||
g.setFill(Color.BLACK);
|
g.setFill(Color.BLACK);
|
||||||
g.fillRect(0, 0, canvasWidth, canvasHeight);
|
g.fillRect(0, 0, canvasWidth, canvasHeight);
|
||||||
|
|
||||||
|
if (stage.isFullScreen()) {
|
||||||
|
// Scale up to fill the screen but keep the 16:9 display ratio.
|
||||||
|
double aspect = 16.0 / 9.0;
|
||||||
|
double canvasAspect = canvasWidth / canvasHeight;
|
||||||
|
double drawW;
|
||||||
|
double drawH;
|
||||||
|
if (canvasAspect > aspect) {
|
||||||
|
drawH = canvasHeight;
|
||||||
|
drawW = canvasHeight * aspect;
|
||||||
|
} else {
|
||||||
|
drawW = canvasWidth;
|
||||||
|
drawH = canvasWidth / aspect;
|
||||||
|
}
|
||||||
|
double x = (canvasWidth - drawW) / 2.0;
|
||||||
|
double y = (canvasHeight - drawH) / 2.0;
|
||||||
|
g.drawImage(image, x, y, drawW, drawH);
|
||||||
|
} else {
|
||||||
// The PSP stretches the anamorphic 720x480 frame to fill 480x272.
|
// The PSP stretches the anamorphic 720x480 frame to fill 480x272.
|
||||||
g.drawImage(image, 0, 0, canvasWidth, canvasHeight);
|
g.drawImage(image, 0, 0, canvasWidth, canvasHeight);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user