Search in sources :

Example 41 with Vector2i

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

the class CanvasImpl method processMousePosition.

@Override
public void processMousePosition(Vector2i position) {
    if (clickedRegion != null) {
        Vector2i relPos = new Vector2i(position);
        relPos.sub(clickedRegion.offset);
        clickedRegion.listener.onMouseDrag(new NUIMouseDragEvent(mouse, keyboard, relPos));
    }
    Set<InteractionRegion> newMouseOverRegions = Sets.newLinkedHashSet();
    Iterator<InteractionRegion> iter = interactionRegions.descendingIterator();
    while (iter.hasNext()) {
        InteractionRegion next = iter.next();
        if (next.region.contains(position)) {
            Vector2i relPos = new Vector2i(position);
            relPos.sub(next.offset);
            boolean isTopMostElement = newMouseOverRegions.isEmpty();
            next.listener.onMouseOver(new NUIMouseOverEvent(mouse, keyboard, relPos, isTopMostElement));
            newMouseOverRegions.add(next);
        }
    }
    mouseOverRegions.stream().filter(region -> !newMouseOverRegions.contains(region)).forEach(region -> region.listener.onMouseLeave());
    if (clickedRegion != null && !interactionRegions.contains(clickedRegion)) {
        clickedRegion = null;
    }
    mouseOverRegions = newMouseOverRegions;
    if (mouseOverRegions.isEmpty()) {
        topMouseOverRegion = null;
    } else {
        InteractionRegion newTopMouseOverRegion = mouseOverRegions.iterator().next();
        if (!newTopMouseOverRegion.equals(topMouseOverRegion)) {
            topMouseOverRegion = newTopMouseOverRegion;
            tooltipTime = time.getGameTime() + newTopMouseOverRegion.element.getTooltipDelay();
            lastTooltipPosition.set(position);
        } else {
            if (lastTooltipPosition.gridDistance(position) > MAX_DOUBLE_CLICK_DISTANCE) {
                tooltipTime = time.getGameTime() + newTopMouseOverRegion.element.getTooltipDelay();
                lastTooltipPosition.set(position);
            }
        }
    }
}
Also used : UIStyle(org.terasology.rendering.nui.skin.UIStyle) MouseDevice(org.terasology.input.device.MouseDevice) LoggerFactory(org.slf4j.LoggerFactory) Time(org.terasology.engine.Time) Vector3f(org.terasology.math.geom.Vector3f) FrameBufferObject(org.terasology.rendering.opengl.FrameBufferObject) InputSystem(org.terasology.input.InputSystem) Material(org.terasology.rendering.assets.material.Material) BaseInteractionListener(org.terasology.rendering.nui.BaseInteractionListener) NUIMouseOverEvent(org.terasology.rendering.nui.events.NUIMouseOverEvent) UITooltip(org.terasology.rendering.nui.widgets.UITooltip) TeraMath(org.terasology.math.TeraMath) NUIMouseReleaseEvent(org.terasology.rendering.nui.events.NUIMouseReleaseEvent) Context(org.terasology.context.Context) InteractionListener(org.terasology.rendering.nui.InteractionListener) SubRegion(org.terasology.rendering.nui.SubRegion) KeyboardDevice(org.terasology.input.device.KeyboardDevice) Set(java.util.Set) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) Queues(com.google.common.collect.Queues) List(java.util.List) Font(org.terasology.rendering.assets.font.Font) TextureRegion(org.terasology.rendering.assets.texture.TextureRegion) ResourceUrn(org.terasology.assets.ResourceUrn) HorizontalAlign(org.terasology.rendering.nui.HorizontalAlign) VerticalAlign(org.terasology.rendering.nui.VerticalAlign) NUIMouseWheelEvent(org.terasology.rendering.nui.events.NUIMouseWheelEvent) Texture(org.terasology.rendering.assets.texture.Texture) UISkin(org.terasology.rendering.nui.skin.UISkin) ScaleMode(org.terasology.rendering.nui.ScaleMode) Rect2i(org.terasology.math.geom.Rect2i) Deque(java.util.Deque) NUIMouseDoubleClickEvent(org.terasology.rendering.nui.events.NUIMouseDoubleClickEvent) Lists(com.google.common.collect.Lists) Mesh(org.terasology.rendering.assets.mesh.Mesh) MouseInput(org.terasology.input.MouseInput) NUIManager(org.terasology.rendering.nui.NUIManager) Assets(org.terasology.utilities.Assets) NUIMouseClickEvent(org.terasology.rendering.nui.events.NUIMouseClickEvent) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Vector2i(org.terasology.math.geom.Vector2i) UIWidget(org.terasology.rendering.nui.UIWidget) NUIMouseDragEvent(org.terasology.rendering.nui.events.NUIMouseDragEvent) UILabel(org.terasology.rendering.nui.widgets.UILabel) Border(org.terasology.math.Border) Quat4f(org.terasology.math.geom.Quat4f) BaseVector2i(org.terasology.math.geom.BaseVector2i) Color(org.terasology.rendering.nui.Color) Preconditions(com.google.common.base.Preconditions) NUIMouseOverEvent(org.terasology.rendering.nui.events.NUIMouseOverEvent) NUIMouseDragEvent(org.terasology.rendering.nui.events.NUIMouseDragEvent) Vector2i(org.terasology.math.geom.Vector2i) BaseVector2i(org.terasology.math.geom.BaseVector2i)

Example 42 with Vector2i

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

the class CanvasImpl method applyStyleToSize.

private Rect2i applyStyleToSize(Rect2i region, UIStyle style) {
    if (region.isEmpty()) {
        return region;
    }
    Vector2i size = applyStyleToSize(region.size(), style);
    int minX = region.minX() + style.getHorizontalAlignment().getOffset(size.x, region.width());
    int minY = region.minY() + style.getVerticalAlignment().getOffset(size.y, region.height());
    return Rect2i.createFromMinAndSize(minX, minY, size.x, size.y);
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) BaseVector2i(org.terasology.math.geom.BaseVector2i)

Example 43 with Vector2i

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

the class CanvasImpl method applyStyleToSize.

private Rect2i applyStyleToSize(Rect2i region, UIStyle style, Vector2i maxSize) {
    if (region.isEmpty()) {
        return region;
    }
    Vector2i size = applyStyleToSize(region.size(), style);
    size.x = Math.min(size.x, maxSize.x);
    size.y = Math.min(size.y, maxSize.y);
    int minX = region.minX() + style.getHorizontalAlignment().getOffset(size.x, region.width());
    int minY = region.minY() + style.getVerticalAlignment().getOffset(size.y, region.height());
    return Rect2i.createFromMinAndSize(minX, minY, size.x, size.y);
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) BaseVector2i(org.terasology.math.geom.BaseVector2i)

Example 44 with Vector2i

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

the class Line method getLineCoordinates.

public static LineCoordinates getLineCoordinates(int startX, int startY, int endX, int endY, Rect2i baseRegion, Rect2i cropRegion) {
    Rect2i region = Rect2i.createFromMinAndMax(Math.min(startX, endX), Math.min(startY, endY), Math.max(startX, endX), Math.max(startY, endY));
    Rect2i absoluteRegion = relativeToAbsolute(region, baseRegion);
    Rect2i finalRegion = cropRegion.intersect(absoluteRegion);
    if (!finalRegion.isEmpty()) {
        int sx = startX > endX ? finalRegion.maxX() : finalRegion.minX();
        int sy = startY > endY ? finalRegion.maxY() : finalRegion.minY();
        int ex = startX > endX ? finalRegion.minX() : finalRegion.maxX();
        int ey = startY > endY ? finalRegion.minY() : finalRegion.maxY();
        return new LineCoordinates(new Vector2i(sx, sy), new Vector2i(ex, ey));
    } else {
        return null;
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) Vector2i(org.terasology.math.geom.Vector2i)

Example 45 with Vector2i

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

the class LwjglCanvasRenderer method drawText.

@Override
public void drawText(String text, Font font, HorizontalAlign hAlign, VerticalAlign vAlign, Rect2i absoluteRegion, Color color, Color shadowColor, float alpha, boolean underlined) {
    TextCacheKey key = new TextCacheKey(text, font, absoluteRegion.width(), hAlign, color, shadowColor, underlined);
    usedText.add(key);
    Map<Material, Mesh> fontMesh = cachedText.get(key);
    List<String> lines = TextLineBuilder.getLines(font, text, absoluteRegion.width());
    if (fontMesh != null) {
        for (Mesh mesh : fontMesh.values()) {
            if (mesh.isDisposed()) {
                fontMesh = null;
                break;
            }
        }
    }
    if (fontMesh == null) {
        fontMesh = fontMeshBuilder.createTextMesh(font, lines, absoluteRegion.width(), hAlign, color, shadowColor, underlined);
        cachedText.put(key, fontMesh);
    }
    Vector2i offset = new Vector2i(absoluteRegion.minX(), absoluteRegion.minY());
    offset.y += vAlign.getOffset(lines.size() * font.getLineHeight(), absoluteRegion.height());
    fontMesh.entrySet().stream().filter(entry -> entry.getKey().isRenderable()).forEach(entry -> {
        entry.getKey().bindTextures();
        entry.getKey().setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX(), requestedCropRegion.maxX(), requestedCropRegion.minY(), requestedCropRegion.maxY());
        entry.getKey().setFloat2("offset", offset.x, offset.y);
        entry.getKey().setFloat("alpha", alpha);
        entry.getValue().render();
    });
}
Also used : FloatBuffer(java.nio.FloatBuffer) AssetManager(org.terasology.assets.management.AssetManager) Vector3f(org.terasology.math.geom.Vector3f) FrameBufferObject(org.terasology.rendering.opengl.FrameBufferObject) GL11.glDisable(org.lwjgl.opengl.GL11.glDisable) FontMeshBuilder(org.terasology.rendering.assets.font.FontMeshBuilder) GL11.glOrtho(org.lwjgl.opengl.GL11.glOrtho) GL11.glTranslatef(org.lwjgl.opengl.GL11.glTranslatef) Material(org.terasology.rendering.assets.material.Material) Map(java.util.Map) GL11(org.lwjgl.opengl.GL11) TeraMath(org.terasology.math.TeraMath) TextLineBuilder(org.terasology.rendering.nui.TextLineBuilder) GL11.glLoadMatrix(org.lwjgl.opengl.GL11.glLoadMatrix) Display(org.lwjgl.opengl.Display) Context(org.terasology.context.Context) GL_PROJECTION(org.lwjgl.opengl.GL11.GL_PROJECTION) GL_SRC_ALPHA(org.lwjgl.opengl.GL11.GL_SRC_ALPHA) GL_DEPTH_TEST(org.lwjgl.opengl.GL11.GL_DEPTH_TEST) Set(java.util.Set) MeshBuilder(org.terasology.rendering.assets.mesh.MeshBuilder) GL11.glLoadIdentity(org.lwjgl.opengl.GL11.glLoadIdentity) Sets(com.google.common.collect.Sets) GL11.glPopMatrix(org.lwjgl.opengl.GL11.glPopMatrix) BufferUtils(org.lwjgl.BufferUtils) Objects(java.util.Objects) List(java.util.List) AABB(org.terasology.math.AABB) Font(org.terasology.rendering.assets.font.Font) TextureRegion(org.terasology.rendering.assets.texture.TextureRegion) GL11.glPushMatrix(org.lwjgl.opengl.GL11.glPushMatrix) ResourceUrn(org.terasology.assets.ResourceUrn) GL_MODELVIEW(org.lwjgl.opengl.GL11.GL_MODELVIEW) HorizontalAlign(org.terasology.rendering.nui.HorizontalAlign) VerticalAlign(org.terasology.rendering.nui.VerticalAlign) MatrixUtils(org.terasology.math.MatrixUtils) Rect2f(org.terasology.math.geom.Rect2f) ScaleMode(org.terasology.rendering.nui.ScaleMode) Rect2i(org.terasology.math.geom.Rect2i) Matrix4f(org.terasology.math.geom.Matrix4f) Mesh(org.terasology.rendering.assets.mesh.Mesh) BaseQuat4f(org.terasology.math.geom.BaseQuat4f) GL11.glClear(org.lwjgl.opengl.GL11.glClear) Assets(org.terasology.utilities.Assets) GL11.glMatrixMode(org.lwjgl.opengl.GL11.glMatrixMode) GL11.glEnable(org.lwjgl.opengl.GL11.glEnable) Iterator(java.util.Iterator) Vector2i(org.terasology.math.geom.Vector2i) Vector2f(org.terasology.math.geom.Vector2f) Maps(com.google.common.collect.Maps) ShaderProgramFeature(org.terasology.rendering.assets.shader.ShaderProgramFeature) LwjglFrameBufferObject(org.terasology.rendering.opengl.LwjglFrameBufferObject) GL11.glBlendFunc(org.lwjgl.opengl.GL11.glBlendFunc) GL11.glScalef(org.lwjgl.opengl.GL11.glScalef) GL_ONE_MINUS_SRC_ALPHA(org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA) Border(org.terasology.math.Border) Quat4f(org.terasology.math.geom.Quat4f) BaseVector2i(org.terasology.math.geom.BaseVector2i) Color(org.terasology.rendering.nui.Color) GL_BLEND(org.lwjgl.opengl.GL11.GL_BLEND) Mesh(org.terasology.rendering.assets.mesh.Mesh) Material(org.terasology.rendering.assets.material.Material) Vector2i(org.terasology.math.geom.Vector2i) BaseVector2i(org.terasology.math.geom.BaseVector2i)

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