Canvas Layer Created
- Canvas is created via layering. - Resizable canvas is now a seperate abstract class #story[782]
This commit is contained in:
@@ -18,8 +18,7 @@ import java.util.List;
|
||||
* Cannot be downsized.
|
||||
* Created by fwy13 on 17/03/17.
|
||||
*/
|
||||
public class ResizableRaceCanvas extends Canvas {
|
||||
private GraphicsContext gc;
|
||||
public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
private RaceMap map;
|
||||
private List<Boat> boats;
|
||||
private boolean raceAnno = true;
|
||||
@@ -28,15 +27,11 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
private boolean annoSpeed = true;
|
||||
private boolean annoPath = true;
|
||||
private List<Color> colours;
|
||||
private List<GPSCoordinate> raceBoundaries;
|
||||
private List<Marker> markers;
|
||||
double[] xpoints = {}, ypoints = {};
|
||||
|
||||
public ResizableRaceCanvas(RaceDataSource raceData) {
|
||||
gc = this.getGraphicsContext2D();
|
||||
// Redraw canvas when size changes.
|
||||
widthProperty().addListener(evt -> drawRaceMap());
|
||||
heightProperty().addListener(evt -> drawRaceMap());
|
||||
super();
|
||||
|
||||
double lat1 = raceData.getMapTopLeft().getLatitude();
|
||||
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()));
|
||||
|
||||
this.raceBoundaries = raceData.getBoundary();
|
||||
this.markers = raceData.getMarkers();
|
||||
makeColours();
|
||||
}
|
||||
@@ -79,7 +73,7 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
*/
|
||||
public void displayMark(GraphCoordinate graphCoordinate, Paint paint) {
|
||||
double d = 25;
|
||||
gc.setFill(paint);
|
||||
this.gc.setFill(paint);
|
||||
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.
|
||||
*/
|
||||
public void update() {
|
||||
this.drawRaceMap();
|
||||
this.draw();
|
||||
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
|
||||
*/
|
||||
@@ -236,7 +216,7 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
/**
|
||||
* Draws the Race Map
|
||||
*/
|
||||
public void drawRaceMap() {
|
||||
public void draw() {
|
||||
|
||||
double width = getWidth();
|
||||
double height = getHeight();
|
||||
@@ -252,7 +232,6 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
gc.setLineWidth(2);
|
||||
updateBoats();
|
||||
drawMarkers();
|
||||
drawBoundaries();
|
||||
|
||||
//display wind direction arrow - specify origin point and angle - angle now set to random angle
|
||||
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() {
|
||||
colours = new ArrayList<Color>(Arrays.asList(
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user