Commit 714728eb authored by Martin Kröning's avatar Martin Kröning

Rename durationLabel to timeLabel

Fixes #2.
parent f3f887b3
...@@ -18,7 +18,7 @@ public: ...@@ -18,7 +18,7 @@ public:
void addOrReplaceCar(std::string_view vehicleName, std::string_view laneName, void addOrReplaceCar(std::string_view vehicleName, std::string_view laneName,
double positionOnLane, double speed, double positionOnLane, double speed,
double remainingFuel); double remainingFuel);
void setDurationLabel(std::chrono::minutes minutes); void setTimeLabel(std::chrono::minutes time);
private: private:
MapApp *mapApp; MapApp *mapApp;
......
...@@ -40,7 +40,7 @@ void Map::simulate(const std::chrono::seconds duration, ...@@ -40,7 +40,7 @@ void Map::simulate(const std::chrono::seconds duration,
junction->processVehicles(time); junction->processVehicles(time);
junction->drawVehicles(mapApp); junction->drawVehicles(mapApp);
} }
mapApp.setDurationLabel(std::chrono::minutes(static_cast<int>(time * 60))); mapApp.setTimeLabel(std::chrono::minutes(static_cast<int>(time * 60)));
std::this_thread::sleep_for(std::chrono::nanoseconds( std::this_thread::sleep_for(std::chrono::nanoseconds(
static_cast<size_t>(std::nano::den / frequency))); static_cast<size_t>(std::nano::den / frequency)));
} }
......
...@@ -39,6 +39,6 @@ void MapAppAPIWrapper::addOrReplaceCar(std::string_view vehicleName, ...@@ -39,6 +39,6 @@ void MapAppAPIWrapper::addOrReplaceCar(std::string_view vehicleName,
positionOnLane, speed, remainingFuel); positionOnLane, speed, remainingFuel);
} }
void MapAppAPIWrapper::setDurationLabel(const std::chrono::minutes minutes) { void MapAppAPIWrapper::setTimeLabel(const std::chrono::minutes time) {
mapAppSetDurationLabel(mapApp, minutes.count()); mapAppSetTimeLabel(mapApp, time.count());
} }
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="halign">end</property> <property name="halign">end</property>
<property name="label" translatable="yes">Duration: </property> <property name="label" translatable="yes">Time: </property>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkLabel" id="durationLabel"> <object class="GtkLabel" id="timeLabel">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">00:00</property> <property name="label" translatable="yes">00:00</property>
......
...@@ -33,7 +33,7 @@ public: ...@@ -33,7 +33,7 @@ public:
void addOrReplaceCar(const std::string &vehicleName, void addOrReplaceCar(const std::string &vehicleName,
const std::string &laneName, double positionOnLane, const std::string &laneName, double positionOnLane,
double speed, double remainingFuel); double speed, double remainingFuel);
void setDurationLabel(std::chrono::minutes minutes); void setTimeLabel(std::chrono::minutes time);
private: private:
static const std::vector<std::string> zoomLevels; static const std::vector<std::string> zoomLevels;
...@@ -51,7 +51,7 @@ private: ...@@ -51,7 +51,7 @@ private:
MapArea mapArea; MapArea mapArea;
Gtk::Window win; Gtk::Window win;
Gtk::ListBox *listBox; Gtk::ListBox *listBox;
Gtk::Label *durationLabel; Gtk::Label *timeLabel;
Gtk::Label *laneLabel; Gtk::Label *laneLabel;
Gtk::Label *lanePositionPercentageLabel; Gtk::Label *lanePositionPercentageLabel;
Gtk::Label *speedLabel; Gtk::Label *speedLabel;
......
...@@ -66,9 +66,9 @@ void mapAppAddOrReplaceCar(MapApp *mapApp, const char *vehicleName, ...@@ -66,9 +66,9 @@ void mapAppAddOrReplaceCar(MapApp *mapApp, const char *vehicleName,
double speed, double remainingFuel); double speed, double remainingFuel);
/** /**
* Sets the duration label of \p mapApp to \p minutes * Sets the time label of \p mapApp to \p minutes
*/ */
void mapAppSetDurationLabel(MapApp *mapApp, int64_t minutes); void mapAppSetTimeLabel(MapApp *mapApp, int64_t minutes);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -31,7 +31,7 @@ const std::vector<std::string> MapApp::zoomLevels = {"60%", "80%", "100%"}; ...@@ -31,7 +31,7 @@ const std::vector<std::string> MapApp::zoomLevels = {"60%", "80%", "100%"};
MapApp::MapApp(std::string windowTitle) MapApp::MapApp(std::string windowTitle)
: app(Gtk::Application::create()), : app(Gtk::Application::create()),
mapArea(junctions, roads, nameVehicleMap), listBox(nullptr), mapArea(junctions, roads, nameVehicleMap), listBox(nullptr),
durationLabel(nullptr), laneLabel(nullptr), timeLabel(nullptr), laneLabel(nullptr),
lanePositionPercentageLabel(nullptr), speedLabel(nullptr), lanePositionPercentageLabel(nullptr), speedLabel(nullptr),
remainingFuelLabel(nullptr), zoomComboBoxText(nullptr) { remainingFuelLabel(nullptr), zoomComboBoxText(nullptr) {
win.set_title(std::move(windowTitle)); win.set_title(std::move(windowTitle));
...@@ -46,7 +46,7 @@ MapApp::MapApp(std::string windowTitle) ...@@ -46,7 +46,7 @@ MapApp::MapApp(std::string windowTitle)
builder->get_widget("listBox", listBox); builder->get_widget("listBox", listBox);
builder->get_widget("durationLabel", durationLabel); builder->get_widget("timeLabel", timeLabel);
builder->get_widget("laneLabel", laneLabel); builder->get_widget("laneLabel", laneLabel);
builder->get_widget("lanePositionPercentageLabel", builder->get_widget("lanePositionPercentageLabel",
lanePositionPercentageLabel); lanePositionPercentageLabel);
...@@ -140,15 +140,15 @@ void MapApp::refreshVehicleLabels(const DrawableVehicle &vehicle) { ...@@ -140,15 +140,15 @@ void MapApp::refreshVehicleLabels(const DrawableVehicle &vehicle) {
remainingFuelLabel->set_text(remainingFuelBuffer.str()); remainingFuelLabel->set_text(remainingFuelBuffer.str());
} }
void MapApp::setDurationLabel(const std::chrono::minutes minutes) { void MapApp::setTimeLabel(const std::chrono::minutes minutes) {
std::ostringstream durationBuffer; std::ostringstream timeBuffer;
durationBuffer timeBuffer
<< std::setfill('0') << std::setw(2) << std::setfill('0') << std::setw(2)
<< std::chrono::duration_cast<std::chrono::hours>(minutes).count() << ':' << std::chrono::duration_cast<std::chrono::hours>(minutes).count() << ':'
<< std::setw(2) << minutes.count() % 60; << std::setw(2) << minutes.count() % 60;
Glib::signal_idle().connect_once( Glib::signal_idle().connect_once(
[this, durationString = durationBuffer.str()]() mutable { [this, timeString = timeBuffer.str()]() mutable {
durationLabel->set_text(std::move(durationString)); timeLabel->set_text(std::move(timeString));
}, },
Glib::PRIORITY_HIGH_IDLE + 20); Glib::PRIORITY_HIGH_IDLE + 20);
} }
......
...@@ -49,6 +49,6 @@ void mapAppAddOrReplaceCar(MapApp *mapApp, gsl::czstring<> vehicleName, ...@@ -49,6 +49,6 @@ void mapAppAddOrReplaceCar(MapApp *mapApp, gsl::czstring<> vehicleName,
remainingFuel); remainingFuel);
} }
void mapAppSetDurationLabel(MapApp *mapApp, int64_t minutes) { void mapAppSetTimeLabel(MapApp *mapApp, int64_t minutes) {
mapApp->setDurationLabel(std::chrono::minutes(minutes)); mapApp->setTimeLabel(std::chrono::minutes(minutes));
} }
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