Search in sources :

Example 1 with SubRegion

use of org.terasology.rendering.nui.SubRegion in project Terasology by MovingBlocks.

the class ScrollableArea method layoutWithJustHorizontal.

private void layoutWithJustHorizontal(Canvas canvas, Vector2i contentSize, int availableWidth, int fullHeight, int scrollbarHeight) {
    int availableHeight = fullHeight - scrollbarHeight;
    Rect2i contentRegion = Rect2i.createFromMinAndSize(0, 0, availableWidth, availableHeight);
    horizontalBar.setRange(contentSize.x - contentRegion.width());
    canvas.addInteractionRegion(scrollListener);
    canvas.drawWidget(horizontalBar, Rect2i.createFromMinAndSize(0, availableHeight, availableWidth, scrollbarHeight));
    try (SubRegion ignored = canvas.subRegion(contentRegion, true)) {
        canvas.drawWidget(content, Rect2i.createFromMinAndSize(-horizontalBar.getValue(), 0, contentSize.x, availableHeight));
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) SubRegion(org.terasology.rendering.nui.SubRegion) LayoutHint(org.terasology.rendering.nui.LayoutHint)

Example 2 with SubRegion

use of org.terasology.rendering.nui.SubRegion in project Terasology by MovingBlocks.

the class ScrollableArea method layoutWithBothScrollbars.

private void layoutWithBothScrollbars(Canvas canvas, Vector2i contentSize, int fullWidth, int fullHeight, int scrollbarWidth, int scrollbarHeight) {
    int availableWidth = fullWidth - scrollbarWidth;
    int availableHeight = fullHeight - scrollbarHeight;
    boolean atBottom = verticalBar.getRange() == verticalBar.getValue();
    Rect2i contentRegion = Rect2i.createFromMinAndSize(0, 0, availableWidth, availableHeight);
    verticalBar.setRange(contentSize.y - contentRegion.height());
    horizontalBar.setRange(contentSize.x - contentRegion.width());
    if ((stickToBottom && atBottom) || moveToBottomPending) {
        verticalBar.setValue(verticalBar.getRange());
        moveToBottomPending = false;
    }
    if (moveToTopPending) {
        verticalBar.setValue(0);
        moveToTopPending = false;
    }
    canvas.addInteractionRegion(scrollListener);
    canvas.drawWidget(verticalBar, Rect2i.createFromMinAndSize(availableWidth, 0, scrollbarWidth, availableHeight));
    canvas.drawWidget(horizontalBar, Rect2i.createFromMinAndSize(0, availableHeight, availableWidth, scrollbarHeight));
    try (SubRegion ignored = canvas.subRegion(contentRegion, true)) {
        canvas.drawWidget(content, Rect2i.createFromMinAndSize(-horizontalBar.getValue(), -verticalBar.getValue(), contentSize.x, contentSize.y));
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) SubRegion(org.terasology.rendering.nui.SubRegion) LayoutHint(org.terasology.rendering.nui.LayoutHint)

Example 3 with SubRegion

use of org.terasology.rendering.nui.SubRegion in project Terasology by MovingBlocks.

the class CanvasImpl method subRegionForWidget.

private SubRegion subRegionForWidget(UIWidget widget, Rect2i region, boolean crop) {
    SubRegion result = subRegion(region, crop);
    state.element = widget;
    if (widget.getSkin() != null) {
        setSkin(widget.getSkin());
    }
    if (widget.getFamily() != null) {
        setFamily(widget.getFamily());
    }
    setPart(UIWidget.BASE_PART);
    setMode(widget.getMode());
    return result;
}
Also used : SubRegion(org.terasology.rendering.nui.SubRegion)

Example 4 with SubRegion

use of org.terasology.rendering.nui.SubRegion in project Terasology by MovingBlocks.

the class CanvasImpl method calculateMaximumSize.

@Override
public Vector2i calculateMaximumSize(UIWidget widget) {
    if (widget == null) {
        return new Vector2i(Integer.MAX_VALUE, Integer.MAX_VALUE);
    }
    String family = (widget.getFamily() != null) ? widget.getFamily() : state.family;
    UIStyle elementStyle = state.skin.getStyleFor(family, widget.getClass(), UIWidget.BASE_PART, widget.getMode());
    try (SubRegion ignored = subRegionForWidget(widget, getRegion(), false)) {
        return applyStyleToSize(elementStyle.getMargin().grow(widget.getMaxContentSize(this)), elementStyle);
    }
}
Also used : UIStyle(org.terasology.rendering.nui.skin.UIStyle) Vector2i(org.terasology.math.geom.Vector2i) BaseVector2i(org.terasology.math.geom.BaseVector2i) SubRegion(org.terasology.rendering.nui.SubRegion)

Example 5 with SubRegion

use of org.terasology.rendering.nui.SubRegion in project Terasology by MovingBlocks.

the class CanvasImpl method drawWidget.

@Override
public void drawWidget(UIWidget element, Rect2i region) {
    if (element == null || !element.isVisible()) {
        return;
    }
    if (nuiManager.getFocus() == element) {
        focusDrawn = true;
    }
    String family = (element.getFamily() != null) ? element.getFamily() : state.family;
    UISkin skin = (element.getSkin() != null) ? element.getSkin() : state.skin;
    UIStyle newStyle = skin.getStyleFor(family, element.getClass(), UIWidget.BASE_PART, element.getMode());
    Rect2i regionArea;
    try (SubRegion ignored = subRegionForWidget(element, region, false)) {
        regionArea = applyStyleToSize(region, newStyle, calculateMaximumSize(element));
    }
    try (SubRegion ignored = subRegionForWidget(element, regionArea, false)) {
        if (element.isSkinAppliedByCanvas()) {
            drawBackground();
            try (SubRegion withMargin = subRegionForWidget(element, newStyle.getMargin().shrink(Rect2i.createFromMinAndSize(Vector2i.zero(), regionArea.size())), false)) {
                drawStyledWidget(element);
            }
        } else {
            drawStyledWidget(element);
        }
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) UISkin(org.terasology.rendering.nui.skin.UISkin) UIStyle(org.terasology.rendering.nui.skin.UIStyle) SubRegion(org.terasology.rendering.nui.SubRegion)

Aggregations

SubRegion (org.terasology.rendering.nui.SubRegion)13 Rect2i (org.terasology.math.geom.Rect2i)8 Vector2i (org.terasology.math.geom.Vector2i)4 UIStyle (org.terasology.rendering.nui.skin.UIStyle)4 LayoutHint (org.terasology.rendering.nui.LayoutHint)3 BaseVector2i (org.terasology.math.geom.BaseVector2i)2 UISkin (org.terasology.rendering.nui.skin.UISkin)2 InputSystem (org.terasology.input.InputSystem)1 MouseDevice (org.terasology.input.device.MouseDevice)1 Vector2f (org.terasology.math.geom.Vector2f)1 UIWidget (org.terasology.rendering.nui.UIWidget)1