Search in sources :

Example 16 with Vector2i

use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.

the class CanvasImpl method processMouseRelease.

@Override
public boolean processMouseRelease(MouseInput button, Vector2i pos) {
    if (clickedRegion != null) {
        Vector2i relPos = new Vector2i(pos);
        relPos.sub(clickedRegion.region.min());
        clickedRegion.listener.onMouseRelease(new NUIMouseReleaseEvent(mouse, keyboard, relPos, button));
        clickedRegion = null;
        return true;
    }
    return false;
}
Also used : NUIMouseReleaseEvent(org.terasology.rendering.nui.events.NUIMouseReleaseEvent) Vector2i(org.terasology.math.geom.Vector2i) BaseVector2i(org.terasology.math.geom.BaseVector2i)

Example 17 with Vector2i

use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.

the class CanvasImpl method calculateMaximumSize.

@Override
public Vector2i calculateMaximumSize(UIWidget widget) {
    if (widget == null) {
        return new Vector2i(Integer.MAX_VALUE, Integer.MAX_VALUE);
    }
    String family = (widget.getFamily() != null) ? widget.getFamily() : state.family;
    UIStyle elementStyle = state.skin.getStyleFor(family, widget.getClass(), UIWidget.BASE_PART, widget.getMode());
    try (SubRegion ignored = subRegionForWidget(widget, getRegion(), false)) {
        return applyStyleToSize(elementStyle.getMargin().grow(widget.getMaxContentSize(this)), elementStyle);
    }
}
Also used : UIStyle(org.terasology.rendering.nui.skin.UIStyle) Vector2i(org.terasology.math.geom.Vector2i) BaseVector2i(org.terasology.math.geom.BaseVector2i) SubRegion(org.terasology.rendering.nui.SubRegion)

Example 18 with Vector2i

use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.

the class LwjglCanvasRenderer method drawTextureBordered.

@Override
public void drawTextureBordered(TextureRegion texture, Rect2i region, Border border, boolean tile, float ux, float uy, float uw, float uh, float alpha) {
    if (!texture.getTexture().isLoaded()) {
        return;
    }
    if (!currentTextureCropRegion.equals(requestedCropRegion) && !(currentTextureCropRegion.contains(region) && requestedCropRegion.contains(region))) {
        textureMat.setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX(), requestedCropRegion.maxX(), requestedCropRegion.minY(), requestedCropRegion.maxY());
        currentTextureCropRegion = requestedCropRegion;
    }
    Vector2i textureSize = new Vector2i(TeraMath.ceilToInt(texture.getWidth() * uw), TeraMath.ceilToInt(texture.getHeight() * uh));
    TextureCacheKey key = new TextureCacheKey(textureSize, region.size(), border, tile);
    usedTextures.add(key);
    Mesh mesh = cachedTextures.get(key);
    if (mesh == null || mesh.isDisposed()) {
        MeshBuilder builder = new MeshBuilder();
        float topTex = (float) border.getTop() / textureSize.y;
        float leftTex = (float) border.getLeft() / textureSize.x;
        float bottomTex = 1f - (float) border.getBottom() / textureSize.y;
        float rightTex = 1f - (float) border.getRight() / textureSize.x;
        int centerHoriz = region.width() - border.getTotalWidth();
        int centerVert = region.height() - border.getTotalHeight();
        float top = (float) border.getTop() / region.height();
        float left = (float) border.getLeft() / region.width();
        float bottom = 1f - (float) border.getBottom() / region.height();
        float right = 1f - (float) border.getRight() / region.width();
        if (border.getTop() != 0) {
            if (border.getLeft() != 0) {
                addRectPoly(builder, 0, 0, left, top, 0, 0, leftTex, topTex);
            }
            if (tile) {
                addTiles(builder, Rect2i.createFromMinAndSize(border.getLeft(), 0, centerHoriz, border.getTop()), Rect2f.createFromMinAndMax(left, 0, right, top), new Vector2i(textureSize.x - border.getTotalWidth(), border.getTop()), Rect2f.createFromMinAndMax(leftTex, 0, rightTex, topTex));
            } else {
                addRectPoly(builder, left, 0, right, top, leftTex, 0, rightTex, topTex);
            }
            if (border.getRight() != 0) {
                addRectPoly(builder, right, 0, 1, top, rightTex, 0, 1, topTex);
            }
        }
        if (border.getLeft() != 0) {
            if (tile) {
                addTiles(builder, Rect2i.createFromMinAndSize(0, border.getTop(), border.getLeft(), centerVert), Rect2f.createFromMinAndMax(0, top, left, bottom), new Vector2i(border.getLeft(), textureSize.y - border.getTotalHeight()), Rect2f.createFromMinAndMax(0, topTex, leftTex, bottomTex));
            } else {
                addRectPoly(builder, 0, top, left, bottom, 0, topTex, leftTex, bottomTex);
            }
        }
        if (tile) {
            addTiles(builder, Rect2i.createFromMinAndSize(border.getLeft(), border.getTop(), centerHoriz, centerVert), Rect2f.createFromMinAndMax(left, top, right, bottom), new Vector2i(textureSize.x - border.getTotalWidth(), textureSize.y - border.getTotalHeight()), Rect2f.createFromMinAndMax(leftTex, topTex, rightTex, bottomTex));
        } else {
            addRectPoly(builder, left, top, right, bottom, leftTex, topTex, rightTex, bottomTex);
        }
        if (border.getRight() != 0) {
            if (tile) {
                addTiles(builder, Rect2i.createFromMinAndSize(region.width() - border.getRight(), border.getTop(), border.getRight(), centerVert), Rect2f.createFromMinAndMax(right, top, 1, bottom), new Vector2i(border.getRight(), textureSize.y - border.getTotalHeight()), Rect2f.createFromMinAndMax(rightTex, topTex, 1, bottomTex));
            } else {
                addRectPoly(builder, right, top, 1, bottom, rightTex, topTex, 1, bottomTex);
            }
        }
        if (border.getBottom() != 0) {
            if (border.getLeft() != 0) {
                addRectPoly(builder, 0, bottom, left, 1, 0, bottomTex, leftTex, 1);
            }
            if (tile) {
                addTiles(builder, Rect2i.createFromMinAndSize(border.getLeft(), region.height() - border.getBottom(), centerHoriz, border.getBottom()), Rect2f.createFromMinAndMax(left, bottom, right, 1), new Vector2i(textureSize.x - border.getTotalWidth(), border.getBottom()), Rect2f.createFromMinAndMax(leftTex, bottomTex, rightTex, 1));
            } else {
                addRectPoly(builder, left, bottom, right, 1, leftTex, bottomTex, rightTex, 1);
            }
            if (border.getRight() != 0) {
                addRectPoly(builder, right, bottom, 1, 1, rightTex, bottomTex, 1, 1);
            }
        }
        mesh = builder.build();
        cachedTextures.put(key, mesh);
    }
    textureMat.setFloat2("scale", region.width(), region.height());
    textureMat.setFloat2("offset", region.minX(), region.minY());
    Rect2f textureArea = texture.getRegion();
    textureMat.setFloat2("texOffset", textureArea.minX() + ux * textureArea.width(), textureArea.minY() + uy * textureArea.height());
    textureMat.setFloat2("texSize", uw * textureArea.width(), uh * textureArea.height());
    textureMat.setTexture("texture", texture.getTexture());
    textureMat.setFloat4("color", 1, 1, 1, alpha);
    textureMat.bindTextures();
    mesh.render();
}
Also used : Rect2f(org.terasology.math.geom.Rect2f) FontMeshBuilder(org.terasology.rendering.assets.font.FontMeshBuilder) MeshBuilder(org.terasology.rendering.assets.mesh.MeshBuilder) Mesh(org.terasology.rendering.assets.mesh.Mesh) Vector2i(org.terasology.math.geom.Vector2i) BaseVector2i(org.terasology.math.geom.BaseVector2i)

Example 19 with Vector2i

use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.

the class AtlasFormat method load.

@Override
public AtlasData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
    try (Reader reader = new InputStreamReader(inputs.get(0).openStream(), Charsets.UTF_8)) {
        AtlasDefinition def = gson.fromJson(reader, AtlasDefinition.class);
        Optional<? extends Texture> texture = assetManager.getAsset(def.getTexture(), Texture.class);
        if (texture.isPresent()) {
            Vector2i size = def.getTextureSize();
            if (size == null) {
                size = new Vector2i(texture.get().getWidth(), texture.get().getHeight());
            }
            Map<Name, SubtextureData> result = Maps.newHashMap();
            if (def.getGrid() != null) {
                process(def.getGrid(), texture.get(), size, result);
            }
            if (def.getGrids() != null) {
                for (GridDefinition grid : def.getGrids()) {
                    process(grid, texture.get(), size, result);
                }
            }
            if (def.getSubimage() != null) {
                process(def.getSubimage(), texture.get(), size, result);
            }
            if (def.getSubimages() != null) {
                for (FreeformDefinition freeform : def.getSubimages()) {
                    process(freeform, texture.get(), size, result);
                }
            }
            return new AtlasData(result);
        }
        return null;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Vector2i(org.terasology.math.geom.Vector2i) Name(org.terasology.naming.Name)

Example 20 with Vector2i

use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.

the class ZoomableLayout method drawWidget.

protected void drawWidget(Canvas canvas, PositionalWidget widget) {
    if (!widget.isVisible()) {
        return;
    }
    Vector2i screenStart = worldToScreen(widget.getPosition());
    Vector2f worldEnd = new Vector2f(widget.getPosition());
    worldEnd.add(widget.getSize());
    Vector2i screenEnd = worldToScreen(worldEnd);
    canvas.drawWidget(widget, Rect2i.createFromMinAndMax(screenStart, screenEnd));
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) Vector2i(org.terasology.math.geom.Vector2i)

Aggregations

Vector2i (org.terasology.math.geom.Vector2i)76 UIWidget (org.terasology.rendering.nui.UIWidget)17 Rect2i (org.terasology.math.geom.Rect2i)14 BaseVector2i (org.terasology.math.geom.BaseVector2i)13 LayoutHint (org.terasology.rendering.nui.LayoutHint)13 List (java.util.List)9 Test (org.junit.Test)9 Vector2f (org.terasology.math.geom.Vector2f)6 Canvas (org.terasology.rendering.nui.Canvas)5 SubRegion (org.terasology.rendering.nui.SubRegion)5 UIStyle (org.terasology.rendering.nui.skin.UIStyle)5 UILabel (org.terasology.rendering.nui.widgets.UILabel)5 Before (org.junit.Before)4 Font (org.terasology.rendering.assets.font.Font)4 Color (org.terasology.rendering.nui.Color)4 Border (org.terasology.math.Border)3 Vector3f (org.terasology.math.geom.Vector3f)3 Mesh (org.terasology.rendering.assets.mesh.Mesh)3 HorizontalAlign (org.terasology.rendering.nui.HorizontalAlign)3 Sets (com.google.common.collect.Sets)2