HorizontalProgressBar.java now can be filled left to right or the other way

This commit is contained in:
Antoine
2021-06-12 03:09:43 +02:00
parent 8b9d698acc
commit f93f801e0b
4 changed files with 51 additions and 34 deletions

View File

@ -4,16 +4,18 @@ import engine.math.Vector3f;
import static org.lwjgl.glfw.GLFW.glfwGetTime;
public class ProgressBar extends ObjectGl{
public class HorizontalProgressBar extends ObjectGl{
private float max;
private float current;
private int leftToRight;
public ProgressBar(float z, float w, float h, float size, float current, float max) {
public HorizontalProgressBar(float z, float w, float h, float size, float current, float max, boolean leftToRight) {
super(z, w, h, size, null, new Vector3f(0f, 1f, 0f));
this.current = current;
this.max = max;
this.setShader("shaders/StylishShaders/BasicNoTexVert.glsl", "shaders/StylishShaders/ProgressBarFrag.glsl");
this.current = current;
this.leftToRight = leftToRight ? 1 : 0;
this.setShader("shaders/StylishShaders/BasicNoTexVert.glsl", "shaders/StylishShaders/HorizontalProgressBar.glsl");
}
public void setCurrent(float newCurrent){
@ -32,7 +34,14 @@ public class ProgressBar extends ObjectGl{
this.shader.enable();
if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime());
this.shader.setUniform1f("fill", (this.current / this.max) * this.getWidth());
if (this.leftToRight == 1){
this.shader.setUniform1f("fill", (this.current / this.max) * this.getWidth());
} else {
this.shader.setUniform1f("fill", Math.abs(((this.current / this.max) * this.getWidth()) - this.getWidth()));
}
this.shader.setUniform1i("leftToRight", this.leftToRight);
this.shader.setUniformMat4f("projection", projection);
this.shader.setUniformMat4f("view", view);