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.
Page Index Toggle Pages: 1
controlP5 problems (Read 4125 times)
controlP5 problems
Jan 13th, 2008, 3:49pm
 
hi andreas,

some isses we (mostly my students) ran into using (your much appreciated and often used) controlP5 library:

- updating the value of a textfield (setValue()) does not update the text that's been rendered in the field (value seems to get set though, try to type something in)

- removing items from a scroll list does not update internal item counter (i.e. addItem() / removeItem() will show the scroll bar to the right after a couple of calls although the list only is one item long)

- controlEvent() callback passes the clicked Button for an item of a scroll list. since there's no way to access it's parent (not public) one can't tell if event.controller() was a scroll list item button or a normal button (we needed to know where the clicked item came from)

- adding many (2000+) items to a scroll list takes forever

- controlEvents seem to get fired while others still are running. one student manipulates a scroll list inside controlEvent which seems to fire a second controlEvent for the vertical scroll bar being updated .. not sure this is wanted.

many thanks, i hope this is the right place for you to have issues reported to ...

best
F

Re: controlP5 problems
Reply #1 - Jan 14th, 2008, 10:36am
 
hi florian,
so i made some changes, version 0.2.7, ready for download.

(1) update of textfield.setValue(String) works now.
(2) removing, adding items show/hide scrollbar works now. (check with example below)
(3) parent() is public now, see example below.
(4) there is a conceptual error in how the scrollList is designed so a lot of scrollList items take a long time to load since for each item a button is created, but actually only as many buttons as are visible should be created. this might take a few more days to be fixed.

Quote:
- controlEvents seem to get fired while others still are running. one student manipulates a scroll list inside controlEvent which seems to fire a second controlEvent for the vertical scroll bar being updated .. not sure this is wanted.

hm, that shouldnt happen, can you provide the code for the controlEvent (pm if too long)?

Code:

import controlP5.*;
ControlP5 controlP5;

ScrollList l;
int cnt;

void setup() {
size(400,400);
frameRate(30);
controlP5 = new ControlP5(this);
l = controlP5.addScrollList("myList",100,100,120,280);

l.setLabel("myLabel");
for(int i=0;i<40;i++) {
controlP5.Button b = l.addItem("a"+i,i);
b.setId(100 + i);
}
}


void controlEvent(ControlEvent theEvent) {
println(theEvent.controller().parent()+" / "+l);
// check if the parent of the controller equals our scrollList
if(theEvent.controller().parent().equals(l)) {
println("an event from our list");
}
}

void keyPressed() {
if(key==',') {
l.addItem("av"+((int)random(10000)),0);
} else if(key=='.') {
cnt++;
l.removeItem("a"+cnt);
}
}
void draw() {
background(0);
}

Re: controlP5 problems
Reply #2 - Jan 14th, 2008, 1:46pm
 
many many thanks! this is really super!

sample code showing the event in event thing:
Code:

// click an scroll list item and it will set the slider which will issue another controlEvent

import controlP5.*;
ControlP5 controlP5;

ScrollList l;
Slider sl;

void setup()
{
size(400,400);

controlP5 = new ControlP5(this);
l = controlP5.addScrollList("l",100,100,120,280);
sl = controlP5.addSlider("sl",0,100,250,120,10,200);

for(int i=0;i<40;i++) {
controlP5.Button b = l.addItem( "a"+i, i);
}
}

String lev = "";

void controlEvent(ControlEvent ce)
{
println( lev + "in " + ce );
lev = lev + " ";

if ( ce.controller() != sl ) sl.setValue(random(100));

lev = lev.substring(0,lev.length()-4);
println( lev + "out" );
}

void draw () { background(0); }


thanks again .. i'll post a link to the projects for you once they're online!
F
Re: controlP5 problems
Reply #3 - Jan 14th, 2008, 3:23pm
 
looking at the code..
what happens in the controlEvent when you press an item in the scroll list is, that the button from the scroll list triggers a controlEvent first. then, while the controlEvent is still going on, a second controlEvent is called with sl.setValue() (each setValue automatically calls controlEvent). this happens immediately before the first event has finished. e.g.
Code:

void setup() {
setValue();
}
int cnt;
void setValue() {
controlEvent();
}

void controlEvent() {
println("controlEvent() "+cnt+" start ");
cnt++;
if(cnt==1) {
setValue();
}
cnt--;
println("controlEvent() "+cnt+" end");
}


to make one event finish after the other you would need to interrupt the controlEvent after you do the setValue() with return;

Code:

void controlEvent(ControlEvent ce) {
println( lev + "in " + ce.controller().name() );
lev = lev + " ";

if ( ce.controller() != sl ) {
println( lev + "out "+ce.controller().name());
lev = lev.substring(0,lev.length()-4);
sl.setValue(random(100));
return;
}

println( lev + "out "+ce.controller().name());
lev = lev.substring(0,lev.length()-4);
}


hope this helps, might get complicated if you need to execute code after return has been called.

looking forward to seeing the projects Smiley
best,
andi
Re: controlP5 problems
Reply #4 - Jan 18th, 2008, 11:26am
 
hi andreas,

my students ran into another problem that we can't seem to be able to navigate around:

they have a scroll list populating another scroll list. this happens inside a controlEvent. clicking an item in the second list repopulates itself. to be exact they have a list of artists names (bands) and a second list for all found combinations that contain that name ("xx feat. yy", ..) if any are found

the problems are:
- calling Button.remove() on a scroll list button will leave a blank spot in the list
- calling Scrollist.removeItem( "myItem" ) will remove all items with same names, a removeItem( Controller ) would be great for such cases

thanks so much!
F
Re: controlP5 problems
Reply #5 - Jan 18th, 2008, 12:55pm
 
just found a fix for the moment. we're renaming items to be removed, keep them in a list and remove them on the next draw() call. not perfect but it works for now.

F
Re: controlP5 problems
Reply #6 - Jan 18th, 2008, 3:35pm
 
seems like the current version of scroll list needs to be rewritten, will do so soon.
andi
Re: controlP5 problems
Reply #7 - Jan 31st, 2008, 11:16pm
 
hi, im having problems with adding controlp5 in a opengl window where i render 3d scenery.

i disabled AutoDraw so i could render the gui after my rendering but it does not seem to work well.
its positioning is not correct

a simple example:


[EDIT]
void draw()
{
 //
 // render cubic scenery
 perspective( PI*0.5, aspectRatio, 1, 8000 );
 camera( cam.x, cam.y, cam.z, 0, 0, 0, 0, 1, 0 );
 pushMatrix();
 renderAllCubex();
 popMatrix();

 //
 // render GUI
 pushMatrix();
 resetMatrix();
 ortho( -width/2, width/2, -height/2, height/2, -10, 10 );
 translate( -width/2, -height/2, 0 ); // [0,0] is top-left
 controlP5.draw();
 popMatrix();
}

any idea on that ?
Re: controlP5 problems
Reply #8 - Feb 1st, 2008, 12:39am
 
while i couldnt get it to work i was able to find the ControlWindow method.

awesome work there, really what i was looking for!

best regards,
Re: controlP5 problems
Reply #9 - Mar 11th, 2009, 9:21pm
 
Is there a way to send a camera matrix to the ControlP5 pick buffer?  I'm working in OpenGL and the MultiList "button" is way off the visible rect.
Re: controlP5 problems
Reply #10 - Mar 19th, 2009, 4:41am
 
unfortunately not, controlP5 is currently limited to 2D-origin-top-left mouse picking.
Page Index Toggle Pages: 1