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.
IndexProgramming Questions & HelpPrograms › Automatically (re)draw something...
Page Index Toggle Pages: 1
Automatically (re)draw something... (Read 404 times)
Automatically (re)draw something...
May 9th, 2008, 9:59pm
 
I have been messing around with the ControlP5 library and noticed that the library manages to redraw objects (say, a slider bar or toggle box) without explicitly calling a draw() method for the object.

All examples I can find on the processing site seem to take this (or similar) approach (pseudo-code):

void draw() {
 a.draw();
 b.update();
}

But the ControlP5 library somehow updates objects (such as changing the color of a box from a mouseover) without explicitly calling a 'draw()' or 'update()' method.

My question is: Is there a way to incorporate 'automatic' updating somehow so each object doesn't have to be explicitly called? Could this be done with a listener? If so, could an 'event' be triggered for a mouseover?

Thanks in advance!
Re: Automatically (re)draw something...
Reply #1 - May 9th, 2008, 10:09pm
 
I actually just discovered this link: http://dev.processing.org/libraries/  and am reading through it.
It appears Libraries have the ability to include a public void draw() method that gets called at the end of draw().
Is it possible to implement this in a class within the sketch without having to create a library file?
Re: Automatically (re)draw something...
Reply #2 - May 10th, 2008, 10:22pm
 
Yes it is, the function is "registerDraw(myObject)" and that will call a draw(); function of the object you pass every frame.
Re: Automatically (re)draw something...
Reply #3 - May 10th, 2008, 10:34pm
 
Thanks for the reply JohnG!

I had just found this article which explains using registerDraw(myObject) as well as registerMouseEvent(myObject) and was about to post my findings so it may help others wondering how to do this:
http://processing.org/hacks/doku.php?id=hacks:registerevents
Page Index Toggle Pages: 1