Refine search
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)); }
this.justTouched = true; JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId; touchMap.put(real, touchId = getAvailablePointer()); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); deltaX[touchId] = getRelativeX(touch, canvas) - touchX[touchId]; for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); touchMap.remove(real); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); touchMap.remove(real);
@Override public void onTouchStart(TouchStartEvent event) { if (event.getTouches().length() == 1) { dragging = true; Element e = event.getRelativeElement(); startX = event.getTouches().get(0).getRelativeX(e); startY = event.getTouches().get(0).getRelativeY(e); } // Stop the event from reaching the map controller: no panning while we're dragging the rectangle. event.stopPropagation(); }
@Override public void onTouchMove(TouchMoveEvent event) { switch (state) { case WAITING: case FINGERS_DOWN: case FINGERS_UP: // compare positions JsArray<Touch> currentTouches = event.getTouches(); for (int i = 0; i < currentTouches.length(); i++) { Touch currentTouch = currentTouches.get(i); for (TouchPoint startTouch : startPositions) { if (currentTouch.getIdentifier() == startTouch.getId()) { if (Math.abs(currentTouch.getPageX() - startTouch.getX()) > DEFAULT_MAX_DISTANCE || Math.abs(currentTouch.getPageY() - startTouch.getY()) > DEFAULT_MAX_DISTANCE) { state = State.INVALID; break; } } if (state == State.INVALID) { break; } } } break; default: state = State.INVALID; break; } }
private boolean isSignificantMove(Event event) { if (touchStart == null) { // no touch start return false; } /* * TODO calculate based on real distance instead of separate * axis checks */ Touch touch = event.getChangedTouches().get(0); if (Math.abs(touch.getClientX() - touchStartX) > TouchScrollDelegate.SIGNIFICANT_MOVE_THRESHOLD) { return true; } if (Math.abs(touch.getClientY() - touchStartY) > TouchScrollDelegate.SIGNIFICANT_MOVE_THRESHOLD) { return true; } return false; }
protected int getClientX(Event e) { if (touchSupported) { return e.getTouches().get(0).getClientX(); } else { return e.getClientX(); } }
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); }
protected int getClientY(Event e) { if (touchSupported) { return e.getTouches().get(0).getClientY(); } else { return e.getClientY(); } } }
@Override public Coordinate getLocation(HumanInputEvent<?> event, RenderSpace renderSpace) { switch (renderSpace) { case WORLD: Coordinate screen = getLocation(event, RenderSpace.SCREEN); return mapPresenter.getViewPort().getTransformationService() .transform(screen, RenderSpace.SCREEN, RenderSpace.WORLD); case SCREEN: default: Element element = mapPresenter.asWidget().getElement(); if (event instanceof MouseEvent<?>) { double offsetX = ((MouseEvent<?>) event).getRelativeX(element); double offsetY = ((MouseEvent<?>) event).getRelativeY(element); return new Coordinate(offsetX, offsetY); } else if (event instanceof TouchEvent<?>) { Touch touch = null; if (event instanceof TouchEndEvent) { touch = ((TouchEvent<?>) event).getChangedTouches().get(0); } else { touch = ((TouchEvent<?>) event).getTouches().get(0); } double offsetX = touch.getRelativeX(element); double offsetY = touch.getRelativeY(element); return new Coordinate(offsetX, offsetY); } return new Coordinate(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY()); } }
private Event.Impl eventFromTouch(final Element rootElement, Touch touch) { float x = touch.getRelativeX(rootElement), y = touch.getRelativeY(rootElement); Point xy = platform.graphics().transformMouse(x, y); return new Event.Impl(new Events.Flags.Impl(), PlayN.currentTime(), xy.x, xy.y, true); } }
public TouchPoint(Touch touch) { this.id = touch.getIdentifier(); this.x = touch.getPageX(); this.y = touch.getPageY(); }
/** * Gets the touch x-position relative to a given element. * * @param target the element whose coordinate system is to be used * @return the relative x-position */ public final int getRelativeX(Element target) { return getClientX() - target.getAbsoluteLeft() + target.getScrollLeft() + target.getOwnerDocument().getScrollLeft(); }
/** * Gets the touch y-position relative to a given element. * * @param target the element whose coordinate system is to be used * @return the relative y-position */ public final int getRelativeY(Element target) { return getClientY() - target.getAbsoluteTop() + target.getScrollTop() + target.getOwnerDocument().getScrollTop(); }