public void handleEvent (Event event) { if (event.widget == plat.graphics().canvas) { emitMouseWheel(mods(event), event.time, event.x, event.y, -event.count); } } });
@Override void setTitle (String title) { plat.shell().setText(title); }
@Override public void run () { long now = _platform.tick(); if (now - _req < 75) _platform.invokeLater(this); else { _pendingRefresh = null; for (SWTNativeOverlay overlay : _overlays) overlay.refreshBounds(); } } };
@Override public void run(final Game game) { init(game); // canvas.addListener(SWT.Paint, new Listener() { // public void handleEvent (Event event) { // run.run(); // } // }); shell.open(); while (!shell.isDisposed()) { long now = tick(); if (now - lastFrame >= FRAME_MILLIS) { processFrame(game); lastFrame = now; } if (!display.readAndDispatch()) { try { Thread.sleep(1); } catch (InterruptedException ie) {} // no problem! } } display.dispose(); shutdown(); }
protected void request () { _req = _platform.tick(); } protected Runnable _buddy = new Runnable() {
public SWTTPPlatform (SWTPlatform platform, JavaPlatform.Config config) { _platform = platform; _overlay = _platform.composite(); _convert = new SWTConvert(display()); // Figure out the os String osname = System.getProperty("os.name"); osname = (osname == null) ? "" : osname; if (osname.indexOf("Windows") != -1) _os = OS.WINDOWS; else if (osname.indexOf("Mac OS") != -1 || osname.indexOf("MacOS") != -1) _os = OS.MAC; else if (osname.indexOf("Linux") != -1) _os = OS.LINUX; else System.err.println("Unmatching os name: " + osname); if (_os == OS.MAC) { // TODO: figure out why this hack allows native text fields to work on Mac // In my investigation so far, the hack has to be added on startup, moveAbove must be // called and the bounds must overlap with the canvas'. Composite hack = new Composite(_overlay, SWT.NONE); hack.moveAbove(null); // make the hack small and black; TODO: expose color to apps if this hack is permanent hack.setBounds(0, 0, 1, 1); hack.setBackground(new Color(display(), 0, 0, 0)); } display().addFilter(SWT.MouseDown, new Listener() { @Override public void handleEvent (Event event) { if (event.widget == _platform.graphics().canvas() && (_kfc == null || _kfc.unfocusForLocation(new Point(event.x, event.y)))) { clearFocus(); } } }); }
@Override public IDimension screenSize () { Rectangle db = plat.display().getBounds(); return new Dimension(db.width, db.height); }
public void shellDeactivated (ShellEvent e) { dispatchEvent(lifecycle, Lifecycle.PAUSE); } });
public static SWTPlatform register (Config config) { SWTPlatform instance = new SWTPlatform(config); PlayN.setPlatform(instance); return instance; }
public PendingRefresh () { _platform.invokeLater(_buddy); } protected void request () {
@Override public void run(final Game game) { init(game); // canvas.addListener(SWT.Paint, new Listener() { // public void handleEvent (Event event) { // run.run(); // } // }); shell.open(); while (!shell.isDisposed()) { long now = tick(); if (now - lastFrame >= FRAME_MILLIS) { processFrame(game); lastFrame = now; } if (!display.readAndDispatch()) { try { Thread.sleep(1); } catch (InterruptedException ie) {} // no problem! } } display.dispose(); shutdown(); }
@Override public IDimension screenSize () { Rectangle db = plat.display().getBounds(); return new Dimension(db.width, db.height); }
public void shellDeactivated (ShellEvent e) { dispatchEvent(lifecycle, Lifecycle.PAUSE); } });
public static SWTPlatform register (Config config) { SWTPlatform instance = new SWTPlatform(config); PlayN.setPlatform(instance); return instance; }
/** * Processes a change to the currently focused control. */ public void onFocusChange () { // deal with this on the next frame, avoiding platform-specific issues _platform.invokeLater(new Runnable() { @Override public void run () { Control focus = display().getFocusControl(); // ignore focusing on null, this seems to happen on window deactivation if (focus == null) return; // find a native text field corresponding to the new focus for (SWTNativeOverlay overlay : _overlays) { if (overlay instanceof SWTNativeTextField && overlay.ctrl == focus) { _focus.update(((SWTNativeTextField)overlay).field()); return; } } // any other focus for our purposes is a loss of focus _focus.update(null); } }); }
public void handleEvent (Event event) { if (event.widget == plat.graphics().canvas) { float dx = event.x - lastX, dy = event.y - lastY; emitMouseMotion(mods(event), event.time, event.x, event.y, dx, dy); } } private float lastX, lastY;
public Display display () { return _platform.shell().getDisplay(); }
plat.display().addFilter(SWT.MouseDown, new org.eclipse.swt.widgets.Listener() { public void handleEvent (Event event) { if (event.widget == plat.graphics().canvas) { plat.display().addFilter(SWT.MouseUp, new org.eclipse.swt.widgets.Listener() { public void handleEvent (Event event) { if (event.widget == plat.graphics().canvas) { plat.display().addFilter(SWT.MouseMove, new org.eclipse.swt.widgets.Listener() { public void handleEvent (Event event) { if (event.widget == plat.graphics().canvas) { plat.display().addFilter(SWT.MouseWheel, new org.eclipse.swt.widgets.Listener() { public void handleEvent (Event event) { if (event.widget == plat.graphics().canvas) { plat.display().addFilter(SWT.KeyDown, new org.eclipse.swt.widgets.Listener() { public void handleEvent (Event event) { Key key = translateKey(event.keyCode); plat.display().addFilter(SWT.KeyUp, new org.eclipse.swt.widgets.Listener() { public void handleEvent (Event event) { Key key = translateKey(event.keyCode);