working with events

hello,

I’m trying to figure out how events work, but cannot find any reference to it…

I created a Circle Class that I instatiated in testApp, but now I want to use mouse events in them.
I tried addListener but didn’t manage to figure out how it works…

In testApp methods (draw…update…mousePressed…etc) I added circ[i]->draw() … etc. to make it work

How can I make my Circle class listen to events?

thanks,
Miguel

src.zip

Hi,

You want to control circles with mouse?

here’s my suggestion,
(but, I’m not good at OF, I think You already knew this way and doesn’t want to use :oops: )

in Circle.h---------------------------------------------------------

deleted “: public ofBaseApp”.

because ofBaseApp should be only one.

and changed the method name like below

void mousePressed(); -> void mouseCircle();

in Circle.cpp-------------------------------------------------------

add this method>

void Circle::mouseCircle(){
printf(“click mouse”);
}

in testApp.cpp--------------------------------------------------------

void testApp::mousePressed(int x, int y, int button){

circ[0] -> mouseCircle();

}

good luck~

thanks Jung,

yeah, that’s how I was doing it in the src I posted, but I’m sure there must be a way for the Circle class to listen to uddate, draw, mouse actions, etc in the class itself, without calling the methods from testApp.

I’m planning to do a manager for this, but I’m sure this is already implemented in oF…

thanks anyway, :smiley:

you can register any class to listen for events:

  
ofAddListener(ofEvents.mousePressed, this, &Circle::mousePressed);  

where Circle::mousePressed has the following parameter:

  
void Circle::mousePressed(ofMouseEventArgs & mouse)  

there’s an example in the advancedEventsExample, and the documentation is here:

http://www.openframeworks.cc/documentat-…-EventUtils

thanks!
:smiley:

I saw the example but hadn’t managed to put it working with my class.

thanks for the help