Skip to content
Snippets Groups Projects
Commit d101a444 authored by Tam Minh Le's avatar Tam Minh Le
Browse files

Merge branch 'ScaleCanvas' into 'dev'

Added scaling of the canvas

See merge request !45
parents e5efffec f4a04b67
No related branches found
No related tags found
2 merge requests!54Final release,!45Added scaling of the canvas
......@@ -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());
......
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);
}
}
......@@ -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());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment