1 | package g0803.bindingofshiba.textures; | |
2 | ||
3 | import g0803.bindingofshiba.math.Vec2D; | |
4 | import java.awt.*; | |
5 | import java.awt.font.FontRenderContext; | |
6 | import java.awt.font.LineMetrics; | |
7 | import java.awt.image.BufferedImage; | |
8 | ||
9 | public class TextTextureBuilder implements ITextureBuilder { | |
10 | ||
11 | private final Font font; | |
12 | private String text = ""; | |
13 | private Color color = Color.white; | |
14 | private Vec2D anchorPoint = null; | |
15 | ||
16 | public TextTextureBuilder(Font font) { | |
17 | this.font = font; | |
18 | } | |
19 | ||
20 | public TextTextureBuilder setText(String text) { | |
21 | this.text = text; | |
22 |
1
1. setText : replaced return value with null for g0803/bindingofshiba/textures/TextTextureBuilder::setText → KILLED |
return this; |
23 | } | |
24 | ||
25 | public TextTextureBuilder setColor(Color color) { | |
26 | this.color = color; | |
27 |
1
1. setColor : replaced return value with null for g0803/bindingofshiba/textures/TextTextureBuilder::setColor → KILLED |
return this; |
28 | } | |
29 | ||
30 | public TextTextureBuilder setAnchorPoint(double x, double y) { | |
31 |
1
1. setAnchorPoint : replaced return value with null for g0803/bindingofshiba/textures/TextTextureBuilder::setAnchorPoint → KILLED |
return this.setAnchorPoint(new Vec2D(x, y)); |
32 | } | |
33 | ||
34 | public TextTextureBuilder setAnchorPoint(Vec2D anchorPoint) { | |
35 | this.anchorPoint = anchorPoint; | |
36 |
1
1. setAnchorPoint : replaced return value with null for g0803/bindingofshiba/textures/TextTextureBuilder::setAnchorPoint → KILLED |
return this; |
37 | } | |
38 | ||
39 | @Override | |
40 | public StaticTexture build() { | |
41 | FontRenderContext frc = new FontRenderContext(null, false, false); | |
42 | LineMetrics metrics = font.getLineMetrics(text, frc); | |
43 | ||
44 | int width = (int) font.getStringBounds(text, frc).getWidth(); | |
45 | int height = (int) metrics.getHeight(); | |
46 | int ascent = (int) metrics.getAscent(); | |
47 | ||
48 | BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); | |
49 | ||
50 | Graphics graphics = image.getGraphics(); | |
51 |
1
1. build : removed call to java/awt/Graphics::setColor → KILLED |
graphics.setColor(color); |
52 |
1
1. build : removed call to java/awt/Graphics::setFont → KILLED |
graphics.setFont(font); |
53 |
1
1. build : removed call to java/awt/Graphics::drawString → KILLED |
graphics.drawString(text, 0, ascent); |
54 | ||
55 |
1
1. build : Replaced integer subtraction with addition → SURVIVED |
ImageTextureBuilder builder = new ImageTextureBuilder(image).setAnchorPoint(0, height - 1); |
56 | ||
57 |
1
1. build : negated conditional → KILLED |
if (this.anchorPoint != null) builder.setAnchorPoint(this.anchorPoint); |
58 | ||
59 |
1
1. build : replaced return value with null for g0803/bindingofshiba/textures/TextTextureBuilder::build → KILLED |
return builder.build(); |
60 | } | |
61 | } | |
Mutations | ||
22 |
1.1 |
|
27 |
1.1 |
|
31 |
1.1 |
|
36 |
1.1 |
|
51 |
1.1 |
|
52 |
1.1 |
|
53 |
1.1 |
|
55 |
1.1 |
|
57 |
1.1 |
|
59 |
1.1 |