Implemented zooming and clipping of race border. Implementation is still hackish.

#pair[ptg19, cir27] #story[1121]
This commit is contained in:
Calum
2017-08-09 16:56:46 +12:00
parent 0fbca89030
commit 2c5fddb695
5 changed files with 50 additions and 106 deletions
+4 -55
View File
@@ -9,14 +9,10 @@ import java.util.Map;
import javafx.animation.AnimationTimer; import javafx.animation.AnimationTimer;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
@@ -93,18 +89,14 @@ public class GameView extends Pane {
public void zoomOut() { public void zoomOut() {
scaleFactor = 0.95; scaleFactor = 0.95;
for (Node child : getChildren()) { this.setScaleX(this.getScaleX() * scaleFactor);
child.setScaleX(child.getScaleX() * scaleFactor); this.setScaleY(this.getScaleY() * scaleFactor);
child.setScaleY(child.getScaleY() * scaleFactor);
}
} }
public void zoomIn() { public void zoomIn() {
scaleFactor = 1.05; scaleFactor = 1.05;
for (Node child : getChildren()) { this.setScaleX(this.getScaleX() * scaleFactor);
child.setScaleX(child.getScaleX() * scaleFactor); this.setScaleY(this.getScaleY() * scaleFactor);
child.setScaleY(child.getScaleY() * scaleFactor);
}
} }
private enum ScaleDirection { private enum ScaleDirection {
@@ -122,45 +114,6 @@ public class GameView extends Pane {
gameObjects.add(fpsDisplay); gameObjects.add(fpsDisplay);
gameObjects.add(raceBorder); gameObjects.add(raceBorder);
gameObjects.add(markers); gameObjects.add(markers);
//
// this.setOnKeyPressed(new EventHandler<KeyEvent>() {
// @Override public void handle(KeyEvent event) {
// event.consume();
// switch (event.getCode()) {
// case Z:
// scaleFactor = scaleFactor * 1.2;
// break;
// case X:
// scaleFactor = scaleFactor * 0.8;
// break;
// }
// if (event.getCode() == KeyCode.Z || event.getCode() == KeyCode.X) {
// for (Node child : getChildren()) {
// child.setScaleX(child.getScaleX() * scaleFactor);
// child.setScaleY(child.getScaleY() * scaleFactor);
// }
// }
// }
// });
//
// this.setOnScroll(new EventHandler<ScrollEvent>() {
// @Override public void handle(ScrollEvent event) {
// event.consume();
// if (event.getDeltaY() == 0) {
// return;
// }
//
// double scaleFactor =
// (event.getDeltaY() > 0)
// ? SCALE_DELTA
// : 1/SCALE_DELTA;
// for (Node child : getChildren()) {
// child.setScaleX(child.getScaleX() * scaleFactor);
// child.setScaleY(child.getScaleY() * scaleFactor);
// }
// }
// });
initializeTimer(); initializeTimer();
} }
@@ -393,9 +346,6 @@ public class GameView extends Pane {
BoatObject bo = boatObjects.get(boat); BoatObject bo = boatObjects.get(boat);
Point2D p2d = findScaledXY(lat, lon); Point2D p2d = findScaledXY(lat, lon);
bo.moveTo(p2d.getX(), p2d.getY(), heading, velocity, sailIn, windDir); bo.moveTo(p2d.getX(), p2d.getY(), heading, velocity, sailIn, windDir);
// annotations.get(boat).setLayoutX(p2d.getX());
// annotations.get(boat).setLayoutY(p2d.getY());
// annotations.get(boat).setLocation(100d, 100d);
annotations.get(boat).setLocation(p2d.getX(), p2d.getY()); annotations.get(boat).setLocation(p2d.getX(), p2d.getY());
bo.setTrajectory( bo.setTrajectory(
heading, heading,
@@ -410,7 +360,6 @@ public class GameView extends Pane {
gameObjects.addAll(wakes); gameObjects.addAll(wakes);
gameObjects.addAll(annotationsGroup); gameObjects.addAll(annotationsGroup);
gameObjects.addAll(boatObjectGroup); gameObjects.addAll(boatObjectGroup);
}); });
} }
@@ -115,7 +115,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
initialiseSparkLine(); initialiseSparkLine();
gameView = new GameView(); gameView = new GameView();
Platform.runLater(() -> contentAnchorPane.getChildren().add(gameView)); Platform.runLater(() -> contentAnchorPane.getChildren().add(0, gameView));
gameView.setBoats(new ArrayList<>(participants.values())); gameView.setBoats(new ArrayList<>(participants.values()));
gameView.updateBorder(raceData.getCourseLimit()); gameView.updateBorder(raceData.getCourseLimit());
gameView.updateCourse( gameView.updateCourse(
@@ -95,7 +95,7 @@ public class AnnotationBox extends Group {
background.setStroke(theme); background.setStroke(theme);
background.setStrokeWidth(2); background.setStrokeWidth(2);
background.setCache(true); background.setCache(true);
background.setCacheHint(CacheHint.SPEED); background.setCacheHint(CacheHint.SCALE);
this.getChildren().add(background); this.getChildren().add(background);
} }
@@ -213,7 +213,7 @@ public class AnnotationBox extends Group {
Text text = new Text(); Text text = new Text();
text.setFill(theme); text.setFill(theme);
text.setStrokeWidth(2); text.setStrokeWidth(2);
text.setCacheHint(CacheHint.SPEED); // text.setCacheHint(CacheHint.QUALITY);
text.setCache(true); text.setCache(true);
return text; return text;
} }
@@ -3,7 +3,6 @@ package seng302.visualiser.fxObjects;
import java.util.ArrayList; import java.util.ArrayList;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.CacheHint;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
@@ -85,7 +84,7 @@ public class BoatObject extends Group {
}); });
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected)); boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
boatPoly.setCache(true); boatPoly.setCache(true);
boatPoly.setCacheHint(CacheHint.SPEED); // boatPoly.setCacheHint(CacheHint.SPEED);
// annotationBox = new AnnotationBox(); // annotationBox = new AnnotationBox();
// annotationBox.setFill(colour); // annotationBox.setFill(colour);
+11 -15
View File
@@ -1,5 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.chart.CategoryAxis?> <?import javafx.scene.chart.CategoryAxis?>
<?import javafx.scene.chart.LineChart?> <?import javafx.scene.chart.LineChart?>
<?import javafx.scene.chart.NumberAxis?> <?import javafx.scene.chart.NumberAxis?>
@@ -17,18 +23,11 @@
<?import javafx.scene.shape.Circle?> <?import javafx.scene.shape.Circle?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?> <?import javafx.scene.text.Text?>
<GridPane prefHeight="960.0" prefWidth="1530.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.visualiser.controllers.RaceViewController">
<columnConstraints> <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="998.0" prefWidth="1530.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.visualiser.controllers.RaceViewController">
<ColumnConstraints maxWidth="246.0" minWidth="246.0" prefWidth="246.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="1034.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="500.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints />
<RowConstraints />
</rowConstraints>
<children> <children>
<AnchorPane prefHeight="960.0" prefWidth="250.0" style="-fx-background-color: #2C2c36;" GridPane.rowSpan="3"> <AnchorPane fx:id="contentAnchorPane" layoutX="322.0" layoutY="130.0" prefHeight="998.0" prefWidth="1281.0" style="-fx-background-color: skyblue;" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<AnchorPane prefHeight="960.0" prefWidth="250.0" style="-fx-background-color: #2C2c36;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
<children> <children>
<Label layoutX="11.0" layoutY="283.0" text="Team Position" textFill="WHITE" /> <Label layoutX="11.0" layoutY="283.0" text="Team Position" textFill="WHITE" />
<Label layoutX="13.0" layoutY="432.0" text="Settings" textFill="WHITE" /> <Label layoutX="13.0" layoutY="432.0" text="Settings" textFill="WHITE" />
@@ -76,8 +75,5 @@
</LineChart> </LineChart>
</children> </children>
</AnchorPane> </AnchorPane>
<AnchorPane fx:id="contentAnchorPane" style="-fx-background-color: skyblue;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowSpan="2147483647" GridPane.valignment="TOP">
</AnchorPane>
</children> </children>
</GridPane> </AnchorPane>