Removed trash, improved constraint system (nicer names)
This commit is contained in:
@@ -56,7 +56,7 @@ public class App extends BaseApp {
|
||||
screens.add(new ScreenTestFont(this));
|
||||
screens.add(new ScreenTestRender(this));
|
||||
|
||||
screens.showScreen("test.cat");
|
||||
screens.showScreen("test.bouncy");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@ package mightypork.rogue.screens;
|
||||
|
||||
|
||||
import static mightypork.utils.math.constraints.Constraints.*;
|
||||
import mightypork.gamecore.gui.Action;
|
||||
import mightypork.gamecore.gui.components.painters.TextPainter;
|
||||
import mightypork.gamecore.gui.screens.Screen;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.gamecore.input.Keys;
|
||||
import mightypork.gamecore.render.fonts.FontRenderer.Align;
|
||||
import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.rogue.Res;
|
||||
@@ -22,20 +25,31 @@ public class LayerFps extends ScreenLayer {
|
||||
public LayerFps(Screen screen) {
|
||||
super(screen);
|
||||
|
||||
final StringProvider text = new StringProvider() {
|
||||
/*
|
||||
* Toggle key: F3
|
||||
*/
|
||||
bindKeyStroke(new KeyStroke(Keys.KEY_F3), new Action() {
|
||||
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
setVisible(!isVisible());
|
||||
}
|
||||
});
|
||||
|
||||
final GLFont font = Res.getFont("default");
|
||||
|
||||
final RectConstraint constraint = cBox(cAdd(cTopRight(this), -8, 8), 0, 32);
|
||||
|
||||
tp = new TextPainter(font, Align.RIGHT, RGB.WHITE, new StringProvider() {
|
||||
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
return getDisplay().getFps() + " fps";
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
final GLFont font = Res.getFont("default");
|
||||
|
||||
final RectConstraint constraint = _box(_sub(_top_right(this), 8, 8), 0, 32);
|
||||
|
||||
tp = new TextPainter(font, Align.RIGHT, RGB.WHITE, text);
|
||||
tp.setContext(constraint);
|
||||
|
||||
tp.setShadow(RGB.BLACK, Vec.ONE);
|
||||
|
||||
@@ -26,16 +26,16 @@ public class BouncyBox extends PluggableRenderer implements Updateable {
|
||||
|
||||
public BouncyBox() {
|
||||
// create box
|
||||
final NumberConstraint side = _height(this);
|
||||
RectConstraint abox = _box(this, side, side);
|
||||
final NumberConstraint side = cHeight(this);
|
||||
RectConstraint abox = cBox(this, side, side);
|
||||
|
||||
// move
|
||||
final NumberConstraint move_length = _sub(_width(this), side);
|
||||
final NumberConstraint offset = _mul(move_length, pos);
|
||||
abox = _move(abox, offset, 0);
|
||||
final NumberConstraint move_length = cSub(cWidth(this), side);
|
||||
final NumberConstraint offset = cMul(move_length, pos);
|
||||
abox = cMove(abox, offset, 0);
|
||||
|
||||
// add padding
|
||||
abox = _shrink(abox, _percent(side, 10));
|
||||
abox = cShrink(abox, cPerc(side, 10));
|
||||
|
||||
box = abox;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ 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;
|
||||
import mightypork.utils.math.coord.FixedCoord;
|
||||
|
||||
|
||||
public class LayerBouncyBoxes extends ScreenLayer {
|
||||
@@ -47,7 +47,7 @@ public class LayerBouncyBoxes extends ScreenLayer {
|
||||
});
|
||||
|
||||
// shrink screen rect by 8% on all sides
|
||||
final RectConstraint holder_rect = _shrink(this, _percent(_height(this), 4));
|
||||
final RectConstraint holder_rect = cShrink(this, cPerc(cWidth(this), 4));
|
||||
|
||||
addChildClient(layout = new RowHolder(screen, holder_rect, 11));
|
||||
|
||||
@@ -57,14 +57,11 @@ public class LayerBouncyBoxes extends ScreenLayer {
|
||||
boxes.add(bbr);
|
||||
}
|
||||
|
||||
layout.add(new TextPainter(Res.getFont("default"), Align.LEFT, RGB.WHITE, new StringProvider() {
|
||||
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
return "Running at " + getDisplay().getFps() + " fps!";
|
||||
}
|
||||
}));
|
||||
final TextPainter tp = new TextPainter(Res.getFont("default"), Align.LEFT, RGB.WHITE);
|
||||
tp.setText("Press \"C\" for \"Cat\" screen.");
|
||||
tp.setShadow(RGB.RED, new FixedCoord(2, 2));
|
||||
|
||||
layout.add(tp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.Random;
|
||||
import mightypork.gamecore.control.bus.events.MouseButtonEvent;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.gamecore.gui.components.painters.ImagePainter;
|
||||
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
||||
import mightypork.gamecore.gui.components.painters.TextPainter;
|
||||
import mightypork.gamecore.gui.screens.Screen;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
@@ -32,6 +33,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
||||
|
||||
private final ImagePainter cat;
|
||||
private final TextPainter tp;
|
||||
private final QuadPainter qp;
|
||||
|
||||
|
||||
public LayerFlyingCat(Screen screen) {
|
||||
@@ -41,14 +43,18 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
||||
|
||||
cat = new ImagePainter(Res.getTxQuad("test.kitten"));
|
||||
|
||||
cat.setContext(_align(_box(size, size), pos));
|
||||
cat.setContext(cCenterTo(cBox(size, size), pos));
|
||||
|
||||
tp = new TextPainter(Res.getFont("default"));
|
||||
tp.setAlign(Align.CENTER);
|
||||
tp.setColor(RGB.YELLOW);
|
||||
tp.setText("Meow!");
|
||||
tp.setShadow(RGB.dark(0.8), new FixedCoord(2, 2));
|
||||
tp.setContext(_align(_box(64, 64), _mouseX, _mouseY));
|
||||
|
||||
tp.setContext(cCenterTo(cBox(64, 64), cMousePos));
|
||||
|
||||
qp = QuadPainter.gradV(RGB.YELLOW, RGB.RED);
|
||||
qp.setContext(cExpand(cBottomLeft(cat), 0, 0, 50, 50));
|
||||
|
||||
/*
|
||||
* Register keys
|
||||
@@ -79,9 +85,9 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
||||
|
||||
final Vec pos = event.getPos();
|
||||
|
||||
this.pos.animateWithSpeed(pos, 200);
|
||||
this.pos.animateWithSpeed(pos, 160);
|
||||
|
||||
size.animate(200 + rand.nextInt(600), this.pos.getDuration() / 2);
|
||||
size.animate(200 + rand.nextInt(600), Math.max(0.2, this.pos.getDuration() / 2));
|
||||
}
|
||||
|
||||
|
||||
@@ -90,8 +96,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
||||
{
|
||||
cat.render();
|
||||
tp.render();
|
||||
|
||||
//System.out.println(tp.getRect());
|
||||
qp.render();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ 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.NumberConstraint;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
|
||||
|
||||
@@ -22,7 +23,9 @@ public class ScreenTestFont extends Screen {
|
||||
tp = new TextPainter(Res.getFont("default"), Align.CENTER, RGB.GREEN);
|
||||
tp.setText("Hello World!");
|
||||
|
||||
final RectConstraint strbox = _align(_box(_div(_screenH, 10)), this);
|
||||
final NumberConstraint fontHeight = cMul(getDisplay().getSize().yc(), 0.1);
|
||||
|
||||
final RectConstraint strbox = cCenterTo(cBox(fontHeight), this);
|
||||
|
||||
tp.setContext(strbox);
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ public class LayerTestGradient extends ScreenLayer {
|
||||
public LayerTestGradient(Screen screen) {
|
||||
super(screen);
|
||||
|
||||
pos1 = _cache(p, _grow_down(_top_edge(this), 64));
|
||||
pos2 = _cache(p, _shrink_top(_grow_right(_left_edge(this), 64), 64));
|
||||
pos1 = cCached(p, cGrowDown(cTopEdge(this), 64));
|
||||
pos2 = cCached(p, cShrinkTop(cGrowRight(cLeftEdge(this), 64), 64));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user