protected int[] getCoordinates(GwtEvent<? extends EventHandler> event) { if (event instanceof TouchEvent) { return getPositionInTouch((TouchEvent<? extends EventHandler>) event); } else if (event instanceof MouseEvent) { MouseEvent<? extends EventHandler> me = (MouseEvent<? extends EventHandler>) event; return new int[] {me.getRelativeX(canvas.getElement()), me.getRelativeY(canvas.getElement())}; } return null; }
private int[] getPositionInTouch(TouchEvent<? extends EventHandler> event) { if (event instanceof TouchEndEvent) return new int[] {previousX, previousY}; JsArray<Touch> touches = event.getTouches(); if (touches == null || touches.length() == 0) return null; // Get the first touch Touch touch = touches.get(0); int x = touch.getRelativeX(canvas.getElement()); int y = touch.getRelativeY(canvas.getElement()); return new int[] {x, y}; }