Canvas Layer Created
- Canvas is created via layering. - Resizable canvas is now a seperate abstract class #story[782]
This commit is contained in:
@@ -36,6 +36,7 @@ public class RaceController extends Controller {
|
|||||||
private ArrayList<Boolean> presetAnno;
|
private ArrayList<Boolean> presetAnno;
|
||||||
|
|
||||||
ResizableRaceCanvas raceMap;
|
ResizableRaceCanvas raceMap;
|
||||||
|
ResizableRaceMap raceBoundaries;
|
||||||
@FXML
|
@FXML
|
||||||
SplitPane race;
|
SplitPane race;
|
||||||
@FXML
|
@FXML
|
||||||
@@ -123,15 +124,25 @@ public class RaceController extends Controller {
|
|||||||
StreamedRace newRace = new StreamedRace(visualiserInput, this);
|
StreamedRace newRace = new StreamedRace(visualiserInput, this);
|
||||||
//newRace.initialiseBoats();
|
//newRace.initialiseBoats();
|
||||||
|
|
||||||
|
|
||||||
|
raceBoundaries = new ResizableRaceMap(visualiserInput.getCourse());
|
||||||
|
raceBoundaries.setMouseTransparent(true);
|
||||||
|
raceBoundaries.widthProperty().bind(canvasBase.widthProperty());
|
||||||
|
raceBoundaries.heightProperty().bind(canvasBase.heightProperty());
|
||||||
|
raceBoundaries.draw();
|
||||||
|
raceBoundaries.setVisible(true);
|
||||||
|
canvasBase.getChildren().add(raceBoundaries);
|
||||||
|
|
||||||
raceMap = new ResizableRaceCanvas(visualiserInput.getCourse());
|
raceMap = new ResizableRaceCanvas(visualiserInput.getCourse());
|
||||||
raceMap.setMouseTransparent(true);
|
raceMap.setMouseTransparent(true);
|
||||||
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
||||||
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
||||||
//raceMap.setBoats(newRace.getStartingBoats());
|
//raceMap.setBoats(newRace.getStartingBoats());
|
||||||
raceMap.drawRaceMap();
|
raceMap.draw();
|
||||||
raceMap.setVisible(true);
|
raceMap.setVisible(true);
|
||||||
|
|
||||||
canvasBase.getChildren().add(0, raceMap);
|
canvasBase.getChildren().add(raceMap);
|
||||||
|
|
||||||
race.setVisible(true);
|
race.setVisible(true);
|
||||||
|
|
||||||
//Initialize save annotation array, fps listener, and annotation listeners
|
//Initialize save annotation array, fps listener, and annotation listeners
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package seng302.Model;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.Canvas;
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by fwy13 on 4/05/17.
|
||||||
|
*/
|
||||||
|
public abstract class ResizableCanvas extends Canvas {
|
||||||
|
protected GraphicsContext gc;
|
||||||
|
|
||||||
|
public ResizableCanvas(){
|
||||||
|
this.gc = this.getGraphicsContext2D();
|
||||||
|
// Redraw canvas when size changes.
|
||||||
|
widthProperty().addListener(evt -> draw());
|
||||||
|
heightProperty().addListener(evt -> draw());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract void draw();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Canvas to resizable.
|
||||||
|
*
|
||||||
|
* @return That the Canvas is resizable.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isResizable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the preferred width of the Canvas
|
||||||
|
*
|
||||||
|
* @param width of canvas
|
||||||
|
* @return Returns the width of the Canvas
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public double prefWidth(double width) {
|
||||||
|
return getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the preferred height of the Canvas
|
||||||
|
*
|
||||||
|
* @param height of canvas
|
||||||
|
* @return Returns the height of the Canvas
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public double prefHeight(double height) {
|
||||||
|
return getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,8 +18,7 @@ import java.util.List;
|
|||||||
* Cannot be downsized.
|
* Cannot be downsized.
|
||||||
* Created by fwy13 on 17/03/17.
|
* Created by fwy13 on 17/03/17.
|
||||||
*/
|
*/
|
||||||
public class ResizableRaceCanvas extends Canvas {
|
public class ResizableRaceCanvas extends ResizableCanvas {
|
||||||
private GraphicsContext gc;
|
|
||||||
private RaceMap map;
|
private RaceMap map;
|
||||||
private List<Boat> boats;
|
private List<Boat> boats;
|
||||||
private boolean raceAnno = true;
|
private boolean raceAnno = true;
|
||||||
@@ -28,15 +27,11 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
private boolean annoSpeed = true;
|
private boolean annoSpeed = true;
|
||||||
private boolean annoPath = true;
|
private boolean annoPath = true;
|
||||||
private List<Color> colours;
|
private List<Color> colours;
|
||||||
private List<GPSCoordinate> raceBoundaries;
|
|
||||||
private List<Marker> markers;
|
private List<Marker> markers;
|
||||||
double[] xpoints = {}, ypoints = {};
|
double[] xpoints = {}, ypoints = {};
|
||||||
|
|
||||||
public ResizableRaceCanvas(RaceDataSource raceData) {
|
public ResizableRaceCanvas(RaceDataSource raceData) {
|
||||||
gc = this.getGraphicsContext2D();
|
super();
|
||||||
// Redraw canvas when size changes.
|
|
||||||
widthProperty().addListener(evt -> drawRaceMap());
|
|
||||||
heightProperty().addListener(evt -> drawRaceMap());
|
|
||||||
|
|
||||||
double lat1 = raceData.getMapTopLeft().getLatitude();
|
double lat1 = raceData.getMapTopLeft().getLatitude();
|
||||||
double long1 = raceData.getMapTopLeft().getLongitude();
|
double long1 = raceData.getMapTopLeft().getLongitude();
|
||||||
@@ -45,7 +40,6 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
|
|
||||||
setMap(new RaceMap(lat1, long1, lat2, long2, (int) getWidth(), (int) getHeight()));
|
setMap(new RaceMap(lat1, long1, lat2, long2, (int) getWidth(), (int) getHeight()));
|
||||||
|
|
||||||
this.raceBoundaries = raceData.getBoundary();
|
|
||||||
this.markers = raceData.getMarkers();
|
this.markers = raceData.getMarkers();
|
||||||
makeColours();
|
makeColours();
|
||||||
}
|
}
|
||||||
@@ -79,7 +73,7 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
*/
|
*/
|
||||||
public void displayMark(GraphCoordinate graphCoordinate, Paint paint) {
|
public void displayMark(GraphCoordinate graphCoordinate, Paint paint) {
|
||||||
double d = 25;
|
double d = 25;
|
||||||
gc.setFill(paint);
|
this.gc.setFill(paint);
|
||||||
gc.fillOval(graphCoordinate.getX() - (d / 2), graphCoordinate.getY() - (d / 2), d, d);
|
gc.fillOval(graphCoordinate.getX() - (d / 2), graphCoordinate.getY() - (d / 2), d, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,24 +193,10 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
* Draws race map with up to date data.
|
* Draws race map with up to date data.
|
||||||
*/
|
*/
|
||||||
public void update() {
|
public void update() {
|
||||||
this.drawRaceMap();
|
this.draw();
|
||||||
this.updateBoats();
|
this.updateBoats();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Draw boundary of the race.
|
|
||||||
*/
|
|
||||||
public void drawBoundaries() {
|
|
||||||
if (this.raceBoundaries == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//gc.setFill(Color.AQUA);
|
|
||||||
setRaceBoundCoordinates();
|
|
||||||
|
|
||||||
gc.setLineWidth(1);
|
|
||||||
gc.strokePolygon(xpoints, ypoints, xpoints.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw race markers
|
* Draw race markers
|
||||||
*/
|
*/
|
||||||
@@ -236,7 +216,7 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
/**
|
/**
|
||||||
* Draws the Race Map
|
* Draws the Race Map
|
||||||
*/
|
*/
|
||||||
public void drawRaceMap() {
|
public void draw() {
|
||||||
|
|
||||||
double width = getWidth();
|
double width = getWidth();
|
||||||
double height = getHeight();
|
double height = getHeight();
|
||||||
@@ -252,7 +232,6 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
gc.setLineWidth(2);
|
gc.setLineWidth(2);
|
||||||
updateBoats();
|
updateBoats();
|
||||||
drawMarkers();
|
drawMarkers();
|
||||||
drawBoundaries();
|
|
||||||
|
|
||||||
//display wind direction arrow - specify origin point and angle - angle now set to random angle
|
//display wind direction arrow - specify origin point and angle - angle now set to random angle
|
||||||
displayArrow(new GraphCoordinate((int) getWidth() - 40, 40), 150);
|
displayArrow(new GraphCoordinate((int) getWidth() - 40, 40), 150);
|
||||||
@@ -368,24 +347,6 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRaceBoundaries(List<GPSCoordinate> boundaries) {
|
|
||||||
this.raceBoundaries = new ArrayList<>();
|
|
||||||
for (GPSCoordinate bound : boundaries) {
|
|
||||||
raceBoundaries.add(bound);
|
|
||||||
}
|
|
||||||
setRaceBoundCoordinates();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRaceBoundCoordinates() {
|
|
||||||
xpoints = new double[this.raceBoundaries.size()];
|
|
||||||
ypoints = new double[this.raceBoundaries.size()];
|
|
||||||
for (int i = 0; i < raceBoundaries.size(); i++) {
|
|
||||||
GraphCoordinate coord = map.convertGPS(raceBoundaries.get(i));
|
|
||||||
xpoints[i] = coord.getX();
|
|
||||||
ypoints[i] = coord.getY();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void makeColours() {
|
private void makeColours() {
|
||||||
colours = new ArrayList<Color>(Arrays.asList(
|
colours = new ArrayList<Color>(Arrays.asList(
|
||||||
Color.BLUEVIOLET,
|
Color.BLUEVIOLET,
|
||||||
@@ -400,36 +361,4 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the Canvas to resizable.
|
|
||||||
*
|
|
||||||
* @return That the Canvas is resizable.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isResizable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the preferred width of the Canvas
|
|
||||||
*
|
|
||||||
* @param width of canvas
|
|
||||||
* @return Returns the width of the Canvas
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public double prefWidth(double width) {
|
|
||||||
return getWidth();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the preferred height of the Canvas
|
|
||||||
*
|
|
||||||
* @param height of canvas
|
|
||||||
* @return Returns the height of the Canvas
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public double prefHeight(double height) {
|
|
||||||
return getHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package seng302.Model;
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import seng302.GPSCoordinate;
|
||||||
|
import seng302.GraphCoordinate;
|
||||||
|
import seng302.Mock.StreamedCourse;
|
||||||
|
import seng302.RaceDataSource;
|
||||||
|
import seng302.RaceMap;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by fwy13 on 4/05/17.
|
||||||
|
*/
|
||||||
|
public class ResizableRaceMap extends ResizableCanvas {
|
||||||
|
private RaceMap map;
|
||||||
|
RaceDataSource raceData;
|
||||||
|
private List<GPSCoordinate> raceBoundaries;
|
||||||
|
double[] xpoints = {}, ypoints = {};
|
||||||
|
|
||||||
|
public ResizableRaceMap(RaceDataSource raceData){
|
||||||
|
super();
|
||||||
|
this.raceData = raceData;
|
||||||
|
raceBoundaries = this.raceData.getBoundary();
|
||||||
|
|
||||||
|
double lat1 = raceData.getMapTopLeft().getLatitude();
|
||||||
|
double long1 = raceData.getMapTopLeft().getLongitude();
|
||||||
|
double lat2 = raceData.getMapBottomRight().getLatitude();
|
||||||
|
double long2 = raceData.getMapBottomRight().getLongitude();
|
||||||
|
setMap(new RaceMap(lat1, long1, lat2, long2, (int) getWidth(), (int) getHeight()));
|
||||||
|
//draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMap(RaceMap map) {
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Draw boundary of the race.
|
||||||
|
*/
|
||||||
|
public void drawBoundaries() {
|
||||||
|
if (this.raceBoundaries == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gc.setFill(Color.AQUA);
|
||||||
|
setRaceBoundCoordinates();
|
||||||
|
|
||||||
|
gc.setLineWidth(1);
|
||||||
|
gc.fillPolygon(xpoints, ypoints, xpoints.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRaceBoundCoordinates() {
|
||||||
|
xpoints = new double[this.raceBoundaries.size()];
|
||||||
|
ypoints = new double[this.raceBoundaries.size()];
|
||||||
|
for (int i = 0; i < raceBoundaries.size(); i++) {
|
||||||
|
GraphCoordinate coord = map.convertGPS(raceBoundaries.get(i));
|
||||||
|
xpoints[i] = coord.getX();
|
||||||
|
ypoints[i] = coord.getY();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(){
|
||||||
|
|
||||||
|
double width = getWidth();
|
||||||
|
double height = getHeight();
|
||||||
|
|
||||||
|
gc.clearRect(0, 0, width, height);
|
||||||
|
|
||||||
|
if (map == null) {
|
||||||
|
return;//TODO this should return a exception in the future
|
||||||
|
}
|
||||||
|
this.map.setHeight((int) height);
|
||||||
|
this.map.setWidth((int) width);
|
||||||
|
|
||||||
|
gc.setLineWidth(2);
|
||||||
|
drawBoundaries();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user