Search in sources :

Example 11 with Point

use of pythagoras.f.Point in project playn by threerings.

the class HtmlPointer method eventFromTouch.

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);
}
Also used : PointerImpl(playn.core.PointerImpl) Point(pythagoras.f.Point)

Example 12 with Point

use of pythagoras.f.Point in project playn by threerings.

the class HtmlPointer method eventFromMouse.

private Event.Impl eventFromMouse(final Element rootElement, NativeEvent nativeEvent) {
    float x = HtmlInput.getRelativeX(nativeEvent, rootElement);
    float y = HtmlInput.getRelativeY(nativeEvent, rootElement);
    Point xy = platform.graphics().transformMouse(x, y);
    return new Event.Impl(new Events.Flags.Impl(), PlayN.currentTime(), xy.x, xy.y, false);
}
Also used : PointerImpl(playn.core.PointerImpl) Point(pythagoras.f.Point)

Example 13 with Point

use of pythagoras.f.Point in project playn by threerings.

the class HtmlTouch method toEvents.

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;
}
Also used : TouchImpl(playn.core.TouchImpl) Point(pythagoras.f.Point) Point(pythagoras.f.Point) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 14 with Point

use of pythagoras.f.Point in project playn by threerings.

the class LayerUtilTest method testTransformWithScale.

@Test
public void testTransformWithScale() {
    TestGroupLayer root = new TestGroupLayer();
    TestGroupLayer middle = new TestGroupLayer();
    TestLayer child = new TestLayer();
    root.add(middle);
    middle.add(child);
    middle.setScale(2f, 0.1f);
    Point point = new Point(100f, 100f);
    Point pointOnChild = new Point(0f, 0f);
    Layer.Util.screenToLayer(child, point, pointOnChild);
    assertEquals(point.x() * 0.5, pointOnChild.x(), tol);
    assertEquals(point.y() * 10, pointOnChild.y(), tol);
    Point pointOnParent = new Point(0f, 0f);
    Layer.Util.layerToScreen(child, pointOnChild, pointOnParent);
    assertEquals(point.x(), pointOnParent.x(), tol);
    assertEquals(point.y(), pointOnParent.y(), tol);
    root.clear();
}
Also used : Point(pythagoras.f.Point) Test(org.junit.Test)

Aggregations

Point (pythagoras.f.Point)14 Test (org.junit.Test)4 PointerImpl (playn.core.PointerImpl)2 NativeEvent (com.google.gwt.dom.client.NativeEvent)1 TouchImpl (playn.core.TouchImpl)1 NoninvertibleTransformException (pythagoras.util.NoninvertibleTransformException)1