SimpleJavaEngine/src/main/java/speiger/src/coreengine/rendering/gui/components/GradientSliderComponent.java

58 lines
2.5 KiB
Java

package speiger.src.coreengine.rendering.gui.components;
import java.util.function.IntFunction;
import speiger.src.coreengine.math.misc.Facing;
public class GradientSliderComponent extends SliderComponent
{
int fromColor;
int toColor;
Facing direction;
public GradientSliderComponent(float x, float y, float width, float height, int min, int max, int value, int color, int fromColor, int toColor, Facing direction, IntFunction<String> textBuilder)
{
super(x, y, width, height, min, max, value, color, textBuilder);
this.direction = direction;
this.fromColor = fromColor;
this.toColor = toColor;
}
public GradientSliderComponent(int min, int max, int value, int color, int fromColor, int toColor, Facing direction, IntFunction<String> textBuilder)
{
super(min, max, value, color, textBuilder);
this.direction = direction;
this.fromColor = fromColor;
this.toColor = toColor;
}
@Override
public boolean renderSelf(int mouseX, int mouseY, float particalTicks)
{
float brightness = getActiveBrightness();
float minX = getBox().getMinX(5F);
float minY = getBox().getMinY(2F);
float maxX = getBox().getMaxX(-5F);
float maxY = getBox().getMaxY(-2F);
float scale = 0.6F * getBox().getScale();
if(vertical)
{
float extra = (((float)(value - min) / (float)(max - min)) * (getBox().getMaxY(-3F) - getBox().getMinY(3F))) + getBox().getMinY(3F);
float left = getBox().getMinX(2F);
getRenderer().setBrightness(brightness).drawGradientQuad(minX, minY, maxX, maxY, fromColor, toColor, direction).setBrightness(brightness * 0.7F).drawFrame(minX, minY, maxX, maxY, 0.001F, color);
getRenderer().setBrightness(brightness * 0.5F).translate(left, extra, 0.002F).scale(scale).drawBuffers(buffer, maxX - minX, maxX - minX).setBrightness(brightness).unscale(scale).translate(-left, -extra, -0.002F);
}
else
{
float extra = (((float)(value - min) / (float)(max - min)) * (getBox().getMaxX(-6F) - getBox().getMinX(6F))) + getBox().getMinX(6F);
float top = getBox().getMinY();
getRenderer().setBrightness(brightness).drawGradientQuad(minX, minY, maxX, maxY, fromColor, toColor, direction).setBrightness(brightness * 0.7F).drawFrame(minX, minY, maxX, maxY, 0.001F, color);
getRenderer().setBrightness(brightness * 0.5F).translate(extra, top, 0.002F).scale(scale).drawBuffers(buffer, maxX - minX, maxX - minX).setBrightness(brightness).unscale(scale).translate(-extra, -top, -0.002F);
}
getRenderer().setBrightness(getBrightness(mouseX, mouseY));
renderChildren(mouseX, mouseY, particalTicks);
getRenderer().setBrightness(1F);
return false;
}
}