aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/bscv/tools/Text.java
blob: 316a29da9350059cadbfcb9aa4550fad031f839d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package ftbsc.bscv.tools;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import ftbsc.bscv.ICommons;
import net.minecraft.client.MainWindow;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.text.Color;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.Style;


public final class Text implements ICommons {
   String text;
   Anchor anchor;
   Style style;
   int x;
   int y;
   double scale;

   private Text() {
      this.text = "";
      this.anchor = Anchor.TOPLEFT;
      this.style =  Style.EMPTY.withColor(Color.fromRgb(16777215));
      this.x = 0;
      this.y = 0;
      this.scale = 1.0;
   }

   public static Text TextBuilder() {
      return new Text();
   }

   public Text txt(String txt, Object... arg) {
      this.text = String.format(txt, arg);
      return this;
   }

   public Text anchor(Anchor a) {
      this.anchor = a;
      return this;
   }

   public Text style(Style in) {
      this.style = in;
      return this;
   }

   public Text x(int x) {
      this.x = x;
      return this;
   }

   public Text y(int y) {
      this.y = y;
      return this;
   }

   public Text scale(double scale) {
      this.scale = scale;
      return this;
   }

   public void render(MatrixStack stack, MainWindow window) {
      FontRenderer font = MC.font;
      ITextComponent text = new StringTextComponent(this.text).setStyle(this.style);
      Vector2f abs_coords = this.anchor.translate(
         new Vector2f(this.x, this.y),
         font.width(text),
         font.lineHeight,
         (float) this.scale,
         window
      );
      // TODO is there any non-deprecated way?
      RenderSystem.pushMatrix();
      RenderSystem.scaled(this.scale, this.scale, this.scale);
      font.drawShadow(
         stack,
         text,
         abs_coords.x,
         abs_coords.y,
         10 // ???? TODO!
      );
      RenderSystem.popMatrix();
   }
}