Commit e22a8fbe authored by Martin Kröning's avatar Martin Kröning

Allow instancing multiple MapApps sequencially and parallelly

parent 714728eb
......@@ -37,6 +37,8 @@ public:
private:
static const std::vector<std::string> zoomLevels;
static Glib::RefPtr<Gtk::Application> app;
static std::thread thread;
void addOrReplaceVehicle(const std::string &vehicleName,
const std::string &laneName, double positionOnLane,
double speed, double remainingFuel, double red,
......@@ -46,8 +48,6 @@ private:
void onVehicleRowSelected(Gtk::ListBoxRow *row);
void refreshVehicleLabels(const DrawableVehicle &vehicle);
void refreshArea(int x, int y, int width, int height);
Glib::RefPtr<Gtk::Application> app;
std::thread thread;
MapArea mapArea;
Gtk::Window win;
Gtk::ListBox *listBox;
......
......@@ -27,10 +27,11 @@
// https://developer.gnome.org/glibmm/2.55/namespaceGlib.html#a0c450f82b9e34689e2dda2038ba7834faf2d20696a8afab425c00268d981e9897
const std::vector<std::string> MapApp::zoomLevels = {"60%", "80%", "100%"};
Glib::RefPtr<Gtk::Application> MapApp::app = Gtk::Application::create();
std::thread MapApp::thread;
MapApp::MapApp(std::string windowTitle)
: app(Gtk::Application::create()),
mapArea(junctions, roads, nameVehicleMap), listBox(nullptr),
: mapArea(junctions, roads, nameVehicleMap), listBox(nullptr),
timeLabel(nullptr), laneLabel(nullptr),
lanePositionPercentageLabel(nullptr), speedLabel(nullptr),
remainingFuelLabel(nullptr), zoomComboBoxText(nullptr) {
......@@ -70,11 +71,15 @@ MapApp::MapApp(std::string windowTitle)
viewport->add(mapArea);
mapArea.show();
thread = std::thread([this]() {
auto app = Gtk::Application::create();
app->run(win);
app->remove_window(win);
});
if (app->get_windows().empty()) {
thread = std::thread([this]() {
app = Gtk::Application::create();
app->run(win);
});
} else {
app->add_window(win);
win.show();
}
}
void MapApp::onZoomEntryActivate() {
......@@ -110,8 +115,8 @@ void MapApp::refreshArea(int x, int y, int width, int height) {
}
MapApp::~MapApp() {
win.close();
if (thread.joinable()) {
app->remove_window(win);
if (thread.joinable() && app->get_windows().empty()) {
thread.join();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment