/** * Create a standard NiftyJmeDisplay. This uses the old Nifty renderer. It's probably slower then the batched * renderer and is mainly here for backwards compatibility. * * @param assetManager jME AssetManager * @param inputManager jME InputManager * @param audioRenderer jME AudioRenderer * @param vp Viewport to use */ public NiftyJmeDisplay(AssetManager assetManager, InputManager inputManager, AudioRenderer audioRenderer, ViewPort vp){ initialize(assetManager, inputManager, audioRenderer, vp); this.renderDev = new RenderDeviceJme(this); this.batchRendererBackend = null; nifty = new Nifty(renderDev, soundDev, inputSys, new AccurateTimeProvider()); inputSys.setNifty(nifty); resourceLocation = new ResourceLocationJme(); nifty.getResourceLoader().removeAllResourceLocations(); nifty.getResourceLoader().addResourceLocation(resourceLocation); }
@Override public InputStream load(String path) { if (resourceLoader == null) { return null; } return resourceLoader.getResourceAsStream(path); } });
public NiftyResourceLoader() { locations = new ArrayList<ResourceLocation>(); locations.add(new ClasspathLocation()); locations.add(new FileSystemLocation(new File("."))); }
@Nonnull @Override public RenderImage createImage(@Nonnull String filename, boolean filterLinear) { try { BufferedImage image = ImageIO.read(resourceLoader.getResource(filename)); // convert the image to ARGB model BufferedImage bufferedImage = new BufferedImage(image .getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics g = bufferedImage.getGraphics(); g.drawImage(image, 0, 0, null); return new RenderImageJava2dImpl(bufferedImage); } catch (IOException e) { throw new RuntimeException("failed to create image " + filename, e); } }
/** * Get a resource as a URL * * @param ref The reference to the resource to retrieve * @return A stream from which the resource can be read or {@code null} in case the resource was not found */ @Nullable public URL getResource(@Nonnull final String ref) { URL url = null; for (int i = 0; i < locations.size(); i++) { ResourceLocation location = locations.get(i); url = location.getResource(ref); if (url != null) { break; } } return url; } }
/** * Get a resource * * @param ref The reference to the resource to retrieve * @return A stream from which the resource can be read or {@code null} in case the resource was not found */ @Nullable public InputStream getResourceAsStream(@Nonnull final String ref) { InputStream in = null; for (int i = 0; i < locations.size(); i++) { ResourceLocation location = locations.get(i); in = location.getResourceAsStream(ref); if (in != null) { break; } } if (in == null) { return null; } return new BufferedInputStream(in); }
/** * Return an InputStream for the given resource name. This is resolved * using the currently registered ResourceLocations. * * @param ref the name of the resource to load * @return the InputStream of the resource data */ @Nullable public InputStream getResourceAsStream(@Nonnull final String ref) { return resourceLoader.getResourceAsStream(ref); }
private NiftyJmeDisplay( final AssetManager assetManager, final InputManager inputManager, final AudioRenderer audioRenderer, final ViewPort viewport, final BatchRenderConfiguration batchRenderConfiguration) { initialize(assetManager, inputManager, audioRenderer, viewport); this.renderDev = null; this.batchRendererBackend = new JmeBatchRenderBackend(this); nifty = new Nifty( new BatchRenderDevice(batchRendererBackend, batchRenderConfiguration), soundDev, inputSys, new AccurateTimeProvider()); inputSys.setNifty(nifty); resourceLocation = new ResourceLocationJme(); nifty.getResourceLoader().removeAllResourceLocations(); nifty.getResourceLoader().addResourceLocation(resourceLocation); }
@Nonnull @Override public RenderImage createImage(@Nonnull String filename, boolean filterLinear) { try { BufferedImage image = ImageIO.read(resourceLoader.getResource(filename)); // convert the image to ARGB model BufferedImage bufferedImage = new BufferedImage(image .getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics g = bufferedImage.getGraphics(); g.drawImage(image, 0, 0, null); return new RenderImageJava2dImpl(bufferedImage); } catch (IOException e) { throw new RuntimeException("failed to create image " + filename, e); } }
/** * Get the Sound based on a specified WAV file * * @param ref The reference to the WAV file in the classpath * @return The Sound read from the WAV file * @throws IOException Indicates a failure to load the WAV */ @Nonnull public Audio getWAV(@Nonnull String ref, @Nonnull final NiftyResourceLoader resourceLoader) throws IOException { return getWAV(ref, resourceLoader.getResourceAsStream(ref)); }
nifty.getResourceLoader().removeAllResourceLocations(); nifty.getResourceLoader().addResourceLocation(resourceLocation);
public BatchRenderFont( final BatchRenderDevice batchRenderDevice, @Nonnull final String name, @Nonnull final JGLFontFactory factory, @Nonnull final NiftyResourceLoader resourceLoader) throws IOException { this.batchRenderDevice = batchRenderDevice; this.font = factory.loadFont(resourceLoader.getResourceAsStream(name), name); }
/** * Get the Sound based on a specified AIF file * * @param ref The reference to the AIF file in the classpath * @return The Sound read from the AIF file * @throws IOException Indicates a failure to load the AIF */ @Nonnull public Audio getAIF(@Nonnull String ref, @Nonnull final NiftyResourceLoader resourceLoader) throws IOException { return getAIF(ref, resourceLoader.getResourceAsStream(ref)); }
/** * Get the Sound based on a specified OGG file * * @param ref The reference to the OGG file in the classpath * @return The Sound read from the OGG file * @throws IOException Indicates a failure to load the OGG */ @Nonnull public Audio getOgg(@Nonnull String ref, @Nonnull final NiftyResourceLoader resourceLoader) throws IOException { return getOgg(ref, resourceLoader.getResourceAsStream(ref)); }
/** * Get a MOD sound (mod/xm etc) * * @param ref The refernece to the mod to load * @return The sound for play back * @throws IOException Indicates a failure to read the data */ @Nonnull public Audio getMOD(@Nonnull String ref, @Nonnull final NiftyResourceLoader resourceLoader) throws IOException { return getMOD(ref, resourceLoader.getResourceAsStream(ref)); }
/** * load the font with the given name. * * @param filename file to load * @return true on success and false on any error */ public boolean load(@Nonnull final String filename) { InputStream in = resourceLoader.getResourceAsStream(filename); if (in == null) { return false; } return load(in); }
/** * load the font with the given name. * * @param filename file to load * @return true on success and false on any error */ public boolean load(@Nonnull final String filename) { InputStream in = resourceLoader.getResourceAsStream(filename); if (in == null) { return false; } return load(in); }
/** * Initialise our connection to the underlying resource * * @throws IOException Indicates a failure to open the underling resource */ private void initStreams() throws IOException { if (audio != null) { audio.close(); } OggInputStream audio; InputStream in; if (url != null) { in = url.openStream(); } else { in = resourceLoader.getResourceAsStream(ref); } if (in != null) { audio = new OggInputStream(in); this.audio = audio; positionOffset = 0; } else { throw new IOException("Input not found."); } }
@Nonnull private Image createImageFromFile(@Nonnull final String filename) { ImageLoader loader = ImageLoaderFactory.createImageLoader(filename); InputStream imageStream = null; try { assert resourceLoader != null; imageStream = resourceLoader.getResourceAsStream(filename); if (imageStream != null) { ByteBuffer image = loader.loadAsByteBufferRGBA(imageStream); image.rewind(); int width = loader.getImageWidth(); int height = loader.getImageHeight(); return imageFactory.create(image, width, height); } } catch (Exception e) { log.log(Level.WARNING, "Could not load image from file: [" + filename + "]", e); } finally { if (imageStream != null) { try { imageStream.close(); } catch (IOException ignored) { } } } return imageFactory.create(null, 0, 0); } }
@Nonnull private Image createImageFromFile(@Nonnull final String filename) { ImageLoader loader = ImageLoaderFactory.createImageLoader(filename); InputStream imageStream = null; try { assert resourceLoader != null; imageStream = resourceLoader.getResourceAsStream(filename); if (imageStream != null) { ByteBuffer image = loader.loadAsByteBufferRGBA(imageStream); image.rewind(); int width = loader.getImageWidth(); int height = loader.getImageHeight(); return imageFactory.create(image, width, height); } } catch (Exception e) { log.log(Level.WARNING, "Could not load image from file: [" + filename + "]", e); } finally { if (imageStream != null) { try { imageStream.close(); } catch (IOException ignored) { } } } return imageFactory.create(null, 0, 0); } }