Search in sources :

Example 21 with Rectanglei

use of org.terasology.joml.geom.Rectanglei in project Terasology by MovingBlocks.

the class TerasologyCanvasImpl method drawMaterial.

// NOTE: drawMaterial and drawMesh can now only be accessed through CanvasUtility
public void drawMaterial(Material material, Rectanglei region) {
    if (material.isRenderable()) {
        Rectanglei drawRegion = relativeToAbsolute(region);
        if (!state.cropRegion.intersectsRectangle(drawRegion)) {
            return;
        }
        material.setFloat("alpha", state.getAlpha());
        material.bindTextures();
        ((TerasologyCanvasRenderer) renderer).drawMaterialAt(material, drawRegion);
    }
}
Also used : Rectanglei(org.terasology.joml.geom.Rectanglei)

Example 22 with Rectanglei

use of org.terasology.joml.geom.Rectanglei in project Terasology by MovingBlocks.

the class FacetLayerPreview method render.

@Override
public ByteBuffer render(TextureData texData, int scale, ProgressListener progressListener) throws InterruptedException {
    int width = texData.getWidth();
    int height = texData.getWidth();
    final int offX = -width * scale / 2;
    final int offY = -height * scale / 2;
    // trigger building the World now
    worldGenerator.getWorld();
    Rectanglei worldArea = new Rectanglei(offX, offY).setSize(width * scale, height * scale);
    Rectanglei tileArea = worldToTileArea(worldArea);
    AtomicInteger tilesComplete = new AtomicInteger(0);
    int tileCount = tileArea.area();
    int[] masks = colorModel.getMasks();
    DataBufferInt imageBuffer = new DataBufferInt(width * height);
    WritableRaster raster = Raster.createPackedRaster(imageBuffer, width, height, width, masks, null);
    BufferedImage view = new BufferedImage(colorModel, raster, false, null);
    Graphics2D g = view.createGraphics();
    g.scale(1f / scale, 1f / scale);
    g.translate(-offX, -offY);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    Map<Vector2ic, Future<BufferedImage>> imageFutures = new HashMap<>(tileCount);
    for (int z = tileArea.minY(); z < tileArea.maxY(); z++) {
        for (int x = tileArea.minX(); x < tileArea.maxX(); x++) {
            Vector2i pos = new Vector2i(x, z);
            imageFutures.put(pos, threadPool.submit(() -> {
                Region createRegion = createRegion(pos);
                BufferedImage image = rasterize(createRegion);
                if (progressListener != null) {
                    progressListener.onProgress(tilesComplete.incrementAndGet() / (float) tileCount);
                }
                return image;
            }));
        }
    }
    for (int z = tileArea.minY(); z < tileArea.maxY(); z++) {
        for (int x = tileArea.minX(); x < tileArea.maxX(); x++) {
            Vector2i pos = new Vector2i(x, z);
            try {
                BufferedImage tileImage = imageFutures.get(pos).get();
                g.drawImage(tileImage, x * TILE_SIZE_X, z * TILE_SIZE_Y, null);
            } catch (ExecutionException e) {
                logger.warn("Could not rasterize tile {}", pos, e);
            }
            if (Thread.currentThread().isInterrupted()) {
                throw new InterruptedException();
            }
        }
    }
    // draw coordinate lines through 0 / 0
    g.setColor(Color.GRAY);
    g.drawLine(worldArea.minX(), 0, worldArea.maxX(), 0);
    g.drawLine(0, worldArea.minY(), 0, worldArea.maxY());
    g.dispose();
    int[] data = imageBuffer.getData();
    ByteBuffer byteBuffer = texData.getBuffers()[0];
    byteBuffer.asIntBuffer().put(data);
    return byteBuffer;
}
Also used : HashMap(java.util.HashMap) Rectanglei(org.terasology.joml.geom.Rectanglei) DataBufferInt(java.awt.image.DataBufferInt) ByteBuffer(java.nio.ByteBuffer) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WritableRaster(java.awt.image.WritableRaster) Vector2ic(org.joml.Vector2ic) Future(java.util.concurrent.Future) BlockRegion(org.terasology.engine.world.block.BlockRegion) Region(org.terasology.engine.world.generation.Region) Vector2i(org.joml.Vector2i) ExecutionException(java.util.concurrent.ExecutionException)

Example 23 with Rectanglei

use of org.terasology.joml.geom.Rectanglei in project Terasology by MovingBlocks.

the class DocumentRenderer method getParagraphsPreferredHeight.

public static int getParagraphsPreferredHeight(ParagraphRenderStyle baseRenderStyle, Collection<ParagraphData> paragraphs, ContainerRenderSpace containerRenderSpace, int yStart) {
    int containerWidth = containerRenderSpace.getContainerWidth();
    int yShift = yStart;
    for (ParagraphData paragraphData : paragraphs) {
        ParagraphRenderStyle paragraphRenderStyle = getParagraphRenderStyle(baseRenderStyle, paragraphData);
        ParagraphRenderStyle.ClearStyle clearStyle = paragraphRenderStyle.getClearStyle();
        if (clearStyle != ParagraphRenderStyle.ClearStyle.NONE) {
            yShift = Math.max(yShift, containerRenderSpace.getNextClearYPosition(clearStyle));
        }
        ParagraphRenderStyle.FloatStyle floatStyle = paragraphRenderStyle.getFloatStyle();
        if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT || floatStyle == ParagraphRenderStyle.FloatStyle.RIGHT) {
            int paragraphMinWidth = Math.max(paragraphRenderStyle.getParagraphMinimumWidth().getValue(containerWidth), paragraphData.getParagraphContents().getContentsMinWidth(paragraphRenderStyle));
            int paragraphSideIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
            int height = paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
            height += paragraphData.getParagraphContents().getPreferredContentsHeight(paragraphRenderStyle, 0, new ContainerFlowContainerRenderSpace(paragraphMinWidth), paragraphSideIndent);
            height += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
            if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT) {
                Rectanglei position = containerRenderSpace.addLeftFloat(yShift, paragraphMinWidth, height);
                yShift = position.minY;
            } else {
                Rectanglei position = containerRenderSpace.addRightFloat(yShift, paragraphMinWidth, height);
                yShift = position.minY;
            }
        } else {
            yShift += paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
            int paragraphSideIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
            yShift += paragraphData.getParagraphContents().getPreferredContentsHeight(paragraphRenderStyle, yShift, containerRenderSpace, paragraphSideIndent);
            yShift += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
        }
    }
    return yShift - yStart;
}
Also used : ParagraphData(org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData) Rectanglei(org.terasology.joml.geom.Rectanglei) FallbackParagraphRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.FallbackParagraphRenderStyle) ParagraphRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle)

Example 24 with Rectanglei

use of org.terasology.joml.geom.Rectanglei in project Terasology by MovingBlocks.

the class ContainerFlowContainerRenderSpace method getAvailableWidthAt.

private int getAvailableWidthAt(int y) {
    int width = containerWidth;
    Rectanglei lastRight = findLastAtYPosition(rightFloats, y);
    if (lastRight != null) {
        width = lastRight.minX;
    }
    Rectanglei lastLeft = findLastAtYPosition(leftFloats, y);
    if (lastLeft != null) {
        width -= lastLeft.maxX;
    }
    return width;
}
Also used : Rectanglei(org.terasology.joml.geom.Rectanglei)

Aggregations

Rectanglei (org.terasology.joml.geom.Rectanglei)24 Vector2i (org.joml.Vector2i)9 Vector2f (org.joml.Vector2f)6 ByteBuffer (java.nio.ByteBuffer)3 Test (org.junit.jupiter.api.Test)3 FontMeshBuilder (org.terasology.engine.rendering.assets.font.FontMeshBuilder)3 Mesh (org.terasology.engine.rendering.assets.mesh.Mesh)3 MeshBuilder (org.terasology.engine.rendering.assets.mesh.MeshBuilder)3 TextureRegion (org.terasology.engine.rendering.assets.texture.TextureRegion)3 Rectanglef (org.terasology.joml.geom.Rectanglef)3 UITextureRegion (org.terasology.nui.UITextureRegion)3 BufferedImage (java.awt.image.BufferedImage)2 Matrix4f (org.joml.Matrix4f)2 Vector2ic (org.joml.Vector2ic)2 Color (org.terasology.nui.Color)2 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 TIntList (gnu.trove.list.TIntList)1 Graphics2D (java.awt.Graphics2D)1 DataBufferInt (java.awt.image.DataBufferInt)1