Greatly improved Constraints system

This commit is contained in:
Ondřej Hruška
2014-04-10 00:57:39 +02:00
parent f81c349d20
commit 861d007b27
40 changed files with 1324 additions and 702 deletions
+10 -7
View File
@@ -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();
}
@@ -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;
@@ -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,4 +1,4 @@
package mightypork.gamecore.gui.renderers;
package mightypork.gamecore.gui.components;
/**
@@ -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);
}
@@ -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;
@@ -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);
}
@@ -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;
@@ -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();
}
}
@@ -0,0 +1,30 @@
package mightypork.gamecore.gui.constraints;
import mightypork.utils.math.coord.Rect;
/**
* Basic pluggable context implementation
*
* @author MightyPork
*/
public abstract class ContextAdapter implements PluggableContext {
private RectConstraint backing = null;
@Override
public void setContext(RectConstraint rect)
{
this.backing = rect;
}
@Override
public Rect getRect()
{
return backing.getRect();
}
}
@@ -0,0 +1,16 @@
package mightypork.gamecore.gui.constraints;
/**
* Numeric constraint
*
* @author MightyPork
*/
public interface NumberConstraint {
/**
* @return current value
*/
double getValue();
}
@@ -0,0 +1,23 @@
package mightypork.gamecore.gui.constraints;
import mightypork.utils.math.coord.Rect;
/**
* Interface for constraints that can be assigned context
*
* @author MightyPork
*/
public interface PluggableContext extends RectConstraint {
/**
* @param rect context to set
*/
abstract void setContext(RectConstraint rect);
@Override
abstract Rect getRect();
}
@@ -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());
}
}
@@ -0,0 +1,18 @@
package mightypork.gamecore.gui.constraints;
import mightypork.utils.math.coord.Rect;
/**
* Rect constraint (ie. region)
*
* @author MightyPork
*/
public interface RectConstraint {
/**
* @return rect region
*/
Rect getRect();
}
@@ -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;
+1 -22
View File
@@ -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()
+45 -45
View File
@@ -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;
}