/** Posts a key event received from elsewhere (i.e. a native UI component). This is useful for * applications that are using GL in Canvas mode and sharing keyboard focus with other (non-GL) * components. The event will be queued and dispatched on the next frame, after GL keyboard * events. * * <p><em>Note</em>: the resulting event will be sent with time = 0, since the GL event time is * inaccessible and platform dependent.</p> * * @param key the key that was pressed or released, or null for a char typed event * @param pressed whether the key was pressed or released, ignored if key is null * @param typedCh the character that was typed, ignored if key is not null */ public void post(Key key, boolean pressed, char typedCh, Modifiers modifiers) { queue.add( key == null ? new Queued<TypedEvent>(new TypedEvent.Impl(new Events.Flags.Impl(), 0, typedCh), typed) : new Queued<Event>(new Event.Impl(new Events.Flags.Impl(), 0, key, modifiers), pressed ? down : up)); }
public void onKeyDown(int keyCode, KeyEvent nativeEvent) { long time = nativeEvent.getEventTime(); final Keyboard.Event event = new Keyboard.Event.Impl( new Events.Flags.Impl(), time, keyForCode(keyCode), extractModifiers(nativeEvent)); platform.invokeLater(new Runnable() { @Override public void run() { platform.keyboard().onKeyDown(event); } }); int unicodeChar = nativeEvent.getUnicodeChar(); if (unicodeChar != 0) { final Keyboard.TypedEvent typedEvent = new Keyboard.TypedEvent.Impl(event.flags(), time, (char)unicodeChar); platform.invokeLater(new Runnable() { @Override public void run() { platform.keyboard().onKeyTyped(typedEvent); } }); } }
/** Posts a key event received from elsewhere (i.e. a native UI component). This is useful for * applications that are using GL in Canvas mode and sharing keyboard focus with other (non-GL) * components. The event will be queued and dispatched on the next frame, after GL keyboard * events. * * <p><em>Note</em>: the resulting event will be sent with time = 0, since the GL event time is * inaccessible and platform dependent.</p> * * @param key the key that was pressed or released, or null for a char typed event * @param pressed whether the key was pressed or released, ignored if key is null * @param typedCh the character that was typed, ignored if key is not null */ public void post(Key key, boolean pressed, char typedCh, Modifiers modifiers) { queue.add( key == null ? new Queued<TypedEvent>(new TypedEvent.Impl(new Events.Flags.Impl(), 0, typedCh), typed) : new Queued<Event>(new Event.Impl(new Events.Flags.Impl(), 0, key, modifiers), pressed ? down : up)); }
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; } }
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; }
public void handleEvent (org.eclipse.swt.widgets.Event event) { Key key = translateKey(event.keyCode); if (key != null) { dispatch(new Event.Impl(new Events.Flags.Impl(), event.time, key, extractModifiers(event)), down); } else { System.err.println("KEY? " + event.keyCode + " / " + event.character); } char keyChar = event.character; if (Character.isISOControl(keyChar)) { dispatch(new TypedEvent.Impl(new Events.Flags.Impl(), event.time, keyChar), typed); } } });
Event.Impl toTouch (double time, float x, float y, int idoff) { return new Event.Impl(new Events.Flags.Impl(), time, x, y, currentId+idoff); }
Event.Impl toTouch (double time, float x, float y, int idoff) { return new Event.Impl(new Events.Flags.Impl(), time, x, y, currentId+idoff); }
@Override public void handleEvent(NativeEvent nativeEvent) { if (listener != null) { Event.Impl event = new Event.Impl( new Events.Flags.Impl(), PlayN.currentTime(), keyForCode(nativeEvent.getKeyCode()), extractModifiers(nativeEvent) ); listener.onKeyUp(event); if (event.flags().getPreventDefault()) { nativeEvent.preventDefault(); } } } });
@Override public void handleEvent(NativeEvent nativeEvent) { if (listener != null) { Event.Impl event = new Event.Impl( new Events.Flags.Impl(), PlayN.currentTime(), keyForCode(nativeEvent.getKeyCode()), extractModifiers(nativeEvent) ); listener.onKeyDown(event); if (event.flags().getPreventDefault()) { nativeEvent.preventDefault(); } } } });
void onMouseDown(double time, float x, float y) { onPointerStart(new Event.Impl(new Events.Flags.Impl(), time, x, y, false), false); mouseDown = true; }
void onMouseUp(double time, float x, float y) { onPointerEnd(new Event.Impl(new Events.Flags.Impl(), time, x, y, false), false); mouseDown = false; }
@Override public void handleEvent(NativeEvent nativeEvent) { if (inTouchSequence) { Events.Flags flags = new Events.Flags.Impl(); onTouchEnd(toEvents(nativeEvent, flags)); if (flags.getPreventDefault()) nativeEvent.preventDefault(); // if there are no remaining active touches, note that this touch sequence has ended if (nativeEvent.getTouches().length() == 0) inTouchSequence = false; } } });
void onMouseDown(double time, float x, float y) { onPointerStart(new Event.Impl(new Events.Flags.Impl(), time, x, y, false), false); mouseDown = true; }
void onMouseUp(double time, float x, float y) { onPointerEnd(new Event.Impl(new Events.Flags.Impl(), time, x, y, false), false); mouseDown = false; }
public void handleEvent (org.eclipse.swt.widgets.Event event) { Key key = translateKey(event.keyCode); if (key != null) { dispatch(new Event.Impl(new Events.Flags.Impl(), event.time, key, extractModifiers(event)), down); } else { System.err.println("KEY? " + event.keyCode + " / " + event.character); } char keyChar = event.character; if (Character.isISOControl(keyChar)) { dispatch(new TypedEvent.Impl(new Events.Flags.Impl(), event.time, keyChar), typed); } } });
protected void onMouseWheelScroll(double time, float x, float y, int delta) { onMouseWheelScroll(new WheelEvent.Impl(new Events.Flags.Impl(), time, x, y, delta)); } }
public void handleEvent (org.eclipse.swt.widgets.Event event) { Key key = translateKey(event.keyCode); if (key != null) { dispatch(new Event.Impl(new Events.Flags.Impl(), event.time, key, extractModifiers(event)), up); } } });
public void onKeyUp(int keyCode, KeyEvent nativeEvent) { final Keyboard.Event event = new Keyboard.Event.Impl( new Events.Flags.Impl(), nativeEvent.getEventTime(), keyForCode(keyCode), extractModifiers(nativeEvent)); platform.invokeLater(new Runnable() { @Override public void run() { platform.keyboard().onKeyUp(event); } }); }
protected void onMouseDown(double time, float x, float y, int btn) { onMouseDown(new ButtonEvent.Impl(new Events.Flags.Impl(), time, x, y, btn)); if (btn == 0) pointer.onMouseDown(time, x, y); }