Search in sources :

Example 1 with Border

use of org.terasology.math.Border in project Terasology by MovingBlocks.

the class UIList method onDraw.

@Override
public void onDraw(Canvas canvas) {
    updateItemListeners();
    canvas.setPart("item");
    boolean enabled = isEnabled();
    Border margin = canvas.getCurrentStyle().getMargin();
    int yOffset = 0;
    for (int i = 0; i < list.get().size(); ++i) {
        T item = list.get().get(i);
        Vector2i preferredSize = margin.grow(itemRenderer.getPreferredSize(item, canvas));
        Rect2i itemRegion = Rect2i.createFromMinAndSize(0, yOffset, canvas.size().x, preferredSize.y);
        ItemInteractionListener listener = itemListeners.get(i);
        if (enabled) {
            if (Objects.equals(item, selection.get())) {
                canvas.setMode(ACTIVE_MODE);
            } else if (listener.isMouseOver()) {
                canvas.setMode(HOVER_MODE);
            } else {
                canvas.setMode(DEFAULT_MODE);
            }
            if (isInteractive()) {
                canvas.addInteractionRegion(listener, itemRenderer.getTooltip(item), itemRegion);
            }
        } else {
            canvas.setMode(DISABLED_MODE);
        }
        canvas.drawBackground(itemRegion);
        itemRenderer.draw(item, canvas, margin.shrink(itemRegion));
        yOffset += preferredSize.getY();
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) Vector2i(org.terasology.math.geom.Vector2i) Border(org.terasology.math.Border)

Aggregations

Border (org.terasology.math.Border)1 Rect2i (org.terasology.math.geom.Rect2i)1 Vector2i (org.terasology.math.geom.Vector2i)1