mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-04 03:13:49 +00:00
started to move new boat icons to resources; started with preliminary boat rotation depending on bearing
This commit is contained in:
1 parent
a524baf0d0
commit
8e8034a57c
22 files changed
+80
-3
No files matched your search
+13
-1
@@ -23,6 +23,18 @@ interface AdminConsoleResources extends ClientBundle {
|
||||
@Source("com/sap/sailing/gwt/ui/client/images/dice.png")
|
||||
ImageResource scoresIcon();
|
||||
|
||||
@Source("com/sap/sailing/gwt/ui/client/images/reddiamond.png")
|
||||
@Source("com/sap/sailing/gwt/ui/client/images/coursemark.png")
|
||||
ImageResource buoyIcon();
|
||||
|
||||
@Source("com/sap/sailing/gwt/ui/client/images/DarkGreyBoats/DarkGreyDW_Port.png")
|
||||
ImageResource lowlightedBoatIconDW_Port();
|
||||
|
||||
@Source("com/sap/sailing/gwt/ui/client/images/DarkGreyBoats/DarkGreyDW_Starbord.png")
|
||||
ImageResource lowlightedBoatIconDW_Starboard();
|
||||
|
||||
@Source("com/sap/sailing/gwt/ui/client/images/YellowBoats/YellowDW_Port.png")
|
||||
ImageResource highlightedBoatIconDW_Port();
|
||||
|
||||
@Source("com/sap/sailing/gwt/ui/client/images/YellowBoats/YellowDW_Starbord.png")
|
||||
ImageResource highlightedBoatIconDW_Starboard();
|
||||
}
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
package com.sap.sailing.gwt.ui.client;
|
||||
|
||||
import com.google.gwt.canvas.client.Canvas;
|
||||
import com.google.gwt.canvas.dom.client.Context2d;
|
||||
import com.google.gwt.dom.client.ImageElement;
|
||||
import com.google.gwt.event.dom.client.LoadEvent;
|
||||
import com.google.gwt.event.dom.client.LoadHandler;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
|
||||
/**
|
||||
* Loads an image from a URL, draws it to a {@link Canvas}, rotates it by a specified angle and allows clients
|
||||
* to obtain a URL for the rotated image contents to be used in other contexts requiring an image URL.
|
||||
*
|
||||
* @author Axel Uhl (d043530)
|
||||
*
|
||||
*/
|
||||
public class ImageRotator {
|
||||
private final String unrotatedImageURL;
|
||||
|
||||
private final Canvas canvas;
|
||||
|
||||
private ImageElement imageElement;
|
||||
|
||||
public ImageRotator(String unrotatedImageURL) {
|
||||
this.unrotatedImageURL = unrotatedImageURL;
|
||||
canvas = Canvas.createIfSupported();
|
||||
final Image image = new Image(unrotatedImageURL.toString());
|
||||
imageElement = (ImageElement) image.getElement().cast();
|
||||
image.addLoadHandler(new LoadHandler() {
|
||||
@Override
|
||||
public void onLoad(LoadEvent event) {
|
||||
imageElement = (ImageElement) image.getElement().cast();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String getUnrotatedImageURL() {
|
||||
return unrotatedImageURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the platform supports the {@link Canvas} element, returns a view rotated by <code>degrees</code> degrees. Otherwise,
|
||||
* the {@link #getUnrotatedImageURL() unrotated image's URL} is returned.
|
||||
*/
|
||||
public String getRotatedImageURL(double angleInDegrees) {
|
||||
String result = getUnrotatedImageURL();
|
||||
if (canvas != null) {
|
||||
Context2d context = canvas.getContext2d();
|
||||
if (imageElement != null) {
|
||||
context.clearRect(0, 0, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight());
|
||||
double angleInRadians = angleInDegrees/180.*Math.PI;
|
||||
context.rotate(angleInRadians);
|
||||
context.drawImage(imageElement, 0, 0);
|
||||
result = canvas.toDataUrl("image/png");
|
||||
context.rotate(-angleInRadians);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+7
-2
@@ -78,6 +78,7 @@ public class RaceMapPanel extends FormPanel implements EventDisplayer, TimeListe
|
||||
private final TimePanel timePanel;
|
||||
private Icon boatIcon;
|
||||
private Icon boatIconHighlighted;
|
||||
private ImageRotator boatIconHighlightedRotator;
|
||||
private Icon buoyIcon;
|
||||
private Icon tackToStarboardIcon;
|
||||
private Icon tackToPortIcon;
|
||||
@@ -386,11 +387,14 @@ public class RaceMapPanel extends FormPanel implements EventDisplayer, TimeListe
|
||||
lastMousePosition = event.getLatLng();
|
||||
}
|
||||
});
|
||||
boatIcon = Icon.newInstance("/images/blackdot.png");
|
||||
// FIXME anchor for new icon is probably somewhere else
|
||||
boatIcon = Icon.newInstance(resources.lowlightedBoatIconDW_Port().getSafeUri().asString());
|
||||
boatIcon.setIconAnchor(Point.newInstance(8, 8));
|
||||
boatIconHighlighted = Icon.newInstance("/images/reddot.png");
|
||||
boatIconHighlighted = Icon.newInstance(resources.highlightedBoatIconDW_Port().getSafeUri().asString());
|
||||
boatIconHighlighted.setIconAnchor(Point.newInstance(8, 8));
|
||||
boatIconHighlightedRotator = new ImageRotator(resources.lowlightedBoatIconDW_Port().getSafeUri().asString());
|
||||
buoyIcon = Icon.newInstance(resources.buoyIcon().getSafeUri().asString());
|
||||
// FIXME anchor for smaller icon is probably closer to 3,3 than to 7,7
|
||||
buoyIcon.setIconAnchor(Point.newInstance(7, 7));
|
||||
tackToStarboardIcon = Icon
|
||||
.newInstance("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=T|00FF00|000000");
|
||||
@@ -756,6 +760,7 @@ public class RaceMapPanel extends FormPanel implements EventDisplayer, TimeListe
|
||||
} else {
|
||||
competitorDAOsOfUnusedMarkers.remove(competitorDAO);
|
||||
boatMarker.setLatLng(LatLng.newInstance(lastPos.position.latDeg, lastPos.position.lngDeg));
|
||||
boatMarker.setImage(boatIconHighlightedRotator.getRotatedImageURL(lastPos.speedWithBearing.bearingInDegrees));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user