use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.
the class UITreeView method onDraw.
@Override
public void onDraw(Canvas canvas) {
updateListeners();
canvas.setPart(TREE_NODE);
int currentHeight = 0;
for (int i = 0; i < model.get().getNodeCount(); i++) {
Tree<T> node = model.get().getNode(i);
TreeViewListenerSet treeViewListenerSet = treeViewListenerSets.get(i);
ExpandButtonInteractionListener buttonListener = expandListeners.get(i);
// Calculate the node's height and overall region.
int nodeHeight = canvas.getCurrentStyle().getMargin().grow(itemRenderer.getPreferredSize(node.getValue(), canvas).addX(node.getDepth() * levelIndent.get())).getY();
Rect2i nodeRegion = Rect2i.createFromMinAndSize((node.getDepth() + 1) * levelIndent.get(), currentHeight, canvas.size().x - (node.getDepth() + 1) * levelIndent.get(), nodeHeight);
// Draw the expand/contract button.
if (!node.isLeaf()) {
canvas.setPart(EXPAND_BUTTON);
setButtonMode(canvas, node, buttonListener);
Rect2i buttonRegion = Rect2i.createFromMinAndSize(node.getDepth() * levelIndent.get(), currentHeight, levelIndent.get(), nodeHeight);
drawButton(canvas, buttonRegion, buttonListener);
canvas.setPart(TREE_NODE);
}
if (state.getSelectedIndex() != null && state.getSelectedIndex() == i && state.getAlternativeWidget() != null) {
// Draw an alternative widget in place of the node (with the same size).
canvas.drawWidget(state.getAlternativeWidget(), nodeRegion);
currentHeight += nodeHeight;
} else {
// Draw the node itself.
setNodeMode(canvas, node, treeViewListenerSet);
drawNode(canvas, nodeRegion, node, treeViewListenerSet);
currentHeight += nodeHeight;
// Draw the dragging hints if the current node is a drag&drop target.
if (state.getMouseOverIndex() != null && state.getMouseOverIndex() == i) {
drawDragHint(canvas, nodeRegion);
}
}
}
}
use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.
the class FlowParagraphRenderable method renderContents.
@Override
public void renderContents(Canvas canvas, Vector2i startPos, ContainerRenderSpace containerRenderSpace, int leftIndent, int rightIndent, ParagraphRenderStyle defaultStyle, HorizontalAlign horizontalAlign, HyperlinkRegister hyperlinkRegister) {
int y = startPos.y;
for (LaidFlowLine<FlowRenderable> line : updateCacheIfNeeded(defaultStyle, startPos.y, containerRenderSpace)) {
int x = 0;
int insetXAdvance = containerRenderSpace.getAdvanceForVerticalPosition(y);
int availableWidth = containerRenderSpace.getWidthForVerticalPosition(y);
if (horizontalAlign == HorizontalAlign.LEFT || horizontalAlign == HorizontalAlign.CENTER) {
availableWidth -= leftIndent;
}
if (horizontalAlign == HorizontalAlign.RIGHT || horizontalAlign == HorizontalAlign.CENTER) {
availableWidth -= rightIndent;
}
int lineHeight = line.getHeight();
int lineWidth = line.getWidth();
int alignOffset = horizontalAlign.getOffset(lineWidth, availableWidth);
for (FlowRenderable flowRenderable : line.getFlowRenderables()) {
int elementWidth = flowRenderable.getWidth(defaultStyle);
Rect2i renderableRegion = Rect2i.createFromMinAndSize(insetXAdvance + leftIndent + alignOffset + startPos.x + x, y, elementWidth, lineHeight);
String hyperlink = flowRenderable.getAction();
if (hyperlink != null) {
hyperlinkRegister.registerHyperlink(renderableRegion, hyperlink);
}
flowRenderable.render(canvas, renderableRegion, defaultStyle);
x += elementWidth;
}
y += lineHeight;
}
}
use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.
the class TextFlowRenderable method render.
@Override
public void render(Canvas canvas, Rect2i bounds, TextRenderStyle defaultRenderStyle) {
TextRenderStyle safeRenderStyle = getTextRenderStyle(defaultRenderStyle);
Font font = safeRenderStyle.getFont(hyperlink != null);
int lineHeight = font.getLineHeight();
Rect2i bottomBounds = Rect2i.createFromMinAndSize(bounds.minX(), bounds.maxY() - lineHeight, bounds.sizeX(), lineHeight);
canvas.drawTextRaw(text, font, safeRenderStyle.getColor(hyperlink != null), bottomBounds);
}
use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.
the class ContainerFlowContainerRenderSpace method addLeftFloat.
@Override
public Rect2i addLeftFloat(int y, int width, int height) {
int posY = y;
while (true) {
int availableWidth = getAvailableWidthAt(posY);
if (availableWidth >= width) {
int x = 0;
Rect2i lastLeft = findLastAtYPosition(leftFloats, posY);
if (lastLeft != null) {
x = lastLeft.maxX();
}
Rect2i floatRect = Rect2i.createFromMinAndSize(x, posY, width, height);
leftFloats.add(floatRect);
return floatRect;
} else {
Rect2i lastLeft = findLastAtYPosition(leftFloats, posY);
Rect2i lastRight = findLastAtYPosition(rightFloats, posY);
if (lastLeft != null && lastRight != null) {
posY = Math.min(lastLeft.maxY(), lastRight.maxY());
} else if (lastLeft != null) {
posY = lastLeft.maxY();
} else if (lastRight != null) {
posY = lastRight.maxY();
}
}
}
}
use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.
the class ContainerFlowContainerRenderSpace method getAvailableWidthAt.
private int getAvailableWidthAt(int y) {
int width = containerWidth;
Rect2i lastRight = findLastAtYPosition(rightFloats, y);
if (lastRight != null) {
width = lastRight.minX();
}
Rect2i lastLeft = findLastAtYPosition(leftFloats, y);
if (lastLeft != null) {
width -= lastLeft.maxX();
}
return width;
}
Aggregations