use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.
the class UIScrollbar method onDraw.
@Override
public void onDraw(Canvas canvas) {
if (vertical) {
canvas.setPart("sliderVertical");
} else {
canvas.setPart("sliderHorizontal");
}
canvas.drawBackground();
canvas.addInteractionRegion(sliderListener);
canvas.setPart("handle");
if (vertical) {
sliderSize = canvas.size().y - canvas.getCurrentStyle().getFixedHeight();
} else {
sliderSize = canvas.size().x - canvas.getCurrentStyle().getFixedWidth();
}
if (sliderSize > handleSize) {
int drawLocation = pixelOffsetFor(getValue());
Rect2i handleRegion;
if (vertical) {
handleSize = canvas.getCurrentStyle().getFixedHeight();
handleRegion = Rect2i.createFromMinAndSize(0, drawLocation, canvas.getCurrentStyle().getFixedWidth(), handleSize);
} else {
handleSize = canvas.getCurrentStyle().getFixedWidth();
handleRegion = Rect2i.createFromMinAndSize(drawLocation, 0, handleSize, canvas.getCurrentStyle().getFixedHeight());
}
canvas.drawBackground(handleRegion);
canvas.addInteractionRegion(handleListener, handleRegion);
}
}
use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.
the class UISlider method onDraw.
@Override
public void onDraw(Canvas canvas) {
canvas.setPart(SLIDER);
canvas.drawBackground();
canvas.setPart(TICKER);
String display = getDisplayText();
int tickerWidth = canvas.getCurrentStyle().getFont().getWidth(display);
tickerWidth += canvas.getCurrentStyle().getMargin().getTotalWidth();
sliderWidth = canvas.size().x - tickerWidth;
int drawLocation = pixelOffsetFor(getValue(), sliderWidth);
Rect2i tickerRegion = Rect2i.createFromMinAndSize(drawLocation, 0, tickerWidth, canvas.size().y);
try (SubRegion ignored = canvas.subRegion(tickerRegion, false)) {
canvas.drawBackground();
canvas.drawText(display);
if (isEnabled()) {
canvas.addInteractionRegion(tickerListener);
}
}
}
use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.
the class UITabBox method onDraw.
@Override
public void onDraw(Canvas canvas) {
if (contents.size() != 0) {
Rect2i region = canvas.getRegion();
Rect2i buttonRegion = Rect2i.createFromMinAndSize(region.minX(), region.minY(), region.width(), tabBarHeight);
Rect2i boxRegion = Rect2i.createFromMinAndMax(region.minX(), region.minY() + tabBarHeight, region.width(), region.height() - tabBarHeight);
canvas.drawWidget(contents.get(currentTab), boxRegion);
canvas.drawWidget(buttonLayout, buttonRegion);
}
}
use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.
the class UIText method drawCursor.
/**
* Draws the cursor in the text field.
*
* @param canvas The canvas on which the widget resides
*/
protected void drawCursor(Canvas canvas) {
if (blinkCounter < BLINK_RATE) {
Font font = canvas.getCurrentStyle().getFont();
String beforeCursor = text.get();
if (getCursorPosition() < text.get().length()) {
beforeCursor = beforeCursor.substring(0, getCursorPosition());
}
List<String> lines = TextLineBuilder.getLines(font, beforeCursor, canvas.size().x);
// TODO: Support different alignments
int lastLineWidth = font.getWidth(lines.get(lines.size() - 1));
Rect2i region = Rect2i.createFromMinAndSize(lastLineWidth, (lines.size() - 1) * font.getLineHeight(), 1, font.getLineHeight());
canvas.drawTexture(cursorTexture, region, canvas.getCurrentStyle().getTextColor());
}
}
use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.
the class ContainerFlowContainerRenderSpace method addRightFloat.
@Override
public Rect2i addRightFloat(int y, int width, int height) {
int posY = y;
while (true) {
int availableWidth = getAvailableWidthAt(posY);
if (availableWidth >= width) {
int x = 0;
Rect2i lastRight = findLastAtYPosition(rightFloats, posY);
if (lastRight != null) {
x = lastRight.minX();
}
Rect2i floatRect = Rect2i.createFromMinAndSize(x - width, posY, width, height);
rightFloats.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();
}
}
}
}
Aggregations