setBackground added in UIElementText.java

This commit is contained in:
Antoine
2021-06-16 16:05:06 +02:00
parent 9edc455895
commit 24fc20be39
2 changed files with 26 additions and 5 deletions

View File

@ -13,8 +13,10 @@ import java.util.List;
*/
public class UIElementText extends UIDummy{
private final List<Letter> objs;
private List<Letter> objs;
private final Text txt;
private ObjectGl background;
private Vector3f colorBg;
/**
* Crée du texte qui suit la caméra
@ -33,6 +35,13 @@ public class UIElementText extends UIDummy{
this.yPos = posY;
this.zPos = posZ;
this.getObjInPosition();
this.background = null;
}
public void setBackground(Vector3f color){
this.colorBg = color;
this.background = new ObjectGl(this.zPos, objs.size() * 10f, 10f, this.scalingFactor, null, this.colorBg );
engine.add_objectGl(this.background);
}
/**
@ -50,6 +59,11 @@ public class UIElementText extends UIDummy{
*/
public void setText(String txt){
this.txt.setNewText(txt);
this.objs = this.txt.getCharList(); //Trop bizarre, on dirait que this.objs prends bien en compte le rajout des nouveaux elements mais pas les suppressions ??????????????
if (this.background != null){
engine.remove_objectGl(background);
setBackground(this.colorBg);
}
}
public void setShader(String vert, String frag, boolean indexBasedShader, boolean useTime){
@ -62,20 +76,25 @@ public class UIElementText extends UIDummy{
protected void getObjInPosition(){
int i = 0;
float dimension = this.camera.getDimension();
float ar = this.camera.getAspectRatio().y / this.camera.getAspectRatio().x;
float x = dimension * 2 * this.xPos - dimension;
float y = dimension * ar * 2 * this.yPos - dimension * ar;
for (ObjectGl obj : this.txt.getCharList()){
obj.resetTransform();
obj.scale(new Vector3f(this.scalingFactor, this.scalingFactor, 1.0f));
// Position in the camera space
float dimension = this.camera.getDimension();
float ar = this.camera.getAspectRatio().y / this.camera.getAspectRatio().x;
float x = dimension * 2 * this.xPos - dimension;
float y = dimension * ar * 2 * this.yPos - dimension * ar;
obj.translate(new Vector3f(x, y, this.zPos));
obj.translate(new Vector3f(10.0f * i * this.scalingFactor)); // 10.0f est dependant de la taille de la police à changer si besoin rendre dynamique si plusieurs police
// Camera position
obj.translate(new Vector3f(- engine.getTransformationView().x, - engine.getTransformationView().y));
i++;
}
if (background != null){
background.resetTransform();
background.scale(new Vector3f(this.scalingFactor, this.scalingFactor, 1f));
background.translate(new Vector3f(x, y));
}
}
}