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:
2026-09-15 23:26:22 -04:00
parent d749d6753e
commit 67b3c4a8cd
@@ -43,6 +43,7 @@ public final class PlayerApp extends Application {
private RcoRenderer renderer;
private volatile Controller controller;
private volatile MoviePlayer moviePlayer;
private Stage stage;
@Override
public void start(Stage stage) {
@@ -51,17 +52,30 @@ public final class PlayerApp extends Application {
? null
: String.join(" ", getParameters().getRaw());
menuCanvas = new Canvas(WIDTH, HEIGHT);
videoCanvas = new Canvas(WIDTH, HEIGHT);
this.stage = stage;
menuCanvas = new Canvas();
videoCanvas = new Canvas();
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.setFill(Color.BLACK);
stage.setTitle("useless-umd-player");
stage.setScene(scene);
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) {
String path = isoPath;
@@ -198,8 +212,26 @@ public final class PlayerApp extends Application {
g.setFill(Color.BLACK);
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.
g.drawImage(image, 0, 0, canvasWidth, canvasHeight);
}
});
}