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

Merge branch 'Zoom' into 'dev'

Zoom

See merge request !29
parents 97ea3831 8e7b0147
No related branches found
No related tags found
2 merge requests!54Final release,!29Zoom
...@@ -14,9 +14,11 @@ public class GameController { ...@@ -14,9 +14,11 @@ public class GameController {
public void setMinCoords(double minX0, double minX1) { public void setMinCoords(double minX0, double minX1) {
ChaosGame.getInstance().getDescription().setMinCoords(new Vector2D(minX0, minX1)); ChaosGame.getInstance().getDescription().setMinCoords(new Vector2D(minX0, minX1));
} }
public void setMaxCoords(double maxX0, double maxX1) { public void setMaxCoords(double maxX0, double maxX1) {
ChaosGame.getInstance().getDescription().setMaxCoords(new Vector2D(maxX0, maxX1)); ChaosGame.getInstance().getDescription().setMaxCoords(new Vector2D(maxX0, maxX1));
} }
public void setChaosGameDescription(ChaosGameDescription description) { public void setChaosGameDescription(ChaosGameDescription description) {
ChaosGame.getInstance().setDescription(description); ChaosGame.getInstance().setDescription(description);
} }
...@@ -44,4 +46,6 @@ public class GameController { ...@@ -44,4 +46,6 @@ public class GameController {
public void setAffineTransformation(List<Transform2D> transforms, Vector2D minCoords, Vector2D maxCoords) { public void setAffineTransformation(List<Transform2D> transforms, Vector2D minCoords, Vector2D maxCoords) {
ChaosGame.getInstance().setDescription(ChaosGameDescription.createWithTransforms(transforms, minCoords, maxCoords)); ChaosGame.getInstance().setDescription(ChaosGameDescription.createWithTransforms(transforms, minCoords, maxCoords));
} }
} }
package edu.ntnu.idatt2003.mappevurderingprog2.views.Components;
import javafx.scene.Node;
import javafx.scene.transform.Scale;
public class Zoom {
private double mouseX, mouseY;
public void setUpZoomAndMovement(Node node) {
zoomInAndOut(node);
screenMovement(node);
}
private void zoomInAndOut(Node node) {
node.setOnScroll(event -> {
double zoomFactor = 1.05;
double deltaY = event.getDeltaY();
if (deltaY < 0) {
zoomFactor = 2.0 - zoomFactor;
}
Scale scale = new Scale(zoomFactor, zoomFactor, event.getX(), event.getY());
node.getTransforms().add(scale);
event.consume();
});
}
private void screenMovement(Node node) {
node.setOnMousePressed(event -> {
mouseX = event.getSceneX();
mouseY = event.getSceneY();
});
node.setOnMouseDragged(event -> {
double deltaX = event.getSceneX() - mouseX;
double deltaY = event.getSceneY() - mouseY;
node.setTranslateX(node.getTranslateX() + deltaX);
node.setTranslateY(node.getTranslateY() + deltaY);
mouseX = event.getSceneX();
mouseY = event.getSceneY();
});
}
}
package edu.ntnu.idatt2003.mappevurderingprog2.views; package edu.ntnu.idatt2003.mappevurderingprog2.views;
import edu.ntnu.idatt2003.mappevurderingprog2.controllers.GameController; import edu.ntnu.idatt2003.mappevurderingprog2.controllers.GameController;
import edu.ntnu.idatt2003.mappevurderingprog2.views.Components.Zoom;
import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosCanvas; import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosCanvas;
import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosGame; import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosGame;
import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosGameDescription; import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosGameDescription;
...@@ -16,6 +17,7 @@ import java.util.Collections; ...@@ -16,6 +17,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.canvas.Canvas; import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
...@@ -25,6 +27,7 @@ import javafx.scene.layout.BackgroundFill; ...@@ -25,6 +27,7 @@ import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.CornerRadii; import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.transform.Scale;
public class View extends BorderPane implements ChaosGameObserver { public class View extends BorderPane implements ChaosGameObserver {
...@@ -32,10 +35,13 @@ public class View extends BorderPane implements ChaosGameObserver { ...@@ -32,10 +35,13 @@ public class View extends BorderPane implements ChaosGameObserver {
private GameController gameController; private GameController gameController;
private Menu menu; private Menu menu;
private int greenThreshold, blueThreshold, redThreshold; private int greenThreshold, blueThreshold, redThreshold;
private Zoom zoom;
public View(GameController gameController) { public View(GameController gameController) {
this.gameController = gameController; this.gameController = gameController;
this.mainCanvas = new Canvas(600, 400); this.mainCanvas = new Canvas(600, 400);
this.zoom = new Zoom();
zoom.setUpZoomAndMovement(mainCanvas);
} }
public Canvas getMainCanvas() { public Canvas getMainCanvas() {
...@@ -55,7 +61,7 @@ public class View extends BorderPane implements ChaosGameObserver { ...@@ -55,7 +61,7 @@ public class View extends BorderPane implements ChaosGameObserver {
for (int j = 0; j < canvasArray[i].length; j++) { for (int j = 0; j < canvasArray[i].length; j++) {
double x = j * pixelWidth + 3; double x = j * pixelWidth + 3;
double y = i * pixelHeight + 3; double y = i * pixelHeight + 3;
gc.setFill(getColorForHits(canvasArray[i][j])); // Use a method to determine color based on hit count gc.setFill(getColorForHits(canvasArray[i][j]));
gc.fillRect(x, y, pixelWidth, pixelHeight); gc.fillRect(x, y, pixelWidth, pixelHeight);
} }
} }
...@@ -92,11 +98,7 @@ public class View extends BorderPane implements ChaosGameObserver { ...@@ -92,11 +98,7 @@ public class View extends BorderPane implements ChaosGameObserver {
public Scene createScene() throws FileNotFoundException { public Scene createScene() throws FileNotFoundException {
this.setBackground(new Background(new BackgroundFill(Colorpalette.Primary, CornerRadii.EMPTY, Insets.EMPTY))); this.setBackground(new Background(new BackgroundFill(Colorpalette.Primary, CornerRadii.EMPTY, Insets.EMPTY)));
this.setCenter(mainCanvas); this.setCenter(mainCanvas);
this.menu = new Menu(this, gameController); this.menu = new Menu(this, gameController);
this.setLeft(menu); this.setLeft(menu);
new Separator(); new Separator();
...@@ -112,4 +114,8 @@ public class View extends BorderPane implements ChaosGameObserver { ...@@ -112,4 +114,8 @@ public class View extends BorderPane implements ChaosGameObserver {
}); });
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment