From a796fbf5046ea91b841abec17b88b67947d0bffc Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Thu, 4 May 2023 13:14:10 +0200 Subject: [PATCH] Positionning on the screen Signed-off-by: Anthony Debucquoy --- app/src/main/java/school_project/GameUI.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/school_project/GameUI.java b/app/src/main/java/school_project/GameUI.java index b5e0b76..84cd28a 100644 --- a/app/src/main/java/school_project/GameUI.java +++ b/app/src/main/java/school_project/GameUI.java @@ -2,26 +2,27 @@ package school_project; import javafx.geometry.Insets; import javafx.geometry.Pos; +import javafx.scene.Group; import javafx.scene.input.MouseButton; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.paint.Color; +import javafx.stage.Screen; import school_project.Utils.MatrixShape; import java.io.FileNotFoundException; -public class GameUI extends BorderPane { +public class GameUI extends Group{ public final static int SEGMENT_SIZE = 50; public final static int SPACE_SIZE = 5; public GameUI(Map level) throws FileNotFoundException { super(); MatrixShape grid = new MatrixShape(level); - grid.setAlignment(Pos.CENTER); - grid.setColor(Color.WHITE); + grid.setLayoutX(Screen.getPrimary().getBounds().getWidth()/2 - grid.boundary_size.x/2); + grid.setLayoutY(Screen.getPrimary().getBounds().getHeight()/2 - grid.boundary_size.y/2); - HBox pieces = new HBox(); - pieces.setSpacing(10); + Group pieces = new Group(); for (Piece p : level.getPieces()) { MatrixShape _piece = new MatrixShape(p); _piece.setOnMouseClicked(event -> { @@ -30,10 +31,13 @@ public class GameUI extends BorderPane { _piece.update(); } }); + _piece.setOnMouseDragged(event -> { + _piece.setLayoutX(event.getSceneX()); + _piece.setLayoutY(event.getSceneY()); + }); pieces.getChildren().add(_piece); } - setCenter(grid); - setBottom(pieces); + getChildren().addAll(grid, pieces); } }