use of pythagoras.f.Rectangle in project playn by threerings.
the class TextTest method init.
@Override
public void init() {
row = new Rectangle(5, 5, 0, 0);
addToRow((style = new NToggle<Style>("Style", Style.PLAIN, Style.BOLD, Style.ITALIC, Style.BOLD_ITALIC)).layer);
addToRow((draw = new NToggle<String>("Draw", "Fill", "Stroke")).layer);
addToRow((effect = new NToggle<String>("Effect", "None", "ShadowUL", "ShadowLR", "Outline")).layer);
addToRow((wrap = new NToggle<Integer>("Wrap", 0, 20, 50, 100)).layer);
addToRow((align = new NToggle<TextBlock.Align>("Align", TextBlock.Align.LEFT, TextBlock.Align.CENTER, TextBlock.Align.RIGHT)).layer);
addToRow((font = new NToggle<String>("Font", "Times New Roman", "Helvetica")).layer);
class SetText extends Pointer.Adapter implements Callback<String> {
final ImageLayer layer = graphics().createImageLayer(TestsGame.makeButtonImage("Set Text"));
{
layer.addListener(this);
}
@Override
public void onPointerEnd(Event event) {
keyboard().getText(TextType.DEFAULT, "Test text", sample.replace("\n", "\\n"), this);
}
public void onSuccess(String result) {
if (result == null)
return;
// parse \n to allow testing line breaks
sample = result.replace("\\n", "\n");
update();
}
public void onFailure(Throwable cause) {
}
}
addToRow(new SetText().layer);
addToRow((lineBounds = new Toggle("Lines")).layer);
// test laying out the empty string
TextLayout layout = graphics().layoutText("", new TextFormat());
ImageLayer empty = graphics().createImageLayer(makeLabel("Empty string size " + layout.width() + "x" + layout.height()));
newRow();
addToRow(empty);
newRow();
addToRow((text = graphics().createImageLayer(makeTextImage())));
}
use of pythagoras.f.Rectangle in project playn by threerings.
the class SurfaceTest method addTests.
protected void addTests(final Image orange, Image tile) {
final Pattern pattern = tile.toPattern();
// make samples big enough to force a buffer size increase
final int samples = 128, hsamples = samples / 2;
final float[] verts = new float[(samples + 1) * 4];
final int[] indices = new int[samples * 6];
tessellateCurve(0, 40 * (float) Math.PI, verts, indices, new F() {
public float apply(float x) {
return (float) Math.sin(x / 20) * 50;
}
});
float ygap = 20, ypos = 10;
// draw some wide lines
ypos = ygap + addTest(10, ypos, new ImmediateLayer.Renderer() {
public void render(Surface surf) {
drawLine(surf, 0, 0, 50, 50, 15);
drawLine(surf, 70, 50, 120, 0, 10);
drawLine(surf, 0, 70, 120, 120, 10);
}
}, 120, 120, "drawLine with width");
ypos = ygap + addTest(20, ypos, new ImmediateLayer.Renderer() {
public void render(Surface surf) {
surf.setFillColor(0xFF0000FF).fillRect(0, 0, 100, 25);
// these two alpha fills should look the same
surf.setFillColor(0x80FF0000).fillRect(0, 0, 50, 25);
surf.setAlpha(0.5f).setFillColor(0xFFFF0000).fillRect(50, 0, 50, 25).setAlpha(1f);
}
}, 100, 25, "left and right half both same color");
ypos = ygap + addTest(20, ypos, new ImmediateLayer.Renderer() {
public void render(Surface surf) {
surf.setFillColor(0xFF0000FF).fillRect(0, 0, 100, 50);
surf.setAlpha(0.5f);
surf.drawImage(orange, 55, 5);
surf.fillRect(0, 50, 50, 50);
surf.drawImage(orange, 55, 55);
surf.setAlpha(1f);
}
}, 100, 100, "fillRect and drawImage at 50% alpha");
ypos = 10;
ypos = ygap + addTest(160, ypos, new ImmediateLayer.Renderer() {
public void render(Surface surf) {
// fill some shapes with patterns
surf.setFillPattern(pattern).fillRect(10, 0, 100, 100);
// use same fill pattern for the triangles
surf.translate(0, 160);
// render a sliding window of half of our triangles to test the slice rendering
surf.fillTriangles(verts, offset * 4, (hsamples + 1) * 4, indices, offset * 6, hsamples * 6, offset * 2);
offset += doff;
if (offset == 0)
doff = 1;
else if (offset == hsamples)
doff = -1;
}
private int offset = 0, doff = 1;
}, 120, 210, "ImmediateLayer patterned fillRect, fillTriangles");
SurfaceImage patted = graphics().createSurface(100, 100);
patted.surface().setFillPattern(pattern).fillRect(0, 0, 100, 100);
ypos = ygap + addTest(170, ypos, graphics().createImageLayer(patted), "SurfaceImage patterned fillRect");
ypos = 10;
// fill a patterned quad in a clipped group layer
final int twidth = 150, theight = 75;
GroupLayer group = graphics().createGroupLayer();
ypos = ygap + addTest(315, 10, group, twidth, theight, "Clipped pattern should not exceed grey rectangle");
group.add(graphics().createImmediateLayer(new ImmediateLayer.Renderer() {
public void render(Surface surf) {
surf.setFillColor(0xFFCCCCCC).fillRect(0, 0, twidth, theight);
}
}));
group.add(graphics().createImmediateLayer(twidth, theight, new ImmediateLayer.Renderer() {
public void render(Surface surf) {
surf.setFillPattern(pattern).fillRect(-10, -10, twidth + 20, theight + 20);
}
}));
// draw some randomly jiggling dots inside a bounded region
dotBox = new Rectangle(315, ypos, 200, 100);
ypos = ygap + addTest(dotBox.x, dotBox.y, new ImmediateLayer.Renderer() {
public void render(Surface surf) {
surf.setFillColor(0xFFCCCCCC).fillRect(0, 0, dotBox.width, dotBox.height);
}
}, dotBox.width, dotBox.height, "Randomly positioned SurfaceImages");
for (int ii = 0; ii < 10; ii++) {
SurfaceImage dot = graphics().createSurface(10, 10);
dot.surface().setFillColor(0xFFFF0000);
dot.surface().fillRect(0, 0, 5, 5);
dot.surface().fillRect(5, 5, 5, 5);
dot.surface().setFillColor(0xFF0000FF);
dot.surface().fillRect(5, 0, 5, 5);
dot.surface().fillRect(0, 5, 5, 5);
ImageLayer dotl = graphics().createImageLayer(dot);
dotl.setTranslation(dotBox.x + random() * (dotBox.width - 10), dotBox.y + random() * (dotBox.height - 10));
dots.add(dotl);
// System.err.println("Created dot at " + dotl.transform());
graphics().rootLayer().add(dotl);
}
// add a surface layer that is updated on every call to paint (a bad practice, but one that
// should actually work)
paintUpped = graphics().createSurface(100, 100);
ypos = ygap + addTest(315, ypos, graphics().createImageLayer(paintUpped), "SurfaceImage updated in paint()");
}
Aggregations