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

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

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

Touch.getRelativeY介绍

[英]Gets the touch y-position relative to a given element.
[中]获取相对于给定元素的触摸y位置。

代码示例

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

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

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

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

代码示例来源:origin: thothbot/parallax

protected int getRelativeY ( final Touch touch, final CanvasElement target )
{
  final float yScaleRatio = ( target.getHeight() * 1f ) / target.getClientHeight(); // Correct
                                             // for
                                             // canvas
                                             // CSS
                                             // scaling
  return Math.round( yScaleRatio * touch.getRelativeY( target ) );
}

代码示例来源:origin: com.badlogicgames.gdx/gdx-backend-gwt

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

代码示例来源:origin: threerings/playn

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

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

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

代码示例来源:origin: org.geomajas/geomajas-client-gwt2-example-jar

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

代码示例来源:origin: threerings/playn

private Event.Impl[] toEvents(NativeEvent nativeEvent, Events.Flags flags) {
 // Convert the JsArray<Native Touch> to an array of Touch.Events
 JsArray<com.google.gwt.dom.client.Touch> nativeTouches = nativeEvent.getChangedTouches();
 int nativeTouchesLen = nativeTouches.length();
 Event.Impl[] touches = new Event.Impl[nativeTouchesLen];
 for (int t = 0; t < nativeTouchesLen; t++) {
  com.google.gwt.dom.client.Touch touch = nativeTouches.get(t);
  float x = touch.getRelativeX(rootElement);
  float y = touch.getRelativeY(rootElement);
  Point xy = platform.graphics().transformMouse(x, y);
  int id = getTouchIdentifier(nativeEvent, t);
  touches[t] = new Event.Impl(flags, PlayN.currentTime(), xy.x, xy.y, id);
 }
 return touches;
}

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

private Touch.Event[] toTouchEvents (Touch.Event.Kind kind, NativeEvent nevent) {
 // Convert the JsArray<Native Touch> to an array of Touch.Events
 JsArray<com.google.gwt.dom.client.Touch> nativeTouches = nevent.getChangedTouches();
 int nativeTouchesLen = nativeTouches.length();
 Touch.Event[] touches = new Touch.Event[nativeTouchesLen];
 double time = plat.time();
 for (int t = 0; t < nativeTouchesLen; t++) {
  com.google.gwt.dom.client.Touch touch = nativeTouches.get(t);
  float x = touch.getRelativeX(rootElement);
  float y = touch.getRelativeY(rootElement);
  Point xy = plat.graphics().transformMouse(x, y);
  int id = getTouchIdentifier(nevent, t);
  touches[t] = new Touch.Event(0, time, xy.x, xy.y, kind, id);
 }
 return touches;
}

代码示例来源:origin: io.playn/playn-html

private Touch.Event[] toTouchEvents (Touch.Event.Kind kind, NativeEvent nevent) {
 // Convert the JsArray<Native Touch> to an array of Touch.Events
 JsArray<com.google.gwt.dom.client.Touch> nativeTouches = nevent.getChangedTouches();
 int nativeTouchesLen = nativeTouches.length();
 Touch.Event[] touches = new Touch.Event[nativeTouchesLen];
 double time = plat.time();
 for (int t = 0; t < nativeTouchesLen; t++) {
  com.google.gwt.dom.client.Touch touch = nativeTouches.get(t);
  float x = touch.getRelativeX(rootElement);
  float y = touch.getRelativeY(rootElement);
  Point xy = plat.graphics().transformMouse(x, y);
  int id = getTouchIdentifier(nevent, t);
  touches[t] = new Touch.Event(0, time, xy.x, xy.y, kind, id);
 }
 return touches;
}

代码示例来源:origin: com.allen-sauer.gwt.dnd/gwt-dnd

int y = event.getTouches().get(0).getRelativeY(elem);

代码示例来源:origin: com.googlecode.gwt-cropper/gwt-crop

/**
 * {@inheritDoc}
 */
public void onTouchMove(TouchMoveEvent event) {
  if (this.isDown) {
    JsArray<Touch> touches = event.getTouches();
    if (touches.length() > 0) {
      int x = touches.get(0).getRelativeX(this._container.getElement());
      int y = touches.get(0).getRelativeY(this._container.getElement());
      if (x < 0 || y < 0 || x > nOuterWidth || y > nOuterHeight) {
        /*
         * There is no such method as "onMouseOut" for touching, so we can't rely
         * on event handler. We should process manually these cases, when finger (i.e. cursor) is
         * out of the cropper area.
         *
         * If user moves his finger out of the canvas, then "stick" the selection to the canvas edges
         */
        if (x < 0) x = 0;
        if (x > nOuterWidth) x = nOuterWidth;
        if (y < 0) y = 0;
        if (y > nOuterHeight) y = nOuterHeight;
      }
      this.provideDragging(x, y);
    }
  }
}

代码示例来源:origin: org.dashbuilder/dashbuilder-lienzo-core

private final List<TouchPoint> getTouches(final TouchEvent<?> event)
{
  final JsArray<Touch> jsarray = event.getTouches();
  final Element element = event.getRelativeElement();
  if ((null != jsarray) && (jsarray.length() > 0))
  {
    final int size = jsarray.length();
    final ArrayList<TouchPoint> touches = new ArrayList<TouchPoint>(size);
    for (int i = 0; i < size; i++)
    {
      final Touch touch = jsarray.get(i);
      touches.add(new TouchPoint(touch.getRelativeX(element), touch.getRelativeY(element)));
    }
    return touches;
  }
  else
  {
    int x = event.getNativeEvent().getClientX() - element.getAbsoluteLeft() + element.getScrollLeft() + element.getOwnerDocument().getScrollLeft();
    int y = event.getNativeEvent().getClientY() - element.getAbsoluteTop() + element.getScrollTop() + element.getOwnerDocument().getScrollTop();
    return Arrays.asList(new TouchPoint(x, y));
  }
}

代码示例来源:origin: com.rht-emitrom/lienzo-core

private final ArrayList<TouchPoint> getTouches(TouchEvent<?> event)
{
  ArrayList<TouchPoint> touches = new ArrayList<TouchPoint>();
  JsArray<Touch> jsarray = event.getTouches();
  Element element = event.getRelativeElement();
  if ((null != jsarray) && (jsarray.length() > 0))
  {
    int size = jsarray.length();
    for (int i = 0; i < size; i++)
    {
      Touch touch = jsarray.get(i);
      touches.add(new TouchPoint(touch.getRelativeX(element), touch.getRelativeY(element)));
    }
  }
  else
  {
    int x = event.getNativeEvent().getClientX() - element.getAbsoluteLeft() + element.getScrollLeft() + element.getOwnerDocument().getScrollLeft();
    int y = event.getNativeEvent().getClientY() - element.getAbsoluteTop() + element.getScrollTop() + element.getOwnerDocument().getScrollTop();
    touches.add(new TouchPoint(x, y));
  }
  return touches;
}

代码示例来源:origin: com.ahome-it/lienzo-core

private final List<TouchPoint> getTouches(final TouchEvent<?> event)
{
  final JsArray<Touch> jsarray = event.getTouches();
  final Element element = event.getRelativeElement();
  if ((null != jsarray) && (jsarray.length() > 0))
  {
    final int size = jsarray.length();
    final ArrayList<TouchPoint> touches = new ArrayList<>(size);
    for (int i = 0; i < size; i++)
    {
      final Touch touch = jsarray.get(i);
      touches.add(new TouchPoint(touch.getRelativeX(element), touch.getRelativeY(element)));
    }
    return touches;
  }
  else
  {
    final int x = (event.getNativeEvent().getClientX() - element.getAbsoluteLeft()) + element.getScrollLeft() + element.getOwnerDocument().getScrollLeft();
    final int y = (event.getNativeEvent().getClientY() - element.getAbsoluteTop()) + element.getScrollTop() + element.getOwnerDocument().getScrollTop();
    return Arrays.asList(new TouchPoint(x, y));
  }
}

代码示例来源:origin: ahome-it/lienzo-core

private final List<TouchPoint> getTouches(final TouchEvent<?> event)
{
  final JsArray<Touch> jsarray = event.getTouches();
  final Element element = event.getRelativeElement();
  if ((null != jsarray) && (jsarray.length() > 0))
  {
    final int size = jsarray.length();
    final ArrayList<TouchPoint> touches = new ArrayList<>(size);
    for (int i = 0; i < size; i++)
    {
      final Touch touch = jsarray.get(i);
      touches.add(new TouchPoint(touch.getRelativeX(element), touch.getRelativeY(element)));
    }
    return touches;
  }
  else
  {
    final int x = (event.getNativeEvent().getClientX() - element.getAbsoluteLeft()) + element.getScrollLeft() + element.getOwnerDocument().getScrollLeft();
    final int y = (event.getNativeEvent().getClientY() - element.getAbsoluteTop()) + element.getScrollTop() + element.getOwnerDocument().getScrollTop();
    return Arrays.asList(new TouchPoint(x, y));
  }
}

代码示例来源:origin: ahome-it/lienzo-core

private final List<TouchPoint> getTouches(final TouchEvent<?> event)
{
  final JsArray<Touch> jsarray = event.getTouches();
  final Element element = event.getRelativeElement();
  if ((null != jsarray) && (jsarray.length() > 0))
  {
    final int size = jsarray.length();
    final ArrayList<TouchPoint> touches = new ArrayList<>(size);
    for (int i = 0; i < size; i++)
    {
      final Touch touch = jsarray.get(i);
      touches.add(new TouchPoint(touch.getRelativeX(element), touch.getRelativeY(element)));
    }
    return touches;
  }
  else
  {
    final int x = (event.getNativeEvent().getClientX() - element.getAbsoluteLeft()) + element.getScrollLeft() + element.getOwnerDocument().getScrollLeft();
    final int y = (event.getNativeEvent().getClientY() - element.getAbsoluteTop()) + element.getScrollTop() + element.getOwnerDocument().getScrollTop();
    return Arrays.asList(new TouchPoint(x, y));
  }
}

代码示例来源:origin: org.geomajas/geomajas-client-gwt2-example-jar

@Override
public void onTouchMove(TouchMoveEvent event) {
  if (dragging) {
    if (event.getTouches().length() == 1) {
      Element e = event.getRelativeElement();
      int deltaX = event.getTouches().get(0).getRelativeX(e) - startX;
      int deltaY = event.getTouches().get(0).getRelativeY(e) - startY;
      rectangle.setX(rectangle.getX() + deltaX);
      rectangle.setY(rectangle.getY() + deltaY);
      text.setX(text.getX() + deltaX);
      text.setY(text.getY() + deltaY);
    }
  }
}

代码示例来源:origin: org.geomajas.plugin/geomajas-plugin-javascript-api

public Coordinate getLocation(HumanInputEvent<?> event, String renderSpace) {
  Element el = DOM.getElementById(map.getHtmlElementId()).getFirstChildElement();
  Coordinate location = null;
  if (event instanceof MouseEvent) {
    MouseEvent<?> mEvent = (MouseEvent<?>) event;
    event.setRelativeElement(el);
    location = new Coordinate(mEvent.getX(), mEvent.getY());
  } else if (event instanceof TouchEvent) {
    TouchEvent<?> tEvent = (TouchEvent<?>) event;
    if (tEvent.getTouches().length() > 0) {
      location = new Coordinate(tEvent.getTouches().get(0).getRelativeX(el), tEvent.getTouches().get(0)
          .getRelativeY(el));
    }
  }
  if (location == null) {
    location = new Coordinate(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
  }
  if ("world".equalsIgnoreCase(renderSpace)) {
    return map.getViewPort().transform(location, "screen", renderSpace);
  }
  return location;
}

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

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

相关文章