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