Search in sources :

Example 11 with Rectanglei

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

the class TerasologyCanvasImpl method drawMesh.

public void drawMesh(Mesh mesh, Material material, Rectanglei region, Quaternionfc rotation, Vector3fc offset, float scale) {
    if (material == null) {
        logger.warn("Attempted to draw with nonexistent material");
        return;
    }
    if (mesh == null) {
        logger.warn("Attempted to draw nonexistent mesh");
        return;
    }
    Rectanglei drawRegion = relativeToAbsolute(region);
    if (!state.cropRegion.intersectsRectangle(drawRegion)) {
        return;
    }
    ((TerasologyCanvasRenderer) renderer).drawMesh(mesh, material, drawRegion, drawRegion.intersection(state.cropRegion), rotation, offset, scale, state.getAlpha());
}
Also used : Rectanglei(org.terasology.joml.geom.Rectanglei)

Example 12 with Rectanglei

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

the class ContextMenuScreen method onDraw.

@Override
public void onDraw(Canvas canvas) {
    canvas.addInteractionRegion(mainListener);
    Vector2i currentPosition = null;
    int currentWidth = 0;
    for (UIList<AbstractContextMenuItem> level : menuWidgets) {
        if (level.isVisible()) {
            if (currentPosition == null) {
                currentPosition = new Vector2i(position);
            } else {
                currentPosition.x += currentWidth;
            }
            Vector2i preferredSize = canvas.calculatePreferredSize(level);
            Rectanglei region = new Rectanglei(currentPosition.x, currentPosition.y).setSize(preferredSize.x, preferredSize.y);
            double percentageThreshold = 0.9;
            int canvasHeight = canvas.getRegion().getSizeY();
            if (region.maxY > canvasHeight * percentageThreshold) {
                region = new Rectanglei(region.minX, region.minY - (region.maxY - canvasHeight) - (int) (canvasHeight * (1 - percentageThreshold))).setSize(region.maxX, canvasHeight);
            }
            currentWidth = canvas.calculatePreferredSize(level).x() - 8;
            canvas.drawWidget(level, region);
        }
    }
}
Also used : Vector2i(org.joml.Vector2i) Rectanglei(org.terasology.joml.geom.Rectanglei)

Example 13 with Rectanglei

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

the class PortList method onDraw.

public void onDraw(Canvas canvas) {
    Rectanglei region = canvas.getRegion();
    inputPort.updateRect();
    canvas.drawWidget(inputPort, new Rectanglei((int) (inputPort.rect.minX() / 10.f * region.lengthX()), (int) (inputPort.rect.minY() / 5.f * region.lengthY()), (int) (inputPort.rect.maxX() / 10.f * region.lengthX()), (int) (inputPort.rect.maxY() / 5.f * region.lengthY())));
    for (Port port : ports) {
        port.updateRect();
        canvas.drawWidget(port, new Rectanglei((int) (port.rect.minX() / 10.f * region.lengthX()), (int) (port.rect.minY() / 5.f * region.lengthY()), (int) (port.rect.maxX() / 10.f * region.lengthX()), (int) (port.rect.maxY() / 5.f * region.lengthY())));
    }
}
Also used : Rectanglei(org.terasology.joml.geom.Rectanglei)

Example 14 with Rectanglei

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

the class ZoomableLayoutTest method testZoomInAndDrag.

@Test
public void testZoomInAndDrag() throws Exception {
    zoomableLayout.onDraw(canvas);
    // zoom in 2x towards left top corner
    zoomableLayout.zoom(0.5f, 0.5f, new Vector2i(0, 0));
    zoomableLayout.onDraw(canvas);
    // world size halved
    assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH, WORLD_HEIGHT / 2));
    assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT));
    assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / WORLD_WIDTH, CANVAS_HEIGHT / (WORLD_HEIGHT / 2)));
    verify(canvas).drawWidget(item1, new Rectanglei(new Vector2i(ceilToInt(pos1.x), ceilToInt(pos1.y)), new Vector2i(ceilToInt(pos1.x + size1.x), ceilToInt(pos1.y + size1.y))));
    verify(canvas).drawWidget(item2, new Rectanglei(new Vector2i(ceilToInt(pos2.x), ceilToInt(pos2.y)), new Vector2i(ceilToInt(pos2.x + size2.x), ceilToInt(pos2.y + size2.y))));
    verify(canvas).drawWidget(item3, new Rectanglei(new Vector2i(ceilToInt(pos3.x), ceilToInt(pos3.y)), new Vector2i(ceilToInt(pos3.x + size3.x), ceilToInt(pos3.y + size3.y))));
    // simulate drag to item2
    zoomableLayout.setWindowPosition(pos2);
    zoomableLayout.onDraw(canvas);
    // item1 out of canvas
    verify(canvas).drawWidget(item1, new Rectanglei(new Vector2i(ceilToInt(pos1.x - pos2.x), ceilToInt(pos1.y - pos2.y)), new Vector2i(ceilToInt(pos1.x + size1.x - pos2.x), ceilToInt(pos1.y + size1.y - pos2.y))));
    verify(canvas).drawWidget(item2, new Rectanglei(new Vector2i(), new Vector2i(ceilToInt(size2.x), ceilToInt(size2.y))));
    verify(canvas).drawWidget(item3, new Rectanglei(new Vector2i(ceilToInt(pos3.x - pos2.x), ceilToInt(pos3.y - pos2.y)), new Vector2i(ceilToInt(pos3.x + size3.x - pos2.x), ceilToInt(pos3.y + size3.y - pos2.y))));
}
Also used : Vector2f(org.joml.Vector2f) Vector2i(org.joml.Vector2i) Rectanglei(org.terasology.joml.geom.Rectanglei) Test(org.junit.jupiter.api.Test)

Example 15 with Rectanglei

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

the class RectangleiTypeHandler method deserialize.

@Override
public Optional<Rectanglei> deserialize(PersistedData data) {
    if (!data.isNull() && data.isValueMap()) {
        PersistedDataMap map = data.getAsValueMap();
        PersistedDataArray minDataArr = map.get(MIN_FIELD).getAsArray();
        TIntList minArr = minDataArr.getAsIntegerArray();
        if (map.has(SIZE_FIELD)) {
            PersistedDataArray sizedataArray = map.get(SIZE_FIELD).getAsArray();
            TIntList sizeArr = sizedataArray.getAsIntegerArray();
            return Optional.of(new Rectanglei(minArr.get(0), minArr.get(1)).setSize(sizeArr.get(0), sizeArr.get(1)));
        }
        PersistedDataArray maxDataArr = map.get(MAX_FIELD).getAsArray();
        TIntList maxArr = maxDataArr.getAsIntegerArray();
        return Optional.of(new Rectanglei(minArr.get(0), minArr.get(1), maxArr.get(0), maxArr.get(1)));
    }
    return Optional.empty();
}
Also used : PersistedDataArray(org.terasology.persistence.typeHandling.PersistedDataArray) PersistedDataMap(org.terasology.persistence.typeHandling.PersistedDataMap) Rectanglei(org.terasology.joml.geom.Rectanglei) TIntList(gnu.trove.list.TIntList)

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