use of org.terasology.rendering.assets.font.Font in project Terasology by MovingBlocks.
the class StringTextRenderer method draw.
@Override
public void draw(T value, Canvas canvas) {
if (wrap) {
canvas.drawText(getString(value));
} else {
int width = canvas.size().x;
Font font = canvas.getCurrentStyle().getFont();
String text = getString(value);
if (font.getWidth(text) <= width) {
canvas.drawText(text);
} else {
String shortText = "...";
StringBuilder sb = new StringBuilder(text);
while (sb.length() > 0) {
shortText = sb.toString() + "...";
if (font.getWidth(shortText) <= width) {
break;
}
sb.setLength(sb.length() - 1);
}
canvas.drawText(shortText);
}
}
}
use of org.terasology.rendering.assets.font.Font in project Terasology by MovingBlocks.
the class UIInputBind method getPreferredContentSize.
@Override
public Vector2i getPreferredContentSize(Canvas canvas, Vector2i areaHint) {
Font font = canvas.getCurrentStyle().getFont();
String text = "";
if (capturingInput) {
text = "???";
} else if (newInput != null) {
text = newInput.getDisplayName();
}
List<String> lines = TextLineBuilder.getLines(font, text, areaHint.getX());
return font.getSize(lines);
}
use of org.terasology.rendering.assets.font.Font in project Terasology by MovingBlocks.
the class TooltipLineRenderer method getPreferredSize.
@Override
public Vector2i getPreferredSize(TooltipLine value, Canvas canvas) {
Font font = getFont(value);
List<String> lines = TextLineBuilder.getLines(font, value.getText(), canvas.size().x);
return font.getSize(lines);
}
use of org.terasology.rendering.assets.font.Font in project Terasology by MovingBlocks.
the class TooltipLineRenderer method draw.
@Override
public void draw(TooltipLine value, Canvas canvas) {
Font font = getFont(value);
Color color = getColor(value);
canvas.drawTextRaw(value.getText(), font, color, canvas.getRegion());
}
use of org.terasology.rendering.assets.font.Font in project Terasology by MovingBlocks.
the class UIScrollingText method onDraw.
/**
* Handles how this {@code UIScrollingText} is drawn.
* This is called every frame.
*
* @param canvas The {@link Canvas} on which this {@code UIScrollingText} is drawn
*/
@Override
public void onDraw(Canvas canvas) {
if (isScrolling) {
updateYValues(canvas);
}
Font font = canvas.getCurrentStyle().getFont();
int w = canvas.size().x / 2;
boolean finished = true;
for (Entry<String, Integer> entry : textY.entrySet()) {
int y = entry.getValue();
// ignores offsets
if (y >= -offsetTop && y <= canvas.size().y - offsetBottom + font.getHeight(entry.getKey())) {
String line = entry.getKey();
Rect2i coords = Rect2i.createFromMinAndSize(w - font.getWidth(line) / 2, y, font.getWidth(line), font.getHeight(line));
canvas.drawText(entry.getKey(), coords);
}
if (y >= -offsetTop) {
finished = false;
}
}
if (finished && autoReset) {
resetScrolling();
}
}
Aggregations