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);
}
}
}
}
Aggregations