Merge pull request #2716 from Lucwousin/it-wasnt-cox-all-along

client: Make TextComponent not blend text color with color below by default
This commit is contained in:
Owain van Brakel
2020-06-26 22:48:08 +02:00
committed by GitHub

View File

@@ -47,7 +47,8 @@ public class TextComponent implements RenderableEntity
private String text;
private Point position = new Point();
private Color color = Color.WHITE;
private Color borderColor = Color.BLACK;
private boolean outline;
private boolean alpha; // Generates a lot of garbage!
@Override
public Dimension render(Graphics2D graphics)
@@ -59,24 +60,65 @@ public class TextComponent implements RenderableEntity
final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text);
int x = position.x;
for (String textSplitOnCol : parts)
for (String part : parts)
{
final String textWithoutCol = Text.removeTags(textSplitOnCol);
final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">"));
final String textWithoutCol = Text.removeTags(part);
final String colColor = part.substring(part.indexOf('=') + 1, part.indexOf('>'));
final Color col = Color.decode("#" + colColor);
if (alpha)
{
drawAlpha(graphics, x, position.y, part, col);
}
else
{
drawOutline(graphics, textWithoutCol);
renderText(graphics, x, position.y, textWithoutCol, Color.decode("#" + colColor), borderColor);
// actual text
graphics.setColor(col);
graphics.drawString(textWithoutCol, x, position.y);
}
x += fontMetrics.stringWidth(textWithoutCol);
}
}
else
{
renderText(graphics, position.x, position.y, text, color, borderColor);
if (alpha)
{
drawAlpha(graphics, position.x, position.y, text, color);
}
else
{
drawOutline(graphics, text);
// actual text
graphics.setColor(color);
graphics.drawString(text, position.x, position.y);
}
}
return new Dimension(fontMetrics.stringWidth(text), fontMetrics.getHeight());
}
private void renderText(Graphics2D graphics, int x, int y, String text, Color color, Color border)
private void drawOutline(Graphics2D graphics, String str)
{
graphics.setColor(Color.BLACK);
if (outline)
{
graphics.drawString(str, position.x, position.y + 1);
graphics.drawString(str, position.x, position.y - 1);
graphics.drawString(str, position.x + 1, position.y);
graphics.drawString(str, position.x - 1, position.y);
}
else
{
// shadow
graphics.drawString(str, position.x + 1, position.y + 1);
}
}
private void drawAlpha(Graphics2D graphics, int x, int y, String text, Color color)
{
// remember previous composite
Composite originalComposite = graphics.getComposite();
@@ -89,7 +131,7 @@ public class TextComponent implements RenderableEntity
Shape shape = vector.getOutline(x, y);
// draw text border
graphics.setColor(border);
graphics.setColor(Color.BLACK);
graphics.fill(stroke);
// replace the pixels instead of overlaying