SimpleJavaEngine/src/main/java/speiger/src/coreengine/rendering/gui/components/icon/TexturedIcon.java

54 lines
1.2 KiB
Java

package speiger.src.coreengine.rendering.gui.components.icon;
import speiger.src.coreengine.math.misc.ColorUtils;
import speiger.src.coreengine.rendering.gui.renderer.UIRenderer;
import speiger.src.coreengine.rendering.textures.base.ITexture;
public class TexturedIcon implements IIcon
{
int color = ColorUtils.WHITE;
ITexture texture;
boolean forceBounds = false;
public TexturedIcon(ITexture texture)
{
this.texture = texture;
}
public TexturedIcon(int color, ITexture texture)
{
this.color = color;
this.texture = texture;
}
public void setTexture(ITexture newTexture)
{
if(texture != null)
{
texture.deleteTexture();
texture = null;
}
texture = newTexture;
}
public TexturedIcon forceBounds(boolean value)
{
forceBounds = value;
return this;
}
@Override
public void render(UIRenderer render, float minX, float minY, float maxX, float maxY, float scale)
{
if(forceBounds)
{
float width = texture.getWidth();
float height = texture.getHeight();
float ratio = height / width;
maxY = Math.min(minY + ((maxY - minY) * ratio), maxY);
}
render.setActiveTexture(texture).drawTexturedQuad(minX, minY, maxX, maxY, color, texture.getUMin(), texture.getVMin(), texture.getUMax(), texture.getVMax());
}
}