use of org.terasology.rendering.nui.Color in project Terasology by MovingBlocks.
the class MeshBuilder method addColor.
public MeshBuilder addColor(Color c1, Color... colors) {
meshData.getColors().add(c1.rf());
meshData.getColors().add(c1.gf());
meshData.getColors().add(c1.bf());
meshData.getColors().add(c1.af());
for (Color c : colors) {
meshData.getColors().add(c.rf());
meshData.getColors().add(c.gf());
meshData.getColors().add(c.bf());
meshData.getColors().add(c.af());
}
return this;
}
use of org.terasology.rendering.nui.Color 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.nui.Color in project Terasology by MovingBlocks.
the class UIText method drawSelection.
/**
* Draws the selection indication which indicates that a certain part of the text is selected.
*
* @param canvas The canvas on which the widget resides
*/
protected void drawSelection(Canvas canvas) {
Font font = canvas.getCurrentStyle().getFont();
String currentText = getText();
int start = Math.min(getCursorPosition(), selectionStart);
int end = Math.max(getCursorPosition(), selectionStart);
Color textColor = canvas.getCurrentStyle().getTextColor();
int canvasWidth = (multiline) ? canvas.size().x : Integer.MAX_VALUE;
// TODO: Support different text alignments
List<String> rawLinesAfterCursor = TextLineBuilder.getLines(font, currentText, Integer.MAX_VALUE);
int currentChar = 0;
int lineOffset = 0;
for (int lineIndex = 0; lineIndex < rawLinesAfterCursor.size() && currentChar <= end; ++lineIndex) {
String line = rawLinesAfterCursor.get(lineIndex);
List<String> innerLines = TextLineBuilder.getLines(font, line, canvasWidth);
for (int innerLineIndex = 0; innerLineIndex < innerLines.size() && currentChar <= end; ++innerLineIndex) {
String innerLine = innerLines.get(innerLineIndex);
String selectionString;
int offsetX = 0;
if (currentChar + innerLine.length() < start) {
selectionString = "";
} else if (currentChar < start) {
offsetX = font.getWidth(innerLine.substring(0, start - currentChar));
selectionString = innerLine.substring(start - currentChar, Math.min(end - currentChar, innerLine.length()));
} else if (currentChar + innerLine.length() >= end) {
selectionString = innerLine.substring(0, end - currentChar);
} else {
selectionString = innerLine;
}
if (!selectionString.isEmpty()) {
int selectionWidth = font.getWidth(selectionString);
Vector2i selectionTopLeft = new Vector2i(offsetX, (lineOffset) * font.getLineHeight());
Rect2i region = Rect2i.createFromMinAndSize(selectionTopLeft.x, selectionTopLeft.y, selectionWidth, font.getLineHeight());
canvas.drawTexture(cursorTexture, region, textColor);
canvas.drawTextRaw(FontUnderline.strip(FontColor.stripColor(selectionString)), font, textColor.inverse(), region);
}
currentChar += innerLine.length();
lineOffset++;
}
currentChar++;
}
}
use of org.terasology.rendering.nui.Color in project Terasology by MovingBlocks.
the class HTMLLikeParser method parseHTMLLike.
public static Collection<FlowRenderable> parseHTMLLike(String text) {
if (text == null) {
return null;
}
StringReader reader = new StringReader(text);
int character;
try {
StringBuilder sb = new StringBuilder();
Font font = null;
Color color = null;
String hyperlink = null;
List<FlowRenderable> result = new LinkedList<>();
while ((character = reader.read()) != -1) {
char c = (char) character;
if (c == '\n') {
throw new IllegalArgumentException("Parsed text cannot contain line breaks.");
} else if (c == '<') {
char nextChar = (char) reader.read();
if (nextChar == '/') {
char id = (char) reader.read();
if (id == 'f') {
if (sb.length() > 0) {
result.add(new TextFlowRenderable(sb.toString(), new DefaultTextRenderStyle(font, color), hyperlink));
sb.setLength(0);
}
font = null;
} else if (id == 'c') {
if (sb.length() > 0) {
result.add(new TextFlowRenderable(sb.toString(), new DefaultTextRenderStyle(font, color), hyperlink));
sb.setLength(0);
}
color = null;
} else if (id == 'h') {
if (sb.length() > 0) {
result.add(new TextFlowRenderable(sb.toString(), new DefaultTextRenderStyle(font, color), hyperlink));
sb.setLength(0);
}
hyperlink = null;
} else {
throw new IllegalArgumentException("Unable to parse text - " + text);
}
reader.read();
} else if (nextChar == 'f') {
if (sb.length() > 0) {
result.add(new TextFlowRenderable(sb.toString(), new DefaultTextRenderStyle(font, color), hyperlink));
sb.setLength(0);
}
reader.read();
font = Assets.getFont(readUntilCharacter(reader, '>')).get();
} else if (nextChar == 'c') {
if (sb.length() > 0) {
result.add(new TextFlowRenderable(sb.toString(), new DefaultTextRenderStyle(font, color), hyperlink));
sb.setLength(0);
}
reader.read();
color = new Color(Integer.parseInt(readUntilCharacter(reader, '>'), 16));
} else if (nextChar == 'h') {
if (sb.length() > 0) {
result.add(new TextFlowRenderable(sb.toString(), new DefaultTextRenderStyle(font, color), hyperlink));
sb.setLength(0);
}
reader.read();
hyperlink = readUntilCharacter(reader, '>');
} else if (nextChar == 'l') {
readUntilCharacter(reader, '>');
sb.append('\n');
}
} else if (c == '&') {
String escape = readUntilCharacter(reader, ';');
if (escape.equals("gt")) {
sb.append('>');
} else if (escape.equals("lt")) {
sb.append('<');
} else if (escape.equals("amp")) {
sb.append('&');
} else {
throw new IllegalArgumentException("Unknown escape sequence - " + escape);
}
} else {
sb.append(c);
}
}
if (sb.length() > 0) {
result.add(new TextFlowRenderable(sb.toString(), new DefaultTextRenderStyle(font, color), hyperlink));
}
return result;
} catch (IOException exp) {
// Ignore - can't happen
}
return null;
}
use of org.terasology.rendering.nui.Color in project Terasology by MovingBlocks.
the class HTMLUtils method createParagraphRenderStyleFromCommonAttributes.
public static ParagraphRenderStyle createParagraphRenderStyleFromCommonAttributes(Attributes attributes) {
Color textColor = getTextColor(attributes);
ParagraphRenderStyle.FloatStyle floatStyle = getFloatStyle(attributes);
ParagraphRenderStyle.ClearStyle clearStyle = getClearStyle(attributes);
HorizontalAlign horizontalAlign = getHorizontalAlign(attributes);
Color backgroundColor = getBackgroundColor(attributes);
ContainerInteger paragraphMarginTop = getParagraphMarginTop(attributes);
ContainerInteger paragraphMarginBottom = getParagraphMarginBottom(attributes);
ContainerInteger paragraphMarginLeft = getParagraphMarginLeft(attributes);
ContainerInteger paragraphMarginRight = getParagraphMarginRight(attributes);
ContainerInteger paragraphPaddingTop = getParagraphPaddingTop(attributes);
ContainerInteger paragraphPaddingBottom = getParagraphPaddingBottom(attributes);
ContainerInteger paragraphPaddingLeft = getParagraphPaddingLeft(attributes);
ContainerInteger paragraphPaddingRight = getParagraphPaddingRight(attributes);
ContainerInteger minimumWidth = getMinimumWidth(attributes);
return new ParagraphRenderStyle() {
@Override
public Color getColor(boolean hyperlink) {
return textColor;
}
@Override
public FloatStyle getFloatStyle() {
return floatStyle;
}
@Override
public ClearStyle getClearStyle() {
return clearStyle;
}
@Override
public HorizontalAlign getHorizontalAlignment() {
return horizontalAlign;
}
@Override
public Color getParagraphBackground() {
return backgroundColor;
}
@Override
public ContainerInteger getParagraphMarginTop() {
return paragraphMarginTop;
}
@Override
public ContainerInteger getParagraphMarginBottom() {
return paragraphMarginBottom;
}
@Override
public ContainerInteger getParagraphMarginLeft() {
return paragraphMarginLeft;
}
@Override
public ContainerInteger getParagraphMarginRight() {
return paragraphMarginRight;
}
@Override
public ContainerInteger getParagraphPaddingTop() {
return paragraphPaddingTop;
}
@Override
public ContainerInteger getParagraphPaddingBottom() {
return paragraphPaddingBottom;
}
@Override
public ContainerInteger getParagraphPaddingLeft() {
return paragraphPaddingLeft;
}
@Override
public ContainerInteger getParagraphPaddingRight() {
return paragraphPaddingRight;
}
@Override
public ContainerInteger getParagraphMinimumWidth() {
return minimumWidth;
}
};
}
Aggregations