Removed trash, improved constraint system (nicer names)
This commit is contained in:
@@ -52,7 +52,7 @@ public class ColumnHolder extends ElementHolder {
|
||||
{
|
||||
if (elem == null) return;
|
||||
|
||||
elem.setContext(_column(this, cols, col++));
|
||||
elem.setContext(cColumn(this, cols, col++));
|
||||
|
||||
attach(elem);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class RowHolder extends ElementHolder {
|
||||
{
|
||||
if (elem == null) return;
|
||||
|
||||
elem.setContext(_row(this, rows, row++));
|
||||
elem.setContext(cRow(this, rows, row++));
|
||||
|
||||
attach(elem);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,20 @@ public class QuadPainter extends PluggableRenderer {
|
||||
|
||||
|
||||
/**
|
||||
* Painter with cokloured vertices.
|
||||
* Painter with solid color
|
||||
*
|
||||
* @param color
|
||||
*/
|
||||
public QuadPainter(RGB color) {
|
||||
this.colorHMinVMin = color;
|
||||
this.colorHMaxVMin = color;
|
||||
this.colorHMaxVMax = color;
|
||||
this.colorHMinVMax = color;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Painter with coloured vertices.
|
||||
*
|
||||
* @param colorHMinVMin
|
||||
* @param colorHMaxVMin
|
||||
|
||||
@@ -30,7 +30,7 @@ public abstract class LayeredScreen extends Screen {
|
||||
protected void renderScreen()
|
||||
{
|
||||
for (final ScreenLayer layer : layers) {
|
||||
layer.render();
|
||||
if (layer.isVisible()) layer.render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
|
||||
if (!isActive()) return;
|
||||
|
||||
if (needSetupViewport) {
|
||||
Render.setupOrtho();
|
||||
Render.setupOrtho(getDisplay().getSize());
|
||||
}
|
||||
|
||||
Render.pushState();
|
||||
|
||||
@@ -9,6 +9,7 @@ import mightypork.gamecore.input.KeyBindingPool;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
|
||||
|
||||
@@ -21,8 +22,13 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
|
||||
|
||||
private final Screen screen;
|
||||
|
||||
private boolean visible = true;
|
||||
|
||||
private final KeyBindingPool keybindings = new KeyBindingPool();
|
||||
|
||||
protected final VecView cMousePos = getInput().getMousePos();
|
||||
protected final VecView cScreenSize = getDisplay().getSize();
|
||||
|
||||
|
||||
/**
|
||||
* @param screen parent screen
|
||||
@@ -65,6 +71,18 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
|
||||
}
|
||||
|
||||
|
||||
public boolean isVisible()
|
||||
{
|
||||
return visible;
|
||||
}
|
||||
|
||||
|
||||
public void setVisible(boolean visible)
|
||||
{
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final int compareTo(ScreenLayer o)
|
||||
{
|
||||
|
||||
@@ -7,10 +7,10 @@ import mightypork.gamecore.control.bus.events.KeyEvent;
|
||||
import mightypork.gamecore.control.bus.events.MouseButtonEvent;
|
||||
import mightypork.gamecore.control.bus.events.MouseMotionEvent;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.rogue.events.ActionRequest;
|
||||
import mightypork.rogue.events.ActionRequest.RequestType;
|
||||
import mightypork.utils.math.coord.MutableCoord;
|
||||
import mightypork.utils.math.coord.SynthCoord2D;
|
||||
import mightypork.utils.math.coord.VecMutable;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
|
||||
@@ -30,6 +30,26 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
// listeners
|
||||
private final KeyBindingPool keybindings;
|
||||
|
||||
private final VecView mousePos = new SynthCoord2D() {
|
||||
|
||||
@Override
|
||||
public double x()
|
||||
{
|
||||
if (!Mouse.isInsideWindow()) return Integer.MIN_VALUE;
|
||||
|
||||
return Mouse.getX();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double y()
|
||||
{
|
||||
if (!Mouse.isInsideWindow()) return Integer.MIN_VALUE;
|
||||
// flip Y axis
|
||||
return Display.getHeight() - Mouse.getY();
|
||||
}
|
||||
};
|
||||
|
||||
private static boolean inited = false;
|
||||
|
||||
|
||||
@@ -127,10 +147,9 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
|
||||
final int wheeld = Mouse.getEventDWheel();
|
||||
|
||||
if (DisplaySystem.yAxisDown) {
|
||||
flipScrY(pos);
|
||||
move.mul(1, -1, 1);
|
||||
}
|
||||
// flip Y axis
|
||||
pos.setY(Display.getHeight() - pos.y());
|
||||
move.mul(1, -1, 1);
|
||||
|
||||
if (button != -1 || wheeld != 0) {
|
||||
getEventBus().send(new MouseButtonEvent(pos.copy(), button, down, wheeld));
|
||||
@@ -151,22 +170,23 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
}
|
||||
|
||||
|
||||
private static void flipScrY(VecMutable c)
|
||||
{
|
||||
if (DisplaySystem.yAxisDown) c.setY(DisplaySystem.getHeight() - c.y());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get absolute mouse position
|
||||
*
|
||||
* @return mouse position
|
||||
*/
|
||||
public static VecView getMousePos()
|
||||
public VecView getMousePos()
|
||||
{
|
||||
final VecMutable pos = new MutableCoord(Mouse.getX(), Mouse.getY());
|
||||
flipScrY(pos);
|
||||
return pos.view();
|
||||
return mousePos;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return true if mouse is inside window.
|
||||
*/
|
||||
public boolean isMouseInside()
|
||||
{
|
||||
return Mouse.isInsideWindow();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
|
||||
import mightypork.gamecore.control.timing.FpsMeter;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.FixedCoord;
|
||||
import mightypork.utils.math.coord.SynthCoord2D;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.rect.FixedRect;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
@@ -31,10 +31,24 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
||||
|
||||
private DisplayMode windowDisplayMode;
|
||||
private int targetFps;
|
||||
/** Y axis goes down (not up); Used also to adjust inputs. */
|
||||
public static boolean yAxisDown = true;
|
||||
private FpsMeter fpsMeter;
|
||||
|
||||
private final VecView cScreenSize = new SynthCoord2D() {
|
||||
|
||||
@Override
|
||||
public double y()
|
||||
{
|
||||
return Display.getHeight();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double x()
|
||||
{
|
||||
return Display.getWidth();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param app app access
|
||||
@@ -175,27 +189,27 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
||||
*
|
||||
* @return size
|
||||
*/
|
||||
public static VecView getSize()
|
||||
public VecView getSize()
|
||||
{
|
||||
return new FixedCoord(getWidth(), getHeight());
|
||||
return cScreenSize;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return screen width
|
||||
*/
|
||||
public static int getWidth()
|
||||
public int getWidth()
|
||||
{
|
||||
return Display.getWidth();
|
||||
return cScreenSize.xi();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return screen height
|
||||
*/
|
||||
public static int getHeight()
|
||||
public int getHeight()
|
||||
{
|
||||
return Display.getHeight();
|
||||
return cScreenSize.yi();
|
||||
}
|
||||
|
||||
|
||||
@@ -245,43 +259,4 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
||||
{
|
||||
return getSize().half();
|
||||
}
|
||||
|
||||
// private static final VecView size = new SynthCoord2D() {
|
||||
//
|
||||
// @Override
|
||||
// public double y()
|
||||
// {
|
||||
// return getHeight();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public double x()
|
||||
// {
|
||||
// return getWidth();
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// /** Screen width constraint */
|
||||
// private static final NumberConstraint width = size.xc();
|
||||
//
|
||||
// /** Screen height constaint */
|
||||
// private static final NumberConstraint height = size.yc();
|
||||
//
|
||||
// private static final VecView center = new SynthCoord2D() {
|
||||
//
|
||||
// @Override
|
||||
// public double y()
|
||||
// {
|
||||
// return size.half().x();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public double x()
|
||||
// {
|
||||
// return size.half().y();
|
||||
// }
|
||||
// };
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.FixedCoord;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.rect.Rect;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -540,15 +541,15 @@ public class Render {
|
||||
|
||||
/**
|
||||
* Setup Ortho projection for 2D graphics
|
||||
* @param size viewport size (screen size)
|
||||
*/
|
||||
public static void setupOrtho()
|
||||
public static void setupOrtho(VecView size)
|
||||
{
|
||||
// fix projection for changed size
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
final Vec s = DisplaySystem.getSize();
|
||||
glViewport(0, 0, s.xi(), s.yi());
|
||||
glOrtho(0, s.x(), (DisplaySystem.yAxisDown ? 1 : -1) * s.y(), 0, -1000, 1000);
|
||||
glViewport(0, 0, size.xi(), size.yi());
|
||||
glOrtho(0, size.xi(), size.yi(), 0, -1000, 1000);
|
||||
|
||||
// back to modelview
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package mightypork.gamecore.render.fonts;
|
||||
|
||||
|
||||
import static mightypork.utils.math.constraints.Constraints.*;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
@@ -148,16 +147,16 @@ public class FontRenderer {
|
||||
|
||||
switch (align) {
|
||||
case LEFT:
|
||||
start = _top_left(bounds);
|
||||
start = bounds.getTopLeft();
|
||||
break;
|
||||
|
||||
case CENTER:
|
||||
start = _center_top(bounds);
|
||||
start = bounds.getTopCenter();
|
||||
break;
|
||||
|
||||
case RIGHT:
|
||||
default:
|
||||
start = _top_right(bounds);
|
||||
start = bounds.getTopRight();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user