aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2024-09-06 21:44:49 -0400
committersowgro <tpoke.ferrari@gmail.com>2024-09-06 21:44:49 -0400
commitf242db8ae77188951e261e0d4b3ce84304663a31 (patch)
tree1299bcce44f99fc1e0a9034b3792717d02913a32 /src
parenta645b476202bd5b44ab5c22253a70269409b5674 (diff)
downloadNPEhero-f242db8ae77188951e261e0d4b3ce84304663a31.tar.gz
NPEhero-f242db8ae77188951e261e0d4b3ce84304663a31.tar.bz2
NPEhero-f242db8ae77188951e261e0d4b3ce84304663a31.zip
Properly scale game window based on screen height
Diffstat (limited to 'src')
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/LevelSurround.java35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/main/java/net/sowgro/npehero/gui/LevelSurround.java b/src/main/java/net/sowgro/npehero/gui/LevelSurround.java
index 4b11c15..56bb560 100755
--- a/src/main/java/net/sowgro/npehero/gui/LevelSurround.java
+++ b/src/main/java/net/sowgro/npehero/gui/LevelSurround.java
@@ -1,16 +1,12 @@
package net.sowgro.npehero.gui;
import javafx.animation.AnimationTimer;
+import javafx.scene.layout.*;
import net.sowgro.npehero.Driver;
import net.sowgro.npehero.gameplay.SongPlayer;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
-import javafx.scene.layout.AnchorPane;
-import javafx.scene.layout.HBox;
-import javafx.scene.layout.Pane;
-import javafx.scene.layout.StackPane;
-import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import net.sowgro.npehero.levelapi.Difficulty;
import net.sowgro.npehero.gameplay.ScoreController;
@@ -19,7 +15,7 @@ import net.sowgro.npehero.main.Sound;
public class LevelSurround extends Page
{
- private final HBox content = new HBox();
+ private final StackPane content = new StackPane();
public LevelSurround(Difficulty difficulty, Page prev)
{
@@ -104,22 +100,31 @@ public class LevelSurround extends Page
AnchorPane.setBottomAnchor(comboTextBox, 0.0);
comboBox.setPadding(new Insets(10));
- game.minWidthProperty().bind(content.heightProperty().multiply(0.55));
- game.minHeightProperty().bind(content.heightProperty());
+ game.setMinHeight(1080);
+ game.setMinWidth(1080 * 0.55);
+ game.setMaxHeight(1080);
+ game.setMaxWidth(1080 * 0.55);
+ var scale = content.prefHeightProperty().divide(1080);
+ game.scaleXProperty().bind(scale);
+ game.scaleYProperty().bind(scale);
game.getStyleClass().add("box");
+ BorderPane gameHolder = new BorderPane(game);
+ gameHolder.maxHeightProperty().bind(content.prefHeightProperty());
+ gameHolder.maxWidthProperty().bind(content.prefHeightProperty().multiply(0.55));
+ gameHolder.minHeightProperty().bind(content.prefHeightProperty());
+ gameHolder.minWidthProperty().bind(content.prefHeightProperty().multiply(0.55));
- comboBox.minWidthProperty().bind(Driver.primaryPane.widthProperty().subtract(game.widthProperty()).divide(2));
- scoreBox.minWidthProperty().bind(Driver.primaryPane.widthProperty().subtract(game.widthProperty()).divide(2));
+ var widthBind = content.widthProperty().subtract(gameHolder.widthProperty()).divide(2);
+ scoreBox.prefWidthProperty().bind(widthBind);
+ scoreBox.prefWidthProperty().bind(widthBind);
HBox centerBox = new HBox();
- centerBox.getChildren().addAll(comboBox, game, scoreBox);
+ HBox.setHgrow(gameHolder, Priority.NEVER);
+ centerBox.getChildren().addAll(comboBox, gameHolder, scoreBox);
centerBox.setAlignment(Pos.BOTTOM_CENTER);
- StackPane root = new StackPane();
- root.getChildren().addAll(centerBox, topBar);
-
- content.getChildren().add(root);
+ content.getChildren().addAll(centerBox, topBar);
new AnimationTimer() {
@Override