Greatly improved Constraints system
This commit is contained in:
@@ -31,13 +31,7 @@ public class SoundSystem extends RootBusNode implements Updateable {
|
||||
|
||||
private static Coord listener = new Coord();
|
||||
|
||||
static {
|
||||
// initialize sound system
|
||||
SoundStore.get().setMaxSources(MAX_SOURCES);
|
||||
SoundStore.get().init();
|
||||
|
||||
setListener(INITIAL_LISTENER_POS);
|
||||
}
|
||||
private static boolean inited;
|
||||
|
||||
|
||||
/**
|
||||
@@ -86,6 +80,15 @@ public class SoundSystem extends RootBusNode implements Updateable {
|
||||
*/
|
||||
public SoundSystem(AppAccess app) {
|
||||
super(app);
|
||||
|
||||
if (!inited) {
|
||||
SoundStore.get().setMaxSources(MAX_SOURCES);
|
||||
SoundStore.get().init();
|
||||
|
||||
setListener(INITIAL_LISTENER_POS);
|
||||
|
||||
inited = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import mightypork.gamecore.control.bus.events.MainLoopTaskRequest;
|
||||
import mightypork.gamecore.control.bus.events.UpdateEvent;
|
||||
import mightypork.gamecore.control.interf.NoImpl;
|
||||
import mightypork.gamecore.control.timing.TimerDelta;
|
||||
import mightypork.gamecore.gui.renderers.Renderable;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.gamecore.control.bus.events;
|
||||
|
||||
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package mightypork.gamecore.control.interf;
|
||||
|
||||
|
||||
/**
|
||||
* Can be asked to update it's state
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface Pollable {
|
||||
|
||||
/**
|
||||
* Update internal state
|
||||
*/
|
||||
void poll();
|
||||
}
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package mightypork.gamecore.gui.renderers;
|
||||
package mightypork.gamecore.gui.components;
|
||||
|
||||
|
||||
import mightypork.utils.math.constraints.PluggableContext;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.gamecore.gui.constraints.PluggableContext;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package mightypork.gamecore.gui.renderers;
|
||||
package mightypork.gamecore.gui.components;
|
||||
|
||||
|
||||
import mightypork.utils.math.constraints.ContextAdapter;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.gamecore.gui.constraints.ContextAdapter;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mightypork.gamecore.gui.renderers;
|
||||
package mightypork.gamecore.gui.components;
|
||||
|
||||
|
||||
/**
|
||||
+5
-4
@@ -1,9 +1,10 @@
|
||||
package mightypork.gamecore.gui.renderers;
|
||||
package mightypork.gamecore.gui.components.layout;
|
||||
|
||||
|
||||
import static mightypork.utils.math.constraints.ConstraintFactory.*;
|
||||
import static mightypork.gamecore.gui.constraints.Constraints.*;
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.gamecore.gui.components.PluggableRenderable;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,7 +52,7 @@ public class ColumnHolder extends ElementHolder {
|
||||
{
|
||||
if (elem == null) return;
|
||||
|
||||
elem.setContext(c_column(this, cols, col++));
|
||||
elem.setContext(_column(this, cols, col++));
|
||||
|
||||
attach(elem);
|
||||
}
|
||||
+5
-2
@@ -1,4 +1,4 @@
|
||||
package mightypork.gamecore.gui.renderers;
|
||||
package mightypork.gamecore.gui.components.layout;
|
||||
|
||||
|
||||
import java.util.LinkedList;
|
||||
@@ -6,7 +6,10 @@ import java.util.LinkedList;
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.bus.EventBus;
|
||||
import mightypork.gamecore.control.bus.clients.BusNode;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.gamecore.gui.components.PluggableRenderable;
|
||||
import mightypork.gamecore.gui.components.PluggableRenderer;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
+5
-4
@@ -1,9 +1,10 @@
|
||||
package mightypork.gamecore.gui.renderers;
|
||||
package mightypork.gamecore.gui.components.layout;
|
||||
|
||||
|
||||
import static mightypork.utils.math.constraints.ConstraintFactory.*;
|
||||
import static mightypork.gamecore.gui.constraints.Constraints.*;
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.gamecore.gui.components.PluggableRenderable;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,7 +52,7 @@ public class RowHolder extends ElementHolder {
|
||||
{
|
||||
if (elem == null) return;
|
||||
|
||||
elem.setContext(c_row(this, rows, row++));
|
||||
elem.setContext(_row(this, rows, row++));
|
||||
|
||||
attach(elem);
|
||||
}
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package mightypork.gamecore.gui.renderers;
|
||||
package mightypork.gamecore.gui.components.painters;
|
||||
|
||||
|
||||
import mightypork.gamecore.gui.components.PluggableRenderer;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.gamecore.render.textures.TxQuad;
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package mightypork.gamecore.gui.renderers;
|
||||
package mightypork.gamecore.gui.components.painters;
|
||||
|
||||
|
||||
import mightypork.gamecore.gui.components.PluggableRenderer;
|
||||
import mightypork.gamecore.render.fonts.FontRenderer;
|
||||
import mightypork.gamecore.render.fonts.FontRenderer.Align;
|
||||
import mightypork.gamecore.render.fonts.GLFont;
|
||||
@@ -0,0 +1,831 @@
|
||||
package mightypork.gamecore.gui.constraints;
|
||||
|
||||
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
/**
|
||||
* Constraint factory.<br>
|
||||
* Import statically for best experience.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class Constraints {
|
||||
|
||||
/* ================= Variables ================= */
|
||||
|
||||
public static final NumberConstraint _mouseX = new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return InputSystem.getMousePos().x;
|
||||
}
|
||||
};
|
||||
|
||||
public static final NumberConstraint _mouseY = new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return InputSystem.getMousePos().y;
|
||||
}
|
||||
};
|
||||
|
||||
public static final NumberConstraint _screenW = new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return DisplaySystem.getWidth();
|
||||
}
|
||||
};
|
||||
|
||||
public static final NumberConstraint _screenH = new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return DisplaySystem.getHeight();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* ================= Arithmetics ================= */
|
||||
|
||||
public static NumberConstraint _min(final Object a, final Object b)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return Math.min(_nv(a), _nv(b));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _max(final Object a, final Object b)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return Math.max(_nv(a), _nv(b));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _abs(final NumberConstraint a)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return Math.abs(a.getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _half(final NumberConstraint a)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return a.getValue() / 2;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _round(final NumberConstraint a)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return Math.round(a.getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _round(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().round();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _ceil(final NumberConstraint a)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return Math.ceil(a.getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _floor(final NumberConstraint a)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return Math.floor(a.getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _neg(final NumberConstraint a)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return -a.getValue();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _add(final Object a, final Object b)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return _nv(a) + _nv(b);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _sub(final Object a, final Object b)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return _nv(a) - _nv(b);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _mul(final Object a, final Object b)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return _nv(a) * _nv(b);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _div(final Object a, final Object b)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return _nv(a) / _nv(b);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _percent(final Object whole, final Object percent)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return _nv(whole) * (_nv(percent) / 100);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _width(final RectConstraint r)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return r.getRect().getSize().x;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint _height(final RectConstraint r)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return r.getRect().getSize().y;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/* ================= Layout utilities ================= */
|
||||
|
||||
public static RectConstraint _row(final RectConstraint r, final int rows, final int index)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final double height = r.getRect().getSize().y;
|
||||
final double perRow = height / rows;
|
||||
|
||||
final Coord origin = r.getRect().getOrigin().add(0, perRow * index);
|
||||
final Coord size = r.getRect().getSize().setY(perRow);
|
||||
|
||||
return Rect.fromSize(origin, size);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _column(final RectConstraint r, final int columns, final int index)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final double width = r.getRect().getSize().x;
|
||||
final double perCol = width / columns;
|
||||
|
||||
final Coord origin = r.getRect().getOrigin().add(perCol * index, 0);
|
||||
final Coord size = r.getRect().getSize().setX(perCol);
|
||||
|
||||
return Rect.fromSize(origin, size);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _tile(final RectConstraint r, final int rows, final int cols, final int left, final int top)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final double height = r.getRect().getSize().y;
|
||||
final double width = r.getRect().getSize().y;
|
||||
final double perRow = height / rows;
|
||||
final double perCol = width / cols;
|
||||
|
||||
final Coord origin = r.getRect().getOrigin().add(perCol * left, perRow * (rows - top - 1));
|
||||
|
||||
return Rect.fromSize(origin, perCol, perRow);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/* ================= Rect manipulation ================= */
|
||||
|
||||
public static RectConstraint _shrink(RectConstraint r, Object shrink)
|
||||
{
|
||||
final NumberConstraint n = _n(shrink);
|
||||
return _shrink(r, n, n, n, n);
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _shrink(RectConstraint context, Object horiz, Object vert)
|
||||
{
|
||||
return _shrink(context, horiz, vert, horiz, vert);
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _shrink(final RectConstraint r, final Object xmin, final Object ymin, final Object xmax, final Object ymax)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().shrink(_nv(xmin), _nv(ymin), _nv(xmax), _nv(ymax));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _shrink_up(final RectConstraint r, final Object shrink)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().shrink(0, _nv(shrink), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _shrink_down(final RectConstraint r, final Object shrink)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().shrink(0, 0, 0, _nv(shrink));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _shrink_left(final RectConstraint r, final Object shrink)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().shrink(_nv(shrink), 0, 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _shrink_right(final RectConstraint r, final Object shrink)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().shrink(0, 0, _nv(shrink), 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _grow(RectConstraint r, Object grow)
|
||||
{
|
||||
final NumberConstraint n = _n(grow);
|
||||
return _grow(r, n, n, n, n);
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _grow(RectConstraint r, Object horiz, Object vert)
|
||||
{
|
||||
return _grow(r, horiz, vert, horiz, vert);
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _grow(final RectConstraint r, final Object xmin, final Object ymin, final Object xmax, final Object ymax)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().grow(_nv(xmin), _nv(ymin), _nv(xmax), _nv(ymax));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _grow_up(final RectConstraint r, final Object grow)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().grow(0, _nv(grow), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _grow_down(final RectConstraint r, final Object grow)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().grow(0, 0, 0, _nv(grow));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _grow_left(final RectConstraint r, final Object grow)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().grow(_nv(grow), 0, 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _grow_right(final RectConstraint r, final Object grow)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().grow(0, 0, _nv(grow), 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/* ================= Box creation ================= */
|
||||
|
||||
public static RectConstraint _box(final Object width, final Object height)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
//@formatter:off
|
||||
return Rect.fromSize(
|
||||
0,
|
||||
0,
|
||||
_nv(width),
|
||||
_nv(height)
|
||||
);
|
||||
//@formatter:on
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _box(final RectConstraint r, final Object width, final Object height)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final Coord origin = r.getRect().getOrigin();
|
||||
|
||||
//@formatter:off
|
||||
return Rect.fromSize(
|
||||
origin.x,
|
||||
origin.y,
|
||||
_nv(width),
|
||||
_nv(height)
|
||||
);
|
||||
//@formatter:on
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _box(final RectConstraint r, final Object x, final Object y, final Object width, final Object height)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final Coord origin = r.getRect().getOrigin();
|
||||
|
||||
//@formatter:off
|
||||
return Rect.fromSize(
|
||||
origin.x + _nv(x),
|
||||
origin.y + _nv(y),
|
||||
_nv(width),
|
||||
_nv(height)
|
||||
);
|
||||
//@formatter:on
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _box_abs(final RectConstraint r, final Object xmin, final Object ymin, final Object xmax, final Object ymax)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final Coord origin = r.getRect().getOrigin();
|
||||
|
||||
//@formatter:off
|
||||
return new Rect(origin.add(_nv(xmin), _nv(ymin)), origin.add(_nv(xmax), _nv(ymax)));
|
||||
//@formatter:on
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Center rect around given coords
|
||||
*
|
||||
* @param r rect
|
||||
* @param x
|
||||
* @param y
|
||||
* @return centered
|
||||
*/
|
||||
public static RectConstraint _centered(final RectConstraint r, final Object x, final Object y)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final Coord size = r.getRect().getSize();
|
||||
|
||||
return Rect.fromSize(_nv(x) - size.x / 2D, _nv(y) - size.y / 2D, size.x, size.y);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _move(final RectConstraint r, final Object x, final Object y)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().add(_nv(x), _nv(y));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/* ================= Rect bounds ================= */
|
||||
|
||||
/**
|
||||
* Get zero-sized rect at the center
|
||||
*
|
||||
* @param r context
|
||||
* @return center
|
||||
*/
|
||||
public static RectConstraint _center(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return Rect.fromSize(r.getRect().getCenter(), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _left_edge(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().shrink(0, 0, r.getRect().getWidth(), 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _top_edge(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().shrink(0, 0, 0, r.getRect().getHeight());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _right_edge(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().shrink(r.getRect().getWidth(), 0, 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _bottom_edge(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().shrink(0, r.getRect().getHeight(), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _left_top(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return Rect.fromSize(r.getRect().getHMinVMin(), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _left_bottom(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return Rect.fromSize(r.getRect().getHMinVMax(), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _right_top(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return Rect.fromSize(r.getRect().getHMaxVMin(), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _right_bottom(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return Rect.fromSize(r.getRect().getHMaxVMax(), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _center_top(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return Rect.fromSize(r.getRect().getCenterVMin(), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _center_bottom(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return Rect.fromSize(r.getRect().getCenterVMax(), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _center_left(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return Rect.fromSize(r.getRect().getCenterHMin(), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _center_right(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return Rect.fromSize(r.getRect().getCenterHMax(), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/* ================= Helpers ================= */
|
||||
|
||||
public static RectCache _cache(final RectConstraint rc)
|
||||
{
|
||||
return new RectCache(rc);
|
||||
}
|
||||
|
||||
|
||||
public static RectCache _cache(final Poller poller, final RectConstraint rc)
|
||||
{
|
||||
return new RectCache(poller, rc);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert {@link Number} to {@link NumberConstraint} if needed
|
||||
*
|
||||
* @param o unknown numeric value
|
||||
* @return converted
|
||||
*/
|
||||
public static NumberConstraint _n(final Object o)
|
||||
{
|
||||
|
||||
if (o instanceof NumberConstraint) return (NumberConstraint) o;
|
||||
|
||||
if (o instanceof Number) return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return ((Number) o).doubleValue();
|
||||
}
|
||||
};
|
||||
|
||||
throw new IllegalArgumentException("Invalid numeric type.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert {@link Number} or {@link NumberConstraint} to double (current
|
||||
* value)
|
||||
*
|
||||
* @param o unknown numeric value
|
||||
* @return double value
|
||||
*/
|
||||
public static double _nv(final Object o)
|
||||
{
|
||||
return _n(o).getValue();
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mightypork.utils.math.constraints;
|
||||
package mightypork.gamecore.gui.constraints;
|
||||
|
||||
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mightypork.utils.math.constraints;
|
||||
package mightypork.gamecore.gui.constraints;
|
||||
|
||||
|
||||
/**
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mightypork.utils.math.constraints;
|
||||
package mightypork.gamecore.gui.constraints;
|
||||
|
||||
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
@@ -0,0 +1,49 @@
|
||||
package mightypork.gamecore.gui.constraints;
|
||||
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import mightypork.gamecore.control.interf.Pollable;
|
||||
|
||||
|
||||
/**
|
||||
* Used to poll a number of {@link Pollable}s, such as {@link RectCache}
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class Poller implements Pollable {
|
||||
|
||||
private final Set<Pollable> pollables = new LinkedHashSet<>();
|
||||
|
||||
|
||||
/**
|
||||
* Add a pollable
|
||||
*
|
||||
* @param p pollable
|
||||
*/
|
||||
public void add(Pollable p)
|
||||
{
|
||||
pollables.add(p);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a pollalbe
|
||||
*
|
||||
* @param p pollable
|
||||
*/
|
||||
public void remove(Pollable p)
|
||||
{
|
||||
pollables.remove(p);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void poll()
|
||||
{
|
||||
for (final Pollable p : pollables) {
|
||||
p.poll();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package mightypork.gamecore.gui.constraints;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.interf.Pollable;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
/**
|
||||
* {@link RectConstraint} cache, used to reduce CPU load with very complex
|
||||
* constraints.<br>
|
||||
* Calculates only when polled.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class RectCache implements RectConstraint, Pollable {
|
||||
|
||||
private final RectConstraint observed;
|
||||
private final Rect cached = new Rect();
|
||||
|
||||
|
||||
/**
|
||||
* @param observed cached constraint
|
||||
*/
|
||||
public RectCache(RectConstraint observed) {
|
||||
this.observed = observed;
|
||||
poll();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create and join a poller
|
||||
*
|
||||
* @param poller poller to join
|
||||
* @param rc observed constraint
|
||||
*/
|
||||
public RectCache(Poller poller, RectConstraint rc) {
|
||||
this(rc);
|
||||
poller.add(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void poll()
|
||||
{
|
||||
cached.setTo(observed.getRect());
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mightypork.utils.math.constraints;
|
||||
package mightypork.gamecore.gui.constraints;
|
||||
|
||||
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
@@ -6,6 +6,7 @@ import java.util.TreeSet;
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
|
||||
/**
|
||||
@@ -60,4 +61,32 @@ public abstract class LayeredScreen extends Screen {
|
||||
removeChildClient(layer);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onScreenEnter()
|
||||
{
|
||||
for (final ScreenLayer layer : layers) {
|
||||
layer.onScreenEnter();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onScreenLeave()
|
||||
{
|
||||
|
||||
for (final ScreenLayer layer : layers) {
|
||||
layer.onScreenLeave();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(Coord size)
|
||||
{
|
||||
for (final ScreenLayer layer : layers) {
|
||||
layer.onSizeChanged(size);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppSubModule;
|
||||
import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
|
||||
import mightypork.gamecore.control.interf.NoImpl;
|
||||
import mightypork.gamecore.gui.renderers.Renderable;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.gamecore.input.KeyBinder;
|
||||
import mightypork.gamecore.input.KeyBindingPool;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@ package mightypork.gamecore.gui.screens;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.AppSubModule;
|
||||
import mightypork.gamecore.gui.renderers.Renderable;
|
||||
import mightypork.gamecore.control.interf.NoImpl;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.gamecore.input.KeyBinder;
|
||||
import mightypork.gamecore.input.KeyBindingPool;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
@@ -70,6 +72,38 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when the screen becomes active
|
||||
*/
|
||||
@NoImpl
|
||||
protected void onScreenEnter()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when the screen is no longer active
|
||||
*/
|
||||
@NoImpl
|
||||
protected void onScreenLeave()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update GUI for new screen size
|
||||
*
|
||||
* @param size screen size
|
||||
*/
|
||||
@NoImpl
|
||||
protected void onSizeChanged(Coord size)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return higher = on top.
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@ import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppModule;
|
||||
import mightypork.gamecore.control.bus.events.ScreenRequestEvent;
|
||||
import mightypork.gamecore.control.interf.NoImpl;
|
||||
import mightypork.gamecore.gui.renderers.Renderable;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
import mightypork.utils.logging.Log;
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import mightypork.gamecore.control.interf.Updateable;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.rogue.events.ActionRequest;
|
||||
import mightypork.rogue.events.ActionRequest.RequestType;
|
||||
import mightypork.utils.math.constraints.NumberConstraint;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
@@ -54,7 +53,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
}
|
||||
|
||||
|
||||
private static void initDevices()
|
||||
private void initDevices()
|
||||
{
|
||||
if (inited) return;
|
||||
inited = true;
|
||||
@@ -176,24 +175,4 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
{
|
||||
Mouse.setGrabbed(grab);
|
||||
}
|
||||
|
||||
/** Horizontal mouse position */
|
||||
public static final NumberConstraint mouseX = new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return getMousePos().x;
|
||||
}
|
||||
};
|
||||
|
||||
/** Vertical mouse position */
|
||||
public static final NumberConstraint mouseY = new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return getMousePos().y;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppModule;
|
||||
import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
|
||||
import mightypork.gamecore.control.timing.FpsMeter;
|
||||
import mightypork.gamecore.gui.constraints.NumberConstraint;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.constraints.NumberConstraint;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
@@ -134,7 +134,7 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
||||
*
|
||||
* @return screenshot object
|
||||
*/
|
||||
public static Screenshot takeScreenshot()
|
||||
public Screenshot takeScreenshot()
|
||||
{
|
||||
glReadBuffer(GL_FRONT);
|
||||
final int width = Display.getDisplayMode().getWidth();
|
||||
@@ -163,7 +163,7 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
||||
*
|
||||
* @return is fullscreen
|
||||
*/
|
||||
public static boolean isFullscreen()
|
||||
public boolean isFullscreen()
|
||||
{
|
||||
return Display.isFullscreen();
|
||||
}
|
||||
@@ -240,7 +240,7 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
||||
}
|
||||
|
||||
/** Screen width constraint */
|
||||
public static final NumberConstraint width = new NumberConstraint() {
|
||||
public final NumberConstraint width = new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
@@ -250,7 +250,7 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
||||
};
|
||||
|
||||
/** Screen height constaint */
|
||||
public static final NumberConstraint height = new NumberConstraint() {
|
||||
public final NumberConstraint height = new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
|
||||
@@ -291,20 +291,20 @@ public class Render {
|
||||
*/
|
||||
public static void quad(Rect quad)
|
||||
{
|
||||
final double left = quad.x1();
|
||||
final double bottom = quad.y1();
|
||||
final double right = quad.x2();
|
||||
final double top = quad.y2();
|
||||
final double x1 = quad.xMin();
|
||||
final double y1 = quad.yMin();
|
||||
final double x2 = quad.xMax();
|
||||
final double y2 = quad.yMax();
|
||||
|
||||
// draw with color
|
||||
unbindTexture();
|
||||
|
||||
// quad
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2d(left, top);
|
||||
glVertex2d(right, top);
|
||||
glVertex2d(right, bottom);
|
||||
glVertex2d(left, bottom);
|
||||
glVertex2d(x1, y2);
|
||||
glVertex2d(x2, y2);
|
||||
glVertex2d(x2, y1);
|
||||
glVertex2d(x1, y1);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
@@ -331,25 +331,25 @@ public class Render {
|
||||
*/
|
||||
public static void quadUV_nobound(Rect quad, Rect uvs)
|
||||
{
|
||||
final double left = quad.x1();
|
||||
final double bottom = quad.y1();
|
||||
final double right = quad.x2();
|
||||
final double top = quad.y2();
|
||||
final double x1 = quad.xMin();
|
||||
final double y1 = quad.yMin();
|
||||
final double x2 = quad.xMax();
|
||||
final double y2 = quad.yMax();
|
||||
|
||||
final double tleft = uvs.x1();
|
||||
final double tbottom = uvs.y1();
|
||||
final double tright = uvs.x2();
|
||||
final double ttop = uvs.y2();
|
||||
final double tx1 = uvs.xMin();
|
||||
final double ty1 = uvs.yMin();
|
||||
final double tx2 = uvs.xMax();
|
||||
final double ty2 = uvs.yMax();
|
||||
|
||||
// quad with texture
|
||||
glTexCoord2d(tleft, ttop);
|
||||
glVertex2d(left, top);
|
||||
glTexCoord2d(tright, ttop);
|
||||
glVertex2d(right, top);
|
||||
glTexCoord2d(tright, tbottom);
|
||||
glVertex2d(right, bottom);
|
||||
glTexCoord2d(tleft, tbottom);
|
||||
glVertex2d(left, bottom);
|
||||
glTexCoord2d(tx1, ty2);
|
||||
glVertex2d(x1, y2);
|
||||
glTexCoord2d(tx2, ty2);
|
||||
glVertex2d(x2, y2);
|
||||
glTexCoord2d(tx2, ty1);
|
||||
glVertex2d(x2, y1);
|
||||
glTexCoord2d(tx1, ty1);
|
||||
glVertex2d(x1, y1);
|
||||
}
|
||||
|
||||
|
||||
@@ -362,24 +362,24 @@ public class Render {
|
||||
*/
|
||||
public static void quadGradH(Rect quad, RGB colorLeft, RGB colorRight)
|
||||
{
|
||||
final double left = quad.x1();
|
||||
final double bottom = quad.y1();
|
||||
final double right = quad.y2();
|
||||
final double top = quad.y2();
|
||||
final double x1 = quad.xMin();
|
||||
final double y1 = quad.yMin();
|
||||
final double x2 = quad.xMax();
|
||||
final double y2 = quad.yMax();
|
||||
|
||||
// draw with color
|
||||
unbindTexture();
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
setColor(colorLeft);
|
||||
glVertex2d(left, top);
|
||||
glVertex2d(x1, y2);
|
||||
setColor(colorRight);
|
||||
glVertex2d(right, top);
|
||||
glVertex2d(x2, y2);
|
||||
|
||||
setColor(colorRight);
|
||||
glVertex2d(right, bottom);
|
||||
glVertex2d(x2, y1);
|
||||
setColor(colorLeft);
|
||||
glVertex2d(left, bottom);
|
||||
glVertex2d(x1, y1);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
@@ -388,27 +388,27 @@ public class Render {
|
||||
* Draw quad with vertical gradient
|
||||
*
|
||||
* @param quad drawn quad bounds
|
||||
* @param colorTop top color
|
||||
* @param colorBottom bottom color
|
||||
* @param color1 top color
|
||||
* @param color2 bottom color
|
||||
*/
|
||||
public static void quadGradV(Rect quad, RGB colorTop, RGB colorBottom)
|
||||
public static void quadGradV(Rect quad, RGB color1, RGB color2)
|
||||
{
|
||||
final double left = quad.x1();
|
||||
final double bottom = quad.y1();
|
||||
final double right = quad.y2();
|
||||
final double top = quad.y2();
|
||||
final double x1 = quad.xMin();
|
||||
final double y1 = quad.yMin();
|
||||
final double x2 = quad.xMax();
|
||||
final double y2 = quad.yMax();
|
||||
|
||||
// draw with color
|
||||
unbindTexture();
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
setColor(colorTop);
|
||||
glVertex2d(left, top);
|
||||
glVertex2d(right, top);
|
||||
setColor(color1);
|
||||
glVertex2d(x1, y1);
|
||||
glVertex2d(x2, y1);
|
||||
|
||||
setColor(colorBottom);
|
||||
glVertex2d(right, bottom);
|
||||
glVertex2d(left, bottom);
|
||||
setColor(color2);
|
||||
glVertex2d(x2, y2);
|
||||
glVertex2d(x1, y2);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
|
||||
/**
|
||||
* Font renderer
|
||||
@@ -123,6 +125,7 @@ public class FontRenderer {
|
||||
{
|
||||
Render.pushState();
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
Render.translate(pos.round());
|
||||
Render.scaleXY(getScale(height));
|
||||
|
||||
@@ -161,16 +164,16 @@ public class FontRenderer {
|
||||
|
||||
switch (align) {
|
||||
case LEFT:
|
||||
start = bounds.getX1Y1();
|
||||
start = bounds.getHMinVMin();
|
||||
break;
|
||||
|
||||
case CENTER:
|
||||
start = bounds.getCenterV1();
|
||||
start = bounds.getCenterVMin();
|
||||
break;
|
||||
|
||||
case RIGHT:
|
||||
default:
|
||||
start = bounds.getX2Y1();
|
||||
start = bounds.getHMaxVMin();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import mightypork.rogue.events.ActionRequest.RequestType;
|
||||
import mightypork.rogue.screens.test_bouncyboxes.ScreenTestBouncy;
|
||||
import mightypork.rogue.screens.test_cat_sound.ScreenTestCat;
|
||||
import mightypork.rogue.screens.test_font.ScreenTestFont;
|
||||
import mightypork.rogue.screens.test_render.ScreenTestRender;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.logging.LogInstance;
|
||||
|
||||
@@ -164,8 +165,9 @@ public class App extends BaseApp {
|
||||
screens.add(new ScreenTestBouncy(this));
|
||||
screens.add(new ScreenTestCat(this));
|
||||
screens.add(new ScreenTestFont(this));
|
||||
screens.add(new ScreenTestRender(this));
|
||||
|
||||
screens.showScreen("test.bouncy");
|
||||
screens.showScreen("test.cat");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.Date;
|
||||
import mightypork.gamecore.control.BaseApp;
|
||||
import mightypork.gamecore.control.GameLoop;
|
||||
import mightypork.gamecore.gui.Action;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.gamecore.render.Screenshot;
|
||||
import mightypork.rogue.events.ActionRequest;
|
||||
import mightypork.rogue.events.ActionRequest.RequestType;
|
||||
@@ -42,7 +41,9 @@ public class MainLoop extends GameLoop implements ActionRequest.Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/* Take a screenshot */
|
||||
/*
|
||||
* Take a screenshot
|
||||
*/
|
||||
private final Action taskScreenshot = new Action() {
|
||||
|
||||
@Override
|
||||
@@ -53,7 +54,9 @@ public class MainLoop extends GameLoop implements ActionRequest.Listener {
|
||||
}
|
||||
};
|
||||
|
||||
/* Shutdown the application */
|
||||
/*
|
||||
* Shutdown the application
|
||||
*/
|
||||
private final Action taskShutdown = new Action() {
|
||||
|
||||
@Override
|
||||
@@ -63,7 +66,9 @@ public class MainLoop extends GameLoop implements ActionRequest.Listener {
|
||||
}
|
||||
};
|
||||
|
||||
/* Toggle fullscreen */
|
||||
/*
|
||||
* Toggle fullscreen
|
||||
*/
|
||||
private final Action taskFullscreen = new Action() {
|
||||
|
||||
@Override
|
||||
@@ -79,7 +84,7 @@ public class MainLoop extends GameLoop implements ActionRequest.Listener {
|
||||
|
||||
|
||||
public TaskTakeScreenshot() {
|
||||
scr = DisplaySystem.takeScreenshot();
|
||||
scr = getDisplay().takeScreenshot();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,35 +1,47 @@
|
||||
package mightypork.rogue.screens;
|
||||
|
||||
|
||||
import mightypork.gamecore.gui.renderers.TextPainter;
|
||||
import static mightypork.gamecore.gui.constraints.Constraints.*;
|
||||
import mightypork.gamecore.gui.components.painters.TextPainter;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.gamecore.gui.screens.Screen;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.gamecore.render.fonts.FontRenderer;
|
||||
import mightypork.gamecore.render.fonts.FontRenderer.Align;
|
||||
import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.string.StringProvider;
|
||||
|
||||
|
||||
public class LayerFps extends ScreenLayer {
|
||||
|
||||
TextPainter tp;
|
||||
private final FontRenderer fr;
|
||||
|
||||
|
||||
public LayerFps(Screen screen) {
|
||||
super(screen);
|
||||
|
||||
fr = new FontRenderer(Res.getFont("default"), RGB.WHITE);
|
||||
final StringProvider text = new StringProvider() {
|
||||
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
return getDisplay().getFps() + " fps";
|
||||
}
|
||||
};
|
||||
|
||||
final GLFont font = Res.getFont("default");
|
||||
final RectConstraint constraint = _round(_move(_grow_down(_right_top(this), 32), -8, 8));
|
||||
|
||||
tp = new TextPainter(font, Align.RIGHT, RGB.WHITE, text);
|
||||
tp.setContext(constraint);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render()
|
||||
{
|
||||
final Coord pos = new Coord(DisplaySystem.getWidth() - 8, 8);
|
||||
fr.draw(getDisplay().getFps() + " fps", pos, 32, Align.RIGHT);
|
||||
tp.render();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package mightypork.rogue.screens.test_bouncyboxes;
|
||||
|
||||
|
||||
import static mightypork.utils.math.constraints.ConstraintFactory.*;
|
||||
import static mightypork.gamecore.gui.constraints.Constraints.*;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.gamecore.control.interf.Updateable;
|
||||
import mightypork.gamecore.gui.renderers.PluggableRenderer;
|
||||
import mightypork.gamecore.gui.components.PluggableRenderer;
|
||||
import mightypork.gamecore.gui.constraints.NumberConstraint;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.math.animation.AnimDouble;
|
||||
import mightypork.utils.math.animation.Easing;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.constraints.NumberConstraint;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
|
||||
|
||||
public class BouncyBox extends PluggableRenderer implements Updateable {
|
||||
@@ -26,16 +26,16 @@ public class BouncyBox extends PluggableRenderer implements Updateable {
|
||||
|
||||
public BouncyBox() {
|
||||
// create box
|
||||
final NumberConstraint side = c_height(this);
|
||||
RectConstraint abox = c_box(this, side, side);
|
||||
final NumberConstraint side = _height(this);
|
||||
RectConstraint abox = _box(this, side, side);
|
||||
|
||||
// move
|
||||
final NumberConstraint move_length = c_sub(c_width(this), side);
|
||||
final NumberConstraint offset = c_mul(move_length, pos);
|
||||
abox = c_move(abox, offset, 0);
|
||||
final NumberConstraint move_length = _sub(_width(this), side);
|
||||
final NumberConstraint offset = _mul(move_length, pos);
|
||||
abox = _move(abox, offset, 0);
|
||||
|
||||
// add padding
|
||||
abox = c_shrink(abox, c_percent(side, 10));
|
||||
abox = _shrink(abox, _percent(side, 10));
|
||||
|
||||
box = abox;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package mightypork.rogue.screens.test_bouncyboxes;
|
||||
|
||||
|
||||
import static mightypork.utils.math.constraints.ConstraintFactory.*;
|
||||
import static mightypork.gamecore.gui.constraints.Constraints.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mightypork.gamecore.gui.renderers.RowHolder;
|
||||
import mightypork.gamecore.gui.renderers.TextPainter;
|
||||
import mightypork.gamecore.gui.components.layout.RowHolder;
|
||||
import mightypork.gamecore.gui.components.painters.TextPainter;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.gamecore.gui.screens.Screen;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
@@ -15,7 +16,6 @@ import mightypork.gamecore.input.Keys;
|
||||
import mightypork.gamecore.render.fonts.FontRenderer.Align;
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.string.StringProvider;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class LayerBouncyBoxes extends ScreenLayer {
|
||||
});
|
||||
|
||||
// shrink screen rect by 8% on all sides
|
||||
final RectConstraint holder_rect = c_shrink(this, c_percent(c_height(this), 4));
|
||||
final RectConstraint holder_rect = _shrink(this, _percent(_height(this), 4));
|
||||
|
||||
addChildClient(layout = new RowHolder(screen, holder_rect, 11));
|
||||
|
||||
@@ -57,16 +57,14 @@ public class LayerBouncyBoxes extends ScreenLayer {
|
||||
boxes.add(bbr);
|
||||
}
|
||||
|
||||
final StringProvider sp = new StringProvider() {
|
||||
layout.add(new TextPainter(Res.getFont("default"), Align.LEFT, RGB.WHITE, new StringProvider() {
|
||||
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
return "Running at " + getDisplay().getFps() + " fps!";
|
||||
}
|
||||
};
|
||||
|
||||
layout.add(new TextPainter(Res.getFont("default"), Align.LEFT, RGB.WHITE, sp));
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package mightypork.rogue.screens.test_cat_sound;
|
||||
|
||||
|
||||
import static mightypork.utils.math.constraints.ConstraintFactory.*;
|
||||
import static mightypork.gamecore.gui.constraints.Constraints.*;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.gamecore.control.bus.events.MouseButtonEvent;
|
||||
import mightypork.gamecore.control.interf.Updateable;
|
||||
import mightypork.gamecore.gui.renderers.ImagePainter;
|
||||
import mightypork.gamecore.gui.renderers.TextPainter;
|
||||
import mightypork.gamecore.gui.components.painters.ImagePainter;
|
||||
import mightypork.gamecore.gui.components.painters.TextPainter;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.gamecore.gui.screens.Screen;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.gamecore.input.Keys;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
@@ -20,9 +20,7 @@ import mightypork.rogue.Res;
|
||||
import mightypork.utils.math.animation.AnimDouble;
|
||||
import mightypork.utils.math.animation.Easing;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.string.StringProvider;
|
||||
|
||||
|
||||
public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButtonEvent.Listener {
|
||||
@@ -34,7 +32,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
||||
private final Random rand = new Random();
|
||||
|
||||
private final ImagePainter cat;
|
||||
private final TextPainter text;
|
||||
private final TextPainter tp;
|
||||
|
||||
|
||||
public LayerFlyingCat(Screen screen) {
|
||||
@@ -42,24 +40,16 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
||||
|
||||
xPos.setTo(DisplaySystem.getWidth() / 2);
|
||||
yPos.setTo(DisplaySystem.getHeight() / 2);
|
||||
final RectConstraint catbox = _centered(_box(size, size), xPos, yPos);
|
||||
|
||||
cat = new ImagePainter(Res.getTxQuad("test.kitten"));
|
||||
cat.setContext(c_centered(c_box(this, size, size), xPos, yPos));
|
||||
cat.setContext(catbox);
|
||||
|
||||
final RectConstraint fpsbox = c_centered(c_box(this, 0, 64), InputSystem.mouseX, InputSystem.mouseY);
|
||||
final RectConstraint fpsbox = _centered(_box(64, 64), _mouseX, _mouseY);
|
||||
|
||||
final StringProvider sp = new StringProvider() {
|
||||
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
return getDisplay().getFps() + " fps";
|
||||
}
|
||||
};
|
||||
tp = new TextPainter(Res.getFont("default"), Align.CENTER, RGB.YELLOW, "Meow");
|
||||
|
||||
text = new TextPainter(Res.getFont("default"), Align.CENTER, RGB.YELLOW, sp);
|
||||
|
||||
text.setContext(fpsbox);
|
||||
tp.setContext(fpsbox);
|
||||
|
||||
bindKeyStroke(new KeyStroke(Keys.KEY_RETURN), new Runnable() {
|
||||
|
||||
@@ -88,9 +78,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
||||
if (!event.isDown()) return;
|
||||
|
||||
final Coord pos = event.getPos();
|
||||
|
||||
final double t = 2;
|
||||
|
||||
size.fadeTo(100 + rand.nextInt(700), t / 2D);
|
||||
|
||||
xPos.fadeTo(pos.x, t);
|
||||
@@ -102,7 +90,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
||||
public void render()
|
||||
{
|
||||
cat.render();
|
||||
text.render();
|
||||
tp.render();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package mightypork.rogue.screens.test_font;
|
||||
|
||||
|
||||
import static mightypork.utils.math.constraints.ConstraintFactory.*;
|
||||
import static mightypork.gamecore.gui.constraints.Constraints.*;
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.gui.renderers.TextPainter;
|
||||
import mightypork.gamecore.gui.components.painters.TextPainter;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.gamecore.gui.screens.Screen;
|
||||
import mightypork.gamecore.render.fonts.FontRenderer.Align;
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
|
||||
|
||||
public class ScreenTestFont extends Screen {
|
||||
@@ -22,7 +22,7 @@ public class ScreenTestFont extends Screen {
|
||||
tp = new TextPainter(Res.getFont("default"), Align.CENTER, RGB.GREEN);
|
||||
tp.setText("Hello World!");
|
||||
|
||||
final RectConstraint strbox = c_grow(c_center(this), 0, c_div(c_height(this), 10));
|
||||
final RectConstraint strbox = _grow(_center(this), 0, _div(_height(this), 10));
|
||||
|
||||
tp.setContext(strbox);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package mightypork.rogue.screens.test_render;
|
||||
|
||||
|
||||
import static mightypork.gamecore.gui.constraints.Constraints.*;
|
||||
import mightypork.gamecore.gui.constraints.Poller;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.gamecore.gui.screens.Screen;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
|
||||
public class LayerTestGradient extends ScreenLayer {
|
||||
|
||||
private final Poller p = new Poller();
|
||||
|
||||
private final RectConstraint pos1;
|
||||
private final RectConstraint pos2;
|
||||
private final RectConstraint pos3;
|
||||
|
||||
|
||||
public LayerTestGradient(Screen screen) {
|
||||
super(screen);
|
||||
|
||||
pos1 = _cache(p, _grow_down(_top_edge(this), 64));
|
||||
pos2 = _cache(p, _shrink_up(_grow_right(_left_edge(this), 64), 64));
|
||||
pos3 = _cache(p, _move(_grow(_center(this), 70, 10), 100, 100));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render()
|
||||
{
|
||||
Render.quadGradH(pos1.getRect(), RGB.GREEN, RGB.RED);
|
||||
Render.quadGradV(pos2.getRect(), RGB.WHITE, RGB.PURPLE);
|
||||
Render.quad(pos3.getRect(), RGB.RED);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(Coord size)
|
||||
{
|
||||
p.poll();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package mightypork.rogue.screens.test_render;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.gui.screens.LayeredScreen;
|
||||
import mightypork.rogue.screens.LayerFps;
|
||||
|
||||
|
||||
public class ScreenTestRender extends LayeredScreen {
|
||||
|
||||
public ScreenTestRender(AppAccess app) {
|
||||
super(app);
|
||||
|
||||
addLayer(new LayerFps(this));
|
||||
addLayer(new LayerTestGradient(this));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "test.render";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package mightypork.utils.math.animation;
|
||||
|
||||
import mightypork.gamecore.control.interf.Updateable;
|
||||
import mightypork.gamecore.control.timing.Pauseable;
|
||||
import mightypork.gamecore.gui.constraints.NumberConstraint;
|
||||
import mightypork.utils.math.Calc;
|
||||
import mightypork.utils.math.constraints.NumberConstraint;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,467 +0,0 @@
|
||||
package mightypork.utils.math.constraints;
|
||||
|
||||
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
/**
|
||||
* Constraint factory.<br>
|
||||
* Import statically for best experience.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class ConstraintFactory {
|
||||
|
||||
public static NumberConstraint c_min(final Object a, final Object b)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return Math.min(n(a).getValue(), n(b).getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_max(final Object a, final Object b)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return Math.max(n(a).getValue(), n(b).getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_abs(final NumberConstraint a)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return Math.abs(a.getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_half(final NumberConstraint a)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return a.getValue() / 2;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_round(final NumberConstraint a)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return Math.round(a.getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_round(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().round();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_ceil(final NumberConstraint a)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return Math.ceil(a.getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_floor(final NumberConstraint a)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return Math.floor(a.getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_neg(final NumberConstraint a)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return -a.getValue();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_add(final Object a, final Object b)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return n(a).getValue() + n(b).getValue();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_sub(final Object a, final Object b)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return n(a).getValue() - n(b).getValue();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_mul(final Object a, final Object b)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return n(a).getValue() * n(b).getValue();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_div(final Object a, final Object b)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return n(a).getValue() / n(b).getValue();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_percent(final Object whole, final Object percent)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return n(whole).getValue() * (n(percent).getValue() / 100);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_width(final RectConstraint r)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return r.getRect().getSize().x;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint c_height(final RectConstraint r)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return r.getRect().getSize().y;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_row(final RectConstraint r, final int rows, final int index)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final double height = r.getRect().getSize().y;
|
||||
final double perRow = height / rows;
|
||||
|
||||
final Coord origin = r.getRect().getOrigin().add(0, perRow * index);
|
||||
final Coord size = r.getRect().getSize().setY(perRow);
|
||||
|
||||
return Rect.fromSize(origin, size);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_column(final RectConstraint r, final int columns, final int index)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final double width = r.getRect().getSize().x;
|
||||
final double perCol = width / columns;
|
||||
|
||||
final Coord origin = r.getRect().getOrigin().add(perCol * index, 0);
|
||||
final Coord size = r.getRect().getSize().setX(perCol);
|
||||
|
||||
return Rect.fromSize(origin, size);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_shrink(RectConstraint r, Object shrink)
|
||||
{
|
||||
final NumberConstraint n = n(shrink);
|
||||
return c_shrink(r, n, n, n, n);
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_shrink(RectConstraint context, Object horiz, Object vert)
|
||||
{
|
||||
return c_shrink(context, horiz, vert, horiz, vert);
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_shrink(final RectConstraint r, final Object x1, final Object y1, final Object x2, final Object y2)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().shrink(n(x1).getValue(), n(y1).getValue(), n(x2).getValue(), n(y2).getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_center(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return Rect.fromSize(r.getRect().getCenter(), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_grow(RectConstraint r, Object grow)
|
||||
{
|
||||
final NumberConstraint n = n(grow);
|
||||
return c_grow(r, n, n, n, n);
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_grow(RectConstraint r, Object horiz, Object vert)
|
||||
{
|
||||
return c_grow(r, horiz, vert, horiz, vert);
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_grow(final RectConstraint r, final Object x1, final Object y1, final Object x2, final Object y2)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().grow(n(x1).getValue(), n(y1).getValue(), n(x2).getValue(), n(y2).getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_tile(final RectConstraint r, final int rows, final int cols, final int left, final int top)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final double height = r.getRect().getSize().y;
|
||||
final double width = r.getRect().getSize().y;
|
||||
final double perRow = height / rows;
|
||||
final double perCol = width / cols;
|
||||
|
||||
final Coord origin = r.getRect().getOrigin().add(perCol * left, perRow * (rows - top - 1));
|
||||
|
||||
return Rect.fromSize(origin, perCol, perRow);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_box(final RectConstraint r, final Object width, final Object height)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final Coord origin = r.getRect().getOrigin();
|
||||
|
||||
//@formatter:off
|
||||
return Rect.fromSize(
|
||||
origin.x,
|
||||
origin.y,
|
||||
n(width).getValue(),
|
||||
n(height).getValue()
|
||||
);
|
||||
//@formatter:on
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_box(final RectConstraint r, final Object x, final Object y, final Object width, final Object height)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final Coord origin = r.getRect().getOrigin();
|
||||
|
||||
//@formatter:off
|
||||
return Rect.fromSize(
|
||||
origin.x + n(x).getValue(),
|
||||
origin.y + n(y).getValue(),
|
||||
n(width).getValue(),
|
||||
n(height).getValue()
|
||||
);
|
||||
//@formatter:on
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Center rect around given coords
|
||||
*
|
||||
* @param r rect
|
||||
* @param x
|
||||
* @param y
|
||||
* @return centered
|
||||
*/
|
||||
public static RectConstraint c_centered(final RectConstraint r, final Object x, final Object y)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final Coord size = r.getRect().getSize();
|
||||
|
||||
return Rect.fromSize(n(x).getValue() - size.x / 2D, n(y).getValue() - size.y / 2D, size.x, size.y);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_box_abs(final RectConstraint r, final Object x1, final Object y1, final Object x2, final Object y2)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final Coord origin = r.getRect().getOrigin();
|
||||
|
||||
//@formatter:off
|
||||
return new Rect(origin.add(n(x1).getValue(), n(y1).getValue()), origin.add(n(x2).getValue(), n(y2).getValue()));
|
||||
//@formatter:on
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint c_move(final RectConstraint r, final Object x, final Object y)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return r.getRect().add(n(x).getValue(), n(y).getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert {@link Double} to {@link NumberConstraint} if needed
|
||||
*
|
||||
* @param o unknown numeric value
|
||||
* @return converted
|
||||
*/
|
||||
public static NumberConstraint n(final Object o)
|
||||
{
|
||||
|
||||
if (o instanceof NumberConstraint) return (NumberConstraint) o;
|
||||
|
||||
if (o instanceof Number) return new NumberConstraint() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return ((Number) o).doubleValue();
|
||||
}
|
||||
};
|
||||
|
||||
throw new IllegalArgumentException("Invalid numeric type.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package mightypork.utils.math.coord;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.utils.math.Calc;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package mightypork.utils.math.coord;
|
||||
|
||||
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.utils.math.Calc;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
|
||||
|
||||
/**
|
||||
@@ -67,15 +67,15 @@ public class Rect implements RectConstraint {
|
||||
/**
|
||||
* Make rect from min coord and size
|
||||
*
|
||||
* @param xMin min x
|
||||
* @param yMin min y
|
||||
* @param xmin min x
|
||||
* @param ymin min y
|
||||
* @param width size x
|
||||
* @param height size y
|
||||
* @return the new rect
|
||||
*/
|
||||
public static Rect fromSize(double xMin, double yMin, double width, double height)
|
||||
public static Rect fromSize(double xmin, double ymin, double width, double height)
|
||||
{
|
||||
return new Rect(xMin, yMin, xMin + width, yMin + height);
|
||||
return new Rect(xmin, ymin, xmin + width, ymin + height);
|
||||
}
|
||||
|
||||
/** Lowest coordinates xy */
|
||||
@@ -117,13 +117,13 @@ public class Rect implements RectConstraint {
|
||||
/**
|
||||
* New Rect
|
||||
*
|
||||
* @param x1 lower x
|
||||
* @param y1 lower y
|
||||
* @param x2 upper x
|
||||
* @param y2 upper y
|
||||
* @param xmin lower x
|
||||
* @param ymin lower y
|
||||
* @param xmax upper x
|
||||
* @param ymax upper y
|
||||
*/
|
||||
public Rect(double x1, double y1, double x2, double y2) {
|
||||
setTo(x1, y1, x2, y2);
|
||||
public Rect(double xmin, double ymin, double xmax, double ymax) {
|
||||
setTo(xmin, ymin, xmax, ymax);
|
||||
}
|
||||
|
||||
|
||||
@@ -227,7 +227,7 @@ public class Rect implements RectConstraint {
|
||||
*
|
||||
* @return center
|
||||
*/
|
||||
public Coord getCenterV1()
|
||||
public Coord getCenterVMin()
|
||||
{
|
||||
return new Coord((max.x + min.x) / 2D, min.y);
|
||||
}
|
||||
@@ -238,7 +238,7 @@ public class Rect implements RectConstraint {
|
||||
*
|
||||
* @return center
|
||||
*/
|
||||
public Coord getCenterH1()
|
||||
public Coord getCenterHMin()
|
||||
{
|
||||
return new Coord(min.x, (max.y + min.y) / 2D);
|
||||
}
|
||||
@@ -249,7 +249,7 @@ public class Rect implements RectConstraint {
|
||||
*
|
||||
* @return center
|
||||
*/
|
||||
public Coord getCenterH2()
|
||||
public Coord getCenterHMax()
|
||||
{
|
||||
return new Coord(max.x, (max.y + min.y) / 2D);
|
||||
}
|
||||
@@ -260,7 +260,7 @@ public class Rect implements RectConstraint {
|
||||
*
|
||||
* @return center
|
||||
*/
|
||||
public Coord getCenterV2()
|
||||
public Coord getCenterVMax()
|
||||
{
|
||||
return new Coord((max.x + min.x) / 2D, max.y);
|
||||
}
|
||||
@@ -271,7 +271,7 @@ public class Rect implements RectConstraint {
|
||||
*
|
||||
* @return center
|
||||
*/
|
||||
public Coord getX1Y1()
|
||||
public Coord getHMinVMin()
|
||||
{
|
||||
return new Coord(min.x, min.y);
|
||||
}
|
||||
@@ -282,7 +282,7 @@ public class Rect implements RectConstraint {
|
||||
*
|
||||
* @return center
|
||||
*/
|
||||
public Coord getX1Y2()
|
||||
public Coord getHMinVMax()
|
||||
{
|
||||
return new Coord(min.x, max.y);
|
||||
}
|
||||
@@ -295,7 +295,7 @@ public class Rect implements RectConstraint {
|
||||
*/
|
||||
public Coord getMax()
|
||||
{
|
||||
return getX2Y2();
|
||||
return getHMaxVMax();
|
||||
}
|
||||
|
||||
|
||||
@@ -306,7 +306,7 @@ public class Rect implements RectConstraint {
|
||||
*/
|
||||
public Coord getMin()
|
||||
{
|
||||
return getX1Y1();
|
||||
return getHMinVMin();
|
||||
}
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ public class Rect implements RectConstraint {
|
||||
*
|
||||
* @return center
|
||||
*/
|
||||
public Coord getX2Y1()
|
||||
public Coord getHMaxVMin()
|
||||
{
|
||||
return new Coord(max.x, min.y);
|
||||
}
|
||||
@@ -337,7 +337,7 @@ public class Rect implements RectConstraint {
|
||||
*
|
||||
* @return center
|
||||
*/
|
||||
public Coord getX2Y2()
|
||||
public Coord getHMaxVMax()
|
||||
{
|
||||
return new Coord(max.x, max.y);
|
||||
}
|
||||
@@ -399,31 +399,31 @@ public class Rect implements RectConstraint {
|
||||
/**
|
||||
* Shrink the rect
|
||||
*
|
||||
* @param x1 shrink
|
||||
* @param y1 shrink
|
||||
* @param x2 shrink
|
||||
* @param y2 shrink
|
||||
* @param xmin shrink
|
||||
* @param ymin shrink
|
||||
* @param xmax shrink
|
||||
* @param ymax shrink
|
||||
* @return changed copy
|
||||
*/
|
||||
public Rect shrink(double x1, double y1, double x2, double y2)
|
||||
public Rect shrink(double xmin, double ymin, double xmax, double ymax)
|
||||
{
|
||||
return copy().shrink_ip(x1, y1, x2, y2);
|
||||
return copy().shrink_ip(xmin, ymin, xmax, ymax);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shrink the rect in place
|
||||
*
|
||||
* @param x1 shrink
|
||||
* @param y1 shrink
|
||||
* @param x2 shrink
|
||||
* @param y2 shrink
|
||||
* @param xmin shrink
|
||||
* @param ymin shrink
|
||||
* @param xmax shrink
|
||||
* @param ymax shrink
|
||||
* @return this
|
||||
*/
|
||||
public Rect shrink_ip(double x1, double y1, double x2, double y2)
|
||||
public Rect shrink_ip(double xmin, double ymin, double xmax, double ymax)
|
||||
{
|
||||
min.add_ip(x1, y2);
|
||||
max.add_ip(-x2, -y1);
|
||||
min.add_ip(xmin, ymin);
|
||||
max.add_ip(-xmax, -ymax);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -484,31 +484,31 @@ public class Rect implements RectConstraint {
|
||||
/**
|
||||
* Grow the rect
|
||||
*
|
||||
* @param x1 growth
|
||||
* @param y1 growth
|
||||
* @param x2 growth
|
||||
* @param y2 growth
|
||||
* @param xmin growth
|
||||
* @param ymin growth
|
||||
* @param xmax growth
|
||||
* @param ymax growth
|
||||
* @return changed copy
|
||||
*/
|
||||
public Rect grow(double x1, double y1, double x2, double y2)
|
||||
public Rect grow(double xmin, double ymin, double xmax, double ymax)
|
||||
{
|
||||
return copy().grow_ip(x1, y1, x2, y2);
|
||||
return copy().grow_ip(xmin, ymin, xmax, ymax);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Grow the rect in place
|
||||
*
|
||||
* @param x1 growth
|
||||
* @param y1 growth
|
||||
* @param x2 growth
|
||||
* @param y2 growth
|
||||
* @param xmin growth
|
||||
* @param ymin growth
|
||||
* @param xmax growth
|
||||
* @param ymax growth
|
||||
* @return this
|
||||
*/
|
||||
public Rect grow_ip(double x1, double y1, double x2, double y2)
|
||||
public Rect grow_ip(double xmin, double ymin, double xmax, double ymax)
|
||||
{
|
||||
min.add_ip(-x1, -y2);
|
||||
max.add_ip(x2, y1);
|
||||
min.add_ip(-xmin, -ymin);
|
||||
max.add_ip(xmax, ymax);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -617,17 +617,17 @@ public class Rect implements RectConstraint {
|
||||
/**
|
||||
* Set to coordinates
|
||||
*
|
||||
* @param x1 lower x
|
||||
* @param y1 lower y
|
||||
* @param x2 upper x
|
||||
* @param y2 upper y
|
||||
* @param xmin lower x
|
||||
* @param ymin lower y
|
||||
* @param xmax upper x
|
||||
* @param ymax upper y
|
||||
*/
|
||||
public void setTo(double x1, double y1, double x2, double y2)
|
||||
public void setTo(double xmin, double ymin, double xmax, double ymax)
|
||||
{
|
||||
min.x = Calc.min(x1, x2);
|
||||
min.y = Calc.min(y1, y2);
|
||||
max.x = Calc.max(x1, x2);
|
||||
max.y = Calc.max(y1, y2);
|
||||
min.x = Calc.min(xmin, xmax);
|
||||
min.y = Calc.min(ymin, ymax);
|
||||
max.x = Calc.max(xmin, xmax);
|
||||
max.y = Calc.max(ymin, ymax);
|
||||
}
|
||||
|
||||
|
||||
@@ -723,7 +723,7 @@ public class Rect implements RectConstraint {
|
||||
/**
|
||||
* @return lower x
|
||||
*/
|
||||
public double x1()
|
||||
public double xMin()
|
||||
{
|
||||
return min.x;
|
||||
}
|
||||
@@ -732,7 +732,7 @@ public class Rect implements RectConstraint {
|
||||
/**
|
||||
* @return upper x
|
||||
*/
|
||||
public double x2()
|
||||
public double xMax()
|
||||
{
|
||||
return max.x;
|
||||
}
|
||||
@@ -741,7 +741,7 @@ public class Rect implements RectConstraint {
|
||||
/**
|
||||
* @return lower y
|
||||
*/
|
||||
public double y1()
|
||||
public double yMin()
|
||||
{
|
||||
return min.y;
|
||||
}
|
||||
@@ -750,7 +750,7 @@ public class Rect implements RectConstraint {
|
||||
/**
|
||||
* @return upper y
|
||||
*/
|
||||
public double y2()
|
||||
public double yMax()
|
||||
{
|
||||
return max.y;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user