|
|
|
|
@ -40,7 +40,6 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
|
this.boats = boats;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ResizableRaceCanvas(RaceMap map) {
|
|
|
|
|
this.map = map;
|
|
|
|
|
gc = this.getGraphicsContext2D();
|
|
|
|
|
@ -73,9 +72,24 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
|
* @see Color
|
|
|
|
|
* @see Paint
|
|
|
|
|
*/
|
|
|
|
|
private void displayMark(GraphCoordinate graphCoordinate, Paint paint) {
|
|
|
|
|
public void displayMark(GraphCoordinate graphCoordinate, Paint paint){
|
|
|
|
|
double d = 25;
|
|
|
|
|
gc.setFill(paint);
|
|
|
|
|
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 25, 25);
|
|
|
|
|
gc.fillOval(graphCoordinate.getX() - (d/2), graphCoordinate.getY() - (d/2), d, d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void displayBoat(BoatInRace boat, double angle) {
|
|
|
|
|
GraphCoordinate pos = this.map.convertGPS(boat.getCurrentPosition());
|
|
|
|
|
Paint paint = boat.getColour();
|
|
|
|
|
|
|
|
|
|
double[] x = {pos.getX() - 6, pos.getX(), pos.getX() + 6};
|
|
|
|
|
double[] y = {pos.getY() + 12, pos.getY() - 12, pos.getY() + 12};
|
|
|
|
|
gc.setFill(paint);
|
|
|
|
|
|
|
|
|
|
gc.save();
|
|
|
|
|
rotate(angle, pos.getX(), pos.getY());
|
|
|
|
|
gc.fillPolygon(x, y, 3);
|
|
|
|
|
gc.restore();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -156,6 +170,13 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
|
gc.fillText(text, xCoord, yCoord);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Draws race map with up to date data.
|
|
|
|
|
*/
|
|
|
|
|
public void update() {
|
|
|
|
|
this.drawRaceMap();
|
|
|
|
|
this.updateBoats();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Draws the Race Map
|
|
|
|
|
@ -168,9 +189,6 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
|
gc.clearRect(0, 0, width, height);
|
|
|
|
|
//System.out.println("Race Map Canvas Width: "+ width + ", Height:" + height);
|
|
|
|
|
this.map = new RaceMap(32.278, -64.863, 32.320989, -64.821, (int) width, (int) height);
|
|
|
|
|
if (map == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//finish line
|
|
|
|
|
gc.setLineWidth(2);
|
|
|
|
|
@ -208,7 +226,6 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
|
displayArrow(new GraphCoordinate((int)getWidth()-40, 40), 150);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Toggle the raceAnno value
|
|
|
|
|
*/
|
|
|
|
|
@ -220,6 +237,28 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Draws boats while race in progress, when leg heading is set.
|
|
|
|
|
*/
|
|
|
|
|
public void updateBoats() {
|
|
|
|
|
if (boats != null) {
|
|
|
|
|
for (BoatInRace boat : boats) {
|
|
|
|
|
boolean finished = boat.getCurrentLeg().getName().equals("Finish") || boat.getCurrentLeg().getName().equals("DNF");
|
|
|
|
|
if (!finished) {
|
|
|
|
|
displayBoat(boat, boat.calculateHeading());
|
|
|
|
|
GraphCoordinate wakeFrom = this.map.convertGPS(boat.getCurrentPosition());
|
|
|
|
|
GraphCoordinate wakeTo = this.map.convertGPS(boat.getWake());
|
|
|
|
|
displayLine(wakeFrom, wakeTo, boat.getColour());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
displayBoat(boat, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (raceAnno) displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the Canvas to resizable.
|
|
|
|
|
*
|
|
|
|
|
@ -252,4 +291,17 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
|
return getHeight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Draws boats during race setup, when leg heading is not set.
|
|
|
|
|
*/
|
|
|
|
|
public void drawBoats() {
|
|
|
|
|
if (boats != null) {
|
|
|
|
|
for (BoatInRace boat : boats) {
|
|
|
|
|
if (boat != null) {
|
|
|
|
|
displayBoat(boat, 0);
|
|
|
|
|
if (raceAnno) displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|