@Override public SWTGraphics graphics () { return (SWTGraphics)super.graphics(); }
@Override protected TouchImpl createTouch (Config config) { if (config.emulateTouch) { return new SWTEmulatedTouch(); } else { return super.createTouch(config); } }
/** * Creates a new java assets. */ public JavaAssets(JavaPlatform plat) { super(plat.exec()); this.plat = plat; }
@Override public Image getRemoteImage(final String url, float width, float height) { final JavaAsyncImage image = platform.graphics().createAsyncImage(width, height); platform.invokeAsync(new Runnable() { public void run () { try { setImageLater(image, ImageIO.read(new URL(url)), Scale.ONE); } catch (Exception error) { setErrorLater(image, error); } } }); return image; }
@Override protected ImageImpl.Data load (String path) throws Exception { Exception error = null; for (Scale.ScaledResource rsrc : assetScale().getScaledResources(path)) { try { BufferedImage image = requireResource(rsrc.path).readImage(); // if image is at a higher scale factor than the view, scale to the view display factor Scale viewScale = plat.graphics().scale(), imageScale = rsrc.scale; float viewImageRatio = viewScale.factor / imageScale.factor; if (viewImageRatio < 1) { image = scaleImage(image, viewImageRatio); imageScale = viewScale; } if (plat.config.convertImagesOnLoad) { BufferedImage convertedImage = JavaGraphics.convertImage(image); if (convertedImage != image) { plat.log().debug("Converted image: " + path + " [type=" + image.getType() + "]"); image = convertedImage; } } return new ImageImpl.Data(imageScale, image, image.getWidth(), image.getHeight()); } catch (FileNotFoundException fnfe) { error = fnfe; // keep going, checking for lower resolution images } } plat.log().warn("Could not load image: " + path + " [error=" + error + "]"); throw error != null ? error : new FileNotFoundException(path); }
protected Sound getSound(String path, boolean music) { Exception err = null; for (String suff : SUFFIXES) { final String soundPath = path + suff; try { return platform.audio().createSound(requireResource(soundPath), music); } catch (Exception e) { err = e; // note the error, and loop through and try the next format } } platform.log().warn("Sound load error " + path + ": " + err); return new Sound.Error(err); }
@Override public Iterable<String> keys() { try { return Arrays.asList(preferences.keys()); } catch (Exception e) { platform.log().warn("Error reading preferences: " + e.getMessage()); return Collections.emptyList(); } }
this.config = config; if (!config.headless) { unpackNatives(); graphics = createGraphics(config); keyboard = createKeyboard(); storage = new JavaStorage(this, config); touch = createTouch(config); if (touch instanceof JavaEmulatedTouch) { mouse = ((JavaEmulatedTouch)touch).createMouse(this); } else { mouse = createMouse(); setTitle(config.appName);
public static void main(String[] args) { JavaPlatform.Config config = new JavaPlatform.Config(); for (String arg : args) { if (arg.startsWith("@") && arg.endsWith("x")) { config.scaleFactor = Float.parseFloat(arg.substring(1, arg.length()-1)); } } config.width = 800; config.height = 600; JavaPlatform platform = JavaPlatform.register(config); platform.setTitle("Tests"); // let the caller know that we accept some args platform.log().info("Usage: TestsGameJava [@Nx] [test#]"); platform.log().info(" [@Nx] specifies a scale factor: @2x, @1.5x"); platform.log().info(" [test#] specifies a test to launch directly: test0, test12 "); TestsGame.args = args; PlayN.run(new TestsGame()); } }
input().keyboardEvents.connect(new Slot<Keyboard.Event>() { public void onEmit (Keyboard.Event event) { if (event instanceof Keyboard.KeyEvent) { loop(); dispatchEvent(lifecycle, Lifecycle.EXIT);
@Override public void openURL(String url) { try { Desktop.getDesktop().browse(URI.create(url)); } catch (Exception e) { reportError("Failed to open URL [url=" + url + "]", e); } }
public void onEmit (Keyboard.Event event) { if (event instanceof Keyboard.KeyEvent) { Keyboard.KeyEvent kevent = (Keyboard.KeyEvent)event; if (kevent.key == config.activationKey && kevent.down) { toggleActivation(); } } } });
@Override public void keyTyped (KeyEvent e) { _plat.plat.input().postKey(e.getWhen(), null, false, e.getKeyChar(), mods(e)); } @Override public void keyReleased (KeyEvent e) {
/** * Registers the Java platform with a default configuration. */ public static JavaPlatform register() { return register(new Config()); }
@Override protected ImageImpl.Data load (String path) throws Exception { Exception error = null; for (Scale.ScaledResource rsrc : assetScale().getScaledResources(path)) { try { BufferedImage image = requireResource(rsrc.path).readImage(); // if image is at a higher scale factor than the view, scale to the view display factor Scale viewScale = plat.graphics().scale(), imageScale = rsrc.scale; float viewImageRatio = viewScale.factor / imageScale.factor; if (viewImageRatio < 1) { image = scaleImage(image, viewImageRatio); imageScale = viewScale; } if (plat.config.convertImagesOnLoad) { BufferedImage convertedImage = JavaGraphics.convertImage(image); if (convertedImage != image) { plat.log().debug("Converted image: " + path + " [type=" + image.getType() + "]"); image = convertedImage; } } return new ImageImpl.Data(imageScale, image, image.getWidth(), image.getHeight()); } catch (FileNotFoundException fnfe) { error = fnfe; // keep going, checking for lower resolution images } } plat.log().warn("Could not load image: " + path + " [error=" + error + "]"); throw error != null ? error : new FileNotFoundException(path); }
protected Sound getSound(String path, boolean music) { Exception err = null; for (String suff : SUFFIXES) { final String soundPath = path + suff; try { return plat.audio().createSound(requireResource(soundPath), music); } catch (Exception e) { err = e; // note the error, and loop through and try the next format } } plat.log().warn("Sound load error " + path + ": " + err); return new Sound.Error(err); }
@Override public Iterable<String> keys() { try { return Arrays.asList(preferences.keys()); } catch (Exception e) { platform.log().warn("Error reading preferences: " + e.getMessage()); return Collections.emptyList(); } }
this.config = config; if (!config.headless) { unpackNatives(); graphics = createGraphics(config); keyboard = createKeyboard(); storage = new JavaStorage(this, config); touch = createTouch(config); if (touch instanceof JavaEmulatedTouch) { mouse = ((JavaEmulatedTouch)touch).createMouse(this); } else { mouse = createMouse(); setTitle(config.appName);
@Override public Image getRemoteImage(final String url, float width, float height) { final JavaAsyncImage image = platform.graphics().createAsyncImage(width, height); platform.invokeAsync(new Runnable() { public void run () { try { setImageLater(image, ImageIO.read(new URL(url)), Scale.ONE); } catch (Exception error) { setErrorLater(image, error); } } }); return image; }