com.google.gwt.dom.client.Touch.getClientX()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中com.google.gwt.dom.client.Touch.getClientX()方法的一些代码示例,展示了Touch.getClientX()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Touch.getClientX()方法的具体详情如下:
包路径:com.google.gwt.dom.client.Touch
类名称:Touch
方法名:getClientX

Touch.getClientX介绍

[英]Gets the touch x-position within the browser window's client area.
[中]获取浏览器窗口客户端区域内的触摸x位置。

代码示例

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * 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();
}

代码示例来源:origin: geogebra/geogebra

private int getX(TouchEvent<?> event) {
  Touch touch = getRelevantTouch(event);
  return touch == null ? 0
      : (touch.getClientX() - widget.getAbsoluteLeft());
}

代码示例来源:origin: info.magnolia.ui/magnolia-ui-vaadin-common-widgets

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;
}

代码示例来源:origin: com.googlecode.gwtquery/gwtquery

protected int getClientX(Event e) {
 if (touchSupported) {
  return e.getTouches().get(0).getClientX();
 } else {
  return e.getClientX();
 }
}

代码示例来源:origin: dankurka/mgwt

@Override
public void onTouchMove(TouchMoveEvent event) {
 setValueContrained(event.getTouches().get(0).getClientX());
 event.stopPropagation();
 event.preventDefault();
}

代码示例来源:origin: com.googlecode.mgwt/mgwt

@Override
public void onTouchMove(TouchMoveEvent event) {
 setValueContrained(event.getTouches().get(0).getClientX());
 event.stopPropagation();
 event.preventDefault();
}

代码示例来源:origin: net.wetheinter/gwt-user

/**
 * 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();
}

代码示例来源:origin: com.vaadin.external.gwt/gwt-user

/**
 * 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();
}

代码示例来源:origin: info.magnolia.ui/magnolia-ui-vaadin-common-widgets

/**
   * Calculates how many pixels away the user's finger has traveled. This
   * reduces the chance of small non-intentional movements from canceling
   * the long press detection.
   *
   * @param event
   *            the Event for which to check the move distance
   * @return true if this is considered an intentional move by the user
   */
  protected boolean isSignificantMove(Event event) {
    if (touchStart == null) {
      // no touch start
      return false;
    }
    // Calculate the distance between touch start and the current touch
    // position
    Touch touch = event.getChangedTouches().get(0);
    int deltaX = touch.getClientX() - touchStartX;
    int deltaY = touch.getClientY() - touchStartY;
    int delta = deltaX * deltaX + deltaY * deltaY;
    // Compare to the square of the significant move threshold to remove
    // the need for a square root
    if (delta > TouchScrollDelegate.SIGNIFICANT_MOVE_THRESHOLD
        * TouchScrollDelegate.SIGNIFICANT_MOVE_THRESHOLD) {
      return true;
    }
    return false;
  }
}

代码示例来源:origin: sriharshachilakapati/SilenceEngine

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);
}

代码示例来源:origin: com.googlecode.mgwt/mgwt

@Override
public void onTouchMove(TouchMoveEvent event) {
  if (isReadOnly()) {
    return;
  }
  event.stopPropagation();
  event.preventDefault();
  Touch touch = event.getTouches().get(0);
  now_x = touch.getClientX();
  if (!moved) {
    if (Math.abs(now_x - x_start) < appearance.css().DRAG_DEADZONE()) {
      return;
    }
  }
  moved = true;
  int translate_x = now_x - x_start;
  if (translate_x < x_min) {
    return;
  }
  if (translate_x > x_max) {
    return;
  }
  translate(translate_x + offset);
}

代码示例来源:origin: dankurka/mgwt

@Override
public void onTouchMove(TouchMoveEvent event) {
  if (isReadOnly()) {
    return;
  }
  event.stopPropagation();
  event.preventDefault();
  Touch touch = event.getTouches().get(0);
  now_x = touch.getClientX();
  if (!moved) {
    if (Math.abs(now_x - x_start) < appearance.css().DRAG_DEADZONE()) {
      return;
    }
  }
  moved = true;
  int translate_x = now_x - x_start;
  if (translate_x < x_min) {
    return;
  }
  if (translate_x > x_max) {
    return;
  }
  translate(translate_x + offset);
}

代码示例来源:origin: geogebra/geogebra

@Override
  public void onTouchEnd(TouchEndEvent event) {
    if (handler.preventDefault) {
      event.preventDefault();
    }
    if (handler.stopPropagation) {
      event.stopPropagation();
    }
    Touch removedTouch = event.getChangedTouches().get(0);
    handler.onClickEnd(removedTouch.getClientX(),
        removedTouch.getClientY(),
        PointerEventType.TOUCH);
    CancelEventTimer.touchEventOccured();
  }
}, TouchEndEvent.getType());

代码示例来源:origin: com.googlecode.mgwt/mgwt

@Override
public void onTouchStart(TouchStartEvent event) {
 setValueContrained(event.getTouches().get(0).getClientX());
 if (MGWT.getFormFactor().isDesktop()) {
  DOM.setCapture(getElement());
 }
 event.stopPropagation();
 event.preventDefault();
}

代码示例来源:origin: dankurka/mgwt

@Override
public void onTouchStart(TouchStartEvent event) {
 setValueContrained(event.getTouches().get(0).getClientX());
 if (MGWT.getFormFactor().isDesktop()) {
  DOM.setCapture(getElement());
 }
 event.stopPropagation();
 event.preventDefault();
}

代码示例来源:origin: geogebra/geogebra

@Override
  public void onTouchStart(TouchStartEvent event) {
    if (handler.preventDefault) {
      event.preventDefault();
    }
    if (handler.stopPropagation) {
      event.stopPropagation();
    }
    handler.onClickStart(event.getTouches().get(0).getClientX(),
        event.getTouches().get(0).getClientY(),
        PointerEventType.TOUCH);
    CancelEventTimer.touchEventOccured();
  }
}, TouchStartEvent.getType());

代码示例来源:origin: org.geomajas/geomajas-gwt-client-impl

/**
 * Method used to calculate exact middle point between multiple touches of a touch events.
 * 
 * @param event a touch event
 * @return middle point
 */
private Coordinate getMidPoint(TouchEvent<?> event) {
  Coordinate[] coords = new Coordinate[event.getTouches().length()];
  for (int i = 0; i < event.getTargetTouches().length(); i++) {
    coords[i] = new Coordinate(event.getTouches().get(i).getClientX(), event.getTouches().get(i).getClientY());
  }
  double x = 0;
  double y = 0;
  for (Coordinate coord : coords) {
    x += coord.getX();
    y += coord.getY();
  }
  x /= coords.length;
  y /= coords.length;
  return new Coordinate(x, y);
}

代码示例来源:origin: org.geomajas/geomajas-gwt-client-impl

@Override
public Coordinate getLocation(HumanInputEvent<?> event, RenderSpace renderSpace) {
  switch (renderSpace) {
    case WORLD:
      Coordinate screen = getLocation(event, RenderSpace.SCREEN);
      return mapPresenter.getViewPort().transform(screen, RenderSpace.SCREEN, RenderSpace.WORLD);
    case SCREEN:
    default:
      if (event instanceof MouseEvent<?>) {
        Element element = mapPresenter.asWidget().getElement();
        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());
  }
}

代码示例来源:origin: dankurka/mgwt

@Override
  public void onTouchStart(TouchStartEvent event) {
    if (isReadOnly()) {
      return;
    }
    event.stopPropagation();
    event.preventDefault();
    if (MGWT.getFormFactor().isDesktop()) {
      DOM.setCapture(getElement());
    }
    Touch touch = event.getTouches().get(0);
    x_start = touch.getClientX();
    moved = false;
    if (value) {
      x_min = appearance.css().CONTAINER_MIN_ON();
      x_max = appearance.css().CONTAINER_MAX_ON();
      offset = appearance.css().CONTAINER_OFFSET_ON();
    } else {
     x_min = appearance.css().CONTAINER_MIN_OFF();
  x_max = appearance.css().CONTAINER_MAX_OFF();
  offset = appearance.css().CONTAINER_OFFSET_OFF();
    }
  }
}

代码示例来源:origin: com.googlecode.mgwt/mgwt

@Override
  public void onTouchStart(TouchStartEvent event) {
    if (isReadOnly()) {
      return;
    }
    event.stopPropagation();
    event.preventDefault();
    if (MGWT.getFormFactor().isDesktop()) {
      DOM.setCapture(getElement());
    }
    Touch touch = event.getTouches().get(0);
    x_start = touch.getClientX();
    moved = false;
    if (value) {
      x_min = appearance.css().CONTAINER_MIN_ON();
      x_max = appearance.css().CONTAINER_MAX_ON();
      offset = appearance.css().CONTAINER_OFFSET_ON();
    } else {
     x_min = appearance.css().CONTAINER_MIN_OFF();
  x_max = appearance.css().CONTAINER_MAX_OFF();
  offset = appearance.css().CONTAINER_OFFSET_OFF();
    }
  }
}

相关文章