I'm making a cross platform C++ graphing library using SFML. The end goal is to make it so you can quickly pass two arrays of numbers to an object and have them plotted. I've got most of the plotting code working but I also want to handle mouse events so you can scroll around on the plot, but I don't want to put the event loop in the main thread because I want the plots to respond to events while other things are going on in the main loop. For example, this is the kind of program I expect to use as an actual application of my code:
int main(){
int x[] = {1, 2, 3, 4, 5};
int y[] = {2, 4, 6, 8, 10};
MyPlot p(x, y); //Plot displays on screen, mouse can scroll around on window
/*
Lengthy slow calculation solving all of science goes here...
*/
int x2[] = {1, 2, 3, 4, 5};
int y2[] = {42, 42, 42, 42, 42};
p.update(x2, y2); //Plot is updated
p.loop_until_closed(); //Plot remains on screen until window is closed
}
After reading around on the forum and docs it looks like there isn't a way to handle events outside the main thread, but I want to make sure this is true before I change my program so you have to wait to use your nice pretty charts until you can sacrifice the main loop to event handling.
In summary:
1. Is there a way to handle events outside the main thread? (I've tried and been told I can't create a window or handle events from a worker thread)
2. Do you know of any work around so my window can be responsive while the main thread is left open for other (non-event handling) duties?
Thanks in advance