diff --git a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosCanvas.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosCanvas.java index f828143ea069922cd25511fe2b9881d31f52965a..7266582a4bb88666495d302ae8e40251dc59033b 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosCanvas.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosCanvas.java @@ -270,4 +270,5 @@ public class ChaosCanvas { public int[] getCentre() { return new int[]{this.centreX, this.centreY}; } + } diff --git a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/GuiButtonController.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/GuiButtonController.java index df327c576675055242e3463782b6ea2bc42da0e6..2fec05e53af79cd512a9a7ae1dcbe5e2b49106ed 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/GuiButtonController.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/GuiButtonController.java @@ -5,6 +5,7 @@ import edu.ntnu.stud.chaosgame.view.ChaosCanvasToImageConverter; import edu.ntnu.stud.chaosgame.view.ChaosGameGui; import javafx.animation.KeyFrame; import javafx.animation.Timeline; +import javafx.application.Platform; import javafx.scene.canvas.GraphicsContext; import javafx.scene.image.WritableImage; import javafx.util.Duration; @@ -27,6 +28,7 @@ public class GuiButtonController { this.factory = new ChaosGameDescriptionFactory(); this.chaosCanvas = new ChaosCanvas(1000, 1000, this.factory.getDescriptions().get(0).getMinCoords(), this.factory.getDescriptions().get(0).getMaxCoords()); + initializeMainButtons(); } public void runGameSteps(int steps) { @@ -41,6 +43,7 @@ public class GuiButtonController { // Convert the canvas to either an image with coloured pixels based on intensity, or just black and white. ChaosCanvasToImageConverter converter = new ChaosCanvasToImageConverter(chaosCanvas, gui.getColorCheckBox().isSelected()); + WritableImage image = converter.getImage(); gui.getCanvas().getGraphicsContext2D().drawImage(image, 0, 0); gui.getImageView().setImage(image); @@ -52,12 +55,26 @@ public class GuiButtonController { public void stopGame() { timeline.stop(); } + public void newGame() { + game.getCanvas().clearCanvas(); + timeline.play(); + } public void clearImageView() { GraphicsContext gc = gui.getCanvas().getGraphicsContext2D(); gc.clearRect(0, 0, gui.getCanvas().getWidth(), gui.getCanvas().getHeight()); gui.getImageView().setImage(null); } + public void quitGame() { + Platform.exit(); + } + private void initializeMainButtons() { + gui.getStartButton().setOnAction(event -> startGame()); + gui.getStopButton().setOnAction(event -> stopGame()); + gui.getNewButton().setOnAction(event -> newGame()); + gui.getClearButton().setOnAction(event -> clearImageView()); + gui.getQuitButton().setOnAction(event -> quitGame()); + } /** * Update the description of the chaos game. @@ -89,4 +106,6 @@ public class GuiButtonController { game = new ChaosGame(description, chaosCanvas); game.setUseColor(gui.getColorCheckBox().isSelected()); } + + } \ No newline at end of file diff --git a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java index d86c22ea2ebd757fa94eecb5e39a1889ed6a33a6..b773bcbc0a523573a03db045b6e378cc592e10b7 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java @@ -121,10 +121,10 @@ public class ChaosGameGui implements ChaosGameObserver { public ChaosGameGui(Stage primaryStage) throws IOException { - - this.controller = new GuiButtonController(game, this); // Initialize controller here this.initializeComponents(); this.initializeGameComponents(); + this.controller = new GuiButtonController(game, this); // Initialize controller here + primaryStage.setTitle("Fractal Chaos Game"); primaryStage.setScene(scene); @@ -140,11 +140,12 @@ public ChaosGameGui(Stage primaryStage) throws IOException { //this.timeline = new Timeline(new KeyFrame(Duration.seconds(0.05), event -> controller.drawChaosGame())); this.initializeImageView(); + // Side menu - this.initializeMainButtons(); + //this.initializeMainButtons(); this.initializeFractalButtons(); this.initializeSideMenu(); @@ -154,31 +155,31 @@ public ChaosGameGui(Stage primaryStage) throws IOException { /** * Initialize the main buttons for the GUI. */ - private void initializeMainButtons() { - this.startButton = new Button("Start"); - startButton.setOnAction(event -> controller.startGame()); - this.stopButton = new Button("Stop"); - stopButton.setOnAction(event -> controller.stopGame()); - - this.newButton = new Button("New"); - - newButton.setOnAction(event ->{ - this.canvas.getGraphicsContext2D().clearRect(0, 0, canvas.getWidth(), canvas.getHeight()); - chaosCanvas.clearCanvas(); - }); - - this.clearButton = new Button("Clear"); - - clearButton.setOnAction(event -> { - getImageView().setImage(null); - setCurrentLine(0); - }); - - // Quit button - this.quitButton = new Button("Quit"); - quitButton.setOnAction(event -> Platform.exit()); - - } +// private void initializeMainButtons() { +// this.startButton = new Button("Start"); +// startButton.setOnAction(event -> controller.startGame()); +// this.stopButton = new Button("Stop"); +// stopButton.setOnAction(event -> controller.stopGame()); +// +// this.newButton = new Button("New"); +// +// newButton.setOnAction(event ->{ +// this.canvas.getGraphicsContext2D().clearRect(0, 0, canvas.getWidth(), canvas.getHeight()); +// chaosCanvas.clearCanvas(); +// }); +// +// this.clearButton = new Button("Clear"); +// +// clearButton.setOnAction(event -> { +// getImageView().setImage(null); +// setCurrentLine(0); +// }); +// +// // Quit button +// this.quitButton = new Button("Quit"); +// quitButton.setOnAction(event -> Platform.exit()); +// +// } /** * Initialize the components related to the chaos game itself. @@ -264,6 +265,15 @@ public ChaosGameGui(Stage primaryStage) throws IOException { * Initialize the side menu. */ private void initializeSideMenu() { + + + this.startButton = new Button("Start"); + this.stopButton = new Button("Stop"); + this.newButton = new Button("New"); + this.clearButton = new Button("Clear"); + this.quitButton = new Button("Quit"); + this.sideMenuButton = new Button("Side Menu"); + this.sideMenu = new VBox(); // Parameters VBox parameterBox = new VBox(); @@ -342,6 +352,8 @@ public ChaosGameGui(Stage primaryStage) throws IOException { Region sideMenuButtonRegion = new Region(); sideMenuButtonRegion.setMinWidth(200); HBox sideMenuButtonBox = new HBox(); + + sideMenuButtonBox.getChildren().addAll(sideMenuButtonRegion, sideMenuButton); // The right VBox containing both the sidebar and the sidebar toggle button. @@ -473,7 +485,21 @@ public ChaosGameGui(Stage primaryStage) throws IOException { return this.canvas; } - + public Button getStartButton() { + return this.startButton; + } + public Button getStopButton() { + return this.stopButton; + } + public Button getNewButton() { + return this.newButton; + } + public Button getClearButton() { + return this.clearButton; + } + public Button getQuitButton() { + return this.quitButton; + }