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