protected Scale assetScale() { return (assetScale != null) ? assetScale : plat.graphics().scale(); }
protected JavaGraphics createGraphics(Config config) { return new JavaGraphics(this, config); } protected TouchImpl createTouch(Config config) {
@Override protected AsyncImage<BufferedImage> createAsyncImage(float width, float height) { return platform.graphics().createAsyncImage(width, height); }
public static JavaTextLayout layoutText (JavaGraphics gfx, String text, TextFormat format) { // we do some fiddling to work around the fact that TextLayout chokes on the empty string AttributedString astring = new AttributedString(text.length() == 0 ? " " : text); if (format.font != null) { astring.addAttribute(TextAttribute.FONT, gfx.resolveFont(format.font)); } FontRenderContext frc = format.antialias ? gfx.aaFontContext() : gfx.aFontContext(); return new JavaTextLayout(text, format, new TextLayout(astring.getIterator(), frc)); }
@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); }
@Override protected void paint () { makeCurrent(); super.paint(); canvas.swapBuffers(); }
protected Scale assetScale() { return (assetScale != null) ? assetScale : platform.graphics().ctx().scale; }
ByteBuffer checkGetImageBuffer (int byteSize) { if (imgBuf == null) imgBuf = createImageBuffer(Math.max(1024, byteSize)); if (imgBuf.capacity() >= byteSize) imgBuf.clear(); // reuse it! else imgBuf = createImageBuffer(byteSize); return imgBuf; }
@Override protected Image createStaticImage(BufferedImage bufimg, Scale scale) { return platform.graphics().createStaticImage(bufimg, scale); }
public static JavaTextLayout layoutText (JavaGraphics gfx, String text, TextFormat format) { // we do some fiddling to work around the fact that TextLayout chokes on the empty string AttributedString astring = new AttributedString(text.length() == 0 ? " " : text); if (format.font != null) { astring.addAttribute(TextAttribute.FONT, gfx.resolveFont(format.font)); } FontRenderContext frc = format.antialias ? gfx.aaFontContext() : gfx.aFontContext(); return new JavaTextLayout(text, format, new TextLayout(astring.getIterator(), frc)); }
@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); }
@Override protected void paint () { makeCurrent(); super.paint(); canvas.swapBuffers(); }
protected Scale assetScale() { return (assetScale != null) ? assetScale : platform.graphics().ctx().scale; }
ByteBuffer checkGetImageBuffer (int byteSize) { if (imgBuf == null) imgBuf = createImageBuffer(Math.max(1024, byteSize)); if (imgBuf.capacity() >= byteSize) imgBuf.clear(); // reuse it! else imgBuf = createImageBuffer(byteSize); return imgBuf; }
@Override protected Image createStaticImage(BufferedImage bufimg, Scale scale) { return platform.graphics().createStaticImage(bufimg, scale); }
public static JavaTextLayout[] layoutText (JavaGraphics gfx, String text, TextFormat format, TextWrap wrap) { // normalize newlines in the text (Windows: CRLF -> LF, Mac OS pre-X: CR -> LF) text = normalizeEOL(text); // we do some fiddling to work around the fact that TextLayout chokes on the empty string String ltext = text.length() == 0 ? " " : text; // set up an attributed character iterator so that we can measure the text AttributedString astring = new AttributedString(ltext); if (format.font != null) { astring.addAttribute(TextAttribute.FONT, gfx.resolveFont(format.font)); } List<JavaTextLayout> layouts = new ArrayList<JavaTextLayout>(); FontRenderContext frc = format.antialias ? gfx.aaFontContext() : gfx.aFontContext(); LineBreakMeasurer measurer = new LineBreakMeasurer(astring.getIterator(), frc); int lastPos = ltext.length(), curPos = 0; char eol = '\n'; while (curPos < lastPos) { int nextRet = ltext.indexOf(eol, measurer.getPosition()+1); if (nextRet == -1) { nextRet = lastPos; } TextLayout layout = measurer.nextLayout(wrap.width, nextRet, false); int endPos = measurer.getPosition(); while (curPos < endPos && ltext.charAt(curPos) == eol) curPos += 1; // skip over EOLs layouts.add(new JavaTextLayout(ltext.substring(curPos, endPos), format, layout)); curPos = endPos; } return layouts.toArray(new JavaTextLayout[layouts.size()]); }
protected void processFrame(Game game) { // Event handling. mouse.update(); keyboard.update(); pointer.update(); // Execute any pending runnables. runQueue.execute(); // Run the game loop, render the scene graph, and update the display. game.tick(tick()); if (active) graphics.paint(); }
protected Scale assetScale() { return (assetScale != null) ? assetScale : plat.graphics().scale(); }
@Override protected AsyncImage<BufferedImage> createAsyncImage(float width, float height) { return platform.graphics().createAsyncImage(width, height); }
BufferedImage image = requireResource(rsrc.path).readImage(); Scale viewScale = platform.graphics().ctx().scale, imageScale = rsrc.scale; float viewImageRatio = viewScale.factor / imageScale.factor; if (viewImageRatio < 1) {