public ImageFlowRenderable(TextureRegion textureRegion, Integer width, Integer height, String hyperlink) { this.textureRegion = textureRegion; if (width != null && height != null) { this.imageWidth = width; this.imageHeight = height; } else if (width != null) { this.imageWidth = width; this.imageHeight = Math.round((1f * width / textureRegion.getWidth()) * textureRegion.getHeight()); } else if (height != null) { this.imageHeight = height; this.imageWidth = Math.round((1f * height / textureRegion.getHeight()) * textureRegion.getWidth()); } else { this.imageWidth = textureRegion.getWidth(); this.imageHeight = textureRegion.getHeight(); } this.hyperlink = hyperlink; }
@Override public void drawTextureRawBordered(TextureRegion texture, Rect2i region, Border border, boolean tile, int ux, int uy, int uw, int uh) { drawTextureRawBordered(texture, region, border, tile, (float) ux / texture.getWidth(), (float) uy / texture.getHeight(), (float) uw / texture.getWidth(), (float) uh / texture.getHeight()); }
public static BufferedImage convertToImage(TextureRegion textureRegion) { final int width = textureRegion.getWidth(); final int height = textureRegion.getHeight(); final Rect2i pixelRegion = textureRegion.getPixelRegion(); final Texture texture = textureRegion.getTexture(); ByteBuffer textureBytes = texture.getData().getBuffers()[0]; int stride = texture.getWidth() * 4; int posX = pixelRegion.minX(); int posY = pixelRegion.minY(); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int r = UnsignedBytes.toInt(textureBytes.get((posY + y) * stride + (posX + x) * 4)); int g = UnsignedBytes.toInt(textureBytes.get((posY + y) * stride + (posX + x) * 4 + 1)); int b = UnsignedBytes.toInt(textureBytes.get((posY + y) * stride + (posX + x) * 4 + 2)); int a = UnsignedBytes.toInt(textureBytes.get((posY + y) * stride + (posX + x) * 4 + 3)); int argb = (a << 24) + (r << 16) + (g << 8) + b; image.setRGB(x, y, argb); } } return image; }
private Vector2i getIconSize(Canvas canvas) { UIStyle iconStyle = canvas.getCurrentStyle(); int width = iconStyle.getFixedWidth(); int height = iconStyle.getFixedHeight(); if (width == 0) { width = iconStyle.getMinWidth(); } if (height == 0) { height = iconStyle.getMinHeight(); } if (width == 0) { width = icon.getWidth(); } if (height == 0) { height = icon.getHeight(); } return new Vector2i(width, height); }
@Override public void draw(T value, Canvas canvas) { // Drawing the icon TextureRegion texture = getTexture(value); if (texture != null) { if (marginTop + texture.getHeight() + marginBottom > canvas.size().y) { // Icon does not fit within the canvas - vertically shrinking it int iconHeight = canvas.size().y - marginTop - marginBottom; canvas.drawTexture(texture, Rect2i.createFromMinAndSize(marginLeft, marginTop, texture.getWidth(), iconHeight)); } else { // Icon fits within the canvas - vertically centering it int iconVerticalPosition = (canvas.size().y - texture.getHeight()) / 2; canvas.drawTexture(texture, Rect2i.createFromMinAndSize(marginLeft, iconVerticalPosition, texture.getWidth(), texture.getHeight())); } } // Drawing the text, adjusting for icon width String text = getString(value); int iconWidth; if (texture != null) { iconWidth = marginLeft + texture.getWidth() + marginRight; } else { iconWidth = 0; } Rect2i textRegion = Rect2i.createFromMinAndSize(iconWidth, 0, canvas.getRegion().width() - iconWidth, canvas.getRegion().height()); canvas.drawText(text, textRegion); }
@Override public void onDraw(Canvas canvas) { if (fillTexture != null) { int size = TeraMath.floorToInt(canvas.size().x * getValue()); int barWidth = fillTexture.getWidth(); int offset = 0; if (time != null && animate) { offset = (int) ((time.getRealTimeInMs() / 10) % barWidth); } int drawnWidth = 0; // Draw Offset if (offset != 0) { int drawWidth = Math.min(size, offset); canvas.drawTextureRaw(fillTexture, Rect2i.createFromMinAndSize(0, 0, drawWidth, canvas.size().y), ScaleMode.STRETCH, barWidth - offset, 0, drawWidth, canvas.size().y); drawnWidth += drawWidth; } // Draw Remainder while (drawnWidth < size) { int drawWidth = Math.min(size - drawnWidth, barWidth); canvas.drawTextureRaw(fillTexture, Rect2i.createFromMinAndSize(drawnWidth, 0, drawWidth, canvas.size().y), ScaleMode.STRETCH, 0, 0, drawWidth, canvas.size().y); drawnWidth += drawWidth; } } }
@Override public Vector2i getPreferredSize(T value, Canvas canvas) { Font font = canvas.getCurrentStyle().getFont(); String text = getString(value); TextureRegion texture = getTexture(value); if (texture == null) { List<String> lines = TextLineBuilder.getLines(font, text, canvas.size().x); return font.getSize(lines); } else { int iconWidth = marginLeft + texture.getWidth() + marginRight; List<String> lines = TextLineBuilder.getLines(font, text, canvas.size().x - iconWidth); return font.getSize(lines).addX(iconWidth); } }
Vector2f scale = mode.scaleForRegion(absoluteRegion, texture.getWidth(), texture.getHeight()); Rect2f textureArea = texture.getRegion(); Mesh mesh = billboard;
Vector2i textureSize = new Vector2i(TeraMath.ceilToInt(texture.getWidth() * uw), TeraMath.ceilToInt(texture.getHeight() * uh));