Tripleplay Debug Mode..?

33 views
Skip to first unread message

karsten...@gmail.com

unread,
Jun 23, 2017, 10:18:44 AM6/23/17
to PlayN
Hello,

Tripleplay seems extremely optimized and that's great if you know it inside out. However for the beginner it seems very painful to layout or style the UI exactly to your imagination. It truly rivals what is going on in the browser ;)

I wonder if there is some debug mode where 1px borders are drawn around all Groups and Elements, so one can at least guess at what is going on.

Cheers,
Karsten

Dieter

unread,
Jun 27, 2017, 7:41:00 AM6/27/17
to PlayN, karsten...@gmail.com
You could modify playn.scene.Layer to draw a rectangle around all Layers if DEBUG is set to true (default is false):

  public final void paint (Surface surf) {
    if (!visible()) return;

    int otint = surf.combineTint(tint);
    QuadBatch obatch = surf.pushBatch(batch);
    surf.concatenate(transform(), originX(), originY());
    try {
      paintImpl(surf);
      if (DEBUG) drawRect(surf);
    } finally {
      surf.popBatch(obatch);
      surf.setTint(otint);
    }
  }

  final static int[] fillcols = {
 0xFFFFFFFF, // white
 0xFF8B00FF, // violet
 0xFF4B0082, // indigo
 0xFFFF7F00, // orange
 0xFFFF0000, // red
 0xFFFFFF00, // yellow
 0xFF00FF00, // green
 0xFFFF00FF, // magenta
 0xFF00FFFF, // aqua
 0xFF0000FF, // blue
  };
  int nestcount = -1;
protected void drawRect(Surface surf) {
if (nestcount == -1) {
nestcount = 0;
GroupLayer p = parent();
while (p != null) {
nestcount++;
p = p.parent();
}
}
int col = nestcount >= fillcols.length ? 0xFF000000 : fillcols[nestcount];
surf.setFillColor(col);
float x = 0, y = 0, w = this.width(), h = this.height();
int width = 2;
surf.drawLine(x,   y,   x+w, y,   width);
surf.drawLine(x+w, y,   x+w, y+h, width);
surf.drawLine(x+w, y+h, x,   y+h, width);
surf.drawLine(x,   y+h, x,   y,   width);
}

clone both the playn and tripleplay repositories, make those changes and install both 2.1-SNAPSHOT releases in your local repo and use the updated snapshot in your project.

I know this is crude but pretty straightforward and only takes a few minutes to do.


lg...Dieter

karsten...@gmail.com

unread,
Jun 29, 2017, 8:37:35 PM6/29/17
to PlayN, karsten...@gmail.com
Thanks! Perfect :D


On Friday, June 23, 2017 at 4:18:44 PM UTC+2, karsten...@gmail.com wrote:

johnann...@googlemail.com

unread,
Aug 4, 2017, 4:35:08 PM8/4/17
to PlayN, karsten...@gmail.com
Could you add this debug mode to PlayN and/or Tripleplay? Maybe even a way to turn it on/off (keyboard shortcut) during running a game or UI ?

Dieter

unread,
Aug 5, 2017, 1:18:15 PM8/5/17
to PlayN, karsten...@gmail.com, johnann...@googlemail.com
I think the person to ask would be Michael. No complaints to add it from my end. Maybe polish it a bit and make it more user friendly.

Michael Bayne

unread,
Sep 24, 2017, 4:09:25 PM9/24/17
to pl...@googlegroups.com, karsten...@gmail.com, johnann...@googlemail.com
I went ahead and added this. Thanks for the code Dieter!

Inline image 1

I changed the color orders to ROYGBIV (with magenta and cyan tacked onto the end) so you can work out in your head the layer depth based on the color. This is how the PlayN test app wires it up to the 'd' key:

    input.keyboardEvents.connect(new Keyboard.KeySlot() {

      public void onEmit (Keyboard.KeyEvent event) {

        switch (event.key) {

        case ESCAPE:

          if (event.down) displayMenu();

          break;

        case D:

          Layer.DEBUG_RECTS = event.down;

          if (event.down && event.isShiftDown()) {

            rootLayer.debugPrint(log);

          }

          break;

        }

      }

    });


The TP demo app uses a fancier Java 1.8 approach:

        // show debug rectangles when D key is pressed; dump scene graph on shift-D

        plat.input().keyboardEvents.collect(Keyboard.isKey(Key.D)).connect(event -> {

            Layer.DEBUG_RECTS = event.down;

            if (event.down && event.isShiftDown()) {

              rootLayer.debugPrint(plat.log());

            }

        });


I also shipped a 2.0.1 release of PlayN & TP:

--

---
You received this message because you are subscribed to the Google Groups "PlayN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to playn+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages