77import MightyLibrary .mightylib .util .math .Color4f ;
88import MightyLibrary .mightylib .util .math .EDirection ;
99import org .joml .Vector2f ;
10+ import org .joml .Vector3f ;
1011import org .joml .Vector4f ;
1112
1213public class Text extends Renderer {
1314 private static final int NUMBER_INDICES = 4 ;
1415 private static final int SIZE_INDICES = 6 ;
1516 private static final int SIZE_COORDINATES = 8 ;
1617
17- private final WindowInfo windowInfo ;
1818 private float fontSize ;
1919 private final int positionIndex ;
2020 private final int textureIndex ;
2121
2222 private FontFace font ;
2323 private String text ;
2424
25- private final Vector2f referencePosition ;
2625 private final Vector2f rightLeftPosition ;
2726 private final Vector2f rectangleSize ;
2827
2928 private EDirection reference ;
3029 private ETextAlignment alignment ;
3130
32- public Text (WindowInfo windowInfo ) {
31+ public Text () {
3332 super ("coloredText" , true , true );
34- this .windowInfo = windowInfo ;
3533
3634 fontSize = 10.0f ;
3735
@@ -44,7 +42,6 @@ public Text(WindowInfo windowInfo) {
4442 this .reference = EDirection .None ;
4543 this .alignment = ETextAlignment .Left ;
4644
47- this .referencePosition = new Vector2f (0 , 0 );
4845 this .rectangleSize = new Vector2f (0 , 0 );
4946 this .rightLeftPosition = new Vector2f (0 , 0 );
5047
@@ -63,9 +60,8 @@ public void display(){
6360 if (shouldNotDrawText ())
6461 return ;
6562
66- font .getTexture ().bind ();
6763 shadManager .getShader (shape .getShaderId ()).glUniform ("color" , color .getR (), color .getG (), color .getB (), color .getA ());
68- super .draw ();
64+ super .display ();
6965 }
7066
7167
@@ -110,18 +106,11 @@ public Text setPosition(Vector2f position){
110106 if (position == null )
111107 return this ;
112108
113- this .referencePosition .x = position .x ;
114- this .referencePosition .y = position .y ;
115- this .computeRightUpPosition ();
109+ super .setPosition (new Vector3f (position .x , position .y , 0.0f ));
116110
117111 return this ;
118112 }
119113
120-
121- public Vector2f referencePosition () {
122- return this .referencePosition ;
123- }
124-
125114 public Vector2f rightLeftPosition () { return this .rightLeftPosition ; }
126115
127116 public Vector2f size () { return this .rectangleSize ; }
@@ -163,8 +152,8 @@ private void computeRightUpPosition(){
163152 if (shouldNotDrawText ())
164153 return ;
165154
166- rightLeftPosition .x = referencePosition .x ;
167- rightLeftPosition .y = referencePosition .y ;
155+ rightLeftPosition .x = position .x ;
156+ rightLeftPosition .y = position .y ;
168157
169158 rectangleSize .x = 0 ;
170159 rectangleSize .y = 0 ;
@@ -256,18 +245,17 @@ private void computeRightUpPosition(){
256245
257246 fontChar = font .getFontFile ().getCharacter (c );
258247
259- sizeTemp .x = fontChar .getWidth () * fontSize / windowInfo . getVirtualSizeRef (). x * 2.0f - 1.0f ;
260- sizeTemp .y = fontChar .getHeight () * fontSize / windowInfo . getVirtualSizeRef (). y * 2.0f - 1.0f ;
248+ sizeTemp .x = fontChar .getWidth () * fontSize ;
249+ sizeTemp .y = fontChar .getHeight () * fontSize ;
261250
262- posTemp .x = (currentCharOffset .x + fontChar .getxOffset () + referencePosition .x - textReference .x + lineAlignmentOffset )
263- * 2.0f / windowInfo .getVirtualSizeRef ().x ;
264- posTemp .y = (currentCharOffset .y + fontChar .getyOffset () + referencePosition .y - textReference .y )
265- * 2.0f / windowInfo .getVirtualSizeRef ().y ;
251+ posTemp .x = (currentCharOffset .x + fontChar .getxOffset () * fontSize - textReference .x + lineAlignmentOffset );
252+ posTemp .y = (currentCharOffset .y + fontChar .getyOffset () * fontSize - textReference .y );
266253
267- temp .x = - 1.0f + posTemp .x ;
254+ temp .x = posTemp .x ;
268255 temp .y = sizeTemp .x + posTemp .x ;
269- temp .z = 1.0f - posTemp .y ;
270- temp .w = -sizeTemp .y - posTemp .y ;
256+ temp .z = posTemp .y ;
257+ temp .w = sizeTemp .y + posTemp .y ;
258+
271259
272260 position [charCount * SIZE_COORDINATES ] = temp .x ;
273261 position [charCount * SIZE_COORDINATES + 1 ] = temp .z ;
@@ -314,11 +302,11 @@ private void computeRightUpPosition(){
314302 }
315303
316304 public Text createCopy (){
317- Text text = new Text (windowInfo );
305+ Text text = new Text ();
318306 text .setFont (this .font .getName ())
319307 .setColor (color .copy ())
320308 .setFontSize (fontSize )
321- .setPosition (new Vector2f (this .referencePosition .x , this .referencePosition .y ))
309+ .setPosition (new Vector2f (this .position .x , this .position .y ))
322310 .setReference (this .reference )
323311 .setText (this .text );
324312
@@ -330,7 +318,7 @@ public Text copyTo(Text copy){
330318 .setFont (this .font .getName ())
331319 .setColor (color .copy ())
332320 .setFontSize (fontSize )
333- .setPosition (new Vector2f (this .referencePosition .x , this .referencePosition .y ))
321+ .setPosition (new Vector2f (this .position .x , this .position .y ))
334322 .setReference (this .reference )
335323 .setText (this .text );
336324
0 commit comments