@Override public Point apply(Touch touch) { return new Point(touch.getClientX(), touch.getClientY()); }
@Override public void onTouchEvent(TouchEvent event) { NativeEvent nativeEvent = event.getNativeEvent(); JsArray<Touch> touches = nativeEvent.getTouches(); boolean isMouseClick = isMouseClick(touches); // method is also called // when MouseEvents // occur boolean isOneFingerTouch = isOneFingerTouch(touches); switch (event.getType()) { case TOUCH_START: if (isMouseClick || isOneFingerTouch) { onTouchStart(nativeEvent); } else { onTouchCancel(nativeEvent); } break; case TOUCH_CANCEL: case TOUCH_END: onTouchEnd(nativeEvent); break; case TOUCH_MOVE: if (isMouseClick || isOneFingerTouch) { onTouchMove(nativeEvent); } else { onTouchCancel(nativeEvent); } break; default: break; } }
@Override protected int getEventPosition(Event ev) { JsArray<Touch> touches = ev.getTouches(); int retval; if (touches != null && touches.length() > 0) { Touch t = touches.get(0); retval = t.getPageX(); // retval= t.getClientX() - getAbsoluteLeft(); // GwtUtil.showDebugMsg("retval="+retval+ ", cx="+t.getClientX()+ ", al=" +getAbsoluteLeft()); } else { retval = ev.getClientX() + Window.getScrollLeft(); } return retval; }
@Override public void onTouchEnd(TouchEndEvent p_event) { if (!m_hasTouchMoved) { p_event.preventDefault(); Touch touch = p_event.getChangedTouches().get(0); Element current = getElement(); Element parent = current.getParentElement(); int x = touch.getPageX() - current.getOffsetLeft() - parent.getOffsetLeft(); int y = touch.getPageY() - current.getOffsetTop() - parent.getOffsetTop(); onUp(UserAction.Touch, x, y); } }
private Touch getTouch(JsArray<Touch> touches, int identifier) { if (touches != null && !isZoomed()) { if (identifier == -1) { if (touches.length() > 0) { return touches.get(0); } } else if (touches.length() == 1) { Touch touch = touches.get(0); if (touch.getIdentifier() == identifier) { return touch; } } } return null; }
private void postTouchEvents(JsArray<Touch> touches, boolean isDown) { int i, j; // Browsers report only the available touches in a list. So update all the touches in the list accurately. // We ignore the touches past finger 9 (only ten fingers are read). for (i = 0, j = com.shc.silenceengine.input.Touch.FINGER_0; i < touches.length() && j <= com.shc.silenceengine.input.Touch.FINGER_9; i++, j++) { Touch touch = touches.get(i); postTouchEvent(j, isDown, touch.getClientX(), touch.getClientY()); } // For all the remain fingers, set the finger down state to false. Otherwise they are reported as down // continuously. This will fix that issue. while (j <= com.shc.silenceengine.input.Touch.FINGER_9) postTouchEvent(j++, false, 0, 0); }
@Override public Coordinate getLocation(HumanInputEvent<?> event, RenderSpace renderSpace) { switch (renderSpace) { case WORLD: Coordinate screen = getLocation(event, RenderSpace.SCREEN); return mapWidget.getMapModel().getMapView().getWorldViewTransformer().viewToWorld(screen); case SCREEN: default: if (event instanceof MouseEvent<?>) { Element element = mapWidget.getDOM(); double offsetX = ((MouseEvent<?>) event).getRelativeX(element); double offsetY = ((MouseEvent<?>) event).getRelativeY(element); return new Coordinate(offsetX, offsetY); } else if (event instanceof TouchEvent<?>) { Touch touch = ((TouchEvent<?>) event).getTouches().get(0); return new Coordinate(touch.getClientX(), touch.getClientY()); } return new Coordinate(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY()); } }
public void onTouchStart(TouchStartEvent event) { if (isEnabled()) { Touch touch = event.getTouches().get(0).cast(); handleMouseDown(touch.getPageX(), touch.getPageY()); event.stopPropagation(); } }
private boolean isMouseClick(JsArray<Touch> touches) { return (touches == null) && pointerEventsCoordinates.isEmpty(); }
public int getYPositionRelativeToTarget(NativeEvent event, Element target) { Touch touch = getTouch(event); float positionY = 0;// hack dont change to int if (touch == null) { positionY = getRelativeY(event, target); } else { positionY = touch.getRelativeY(target); } return (int) positionY; }
/** * zwraca relatywna pozycje X zdarzenia do elementu target * * @param event * @param target * @return */ public int getXPositionRelativeToTarget(NativeEvent event, Element target) { Touch touch = getTouch(event); float positionX = 0; // hack dont change to int if (touch == null) { positionX = getRelativeX(event, target); } else { positionX = touch.getRelativeX(target); } return (int) positionX; }
private Touch getTouch(NativeEvent event) { JsArray<Touch> touches = event.getChangedTouches(); Touch touch = null; if (touches != null && touches.length() == 1) { touch = touches.get(0); } return touch; }
public void onTouchMove(TouchMoveEvent e) { // GWT.log("touchmove"); e.preventDefault(); Touch t = e.getTouches().get(0); doMouseMove(t.getRelativeX(getElement())); }
public void onTouchStart(TouchStartEvent event) { // GWT.log("touchstart"); event.preventDefault(); dragging=false; Touch t = event.getTouches().get(0); doMouseDown(t.getRelativeX(getElement()), false); }
@Override protected int getEventPosition(Event ev) { JsArray<Touch> touches = ev.getTouches(); int retval; if (touches != null && touches.length() > 0) { Touch t = touches.get(0); retval = t.getPageY(); // retval= t.getClientY() - getAbsoluteTop(); // GwtUtil.showDebugMsg("retval="+retval+ ", cx="+t.getClientY()+ ", al=" +getAbsoluteTop()); } else { retval = ev.getClientY() + Window.getScrollTop(); } return retval; }
private int getAbsoluteX(HumanInputEvent ev) { if (ev instanceof MouseEvent) { return ((MouseEvent)ev).getClientX()+Window.getScrollLeft(); } if (ev instanceof TouchEvent) { JsArray<Touch> tAry= ((TouchEvent)ev).getTargetTouches(); return tAry.get(0).getClientX()+Window.getScrollLeft(); } return 0; }
private int getAbsoluteY(HumanInputEvent ev) { if (ev instanceof MouseEvent) { return ((MouseEvent)ev).getClientY()+ Window.getScrollTop(); } if (ev instanceof TouchEvent) { JsArray<Touch> tAry= ((TouchEvent)ev).getTargetTouches(); return tAry.get(0).getClientY() + Window.getScrollTop(); } return 0; }
public void onTouchMove(TouchMoveEvent ev) { // if (ev.getTouches().length()>1) return; Touch t= ev.getTargetTouches().get(0); if (DEBUG) { GwtUtil.showDebugMsg("move, touches:" + ev.getTargetTouches().length() + " - c: " +t.getClientX()+","+t.getClientY() + " - p: " +t.getPageX()+","+t.getPageY() + " - s: " +t.getScreenX()+","+t.getScreenY() + " - r: " +t.getRelativeX(_mouseMoveArea.getElement())+","+t.getRelativeY(_mouseMoveArea.getElement())+ " - pos: " +_mouseMoveArea.getAbsoluteLeft()+","+_mouseMoveArea.getAbsoluteTop()+"," + " - scroll: " +_mouseMoveArea.getElement().getScrollLeft()+","+ _mouseMoveArea.getElement().getScrollTop()+"," + " - absScroll: " +_mouseMoveArea.getElement().getOwnerDocument().getScrollLeft()+","+ _mouseMoveArea.getElement().getOwnerDocument().getScrollTop()); } ScreenPt spt= makeScreenPt(ev); boolean enabledOthers= true; if (_exclusiveMouse.size()>0) { // MouseInfo mi= _exclusiveMouse.peek(); WebPlotView.MouseInfo mi; int len= _exclusiveMouse.size(); boolean enabledExclusive= true; for(int i= 1; ((len-i)>=0 && enabledExclusive); i++) { mi= _exclusiveMouse.get(len-i); if (mi.isEnabled()) mi.getHandler().onTouchMove(_pv, spt, ev); enabledExclusive= mi.getEnableAllExclusive(); enabledOthers= mi.getEnableAllPersistent(); } } if (enabledOthers) { for(WebPlotView.MouseInfo info : _persistentMouse) { if (info.isEnabled()) info.getHandler().onTouchMove(_pv, spt, ev); } } ev.preventDefault(); }
private ScreenPt makeScreenPt(TouchEvent ev) { Touch t= (Touch)ev.getTouches().get(0); return new ScreenPt(_pv.getScrollX()+t.getClientX() - _mouseMoveArea.getAbsoluteLeft(), _pv.getScrollY()+t.getClientY()- _mouseMoveArea.getAbsoluteTop()); }
@Override public void onTouchStart(TouchStartEvent event) { if (touchId != null || isMouseDown) return; Touch touch = event.getTouches().get(0); touchId = touch.getIdentifier(); x = touch.getClientX(); y = touch.getClientY(); event.preventDefault(); }
@Override public void onTouchEnd(TouchEndEvent event) { if (touchId == null) return; JsArray<Touch> touches = event.getTouches(); for (int i = 0; i < touches.length(); i++) { Touch touch = touches.get(i); if (touch.getIdentifier() == touchId) return; } touchId = null; event.preventDefault(); }
@Override public void onTouchMove(TouchMoveEvent event) { if (touchId == null) return; JsArray<Touch> touches = event.getTouches(); for (int i = 0; i < touches.length(); i++) { Touch touch = touches.get(i); if (touch.getIdentifier() != touchId) continue; pan(touch.getClientX() - x, touch.getClientY() - y); x = touch.getClientX(); y = touch.getClientY(); event.preventDefault(); } }
@Override public void onTouchStart(TouchStartEvent p_event) { Touch touch = getTouch(p_event.getChangedTouches(), -1); if (touch != null) { m_currentTouchEventId = touch.getIdentifier(); onDown(Element.as(touch.getTarget()), touch.getClientX(), touch.getClientY()); } }
@Override public void onTouchMove(TouchMoveEvent p_event) { Touch touch = getTouch(p_event.getChangedTouches(), m_currentTouchEventId); if (touch != null) { if (p_event.getTouches().length() < 2) { // A single finger touch shouldn't be propagated upwards. // This prevents iOS 'bounce-scroll' to happen p_event.preventDefault(); } onMove(Element.as(touch.getTarget()), touch.getClientX(), touch.getClientY()); } }
@Override public void onTouchEnd(TouchEndEvent p_event) { Touch touch = getTouch(p_event.getChangedTouches(), m_currentTouchEventId); if (touch != null) { m_currentTouchEventId = -1; onUp(Element.as(touch.getTarget())); } }
@Override public void onTouchCancel(TouchCancelEvent p_event) { Touch touch = getTouch(p_event.getChangedTouches(), m_currentTouchEventId); if (touch != null) { m_currentTouchEventId = -1; onOut(Element.as(touch.getTarget())); } }
private int[] touchToPoint(JsArray<Touch> touchs){ //JsArray<Touch> touchs=event.getTouches(); if(touchs.length()>0){ Touch touch=touchs.get(0); int x=touch.getRelativeX(canvas.getElement()); int y=touch.getRelativeY(canvas.getElement()); return new int[]{x,y}; } return null; }
private void setColour(TouchEvent event, Canvas targetCanvas, VerticalPanel targetPanel) { if (event.getTouches().length() > 0) { final JsArray<Touch> touches = event.getTargetTouches(); if (touches.length() > 0) { Touch touch = touches.get(0); setColour(touch.getRelativeX(targetCanvas.getElement()), touch.getRelativeY(targetCanvas.getElement()), targetCanvas, targetPanel); } } }
private void setHue(TouchEvent event, Canvas targetCanvas) { if (event.getTouches().length() > 0) { final JsArray<Touch> touches = event.getTargetTouches(); if (touches.length() > 0) { Touch touch = touches.get(0); setHue(touch.getRelativeX(targetCanvas.getElement()), touch.getRelativeY(targetCanvas.getElement()), targetCanvas); } } }
@Override public void onTouchStart(TouchStartEvent event) { if( m_isMouseDown ) return; Touch touch = event.getTouches().get(0); onMouseOrTouchDown(event, touch.getRelativeX(m_container.getElement()), touch.getRelativeY(m_container.getElement()), true); }
@Override public void onTouchMove(TouchMoveEvent event) { s_logger.log(Level.INFO, "move"); Touch touch = event.getTouches().get(0); this.setMousePoint(touch.getRelativeX(m_container.getElement()), touch.getRelativeY(m_container.getElement()), m_mouseEvent.getPoint()); m_mouseEvent.set(E_MouseEventType.MOUSE_MOVE, 0, Element.as(event.getNativeEvent().getEventTarget()), true); dispatchEvent(m_mouseEvent); }
public void onTouchMove(TouchMoveEvent event) { if (isEnabled()) { Touch touch = event.getTouches().get(0).cast(); handleMouseMove(touch.getPageX(), touch.getPageY()); if (dragging) { event.preventDefault(); } } }
private List<Point> getPoints(TouchEvent<? extends EventHandler> touchEvent) { JsArray<Touch> touches = touchEvent.getTouches(); JsArrayIterable<Touch> iterableTouches = JsArrayIterable.create(touches); return FluentIterable.from(iterableTouches).transform(touchToPointTransforemer).toList(); }
private boolean isOneFingerTouch(JsArray<Touch> touches) { return touchEventChecker.isOnlyOneFinger(touches) || pointerEventsCoordinates.isOnePointer(); }
private Point<Integer> getTouchPoint(JsArray<Touch> touches) { Touch touch = touches.get(0); Point<Integer> point = new Point<Integer>(touch.getScreenX(), touch.getScreenY()); return point; }
private double[] canvasPosition(Canvas canvas, Touch t) { return new double[] { t.getRelativeX(canvas.getElement()), t.getRelativeY(canvas.getElement()) }; }
public void onTouchStart(TouchStartEvent ev) { // if (ev.getTouches().length()>1) return; boolean exclusive= _exclusiveMouse.size()>0; Touch t= ev.getTargetTouches().get(0); if (DEBUG) { GwtUtil.showDebugMsg("start, touches:" + ev.getTargetTouches().length() + " - c: " +t.getClientX()+","+t.getClientY() + " - p: " +t.getPageX()+","+t.getPageY() + " - s: " +t.getScreenX()+","+t.getScreenY() + " - r: " +t.getRelativeX(_mouseMoveArea.getElement())+","+t.getRelativeY(_mouseMoveArea.getElement())+ " - pos: " +_mouseMoveArea.getAbsoluteLeft()+","+_mouseMoveArea.getAbsoluteTop()+"," + " - scroll: " +_mouseMoveArea.getElement().getScrollLeft()+","+ _mouseMoveArea.getElement().getScrollTop()+"," + " - absScroll: " +_mouseMoveArea.getElement().getOwnerDocument().getScrollLeft()+","+ _mouseMoveArea.getElement().getOwnerDocument().getScrollTop()); } ScreenPt spt= makeScreenPt(ev); if (!exclusive) addPreventEvent(); _pv.enableFocus(); if (!exclusive) { DOM.releaseCapture(_mouseMoveArea.getElement()); DOM.setCapture(_mouseMoveArea.getElement()); } boolean enabledOthers= true; if (exclusive) { WebPlotView.MouseInfo mi; int len= _exclusiveMouse.size(); boolean enabledExclusive= true; for(int i= 1; ((len-i)>=0 && enabledExclusive); i++) { mi= _exclusiveMouse.get(len-i); if (mi.isEnabled()) mi.getHandler().onTouchStart(_pv, spt, ev); enabledExclusive= mi.getEnableAllExclusive(); enabledOthers= mi.getEnableAllPersistent(); } } if (enabledOthers) { for(WebPlotView.MouseInfo info : _persistentMouse) { if (info.isEnabled()) info.getHandler().onTouchStart(_pv, spt, ev); } } _mouseDown= true; _pv.disableTextSelect(true); ev.preventDefault(); }
protected int getRelativeX (Touch touch, CanvasElement target) { float xScaleRatio = target.getWidth() * 1f / target.getClientWidth(); // Correct for canvas CSS scaling return Math.round(xScaleRatio * touch.getRelativeX(target)); }
protected int getRelativeY (Touch touch, CanvasElement target) { float yScaleRatio = target.getHeight() * 1f / target.getClientHeight(); // Correct for canvas CSS scaling return Math.round(yScaleRatio * touch.getRelativeY(target)); }
private Coordinate getWorldLocation(Touch touch, RenderSpace world) { Element element = mapPresenter.asWidget().getElement(); Coordinate c = new Coordinate(touch.getRelativeX(element), touch.getRelativeY(element)); return mapPresenter.getViewPort().getTransformationService() .transform(c, RenderSpace.SCREEN, RenderSpace.WORLD); }