Search in sources :

Example 1 with IPoint

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

the class IOSTouch method toTouchEvents.

private Event.Impl[] toTouchEvents(NSSet touches, UIEvent event) {
    final Event.Impl[] events = new Event.Impl[Convert.ToInt32(touches.get_Count())];
    touches.Enumerate(new NSSetEnumerator(new NSSetEnumerator.Method() {

        public void Invoke(NSObject obj, boolean[] stop) {
            UITouch touch = (UITouch) obj;
            PointF loc = touch.LocationInView(touch.get_View());
            // transform the point based on our current scale
            IPoint xloc = graphics.transformTouch(loc.get_X(), loc.get_Y());
            // on iOS the memory address of the UITouch object is the unique id
            int id = touch.get_Handle().ToInt32();
            events[_idx++] = new Event.Impl(new Events.Flags.Impl(), touch.get_Timestamp() * 1000, xloc.x(), xloc.y(), id);
            stop[0] = false;
        }

        private int _idx = 0;
    }));
    return events;
}
Also used : TouchImpl(playn.core.TouchImpl) NSObject(cli.MonoTouch.Foundation.NSObject) Events(playn.core.Events) NSSetEnumerator(cli.MonoTouch.Foundation.NSSetEnumerator) PointF(cli.System.Drawing.PointF) UIEvent(cli.MonoTouch.UIKit.UIEvent) IPoint(pythagoras.f.IPoint) UITouch(cli.MonoTouch.UIKit.UITouch) IPoint(pythagoras.f.IPoint)

Example 2 with IPoint

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

the class RoboTouch method toTouchEvents.

private Event.Impl[] toTouchEvents(NSSet<UITouch> touches, UIEvent event) {
    final Event.Impl[] events = new Event.Impl[touches.size()];
    int idx = 0;
    for (UITouch touch : touches) {
        CGPoint loc = touch.getLocationInView(touch.getView());
        // transform the point based on our current scale
        IPoint xloc = platform.graphics().transformTouch((float) loc.getX(), (float) loc.getY());
        // on iOS the memory address of the UITouch object is the unique id
        int id = (int) touch.getHandle();
        events[idx++] = new Event.Impl(new Events.Flags.Impl(), touch.getTimestamp() * 1000, xloc.x(), xloc.y(), id);
    }
    return events;
}
Also used : TouchImpl(playn.core.TouchImpl) Events(playn.core.Events) CGPoint(org.robovm.apple.coregraphics.CGPoint) UIEvent(org.robovm.apple.uikit.UIEvent) IPoint(pythagoras.f.IPoint) UITouch(org.robovm.apple.uikit.UITouch) IPoint(pythagoras.f.IPoint) CGPoint(org.robovm.apple.coregraphics.CGPoint)

Example 3 with IPoint

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

the class TouchEventHandler method parseMotionEvent.

/**
   * Performs the actual parsing of the MotionEvent event.
   *
   * @param event The MotionEvent to process
   * @param preventDefault Shared preventDefault state among returned {@link AndroidTouchEventImpl}
   * @return Processed array of {@link AndroidTouchEventImpl}s which share a preventDefault state.
   */
private Touch.Event.Impl[] parseMotionEvent(MotionEvent event, Events.Flags flags) {
    int eventPointerCount = event.getPointerCount();
    Touch.Event.Impl[] touches = new Touch.Event.Impl[eventPointerCount];
    double time = event.getEventTime();
    float pressure, size;
    int id;
    for (int t = 0; t < eventPointerCount; t++) {
        int pointerIndex = t;
        IPoint xy = platform.graphics().transformTouch(event.getX(pointerIndex), event.getY(pointerIndex));
        pressure = event.getPressure(pointerIndex);
        size = event.getSize(pointerIndex);
        id = event.getPointerId(pointerIndex);
        touches[t] = new Touch.Event.Impl(flags, time, xy.x(), xy.y(), id, pressure, size);
    }
    return touches;
}
Also used : MotionEvent(android.view.MotionEvent) IPoint(pythagoras.f.IPoint) Touch(playn.core.Touch) IPoint(pythagoras.f.IPoint)

Example 4 with IPoint

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

the class IOSPointer method toPointerEvent.

private Event.Impl toPointerEvent(NSSet touches, UIEvent event) {
    final Event.Impl[] eventw = new Event.Impl[1];
    touches.Enumerate(new NSSetEnumerator(new NSSetEnumerator.Method() {

        public void Invoke(NSObject obj, boolean[] stop) {
            UITouch touch = (UITouch) obj;
            int handle = touch.get_Handle().ToInt32();
            // if we have an active touch, we only care about that touch
            if (_active != 0 && handle != _active) {
                stop[0] = false;
            } else {
                _active = handle;
                PointF loc = touch.LocationInView(touch.get_View());
                // transform the point based on our current scale
                IPoint xloc = graphics.transformTouch(loc.get_X(), loc.get_Y());
                eventw[0] = new Event.Impl(new Events.Flags.Impl(), touch.get_Timestamp() * 1000, xloc.x(), xloc.y(), true);
                stop[0] = true;
            }
        }
    }));
    return eventw[0];
}
Also used : PointerImpl(playn.core.PointerImpl) NSObject(cli.MonoTouch.Foundation.NSObject) Events(playn.core.Events) NSSetEnumerator(cli.MonoTouch.Foundation.NSSetEnumerator) PointF(cli.System.Drawing.PointF) UIEvent(cli.MonoTouch.UIKit.UIEvent) IPoint(pythagoras.f.IPoint) UITouch(cli.MonoTouch.UIKit.UITouch) IPoint(pythagoras.f.IPoint)

Example 5 with IPoint

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

the class RoboPointer method toPointerEvent.

private Event.Impl toPointerEvent(NSSet<UITouch> touches, UIEvent event) {
    for (UITouch touch : touches) {
        long handle = touch.getHandle();
        // if we have an active touch, we only care about that touch
        if (_active == 0 || handle == _active) {
            _active = handle;
            CGPoint loc = touch.getLocationInView(touch.getView());
            // transform the point based on our current scale
            IPoint xloc = platform.graphics().transformTouch((float) loc.getX(), (float) loc.getY());
            return new Event.Impl(new Events.Flags.Impl(), touch.getTimestamp() * 1000, xloc.x(), xloc.y(), true);
        }
    }
    return null;
}
Also used : PointerImpl(playn.core.PointerImpl) CGPoint(org.robovm.apple.coregraphics.CGPoint) IPoint(pythagoras.f.IPoint) UITouch(org.robovm.apple.uikit.UITouch)

Aggregations

IPoint (pythagoras.f.IPoint)5 Events (playn.core.Events)3 NSObject (cli.MonoTouch.Foundation.NSObject)2 NSSetEnumerator (cli.MonoTouch.Foundation.NSSetEnumerator)2 UIEvent (cli.MonoTouch.UIKit.UIEvent)2 UITouch (cli.MonoTouch.UIKit.UITouch)2 PointF (cli.System.Drawing.PointF)2 CGPoint (org.robovm.apple.coregraphics.CGPoint)2 UITouch (org.robovm.apple.uikit.UITouch)2 PointerImpl (playn.core.PointerImpl)2 TouchImpl (playn.core.TouchImpl)2 MotionEvent (android.view.MotionEvent)1 UIEvent (org.robovm.apple.uikit.UIEvent)1 Touch (playn.core.Touch)1