Base of Constraints system.
This commit is contained in:
@@ -2,7 +2,6 @@ package mightypork.rogue.display;
|
||||
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
||||
import mightypork.rogue.App;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package mightypork.rogue.display.constraints;
|
||||
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
|
||||
public abstract class Constraint implements ConstraintContext {
|
||||
|
||||
protected ConstraintContext context;
|
||||
|
||||
|
||||
public Constraint(ConstraintContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
public void setContext(ConstraintContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
public ConstraintContext getContext()
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
||||
protected Coord origin() {
|
||||
return context.getRect().getOrigin();
|
||||
}
|
||||
|
||||
protected Coord size() {
|
||||
return context.getRect().getSize();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package mightypork.rogue.display.constraints;
|
||||
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
public interface ConstraintContext {
|
||||
public Rect getRect();
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package mightypork.rogue.testing;
|
||||
|
||||
|
||||
import mightypork.rogue.display.constraints.Constraint;
|
||||
import mightypork.rogue.display.constraints.ConstraintContext;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
public class TestConstraints {
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
ConstraintContext context = new ConstraintContext() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return Rect.fromSize(new Coord(0, 0), new Coord(400, 300));
|
||||
}
|
||||
};
|
||||
|
||||
class Navbar extends Constraint {
|
||||
|
||||
private double height;
|
||||
|
||||
|
||||
public Navbar(ConstraintContext context, double height) {
|
||||
super(context);
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return Rect.fromSize(origin().setY(size().y - height), size().setY(height));
|
||||
}
|
||||
}
|
||||
|
||||
class TileHorizontal extends Constraint {
|
||||
|
||||
private int count;
|
||||
private int tile;
|
||||
|
||||
|
||||
public TileHorizontal(ConstraintContext context, int tileCount, int aTile) {
|
||||
super(context);
|
||||
this.count = tileCount;
|
||||
setTile(aTile);
|
||||
}
|
||||
|
||||
|
||||
public void setTile(int aTile)
|
||||
{
|
||||
if (aTile > count) throw new IndexOutOfBoundsException("Tile count exceeded: " + aTile + " max: " + count);
|
||||
this.tile = aTile;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
Coord size = size().mul(1D / count, 1);
|
||||
return Rect.fromSize(origin().add(size.x * tile, 0), size);
|
||||
}
|
||||
}
|
||||
|
||||
Navbar nb = new Navbar(context, 100);
|
||||
|
||||
TileHorizontal tile = new TileHorizontal(nb, 5, 0);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
tile.setTile(i);
|
||||
|
||||
System.out.println(tile.getRect());
|
||||
}
|
||||
|
||||
System.out.println("nb:" + nb.getRect());
|
||||
|
||||
System.out.println("ctx:" + context.getRect());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,11 +19,12 @@ import org.newdawn.slick.opengl.Texture;
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class RenderUtils {
|
||||
|
||||
|
||||
private static final Coord AXIS_X = new Coord(1, 0, 0);
|
||||
private static final Coord AXIS_Y = new Coord(0, 1, 0);
|
||||
private static final Coord AXIS_Z = new Coord(0, 0, 1);
|
||||
|
||||
|
||||
/**
|
||||
* Render quad 2D
|
||||
*
|
||||
@@ -371,7 +372,7 @@ public class RenderUtils {
|
||||
*/
|
||||
public static void quadRect(Rect rect)
|
||||
{
|
||||
quadCoord(rect.getMin(), rect.getMax());
|
||||
quadCoord(rect.getOrigin(), rect.getMax());
|
||||
}
|
||||
|
||||
|
||||
@@ -384,7 +385,7 @@ public class RenderUtils {
|
||||
public static void quadRect(Rect rect, RGB color)
|
||||
{
|
||||
setColor(color);
|
||||
quadCoord(rect.getMin(), rect.getMax());
|
||||
quadCoord(rect.getOrigin(), rect.getMax());
|
||||
}
|
||||
|
||||
|
||||
@@ -398,7 +399,7 @@ public class RenderUtils {
|
||||
*/
|
||||
public static void quadBorder(Rect rect, double border, RGB borderColor, RGB insideColor)
|
||||
{
|
||||
quadCoordBorder(rect.getMin(), rect.getMax(), border, borderColor, insideColor);
|
||||
quadCoordBorder(rect.getOrigin(), rect.getMax(), border, borderColor, insideColor);
|
||||
}
|
||||
|
||||
|
||||
@@ -411,7 +412,7 @@ public class RenderUtils {
|
||||
*/
|
||||
public static void quadGradH(Rect rect, RGB colorLeft, RGB colorRight)
|
||||
{
|
||||
quadCoordGradH(rect.getMin(), rect.getMax(), colorLeft, colorRight);
|
||||
quadCoordGradH(rect.getOrigin(), rect.getMax(), colorLeft, colorRight);
|
||||
}
|
||||
|
||||
|
||||
@@ -424,7 +425,7 @@ public class RenderUtils {
|
||||
*/
|
||||
public static void quadGradHBilinear(Rect rect, RGB colorOuter, RGB colorMiddle)
|
||||
{
|
||||
quadCoordGradHBilinear(rect.getMin(), rect.getMax(), colorOuter, colorMiddle);
|
||||
quadCoordGradHBilinear(rect.getOrigin(), rect.getMax(), colorOuter, colorMiddle);
|
||||
}
|
||||
|
||||
|
||||
@@ -437,7 +438,7 @@ public class RenderUtils {
|
||||
*/
|
||||
public static void quadGradV(Rect rect, RGB colorTop, RGB colorBottom)
|
||||
{
|
||||
quadCoordGradV(rect.getMin(), rect.getMax(), colorTop, colorBottom);
|
||||
quadCoordGradV(rect.getOrigin(), rect.getMax(), colorTop, colorBottom);
|
||||
}
|
||||
|
||||
|
||||
@@ -450,7 +451,7 @@ public class RenderUtils {
|
||||
*/
|
||||
public static void quadGradVBilinear(Rect rect, RGB colorOuter, RGB colorMiddle)
|
||||
{
|
||||
quadCoordGradVBilinear(rect.getMin(), rect.getMax(), colorOuter, colorMiddle);
|
||||
quadCoordGradVBilinear(rect.getOrigin(), rect.getMax(), colorOuter, colorMiddle);
|
||||
}
|
||||
|
||||
|
||||
@@ -464,7 +465,7 @@ public class RenderUtils {
|
||||
*/
|
||||
public static void quadRectOutset(Rect rect, double border, RGB fill, boolean inset)
|
||||
{
|
||||
quadCoordOutset(rect.getMin(), rect.getMax(), border, fill, inset);
|
||||
quadCoordOutset(rect.getOrigin(), rect.getMax(), border, fill, inset);
|
||||
}
|
||||
|
||||
|
||||
@@ -526,7 +527,7 @@ public class RenderUtils {
|
||||
setColor(tint);
|
||||
TextureManager.bind(texture);
|
||||
|
||||
quadTexturedAbs(quad, txCoords.div(texture.getImageHeight()));
|
||||
quadTexturedAbs(quad, txCoords.mul(1 / texture.getImageHeight()));
|
||||
|
||||
TextureManager.unbind();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
Reference in New Issue
Block a user