diff --git a/src/main/java/edu/ntnu/idatt2003/mappevurderingprog2/views/Components/Menu.java b/src/main/java/edu/ntnu/idatt2003/mappevurderingprog2/views/Components/Menu.java index 78a87a01f60442d82bbc770f51aca15f7de7f55f..ee73e6231e1bc9f07542b35c684bf22cce5168d0 100644 --- a/src/main/java/edu/ntnu/idatt2003/mappevurderingprog2/views/Components/Menu.java +++ b/src/main/java/edu/ntnu/idatt2003/mappevurderingprog2/views/Components/Menu.java @@ -15,12 +15,14 @@ public class Menu extends VBox { private ExistingFractalsMenu existingFractalsMenu; private CreateFractalMenu createFractalMenu; private CurrentFractalMenu editFractalMenu; + private ScaleCanvasSize scaleCanvasSize; private Button quitButton; public Menu(View view, GameController gameController) { existingFractalsMenu = new ExistingFractalsMenu(view, gameController); createFractalMenu = new CreateFractalMenu(view, gameController); editFractalMenu = new CurrentFractalMenu(view, gameController); + scaleCanvasSize = new ScaleCanvasSize(view, gameController); quitButton = new Button("Quit application"); initializeMenu(); } @@ -33,11 +35,11 @@ public class Menu extends VBox { "-fx-font-weight: bold;-fx-border-color: black; "); quitButton.setOnAction(e -> Platform.exit()); - VBox.setMargin(menuLabel, new Insets(10, 0, 10, 0)); - VBox.setMargin(existingFractalsMenu, new Insets(40, 0, 10, 0)); - VBox.setMargin(createFractalMenu, new Insets(40, 0, 10, 0)); - VBox.setMargin(editFractalMenu, new Insets(40, 0, 10, 0)); - VBox.setMargin(quitButton, new Insets(40, 0, 40, 0)); + VBox.setMargin(menuLabel, new Insets(7, 0, 7, 0)); + VBox.setMargin(existingFractalsMenu, new Insets(7, 0, 7, 0)); + VBox.setMargin(createFractalMenu, new Insets(7, 0, 7, 0)); + VBox.setMargin(editFractalMenu, new Insets(7, 0, 7, 0)); + VBox.setMargin(quitButton, new Insets(7, 0, 7, 0)); getChildren().addAll( @@ -47,6 +49,7 @@ public class Menu extends VBox { existingFractalsMenu, createFractalMenu, editFractalMenu, + scaleCanvasSize, new Separator(), quitButton, new Separator()); diff --git a/src/main/java/edu/ntnu/idatt2003/mappevurderingprog2/views/Components/ScaleCanvasSize.java b/src/main/java/edu/ntnu/idatt2003/mappevurderingprog2/views/Components/ScaleCanvasSize.java new file mode 100644 index 0000000000000000000000000000000000000000..77fd1911b416349905682b7d1ff4a06d175d1ee2 --- /dev/null +++ b/src/main/java/edu/ntnu/idatt2003/mappevurderingprog2/views/Components/ScaleCanvasSize.java @@ -0,0 +1,71 @@ +package edu.ntnu.idatt2003.mappevurderingprog2.views.Components; + +import edu.ntnu.idatt2003.mappevurderingprog2.controllers.GameController; +import edu.ntnu.idatt2003.mappevurderingprog2.views.View; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; + +public class ScaleCanvasSize extends VBox { + private static final double MIN_WIDTH = 100; + private static final double MIN_HEIGHT = 100; + private static final double MAX_WIDTH = 800; + private static final double MAX_HEIGHT = 700; + private GameController gameController; + + public ScaleCanvasSize(View view, GameController gameController) { + this.gameController = gameController; + Label scaleLabel = new Label("Scale canvas size"); + scaleLabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;"); + + Label heightLabel = new Label("Height"); + heightLabel.setStyle("-fx-font-size: 14px; -fx-font-weight: bold;"); + Button heightIncrease = new Button("+"); + Button heightDecrease = new Button("-"); + HBox heightControls = new HBox(heightDecrease, heightIncrease); + heightControls.setAlignment(Pos.CENTER); + heightControls.setSpacing(10); + + heightIncrease.setOnAction(e -> { + double currentHeight = view.getMainCanvas().getHeight(); + if (currentHeight + 10 <= MAX_HEIGHT) { + view.setCanvasHeight(currentHeight + 10); + } + }); + + heightDecrease.setOnAction(e -> { + double currentHeight = view.getMainCanvas().getHeight(); + if (currentHeight - 10 >= MIN_HEIGHT) { + view.setCanvasHeight(currentHeight - 10); + } + }); + + Label widthLabel = new Label("Width"); + widthLabel.setStyle("-fx-font-size: 14px; -fx-font-weight: bold;"); + Button widthIncrease = new Button("+"); + Button widthDecrease = new Button("-"); + HBox widthControls = new HBox(widthDecrease, widthIncrease); + widthControls.setAlignment(Pos.CENTER); + widthControls.setSpacing(10); + + widthIncrease.setOnAction(e -> { + double currentWidth = view.getMainCanvas().getWidth(); + if (currentWidth + 10 <= MAX_WIDTH) { + view.setCanvasWidth(currentWidth + 10); + } + }); + + widthDecrease.setOnAction(e -> { + double currentWidth = view.getMainCanvas().getWidth(); + if (currentWidth - 10 >= MIN_WIDTH) { + view.setCanvasWidth(currentWidth - 10); + } + }); + + getChildren().addAll(scaleLabel, heightLabel, heightControls, widthLabel, widthControls); + setAlignment(Pos.TOP_CENTER); + setSpacing(10); + } +} diff --git a/src/main/java/edu/ntnu/idatt2003/mappevurderingprog2/views/View.java b/src/main/java/edu/ntnu/idatt2003/mappevurderingprog2/views/View.java index 18fb2460f9a9d089c0e7038a91bdbcfbe8982061..caa3f3b541ec92ae3c5fa57fe2c24552c95a106c 100644 --- a/src/main/java/edu/ntnu/idatt2003/mappevurderingprog2/views/View.java +++ b/src/main/java/edu/ntnu/idatt2003/mappevurderingprog2/views/View.java @@ -45,7 +45,7 @@ public class View extends BorderPane implements ChaosGameObserver { double pixelWidth = canvasWidth / canvasArray[0].length; double pixelHeight = canvasHeight / canvasArray.length; - gc.clearRect(0, 0, canvasWidth, canvasHeight); + gc.clearRect(0, 0, mainCanvas.getWidth(), mainCanvas.getHeight()); for (int i = 0; i < canvasArray.length; i++) { for (int j = 0; j < canvasArray[i].length; j++) { double x = j * pixelWidth + 3; @@ -117,4 +117,14 @@ public class View extends BorderPane implements ChaosGameObserver { updateCanvasDisplay(canvas); }); } + + public void setCanvasWidth(double width) { + mainCanvas.setWidth(width); + updateCanvasDisplay(ChaosGame.getInstance().getCanvas()); + } + + public void setCanvasHeight(double height) { + mainCanvas.setHeight(height); + updateCanvasDisplay(ChaosGame.getInstance().getCanvas()); + } }