[ControlP5] ControlWindow and ControlP5frame

Using Processing 2.x I would like to have back ControlWindow to move all controls in an external frame.

I wrote for Processing 1.x a simplified GUI based on ControlP5 where for a few controllers I frequently use I don't need to calculate positions or remember strange properties: i.e. ctrlAddButton("function", "label") adds a button finding a place for it, changing font and colors, etc. My code takes care to position each control without overlappings. Not nice but it is extremely fast to add controls as necessary. Using ControlWindow controls are created in main setup() and moveTo() the external frame.

Now ControlWindow is no more available and the controls in the main frame partially hide the image I am working with. I saw the workaround in ControlP5frame's example to create an external frame for controls but the solution is... "dirt".

Is there the possibility to add a control with a call from the main setup() and link it to ControlFrame, instead of putting all calls inside ControlFrame's class setup()?

Alex

Answers

  • Could you explain why is the solution "dirt"?

  • edited October 2014

    Ankhelos, For the sake of simplicity I would like to rewrap ControlP5.

    To put controls on a separate frame I need to extend PApplet (public class ControlFrame extends PApplet {..) with controls created INSIDE. But I need to add them dynamically when necessary.

    I would prefer to define ControlFrame WITHOUT controls creation inside, and add controls dynamically from setup() after ControlFrame has already been created. Alas I couldn't find the syntax to do it (if it is possible in Processing/Java).

    At the moment I can create a set of controls from setup() with some easy calls, but controls are on the main frame, not on the separate one:

    void setup() {
      ctrlInit();  // creates the GUI interface
      ctrlAddSlider("variable1ToControl", "label1", minValue, maxValue);
      ctrlAddSlider("variable2ToControl", "label2", minValue, maxValue);
     ...
    
  • edited November 2014 Answer ✓

    It's not that hard to instantiate more than 1 PApplet. I've got a template which simply does that: :-bd

    http://forum.processing.org/two/discussion/6822/mousepressed-from-another-frame
    http://forum.processing.org/two/discussion/7036/multiple-screens

    static final void main(final String[] args) {
      final String sketch = Thread.currentThread()
        .getStackTrace()[1].getClassName();
    
      final Class[] nested;
      try {
        nested = Class.forName(sketch).getClasses();
      }
      catch (final ClassNotFoundException cause) {
        throw new RuntimeException(cause);
      }
    
      println(nested);
      for (int i = 0, ii = max(0, nested.length-2); i != ii; ++i)
      try {
        main(nested[i].getName(), args);
      }
      catch (final Exception cause) {
        println(nested[i] + " isn't a PApplet or isn't public static!");
      }
    }
    

    It's an ugly boilerplate indeed. But we can place it in another tab, far away from our eyes! :-\"
    Now we can have as many PApplet classes as we want to. They behave as separate sketches: <:-P

    public static final class MyApp extends PApplet {
      void setup() {
        size(300, 200, JAVA2D);
        noLoop();
        println("OK!");
      }
    
      void draw() {
        background(-1);
      }
    }
    
    public static final class MyFrame extends PApplet {
      void setup() {
        noLoop();
        println("Frame!");
      }
    
      void draw() {
        background(0);
      }
    }
    
  • Thank you GoToLoop! It is not as clean as ControlWindow but I will give it a try. Alex

  • Just a note: sketchPath() read from MyApp or MyFrame returns the path of Processing.exe, not the real sketch path...

  • edited November 2014

    Oh, it seems like Processing's IDE somehow fails to send sketchPath, or flat out refuses to, when we provide our own override for Processing's default template of main(): :-w

    static public void main(String[] passedArgs) {
      String[] appletArgs = new String[] { "MySketch" };
      if (passedArgs != null) {
        PApplet.main(concat(appletArgs, passedArgs));
      } else {
        PApplet.main(appletArgs);
      }
    }
    

    Only fix I've found out so far is exporting such sketch w/ CTRL+E and run it outside Processing's IDE. :-\"

    BtW, here's another slightly variation for multi-PApplet instantiation.
    Besides instantiating subclasses, do that for the main sketch as well: \m/

    http://forum.processing.org/two/discussion/7519/how-to-change-background-color-of-present-mode-and-remove-graphical-stop-option

    static final void main(final String[] args) {
      final String sketch = Thread.currentThread()
        .getStackTrace()[1].getClassName();
    
      main(sketch, args);
    
      final Class[] nested;
      try {
        nested = Class.forName(sketch).getClasses();
      }
      catch (final ClassNotFoundException cause) {
        throw new RuntimeException(cause);
      }
    
      println(nested);
      println();
    
      for (int i = 0, ii = max(0, nested.length-2); i != ii; ++i)
      try {
        main(nested[i].getName(), args);
      }
      catch (final Exception cause) {
        println(nested[i] + " isn't a PApplet or isn't public static!");
      }
    }
    
    void setup() {
      size(600, 400, P2D);
      smooth(8);
      noLoop();
      background((color) random(#000000));
    
      println( "\n" + isGL() + "\n" );
    
      println( javaVersionName );
      println( System.getProperty("java.home")  + "\n" );
    
      println( System.getProperty("os.arch") );
      println( System.getProperty("os.name") );
      println( System.getProperty("os.version") + "\n" );
    
      println( System.getProperty("user.home") );
      println( System.getProperty("user.dir")   + "\n" );
    
      println( sketchPath );
      println( dataPath("") );
      println( dataFile("") );
    
      println("\n===[ General Info ]===\n");
      println("OPENGL_VENDOR: " + PGraphicsOpenGL.OPENGL_VENDOR);
      println("OPENGL_RENDERER: " + PGraphicsOpenGL.OPENGL_RENDERER);
      println("OPENGL_VERSION: " + PGraphicsOpenGL.OPENGL_VERSION);
      println("GLSL_VERSION: " + PGraphicsOpenGL.GLSL_VERSION);
    
      println("\n===[ Supported Features ]===\n");
      println("anisoSamplingSupported: " + PGraphicsOpenGL.anisoSamplingSupported);
      println("autoMipmapGenSupported: " + PGraphicsOpenGL.autoMipmapGenSupported);
      println("blendEqSupported: " + PGraphicsOpenGL.blendEqSupported);
      println("fboMultisampleSupported: " + PGraphicsOpenGL.fboMultisampleSupported);
      println("npotTexSupported: " + PGraphicsOpenGL.npotTexSupported);
      println("packedDepthStencilSupported: " + PGraphicsOpenGL.packedDepthStencilSupported);
      println("maxSamples: " + PGraphicsOpenGL.maxSamples);
      println("maxTextureSize: " + PGraphicsOpenGL.maxTextureSize + "\n");
    }
    
    public static final class MyFrame extends PApplet {
      void setup() {
        noLoop();
        println("MyFrame");
      }
    
      void draw() {
        background(0);
      }
    }
    
    public static final class MyApp extends PApplet {
      void setup() {
        size(300, 200, JAVA2D);
        noLoop();
        println("MyApp");
      }
    
      void draw() {
        background(-1);
      }
    }
    
  • Thank you GoToLoop. Lot to learn from your posts, as usual. Alex

Sign In or Register to comment.