96 lines
3.7 KiB
Java
96 lines
3.7 KiB
Java
package speiger.src.coreengine.rendering.gui.helper.box;
|
|
|
|
import speiger.src.coreengine.math.misc.Facing;
|
|
import speiger.src.coreengine.math.misc.FacingList;
|
|
import speiger.src.coreengine.math.vector.floats.Vec2f;
|
|
import speiger.src.coreengine.math.vector.floats.Vec4f;
|
|
|
|
public interface IGuiBox extends IScreenBox
|
|
{
|
|
public IGuiBox addChild(IGuiBox box);
|
|
public IGuiBox removeChild(IGuiBox box);
|
|
public IGuiBox clearChildren();
|
|
public IGuiBox setParent(IGuiBox box);
|
|
public IGuiBox getParent();
|
|
public IGuiBox onChanged();
|
|
|
|
public static IGuiBox of(float x, float y, float width, float height) { return new GuiBox(x, y, width, height); }
|
|
|
|
public default IGuiBox copy() { return GuiBox.clone(this); }
|
|
public default IGuiBox copy(float padding) { return GuiBox.clonePadded(this, padding); }
|
|
|
|
public float getScale();
|
|
public float getBaseX();
|
|
public float getBaseY();
|
|
public float getRelativeX();
|
|
public float getRelativeY();
|
|
public float getWidth();
|
|
public float getWidth(float extra);
|
|
public float getHeight();
|
|
public float getHeight(float extra);
|
|
public default float getSquaredWidth() {
|
|
float value = getWidth();
|
|
return value * value;
|
|
}
|
|
public default float getSquaredHeight() {
|
|
float value = getHeight();
|
|
return value * value;
|
|
}
|
|
|
|
public float getMinX();
|
|
public float getMinX(float extra);
|
|
public float getMinY();
|
|
public float getMinY(float extra);
|
|
public float getMaxX();
|
|
public float getMaxX(float extra);
|
|
public float getMaxY();
|
|
public float getMaxY(float extra);
|
|
public float getCenterX();
|
|
public float getCenterX(float extra);
|
|
public float getCenterY();
|
|
public float getCenterY(float extra);
|
|
|
|
public IGuiBox setX(float x);
|
|
public IGuiBox setY(float y);
|
|
public IGuiBox setWidth(float width);
|
|
public IGuiBox setHeight(float height);
|
|
public IGuiBox setScale(float scale);
|
|
|
|
public IGuiBox move(float xOffset, float yOffset);
|
|
public IGuiBox grow(float xGrowth, float yGrowth);
|
|
public IGuiBox scale(float scale);
|
|
|
|
public default IGuiBox setXY(float x, float y) { return setX(x).setY(y); }
|
|
public default IGuiBox setXY(Vec2f pos) { return setX(pos.x()).setY(pos.y()); }
|
|
|
|
public default IGuiBox setBounds(float width, float height) { return setWidth(width).setHeight(height); }
|
|
public default IGuiBox setBounds(Vec2f bounds) {return setWidth(bounds.x()).setHeight(bounds.y()); }
|
|
|
|
public default IGuiBox set(float x, float y, float width, float height) { return setX(x).setY(y).setWidth(width).setHeight(height); }
|
|
public default IGuiBox set(Vec4f vec) { return setX(vec.x()).setY(vec.y()).setWidth(vec.z()).setHeight(vec.w()); }
|
|
|
|
public default boolean isColiding(float x, float y) { return getMinX() <= x && getMaxX() >= x && getMinY() <= y && getMaxY() >= y; }
|
|
|
|
public default FacingList getColidingBorder(float x, float y, float margin) {
|
|
margin *= getScale();
|
|
float minX = getMinX();
|
|
float maxX = getMaxX();
|
|
float minY = getMinY();
|
|
float maxY = getMaxY();
|
|
FacingList list = FacingList.EMPTY;
|
|
if(y <= minY + margin && y >= minY) list = list.add(Facing.NORTH);
|
|
if(x >= maxX - margin && x <= maxX) list = list.add(Facing.EAST);
|
|
if(y >= maxY - margin && y <= maxY) list = list.add(Facing.SOUTH);
|
|
if(x <= minX + margin && x >= minX) list = list.add(Facing.WEST);
|
|
return list;
|
|
}
|
|
|
|
public default boolean isIntersecting(IGuiBox box) { return isIntersecting(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY()); }
|
|
public default boolean isIntersecting(float minX, float maxX, float minY, float maxY) {
|
|
float xMin = getMinX();
|
|
float yMin = getMinY();
|
|
float xMax = getMaxX();
|
|
float yMax = getMaxY();
|
|
return ((minX >= xMin && minX <= xMax) || (maxX >= xMin && maxX <= xMax)) && ((minY >= yMin && minY <= yMax) || (maxY >= yMin && maxY <= yMax));
|
|
}
|
|
} |