use of org.terasology.rendering.nui.VerticalAlign in project Terasology by MovingBlocks.
the class RelativeLayout method getRegion.
private Rect2i getRegion(WidgetInfo element, Canvas canvas) {
Rect2i cachedRegion = cachedRegions.get(element);
if (cachedRegion != null) {
return cachedRegion;
}
int left = 0;
int right = canvas.size().x;
int center = canvas.size().x / 2;
if (element.layoutHint.getPositionCenterHorizontal() != null) {
HorizontalInfo info = element.layoutHint.getPositionCenterHorizontal();
Rect2i targetRegion = getTargetRegion(info.getWidget(), canvas);
HorizontalAlign align = (info.getTarget() != null) ? info.getTarget() : HorizontalAlign.CENTER;
center = align.getStart(targetRegion) + info.getOffset();
}
if (element.layoutHint.getPositionLeft() != null) {
HorizontalInfo info = element.layoutHint.getPositionLeft();
Rect2i targetRegion = getTargetRegion(info.getWidget(), canvas);
HorizontalAlign align = (info.getTarget() != null) ? info.getTarget() : HorizontalAlign.LEFT;
left = align.getStart(targetRegion) + info.getOffset();
}
if (element.layoutHint.getPositionRight() != null) {
HorizontalInfo info = element.layoutHint.getPositionRight();
Rect2i targetRegion = getTargetRegion(info.getWidget(), canvas);
HorizontalAlign align = (info.getTarget() != null) ? info.getTarget() : HorizontalAlign.RIGHT;
right = align.getStart(targetRegion) - info.getOffset();
}
int top = 0;
int bottom = canvas.size().y;
int vcenter = canvas.size().y / 2;
if (element.layoutHint.getPositionCenterVertical() != null) {
VerticalInfo info = element.layoutHint.getPositionCenterVertical();
Rect2i targetRegion = getTargetRegion(info.getWidget(), canvas);
VerticalAlign align = (info.getTarget() != null) ? info.getTarget() : VerticalAlign.MIDDLE;
vcenter = align.getStart(targetRegion) + info.getOffset();
}
if (element.layoutHint.getPositionTop() != null) {
VerticalInfo info = element.layoutHint.getPositionTop();
Rect2i targetRegion = getTargetRegion(info.getWidget(), canvas);
VerticalAlign align = (info.getTarget() != null) ? info.getTarget() : VerticalAlign.TOP;
top = align.getStart(targetRegion) + info.getOffset();
}
if (element.layoutHint.getPositionBottom() != null) {
VerticalInfo info = element.layoutHint.getPositionBottom();
Rect2i targetRegion = getTargetRegion(info.getWidget(), canvas);
VerticalAlign align = (info.getTarget() != null) ? info.getTarget() : VerticalAlign.BOTTOM;
bottom = align.getStart(targetRegion) - info.getOffset();
}
int width = element.layoutHint.getWidth();
if (width == 0 && element.layoutHint.isUsingContentWidth()) {
width = canvas.calculateRestrictedSize(element.widget, new Vector2i(right - left, bottom - top)).x;
}
if (width == 0) {
width = right - left;
} else {
if (element.layoutHint.getPositionCenterHorizontal() != null) {
left = center - width / 2;
} else if (element.layoutHint.getPositionRight() != null) {
if (element.layoutHint.getPositionLeft() != null) {
center = left + (right - left) / 2;
left = center - width / 2;
} else {
left = right - width;
}
}
}
int height = element.layoutHint.getHeight();
if (height == 0 && element.layoutHint.isUsingContentHeight()) {
height = canvas.calculateRestrictedSize(element.widget, new Vector2i(width, bottom - top)).y;
}
if (height == 0) {
height = bottom - top;
} else {
if (element.layoutHint.getPositionCenterVertical() != null) {
top = vcenter - height / 2;
} else if (element.layoutHint.getPositionBottom() != null) {
if (element.layoutHint.getPositionTop() != null) {
vcenter = top + (bottom - top) / 2;
top = vcenter - height / 2;
} else {
top = bottom - height;
}
}
}
Rect2i region = Rect2i.createFromMinAndSize(left, top, width, height);
cachedRegions.put(element, region);
return region;
}
use of org.terasology.rendering.nui.VerticalAlign in project Terasology by MovingBlocks.
the class LwjglCanvasRenderer method drawText.
@Override
public void drawText(String text, Font font, HorizontalAlign hAlign, VerticalAlign vAlign, Rect2i absoluteRegion, Color color, Color shadowColor, float alpha, boolean underlined) {
TextCacheKey key = new TextCacheKey(text, font, absoluteRegion.width(), hAlign, color, shadowColor, underlined);
usedText.add(key);
Map<Material, Mesh> fontMesh = cachedText.get(key);
List<String> lines = TextLineBuilder.getLines(font, text, absoluteRegion.width());
if (fontMesh != null) {
for (Mesh mesh : fontMesh.values()) {
if (mesh.isDisposed()) {
fontMesh = null;
break;
}
}
}
if (fontMesh == null) {
fontMesh = fontMeshBuilder.createTextMesh(font, lines, absoluteRegion.width(), hAlign, color, shadowColor, underlined);
cachedText.put(key, fontMesh);
}
Vector2i offset = new Vector2i(absoluteRegion.minX(), absoluteRegion.minY());
offset.y += vAlign.getOffset(lines.size() * font.getLineHeight(), absoluteRegion.height());
fontMesh.entrySet().stream().filter(entry -> entry.getKey().isRenderable()).forEach(entry -> {
entry.getKey().bindTextures();
entry.getKey().setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX(), requestedCropRegion.maxX(), requestedCropRegion.minY(), requestedCropRegion.maxY());
entry.getKey().setFloat2("offset", offset.x, offset.y);
entry.getKey().setFloat("alpha", alpha);
entry.getValue().render();
});
}
Aggregations