For this point, you can do, because plotXPos is public, in ofApp:
class ofApp : public ofBaseApp{
public:
PlotParameters p;
void setup(){
p.plotXPos.addListener(this, &ofApp::changedplotXPos);
}
void changedplotXPos(int & param){
cout<<"got it"<<endl;
};
};
You can also create an event dispatched by the PlotParameters, listened by ofApp:
class PlotParameters{
public:
ofEvent<void> changed;
void setup(){
plotXPos.addListener(this, &PlotParameters::changedplotXPos);
};
void changedplotXPos(int & param){
ofNotifyEvent( changed );
} ;
};
class ofApp : public ofBaseApp{
public:
PlotParameters p;
void setup(){
ofAddListener( p.changed, this, & ofApp::onPlotParametersChange);
};
void ofApp::onPlotParametersChange(){
cout<<"got it"<<endl;
}
};
I think this is better than the previous solution because you can now change the PlotParameters code, without touching ofApp, as long as PlotParameters has an ofEvent called "changed".
And if you want to pass some values to the listener function, it is also possible. For example if you want to know which PlotParameters has dispatched the event:
class PlotParameters{
public:
ofEvent< PlotParameters > changed;
string name;
void setup(){
plotXPos.addListener(this, &PlotParameters::changedplotXPos);
};
void changedplotXPos(int & param){
ofNotifyEvent( changed, *this );
} ;
};
class ofApp : public ofBaseApp{
public:
PlotParameters p1;
PlotParameters p2;
void setup(){
p1.name = "PlotParameters 1";
p2.name = "PlotParameters 2";
ofAddListener( p1.changed, this, & ofApp::onPlotParametersChange );
ofAddListener( p2.changed, this, & ofApp::onPlotParametersChange );
};
void ofApp::onPlotParametersChange(PlotParameters & p){
cout << p.name << endl;
}
};