Loading...
Logo
Processing Forum
Dear all,

I've been using ControlP5 for quite a long while now and while it very well does what it says on the can for smallish sketches, it's not so easy/comfortable to deal with in somewhat larger situations. So I finally took the plunge to help me and potentially others writing MUCH less code in the future and actually have the GUI generating itself simply from chosen variables in your code. And here it doesn't really matter if these variables are all stuffed within your main PApplet instance or kept in other classes. The entire GUI generation can be reduced down to 2 lines of setup code and the system is totally customizable and heavily relies on Java annotations to pull off its "magic". And due to the type mapping & builder patterns used you're not restricted to just represent primitive variable types anymore as GUI controllers, but can create custom controller mappings for your own custom types...

I was so very excited to hear that Processing 1.2 would finally support the much nicer Java 5 syntax, alas it seems that annotations have been left out in the cold and are brutally stripped from any code written in the PDE... :( Why, oh why?

So very unfortunately, this library is only useful for those who've ventured outside the PDE sandbox (e.g. using Eclipse or any other fully Java compliant environment).

I've put up the entire project, exported JAR, fairly detailed documentation and usage examples over here:

To see some actual code example using this system, look here:

I might develop this further if the need arises, but here's to hoping this at least shows that annotations can actually be super useful also to Processing heads and that this triggers some further discussion about library design patterns, full language support etc...

Replies(2)

oh wow, this is indeed magic. i have to browse through that code now ... (keen to explore possibilities regarding library design patterns, +1 for annotation support in PDE)
 

andreas schlegel, http://www.sojamo.de
this is very marvellous,
There's just one thing i haven't figured out yet, and that's how to draw the controllers in their own control window. This is especially usefull when working on 3D projects, as it makes the controls impossible to access (unless i'm doing something wrong here).

It used to be simple and possible in controlP5 by making a controller group as per this bundle example:

Copy code
  1. /**
  2.  * ControlP5 ControlWindow
  3.  * by andreas schlegel, 2009
  4.  */

  5. import controlP5.*;

  6. ControlP5 controlP5;

  7. int myColorBackground = color(0,0,0);

  8. ControlWindow controlWindow;

  9. public int sliderValue = 40;

  10. void setup() {
  11.   size(400,400);  
  12.   frameRate(25);
  13.   controlP5 = new ControlP5(this);
  14.   controlP5.setAutoDraw(false);
  15.   controlWindow = controlP5.addControlWindow("controlP5window",100,100,400,200);
  16.   controlWindow.hideCoordinates();
  17.   
  18.   controlWindow.setBackground(color(40));
  19.   Controller mySlider = controlP5.addSlider("sliderValue",0,255,40,40,100,10);
  20.   mySlider.setWindow(controlWindow);
  21.   Textfield field = controlP5.addTextfield("myWindowTextfield",70,130,100,20);
  22.   field.setWindow(controlWindow);

  23.   controlP5.addSlider("sliderValue1",0,255,40,40,100,10);
  24.   controlP5.addTextfield("myTextfield",70,130,40,20);
  25.   controlWindow.setTitle("abc");
  26.   
  27. }

  28. void draw() {
  29.   background(sliderValue);
  30.   controlP5.draw();
  31. }

  32. void myTextfield(String theValue) {
  33.   println(theValue);
  34. }

  35. void myWindowTextfield(String theValue) {
  36.   println("from controlWindow: "+theValue);
  37. }

  38. void keyPressed() {
  39.   if(key==',') controlP5.window("controlP5window").hide();
  40.   if(key=='.') controlP5.window("controlP5window").show();
  41.   // controlWindow = controlP5.addControlWindow("controlP5window2",600,100,400,200);
  42.   // controlP5.controller("sliderValue1").moveTo(controlWindow);
  43.   
  44.   // since version 0.5.0, a controlWindow can be set undecorated.
  45.   if(key=='d') {
  46.     if(controlWindow.isUndecorated()) {
  47.       controlWindow.setUndecorated(false);
  48.     } else {
  49.       controlWindow.setUndecorated(true);
  50.     }
  51.   }
  52.   if(key=='t') {
  53.     controlWindow.toggleUndecorated();
  54.   }
  55. }
would be really great if it was possible with cp5magic. And i must say i hope it is :)