Skip to content
Snippets Groups Projects
Commit a9b32376 authored by Magnus Eik's avatar Magnus Eik
Browse files

Add scaling fractal for window scaling.

parent 6c039314
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,8 @@ public class ChaosGameGui implements ChaosGameObserver {
private Stage primaryStage;
private double aspectRatio;
private Canvas canvas;
......@@ -124,6 +126,8 @@ public class ChaosGameGui implements ChaosGameObserver {
private GuiButtonController controller;
public ChaosGameGui(Stage primaryStage) throws IOException {
this.primaryStage = primaryStage;
this.initializeComponents();
......@@ -135,7 +139,17 @@ public ChaosGameGui(Stage primaryStage) throws IOException {
primaryStage.setScene(scene);
primaryStage.setOnShown(event -> this.imageView.requestFocus());
primaryStage.show();
}
// Initialize aspect ratio based on initial dimensions
this.aspectRatio = (double) width / height;
// Add listeners to handle window size changes
scene.widthProperty().addListener((observable, oldValue, newValue) -> {
resizeCanvas();
});
scene.heightProperty().addListener((observable, oldValue, newValue) -> {
resizeCanvas();
});}
/**
* Initialize the components of the GUI.
*/
......@@ -220,6 +234,10 @@ public ChaosGameGui(Stage primaryStage) throws IOException {
this.canvas = new Canvas(width, height);
//this.imageView.setImage(canvas.snapshot(null, null));
canvas.widthProperty().bind(imageView.fitWidthProperty());
canvas.heightProperty().bind(imageView.fitHeightProperty());
this.clearImageView();
}
......@@ -429,6 +447,8 @@ public ChaosGameGui(Stage primaryStage) throws IOException {
rightVBox.setFocusTraversable(false);
borderPane.setFocusTraversable(false);
}
/**
......@@ -569,4 +589,22 @@ public ChaosGameGui(Stage primaryStage) throws IOException {
public Window getStage() {
return this.primaryStage;
}
private void resizeCanvas() {
double newWidth = scene.getWidth() - sideMenu.getWidth();
double newHeight = scene.getHeight();
if (newWidth / newHeight > aspectRatio) {
newWidth = newHeight * aspectRatio;
} else {
newHeight = newWidth / aspectRatio;
}
// Update imageView size to new calculated dimensions
imageView.setFitWidth(newWidth);
imageView.setFitHeight(newHeight);
// Redraw the fractal to fit the new canvas size
controller.drawChaosGame();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment