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