Greatly improved Constraints system
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user