Hi,
I’ve got an application requiring two or more windows. There’s the main application, which has a window created the standard way with an ofApp running in it, and a number of other windows, which have a simple wrapper class around them. The wrapper only really has a window and an id, which is a number.
Similarly to the examples, these listen for their window’s ‘draw’ event, and then call a function. That function then calls the main application’s “drawToSecondaryWindow” function, with a pointer to the wrapper as an argument.
Here’s the code for the wrapper class:
void SecondaryAppWindow::setup (
shared_ptr<Screensaver> _mainApp,
shared_ptr<ofAppBaseWindow> _mainWindow,
MonitorDefinition _m,
int _id
) {
mainApp = _mainApp;
mainWindow = _mainWindow;
m = _m;
id = _id;
ofGLFWWindowSettings settings;
settings.setGLVersion(3, 2);
settings.decorated = false;
settings.shareContextWith = mainWindow;
settings.setSize(m.resolution.x, m.resolution.y);
settings.setPosition(m.offset);
window = ofCreateWindow(settings);
window->setVerticalSync(false);
this->addListeners();
}
void SecondaryAppWindow::addListeners() {
ofAddListener(window->events().draw, this, &SecondaryAppWindow::onFrameEvent);
ofAddListener(window->events().keyPressed, this, &SecondaryAppWindow::onKeyboardInteraction);
ofAddListener(window->events().keyReleased, this, &SecondaryAppWindow::onKeyboardInteraction);
//...etc
}
void SecondaryAppWindow::onFrameEvent(ofEventArgs &args) {
this->mainApp->drawToSecondaryAppWindow(this); // Here's where the problem seems to be
}
and then in the ofApp
void ofApp::drawToSecondaryAppWindow(SecondaryAppWindow * s) {
cout << s->id << endl; // this always seems to get the same value, regardless of how many there are
//etc
}
The problem is, that in the main application’s drawToSecondaryAppWindow
function, the passed in instance always seems to be the last one created. If there’s three windows, the id is always of the third; four, and it’s the id of the fourth.
Have I just set this up wrong, or do event listeners like this only support one instance at a time? If the latter, is there any way that I can rework this? I’d like to be able to draw different things in different windows based on a single value that identifies the window, because the number of windows is going to vary wildly.
Thanks in advance!