Search in sources :

Example 1 with NUIMouseOverEvent

use of org.terasology.rendering.nui.events.NUIMouseOverEvent 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)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 Queues (com.google.common.collect.Queues)1 Sets (com.google.common.collect.Sets)1 Deque (java.util.Deque)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 ResourceUrn (org.terasology.assets.ResourceUrn)1 Context (org.terasology.context.Context)1 Time (org.terasology.engine.Time)1 InputSystem (org.terasology.input.InputSystem)1 MouseInput (org.terasology.input.MouseInput)1 KeyboardDevice (org.terasology.input.device.KeyboardDevice)1 MouseDevice (org.terasology.input.device.MouseDevice)1 Border (org.terasology.math.Border)1 TeraMath (org.terasology.math.TeraMath)1