Skip to content
Snippets Groups Projects
Commit 394d3490 authored by Edvard Granheim Harbo's avatar Edvard Granheim Harbo
Browse files

Merge branch 'MainView' into 'dev'

Started on the menu

See merge request !23
parents 1b6d1c86 fd8bccc3
No related branches found
No related tags found
2 merge requests!54Final release,!23Started on the menu
......@@ -9,6 +9,7 @@ public enum ButtonEnum {
ZoomIn,
ZoomOut,
ResetZoom,
RotateTransformationLeft,
RotateTransformationRight
Submit,
Clear,
}
package edu.ntnu.idatt2003.mappevurderingprog2.utils;
import javafx.geometry.Rectangle2D;
import javafx.stage.Screen;
/**
* A class that provides the screen size.
*/
public class Size {
/**
* Get the screen width.
*
* @return the screen width
*/
public static double getScreenWidth() {
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
return primaryScreenBounds.getWidth();
}
/**
* Get the screen height.
*
* @return the screen height
*/
public static double getScreenHeight() {
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
return primaryScreenBounds.getHeight();
}
}
\ No newline at end of file
package edu.ntnu.idatt2003.mappevurderingprog2.views.Components;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
public class CreateNewFractal extends VBox {
private final VBox transformations = new VBox();
private final Button createFractalButton = new Button("Create a new fractal");
public CreateNewFractal() {
createFractalButton.setOnAction(event -> createFractalButtons());
transformations.getChildren().add(createFractalButton);
}
private void createFractalButtons() {
transformations.getChildren().clear();
Button affineButton = createTransformationButtons("Affine");
Button juliaButton = createTransformationButtons("Julia");
affineButton.setOnAction(event -> showTransformationMenu("Affine"));
juliaButton.setOnAction(event -> showTransformationMenu("Julia"));
HBox transformationButtons = new HBox(10, affineButton, juliaButton);
Label createFractal = createLabel("Choose fractal type:");
transformations.getChildren().addAll(createFractal, new Separator(), transformationButtons);
transformations.setAlignment(Pos.TOP_CENTER);
}
private void showTransformationMenu(String transformationType) {
transformations.getChildren().clear();
Button backButton = createTransformationButtons("Back");
backButton.setOnAction(event -> createFractalButtons());
VBox transformationMenu = createNewFractal(transformationType);
transformations.getChildren().addAll(transformationMenu, backButton);
}
public Button createTransformationButtons(String text) {
Button button = new Button(text);
return button;
}
public Label createLabel(String text) {
Label label = new Label(text);
label.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
return label;
}
public VBox createNewFractal(String transformationType) {
Label menuLabel = createLabel(transformationType + " Transformation Menu");
Label label = createLabel("Enter " + transformationType + " Parameters:");
TextField textField1 = new TextField();
TextField textField2 = transformationType.equals("Affine") ? new TextField() : null;
TextField textField3 = transformationType.equals("Affine") ? new TextField() : null;
Button applyButton = new Button("Apply");
VBox menuBox = new VBox(10, menuLabel, new Separator(), label, textField1);
if (textField2 != null && textField3 != null) {
menuBox.getChildren().addAll(textField2, textField3);
}
menuBox.getChildren().add(applyButton);
menuBox.setAlignment(Pos.TOP_CENTER);
return menuBox;
}
public VBox getTransformations() {
return transformations;
}
}
package edu.ntnu.idatt2003.mappevurderingprog2.views.Components;
import edu.ntnu.idatt2003.mappevurderingprog2.utils.Size;
import javafx.scene.control.Label;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.layout.VBox;
public class Menu extends VBox {
private final CreateNewFractal transformations = new CreateNewFractal();
public Menu() {
initializeMenu();
}
private void initializeMenu() {
clearLeftBoxUI();
getChildren().addAll(createMenuLabel(),transformations.getTransformations());
setupMenu();
}
private Label createMenuLabel() {
Label menuLabel = new Label("Menu");
menuLabel.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;");
return menuLabel;
}
private void clearLeftBoxUI() {
getChildren().clear();
}
private void setupMenu() {
menuSizeAndPositioning();
menuStyling();
}
private void menuSizeAndPositioning() {
double screenWidth = Size.getScreenWidth();
double screenHeight = Size.getScreenHeight();
setPrefWidth(0.3 * screenWidth);
setMaxWidth(0.3 * screenWidth);
setPrefHeight(screenHeight);
setAlignment(Pos.TOP_CENTER);
setPadding(new Insets(10, 0, 10, 0));
}
private void menuStyling() {
setPadding(new Insets(10, 10, 10, 10));
setStyle("-fx-background-color: #f4f4f4;");
}
}
......@@ -8,8 +8,11 @@ import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosGameDescriptionF
import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosGameFileHandler;
import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosGameObserver;
import edu.ntnu.idatt2003.mappevurderingprog2.utils.Colorpalette;
import edu.ntnu.idatt2003.mappevurderingprog2.utils.Size;
import edu.ntnu.idatt2003.mappevurderingprog2.views.Components.MainBar;
import java.io.FileNotFoundException;
import edu.ntnu.idatt2003.mappevurderingprog2.views.Components.Menu;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.Scene;
......@@ -24,6 +27,7 @@ public class View extends BorderPane implements ChaosGameObserver {
private Canvas mainCanvas;
private GameController gameController;
private Menu menu;
public View(GameController gameController) {
this.gameController = gameController;
......@@ -56,7 +60,6 @@ public class View extends BorderPane implements ChaosGameObserver {
public Scene createScene() throws FileNotFoundException {
this.setBackground(new Background(new BackgroundFill(Colorpalette.Primary, CornerRadii.EMPTY, Insets.EMPTY)));
mainCanvas = new Canvas(600, 400);
MainBar mainBar = new MainBar( this, gameController);
......@@ -64,7 +67,10 @@ public class View extends BorderPane implements ChaosGameObserver {
this.setTop(mainBar);
this.setCenter(mainCanvas);
return new Scene(this, 900, 700);
this.menu = new Menu();
this.setLeft(menu);
return new Scene(this, Size.getScreenWidth(),Size.getScreenHeight());
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment