mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-04 01:59:35 +00:00
Helper class to capture mouse movements on the canvas for CanvasOverlay class.
This commit is contained in:
1 parent
34c2a47209
commit
fff4e2e4be
1 file changed
+72
+72
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.sap.sailing.gwt.ui.simulator.util;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gwt.canvas.client.Canvas;
|
||||
import com.google.gwt.canvas.dom.client.Context2d;
|
||||
import com.google.gwt.canvas.dom.client.ImageData;
|
||||
import com.google.gwt.event.dom.client.MouseMoveEvent;
|
||||
import com.google.gwt.event.dom.client.MouseMoveHandler;
|
||||
import com.sap.sailing.gwt.ui.shared.WindDTO;
|
||||
|
||||
/**
|
||||
* To handle MouseMoveEvent to display tool tips around WindDTO objects in a wind field
|
||||
*
|
||||
* @author Nidhi Sawhney(D054070)
|
||||
*
|
||||
*/
|
||||
public class WindFieldMouseMoveHandler implements MouseMoveHandler {
|
||||
|
||||
private Canvas canvas;
|
||||
private Map<ToolTip, WindDTO> windFieldPoints = null;
|
||||
private ImageData lastImageData = null;
|
||||
double lastToolx;
|
||||
double lastTooly;
|
||||
|
||||
|
||||
public WindFieldMouseMoveHandler(Canvas canvas) {
|
||||
super();
|
||||
this.canvas = canvas;
|
||||
}
|
||||
|
||||
public void setWindFieldPoints(Map<ToolTip, WindDTO> windFieldPoints) {
|
||||
this.windFieldPoints = windFieldPoints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseMove(MouseMoveEvent event) {
|
||||
|
||||
if (windFieldPoints == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
double x = event.getX();
|
||||
double y = event.getY();
|
||||
ToolTip point = new ToolTip(x, y);
|
||||
Context2d context2d = canvas.getContext2d();
|
||||
if (lastImageData != null) {
|
||||
context2d.putImageData(lastImageData, lastToolx, lastTooly);
|
||||
}
|
||||
lastToolx = x;
|
||||
lastTooly = y;
|
||||
|
||||
lastImageData = context2d.getImageData(x, y, ToolTip.toolRectW, ToolTip.toolRectH);
|
||||
|
||||
if (windFieldPoints.containsKey(point)) {
|
||||
|
||||
WindDTO windDTO = windFieldPoints.get(point);
|
||||
context2d.setFillStyle("#4f4f4f");
|
||||
context2d.fillRect(x, y, ToolTip.toolRectW, ToolTip.toolRectH);
|
||||
|
||||
context2d.setFillStyle("#FFFFFF");
|
||||
context2d.fillRect(x + 3, y + 3, ToolTip.toolRectW - 6, ToolTip.toolRectH - 6);
|
||||
context2d.setFillStyle("Blue");
|
||||
context2d.fillText("Wind " + windDTO.trueWindBearingDeg, x + 15, y + 20);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user