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: ...@@ -37,6 +37,8 @@ public:
private: private:
static const std::vector<std::string> zoomLevels; static const std::vector<std::string> zoomLevels;
static Glib::RefPtr<Gtk::Application> app;
static std::thread thread;
void addOrReplaceVehicle(const std::string &vehicleName, void addOrReplaceVehicle(const std::string &vehicleName,
const std::string &laneName, double positionOnLane, const std::string &laneName, double positionOnLane,
double speed, double remainingFuel, double red, double speed, double remainingFuel, double red,
...@@ -46,8 +48,6 @@ private: ...@@ -46,8 +48,6 @@ private:
void onVehicleRowSelected(Gtk::ListBoxRow *row); void onVehicleRowSelected(Gtk::ListBoxRow *row);
void refreshVehicleLabels(const DrawableVehicle &vehicle); void refreshVehicleLabels(const DrawableVehicle &vehicle);
void refreshArea(int x, int y, int width, int height); void refreshArea(int x, int y, int width, int height);
Glib::RefPtr<Gtk::Application> app;
std::thread thread;
MapArea mapArea; MapArea mapArea;
Gtk::Window win; Gtk::Window win;
Gtk::ListBox *listBox; Gtk::ListBox *listBox;
......
...@@ -27,10 +27,11 @@ ...@@ -27,10 +27,11 @@
// https://developer.gnome.org/glibmm/2.55/namespaceGlib.html#a0c450f82b9e34689e2dda2038ba7834faf2d20696a8afab425c00268d981e9897 // https://developer.gnome.org/glibmm/2.55/namespaceGlib.html#a0c450f82b9e34689e2dda2038ba7834faf2d20696a8afab425c00268d981e9897
const std::vector<std::string> MapApp::zoomLevels = {"60%", "80%", "100%"}; 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) 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), timeLabel(nullptr), laneLabel(nullptr),
lanePositionPercentageLabel(nullptr), speedLabel(nullptr), lanePositionPercentageLabel(nullptr), speedLabel(nullptr),
remainingFuelLabel(nullptr), zoomComboBoxText(nullptr) { remainingFuelLabel(nullptr), zoomComboBoxText(nullptr) {
...@@ -70,11 +71,15 @@ MapApp::MapApp(std::string windowTitle) ...@@ -70,11 +71,15 @@ MapApp::MapApp(std::string windowTitle)
viewport->add(mapArea); viewport->add(mapArea);
mapArea.show(); mapArea.show();
thread = std::thread([this]() { if (app->get_windows().empty()) {
auto app = Gtk::Application::create(); thread = std::thread([this]() {
app->run(win); app = Gtk::Application::create();
app->remove_window(win); app->run(win);
}); });
} else {
app->add_window(win);
win.show();
}
} }
void MapApp::onZoomEntryActivate() { void MapApp::onZoomEntryActivate() {
...@@ -110,8 +115,8 @@ void MapApp::refreshArea(int x, int y, int width, int height) { ...@@ -110,8 +115,8 @@ void MapApp::refreshArea(int x, int y, int width, int height) {
} }
MapApp::~MapApp() { MapApp::~MapApp() {
win.close(); app->remove_window(win);
if (thread.joinable()) { if (thread.joinable() && app->get_windows().empty()) {
thread.join(); 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