/** * 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); } });
@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); } }
new ArrayList<EndOfFrameElementAction>(), new ArrayList<EndOfFrameElementAction>()); resourceLoader = new NiftyResourceLoader();
/** * 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); }
@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)); }
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); }
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); }
nifty.getResourceLoader().removeAllResourceLocations(); nifty.getResourceLoader().addResourceLocation(resourceLocation);
/** * 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)); }
/** * 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); }
/** * 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); }
/** * 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."); } }
public Lwjgl3MouseCursor(final long glfwWindow, @Nonnull final String cursorImageFilename, final int hotspotX, final int hotspotY, @Nonnull final NiftyResourceLoader resourceLoader) throws IOException { this.glfwWindow = glfwWindow; ImageLoader imageLoader = ImageLoaderFactory.createImageLoader(cursorImageFilename); InputStream imageStream = resourceLoader.getResourceAsStream(cursorImageFilename); if (imageStream == null) { throw new IOException("Cannot find / load mouse cursor image file: [" + cursorImageFilename + "]."); } try { ByteBuffer imageData = imageLoader.loadAsByteBufferARGB(imageStream, true); imageData.rewind(); GLFWImage image = new GLFWImage(imageData); cursor = glfwCreateCursor(image, hotspotX, hotspotY); } finally { try { imageStream.close(); } catch (IOException e) { log.log(Level.INFO, "An error occurred while closing the InputStream used to load mouse cursor image: " + "[" + cursorImageFilename + "].", e); } } }
public LwjglMouseCursor( @Nonnull final String cursorImageFilename, final int hotspotX, final int hotspotY, @Nonnull final NiftyResourceLoader resourceLoader) throws IOException { ImageLoader imageLoader = ImageLoaderFactory.createImageLoader(cursorImageFilename); InputStream imageStream = resourceLoader.getResourceAsStream(cursorImageFilename); if (imageStream == null) { throw new IOException("Cannot find / load mouse cursor image file: [" + cursorImageFilename + "]."); } try { ByteBuffer imageData = imageLoader.loadAsByteBufferARGB(imageStream, true); imageData.rewind(); int width = imageLoader.getImageWidth(); int height = imageLoader.getImageHeight(); cursor = new Cursor(width, height, hotspotX, height - hotspotY - 1, 1, imageData.asIntBuffer(), null); } catch (LWJGLException e) { throw new IOException(e); } finally { try { imageStream.close(); } catch (IOException e) { log.log(Level.INFO, "An error occurred while closing the InputStream used to load mouse cursor image: " + "[" + cursorImageFilename + "].", e); } } }
@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); } }