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; }
float textureSize = Math.max(tex.getWidth(), tex.getHeight()); for (int y = 0; y < tex.getHeight(); y++) { for (int x = 0; x < tex.getWidth(); x++) { int r = buffer.get((posY + y) * stride + (posX + x) * 4) & 255; Vector4f color = new Vector4f(r / 255f, g / 255f, b / 255f, a / 255f); TessellatorHelper.addBlockMesh(tessellator, color, 2f / textureSize, 1.0f, 0.5f, 2f / textureSize * x - 1f, 2f / textureSize * (tex.getHeight() - y - 1) - 1f, 0f);
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); }
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));