Event dispatching


I’m building a mobile app with 2 “layers”,
the GUI, and the rest of the app “behind” it.
i’m listening for touch events on both the gui and the back layer.

What would be the proper way to make sure that the back layer does not react to events aimed at the GUI?

I can think of an object that would dispatch events to display objects depending on their “bounding box” and “depth”, but wouldn’t i be reinventing the wheel?

1 Like

Hi @etienne_p,
I ran into similar thing lately using ofxUI and my solution was to check if the gui was hit:

void ofApp::mousePressed(int x, int y, int button){
    if (!gui->isHit(x, y)){
    ///do something here

because ofxUI uses an ofRectangle you can do that… but i dont know what gui are u using…


if you are using your own UI and listening to ofEvents you can create the listener methods like:

bool mousePressed(ofMouseEventArgs & mouse);

if you return true from that method no other listener from that one will get called.

to control the order in which listeners get called you can add them like:


where OF_EVENT_PRIORITY_BEFORE_APP specifes that that listener should be called before the application, the priorities are just numbers but there’s some constants like that that you can use to make things easier


Hi @arturo, what do you mean by before the application? Does this apply to mobile OF only? I had no idea that you could set an order to event calling, good to know.

i mean that the listener will be called before the callbacks in ofApp. you can do this since 0.8.0, for compatibility most calls stayed like they were before but you can now declare listeners as returning a bool to stop the event from propagating and add them with a certain priority so they get called in a certain order. Also this is multiplatform, will work in any of the platforms supported by OF

For example ofxGui does this so when the moving a slider you want get notifications on the ofApp or an easyCamera won’t move while changing a value in the gui

Nice! I remember this with ofxUI in 0.7.4, I had to manually disable ofEasyCam

@arturo , I’m using an ofxGui slider with ofEasycam. But I am not getting the behavior you described. The camera still moves when I try to use the slider. Any ideas?

it should, it could be a bug, will take a look

thanks everybody!

(just noticed my openframeworks notifications where ending in my junk mail folder, shame on me ;))

i’ve just bumped into this issue. it seems that even if i stop mouse event propagation in the gui, ofEasyCam is updated, because it sets its listener on update not on mouse events.

Hi guys, i just wanted to let you know that i finished my app:

OpenFrameworks is really a fun tool to play with ! :wink:

This is exactly the issue I’m having now. Dragging the mouse on a ofxGui component still triggers the ofEasyCam behind it. Is there a way to stop it on 0.8.4?

I suppose all the efforts are on releasing 0.9.0 now, but since it is not ready, it would be great to get some support for this issue on 0.8.4. Thanks!

This is fixed in 0.9 which is by now completely stable, the only things that we are fixing are related to the project generator so you can use the nightly builds without problem and your project will be compatible with the final release.

If you still don’t want to port to 0.9 you can probably get the ofEasyCam class from 0.9 and put in 0.8.4 but there’s several things that have changed and you might need to fix to make it work with it

1 Like

Nice work!