de.lessvoid.nifty.slick2d.render.SlickQuadFill Maven / Gradle / Ivy
package de.lessvoid.nifty.slick2d.render;
import org.newdawn.slick.Color;
import org.newdawn.slick.ShapeFill;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.geom.Vector2f;
import javax.annotation.Nonnull;
/**
* This shape fill implementation is used to render the rectangles of slick that that have a different color on each
* edge. This implementation is not supposed to be used for any other purpose.
*
* @author Martin Karing <[email protected]>
*/
final class SlickQuadFill implements ShapeFill {
/**
* This is the vector that is returned as offset at all times.
*/
private static final Vector2f NULL_VECTOR = new Vector2f(0, 0);
/**
* The color on the bottom left corner of the shape.
*/
@Nonnull
private final Color bottomLeft;
/**
* The color on the bottom right corner of the shape.
*/
@Nonnull
private final Color bottomRight;
/**
* The color on the top left corner of the shape.
*/
@Nonnull
private final Color topLeft;
/**
* The color on the top right corner of the shape.
*/
@Nonnull
private final Color topRight;
/**
* Create a new rectangle filling instance.
*
* @param tlColor the color at the top left
* @param trColor the color at the top right
* @param blColor the color at the bottom left
* @param brColor the color at the bottom right
*/
SlickQuadFill(
@Nonnull final de.lessvoid.nifty.tools.Color tlColor,
@Nonnull final de.lessvoid.nifty.tools.Color trColor,
@Nonnull final de.lessvoid.nifty.tools.Color blColor,
@Nonnull final de.lessvoid.nifty.tools.Color brColor) {
topLeft = SlickRenderUtils.convertColorNiftySlick(tlColor);
topRight = SlickRenderUtils.convertColorNiftySlick(trColor);
bottomLeft = SlickRenderUtils.convertColorNiftySlick(blColor);
bottomRight = SlickRenderUtils.convertColorNiftySlick(brColor);
}
/**
* Change all the color values.
*
* @param tlColor the color at the top left
* @param trColor the color at the top right
* @param blColor the color at the bottom left
* @param brColor the color at the bottom right
*/
public void changeColors(
@Nonnull final de.lessvoid.nifty.tools.Color tlColor,
@Nonnull final de.lessvoid.nifty.tools.Color trColor,
@Nonnull final de.lessvoid.nifty.tools.Color blColor,
@Nonnull final de.lessvoid.nifty.tools.Color brColor) {
SlickRenderUtils.convertColorNiftySlick(tlColor, topLeft);
SlickRenderUtils.convertColorNiftySlick(trColor, topRight);
SlickRenderUtils.convertColorNiftySlick(blColor, bottomLeft);
SlickRenderUtils.convertColorNiftySlick(brColor, bottomRight);
}
/**
* Get the color at one point on the shape.
*/
@Nonnull
@Override
public Color colorAt(@Nonnull final Shape shape, final float x, final float y) {
final boolean isMaxX = Math.abs(x - shape.getMaxX()) < 0.0f;
final boolean isMaxY = Math.abs(y - shape.getMaxY()) < 0.0f;
if (isMaxX) {
return isMaxY ? topRight : topLeft;
} else {
return isMaxY ? bottomRight : bottomLeft;
}
}
/**
* Get the offset at a location.
*/
@Nonnull
@Override
public Vector2f getOffsetAt(final Shape shape, final float x, final float y) {
return NULL_VECTOR;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy