We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Pages: 1 ... 14 15 16 17 
controlP5 (Read 126742 times)
Re: controlP5
Reply #225 - Apr 21st, 2010, 7:18pm
 
Hello everybody,
I am currently doing my senior project for my CS bachelors degree and i am using processing and  controlP5. The application is going to have multiple screens and i want to divide the screens up into classes for cleaner and more maintainable code.
Is there a way to make classes that have ControlP5 controls in them?
I tried making and initialization constructor for the screen but keep getting null pointer errors. Here is what i tried for a class.
Any help is appreciated.

Code:
import controlP5.*;

class createAlbumScreen
{
 ControlP5 controlP52 = new ControlP5(this);
 private controlP5.Button createAlbumButton;
 private controlP5.Button addImageToAblumButton;
 private controlP5.Button saveAlbumButton;


createAlbumScreen() {
 controlP52 = new ControlP5(this);
 createAlbumButton = controlP52.addButton("CreateAlbum",0,400,175,300,100);
 addImageToAblumButton = controlP5.addButton("AddImageToAlbum",0,350,600,200,75);
 saveAlbumButton = controlP5.addButton("SaveAlbum",0,100,600,200,75);

}

void settingVisibility(controlP5.Controller temp)
{
 if(temp.isVisible())
 {
   temp.setVisible(false);
 }
 else
 {
   temp.setVisible(true);
 }
}

void showScreen() {
 
 settingVisibility(createAlbumButton);
 settingVisibility(addImageToAblumButton);
 settingVisibility(saveAlbumButton);
 
}

void hideScreen(){
 
 settingVisibility(createAlbumButton);
 settingVisibility(addImageToAblumButton);
 settingVisibility(saveAlbumButton);
 
}



}//end class
Re: controlP5
Reply #226 - Apr 24th, 2010, 11:01am
 
I tried changing the font, but the text in textfields gets cropped oddly. The example in the picture should read "P1"

Code:
ControlFont fonT = new ControlFont(createFont("Arial",20),10);
controlP5.setControlFont(fonT);


...

Any ideas?  Sad
Re: controlP5
Reply #227 - Apr 25th, 2010, 9:51am
 
@Andrew
yep thats a bug. i will take a look.

@Travis_W
controlP5's constructor can only be initiated with a  reference to your sketch/PApplet, custom classes are not allowed. instead of using multiple instances of controlP5, why not declaring one global instance of controlP5 and use it within your other classes. controllers can be arranged in groups, so each custom class could have its own group of controllers which are turned on/off whenever you need/dont need them?

@Dimitre
thats right, listboxes can't be saved/loaded yet, sorry.

@rosa
taken from the ControlP5radioButton example with adjustments:
Code:

import controlP5.*;

ControlP5 controlP5;

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

RadioButton r;
void setup() {
 size(400,400);
 smooth();
 controlP5 = new ControlP5(this);
 r = controlP5.addRadioButton("radioButton",20,160);
 r.setColorForeground(color(120));
 r.setColorActive(color(255));
 r.setColorLabel(color(255));
 r.setItemsPerRow(5);
 r.setSpacingColumn(50);

 addToRadioButton(r,"red",1, color(255,0,0));
 addToRadioButton(r,"green",2, color(0,255,0));
 addToRadioButton(r,"blue",3, color(0,0,255));
}


void addToRadioButton(RadioButton theRadioButton, String theName, int theValue, int theColor ) {
 Toggle t = theRadioButton.addItem(theName,theValue);
 t.setColorBackground(theColor);
 t.captionLabel().setColorBackground(color(80));
 t.captionLabel().style().movePadding(2,0,-1,2);
 t.captionLabel().style().moveMargin(-2,0,0,-3);
 t.captionLabel().style().backgroundWidth = 46;
}


void draw() {
 background(myColorBackground);
}

Re: controlP5
Reply #228 - Apr 28th, 2010, 5:59am
 
Thanks for the reply! That's much easier than what I had done to make it work.

My last questions with the library are coming up. I thank you for all of the time you've taken to answer my questions.

In my Scroll list I have added multiple buttons. Just like the example in the library for scrolllist, an outline exists around each button. How can I modify the color of it? I would not like you to be able to tell that multiple buttons exist in this scroll  on first view.

Lastly, I have attempted to use captionLabel().toUpperCase(false); to make my font lowercase for the radio buttons. Is this correct? It doesn't appear to be working.

Thank you!

Rosa
Re: controlP5
Reply #229 - Apr 28th, 2010, 11:22am
 
You already answered my second question right above! So only my first question still exists Smiley
Re: controlP5
Reply #230 - May 1st, 2010, 3:42pm
 
Hi sojamo!

I'm stuck with internal variables.
I create controller for variable defined in internal class. After update ControlP5 searches it in global PApplet context. Is it a way to fix this?

Example sketch
Code:

package a3;

import processing.core.PApplet;
import controlP5.ControlEvent;
import controlP5.ControlListener;
import controlP5.ControlP5;
import controlP5.ControlWindow;

public class Controls extends PApplet {
ControlP5 cp5;
ControlWindow cp5w;
Test t;
int tt;

public void setup() {
cp5 = new ControlP5(this);
cp5w = cp5.addControlWindow("Asyan",100,100,400,500);

cp5.addSlider("max", 0, 100, 20, 100, 200, 12).setTab(cp5w,"default");
cp5.addSlider("max", 0, 100, 20, 140, 200, 12).setTab(cp5w,"sketch");

t = new Test();
}

public void draw() {
t.draw();
println("external "+tt);
}


public class Test {

int tt = 0;

public Test()
{
cp5.addSlider("tt", 0, 100, 20, 180, 200, 12).setTab(cp5w,"global");
}

public void draw() {
println("internal "+tt);
}

}

}
Re: controlP5
Reply #231 - May 3rd, 2010, 3:36am
 
controlP5 will only find variables inside your main sketch, here the class that extends PApplet. therefore, your variable tt inside class Test will not be change when making changes to the slider. you can use controlEvent though to forward the change in value to your subclass.

Code:

public void controlEvent(ControlEvent theEvent) {
 if(theEvent.name().matches("tt")) {
   t.tt = (int)theEvent.value();
 }
}


best,andreas
Re: controlP5
Reply #232 - May 3rd, 2010, 12:43pm
 
Thanks. But i try to do some kind of automation.
I have some internal classes that draw different pictures.
I would like to have setupGUI method in each class. This method will create his own Tab with control elements in same control window.
I would like to programm all GUI for internal class in his method, and write nothing about it in main PApplet.
Re: controlP5
Reply #233 - May 3rd, 2010, 7:26pm
 
Hey I want to know if there is any way I can use the slider as a progress bar?  I want it to act as the duration for an mp3 I'm playing through Ess.

Thanks in advance =]
Re: controlP5
Reply #234 - May 10th, 2010, 12:02am
 
I've managed to get around my previous problem (sort of) by setting the control font of each text fields individually

Also I've noticed that for some reason toUpperCase(false) has no effect. Either before or after setting the label value (also talking about the text fields)
Re: controlP5
Reply #235 - May 11th, 2010, 3:04am
 
Hello,

how can I add a ControlListener to an ControlGroup?
I add a class (MenueControlListener), but if I add the controlListener in the method "erstelleControlGroup" I get an NullPointerException. Which name must I choose to add the Listener?
Please look at my sourceCode:

Code:
class ProcessingGUI{
 MenueControlListener menueListener;
 ControlGroup ctrlEinstellungen, ctrlDatei;

 //Construct
 public ProcessingGUI() {
   menueListener = new MenueControlListener();
   ctrlDatei = this.erstelleControlGroup(ctrlDatei, "Datei", 0, 35);
   ctrlEinstellungen =
     this.erstelleControlGroup(ctrlEinstellungen,
                      "Einstellungen", 40, 60);  
 }

 private ControlGroup erstelleControlGroup(ControlGroup ctrl, String nameLabel, int linkePosition, int breite){
     ctrl = controlP5.addGroup(nameLabel,linkePosition,top,breite);
     ctrl.captionLabel().toUpperCase(false);
     ctrl.setColorLabel(color(255));
     ctrl.close();
   try{
     //nameLabel is the wrong name.
     //I also choose "ctrl.toString()", but it doesn't work
     ctrl.controller(nameLabel).addListener(menueListener);
   } catch (Exception e) {
     System.out.println(e);
     System.out.println("Error erstelleControlGroup");
     //Output:
     //NullPointerException
   }
   return ctrl;
 }
}


class MenueControlListener implements ControlListener {
 public void controlEvent(ControlEvent theEvent) {
  //TODO
 }
}
Re: controlP5
Reply #236 - May 11th, 2010, 9:35am
 
Hi am new to processing, i am not able to run the controlP5 examples, i installed controlP5 but it says
( Note that release 1.0, libraries must be installed in a folder named 'libraries' inside the 'sketchbook' folder.)
Thank You.
Re: controlP5
Reply #237 - May 11th, 2010, 9:40am
 
Another doubt, is there a way of marking the selected item on a listbox by color?
I've noticed setColorValue property colorizes the collapsing plus/minus sign, setColorActive is equivalent to "mouseover".
I would like to use color to indicate actual selected value
thank you
Re: controlP5
Reply #238 - May 13th, 2010, 5:30am
 
hello,
...and thanks sojamo for this great library!

i need to hide some toggle but keeping it active, so I try setting all the toggle color (backgroung, foreground, active) with alpha channel at 0 but has no effect.

here is the code i've used:

controlP5.addToggle("toggle", false, 10 , 10, 50, 50);
controlP5.controller("toggle").setColorBackground(color(0,0,0,0));
controlP5.controller("toggle").setColorForeground(colo(0,0,0,0));        
controlP5.controller("toggle").setColorActive(color(0,0,0,0));

sorry for my terrible english, i hope you can help me!
thanks a lot!
manuel
Re: controlP5
Reply #239 - May 16th, 2010, 2:29am
 
Hello,

i've got a problem with the controlWindow. Using controlP5 in my main-class, everything is working great.
Now I want to open a new Window, where a graph should be appear. The functions to plot the graph are stored in a seperate class, wich use only processing-functions like stroke() ,fill(), etc. .

So i make a new instance of my Graph-Class, passing the controlP5 by the constructor and there, i want to open a new ControlWindow.
I've got following error:  java.lang.reflect.InvocationTargetException.

My Code:

import processing.core.*;
import java.util.Vector;
import java.util.Random;
import controlP5.*;


public class MainClass extends PApplet{
     
     private static final long serialVersionUID = 1L;
     DataGraph graph;
     
     //GUI-Components
     ControlP5 controlP5;      
     
     //Words for Computation
     int word1, word2;
     
     //Main-Class
     public static void main(String args[]) {
           
         PApplet.main(new String[] { "--present", "MainClass" });
     }
     
     //Init the Main-Window
     public void setup(){
           
           size(800,640,JAVA2D);
           background(200,200,100);
           
           controlP5 = new ControlP5(this);
               graph = new DataGraph(controlP5,drawDataGraph(1,2));
      }
      .
      .
      .
}


import processing.core.PApplet;
import controlP5.*;

public class DataGraph{
     
     private static final long serialVersionUID = 1L;
     PApplet parent;
     float[] pfad;

     
     DataGraph(ControlP5 control,float[] pfad){
           
           ControlWindow window  =  control.addControlWindow("Neu", 100, 100);

              parent = window.papplet();      
              ...
            parent.fill();
              ...
     }


Hope you can help me.
Thanks!

Tweek
Pages: 1 ... 14 15 16 17