mousePressed function for ofxButton

Hi there,

I’m trying to check if a button is pressed, but don’t really now how to use the mousePressed function. Apparently a ofMouseEventArgs-object is needed, what should I put here?


Check the examples\gui\guiExample.
The ofxButton is a part of the ofxGui. You need to add listener to your button like in the example above.

ringButton.addListener(this, &ofApp::ringButtonPressed);

And then:

void ofApp::ringButtonPressed(){; }

Thanks for the quick reply! The only problem with the solution is that I have about 20 buttons.

I’ve tried to make a function that want an ofxButton object as an parameter (this doesn’t work):
so the function would be:
offApp::buttonFunctionality( ofxButton buttonPressed);

then I could make listeners that just reference to this function, and figure out what button it is by calling getName() in the function. But when I try to add this to the listener VS gives me an error:

"expression must be Ivalue or a function designator "

My addListener function call now is:
Is there a solution for this?

Sorry, I don’t use ofxButton. I would rather create my simple class button and register mouse listeners inside of it.
But, please check those posts:

I wrote a little button class that did this (but for of_iOS). Maybe you’d like to modify it (change the listeners from touchUp/touchDown to mouse stuff.

check the senButton class.