Search in sources :

Example 1 with UIStyle

use of org.terasology.rendering.nui.skin.UIStyle 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 2 with UIStyle

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

Example 3 with UIStyle

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

the class CursorAttachment method onDraw.

@Override
public void onDraw(Canvas canvas) {
    UIStyle style = canvas.getCurrentStyle();
    Vector2i attachmentSize = canvas.calculatePreferredSize(attachment);
    attachmentSize.add(style.getMargin().getTotals());
    // TODO get rid of CoreRegistry. e.g. by updatin a mousePos field with an InteractionListener
    MouseDevice mouse = CoreRegistry.get(InputSystem.class).getMouseDevice();
    int top;
    switch(style.getVerticalAlignment()) {
        case TOP:
            top = mouse.getPosition().y - attachmentSize.y;
            break;
        case MIDDLE:
            top = mouse.getPosition().y - attachmentSize.y / 2;
            break;
        default:
            top = mouse.getPosition().y + MOUSE_CURSOR_HEIGHT;
            break;
    }
    top = TeraMath.clamp(top, 0, canvas.size().y - attachmentSize.y);
    int left;
    switch(style.getHorizontalAlignment()) {
        case RIGHT:
            left = mouse.getPosition().x - attachmentSize.x;
            break;
        case CENTER:
            left = mouse.getPosition().x - attachmentSize.x / 2;
            break;
        default:
            left = mouse.getPosition().x;
            break;
    }
    left = TeraMath.clamp(left, 0, canvas.size().x - attachmentSize.x);
    try (SubRegion ignored = canvas.subRegion(Rect2i.createFromMinAndSize(left, top, attachmentSize.x, attachmentSize.y), false)) {
        canvas.drawBackground();
        canvas.drawWidget(attachment, style.getBackgroundBorder().shrink(canvas.getRegion()));
    }
}
Also used : UIStyle(org.terasology.rendering.nui.skin.UIStyle) InputSystem(org.terasology.input.InputSystem) Vector2i(org.terasology.math.geom.Vector2i) SubRegion(org.terasology.rendering.nui.SubRegion) MouseDevice(org.terasology.input.device.MouseDevice)

Example 4 with UIStyle

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

the class CanvasImpl method calculateRestrictedSize.

@Override
public Vector2i calculateRestrictedSize(UIWidget widget, Vector2i sizeRestrictions) {
    if (widget == null) {
        return sizeRestrictions;
    }
    String family = (widget.getFamily() != null) ? widget.getFamily() : state.family;
    UISkin skin = (widget.getSkin() != null) ? widget.getSkin() : state.skin;
    UIStyle elementStyle = skin.getStyleFor(family, widget.getClass(), UIWidget.BASE_PART, widget.getMode());
    Rect2i region = applyStyleToSize(Rect2i.createFromMinAndSize(Vector2i.zero(), sizeRestrictions), elementStyle);
    try (SubRegion ignored = subRegionForWidget(widget, region, false)) {
        Vector2i preferredSize = widget.getPreferredContentSize(this, elementStyle.getMargin().shrink(sizeRestrictions));
        preferredSize = elementStyle.getMargin().grow(preferredSize);
        return applyStyleToSize(preferredSize, elementStyle);
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) UISkin(org.terasology.rendering.nui.skin.UISkin) 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 UIStyle

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

the class UIIconBar method getIconSize.

private Vector2i getIconSize(Canvas canvas) {
    UIStyle iconStyle = canvas.getCurrentStyle();
    int width = iconStyle.getFixedWidth();
    int height = iconStyle.getFixedHeight();
    if (width == 0) {
        width = iconStyle.getMinWidth();
    }
    if (height == 0) {
        height = iconStyle.getMinHeight();
    }
    if (width == 0) {
        width = icon.getWidth();
    }
    if (height == 0) {
        height = icon.getHeight();
    }
    return new Vector2i(width, height);
}
Also used : UIStyle(org.terasology.rendering.nui.skin.UIStyle) Vector2i(org.terasology.math.geom.Vector2i)

Aggregations

UIStyle (org.terasology.rendering.nui.skin.UIStyle)5 Vector2i (org.terasology.math.geom.Vector2i)4 SubRegion (org.terasology.rendering.nui.SubRegion)4 BaseVector2i (org.terasology.math.geom.BaseVector2i)2 Rect2i (org.terasology.math.geom.Rect2i)2 UISkin (org.terasology.rendering.nui.skin.UISkin)2 InputSystem (org.terasology.input.InputSystem)1 MouseDevice (org.terasology.input.device.MouseDevice)1