From 56a371da8fe145b9faec4d9270b554b548531aa6 Mon Sep 17 00:00:00 2001 From: Andrew Tribick Date: Wed, 1 Nov 2023 20:38:23 +0100 Subject: [PATCH] PR review fixes --- src/celengine/simulation.cpp | 7 +- src/celengine/simulation.h | 2 +- src/celestia/celestiacore.cpp | 2 +- src/celestia/hud.cpp | 50 ------------- src/celestia/hud.h | 3 - src/celestia/textinput.cpp | 56 ++++---------- src/celestia/textinput.h | 1 - src/celestia/timeinfo.h | 4 +- src/celestia/viewmanager.cpp | 134 ++++++++++++++++------------------ src/celestia/viewmanager.h | 7 +- 10 files changed, 88 insertions(+), 178 deletions(-) diff --git a/src/celengine/simulation.cpp b/src/celengine/simulation.cpp index 856901aef84..571761824b0 100644 --- a/src/celengine/simulation.cpp +++ b/src/celengine/simulation.cpp @@ -180,12 +180,9 @@ const Observer& Simulation::getObserver() const } - -Observer* Simulation::addObserver() +Observer* Simulation::duplicateActiveObserver() { - Observer* o = new Observer(); - observers.push_back(o); - return o; + return observers.emplace_back(new Observer(*getActiveObserver())); } diff --git a/src/celengine/simulation.h b/src/celengine/simulation.h index 0c56cef40f8..016d17d05a6 100644 --- a/src/celengine/simulation.h +++ b/src/celengine/simulation.h @@ -100,7 +100,7 @@ class Simulation void setObserverOrientation(const Eigen::Quaternionf&); void reverseObserverOrientation(); - Observer* addObserver(); + Observer* duplicateActiveObserver(); void removeObserver(Observer*); Observer* getActiveObserver(); const Observer* getActiveObserver() const; diff --git a/src/celestia/celestiacore.cpp b/src/celestia/celestiacore.cpp index 88604517d83..3839fe165ea 100644 --- a/src/celestia/celestiacore.cpp +++ b/src/celestia/celestiacore.cpp @@ -1962,7 +1962,7 @@ void CelestiaCore::draw() nFrames++; if (nFrames == 100 || sysTime - fpsCounterStartTime > 10.0) { - timeInfo.fps = (double) nFrames / (sysTime - fpsCounterStartTime); + timeInfo.fps = (float) nFrames / (sysTime - fpsCounterStartTime); nFrames = 0; fpsCounterStartTime = sysTime; } diff --git a/src/celestia/hud.cpp b/src/celestia/hud.cpp index 5717be0758e..fc1ace57561 100644 --- a/src/celestia/hud.cpp +++ b/src/celestia/hud.cpp @@ -58,21 +58,18 @@ constexpr double OneFtInKm = 0.0003048; constexpr double OneLbInKg = 0.45359237; constexpr double OneLbPerFt3InKgPerM3 = OneLbInKg / celmath::cube(OneFtInKm * 1000.0); - constexpr float KelvinToCelsius(float kelvin) { return kelvin - 273.15f; } - constexpr float KelvinToFahrenheit(float kelvin) { return kelvin * 1.8f - 459.67f; } - FormattedNumber SigDigitNum(double v, int digits) { @@ -81,7 +78,6 @@ SigDigitNum(double v, int digits) FormattedNumber::SignificantDigits); } - std::string KelvinToStr(float value, int digits, TemperatureScale temperatureScale) { @@ -104,7 +100,6 @@ KelvinToStr(float value, int digits, TemperatureScale temperatureScale) return fmt::format(unitTemplate, SigDigitNum(value, digits)); } - std::string DistanceLyToStr(double distance, int digits, MeasurementSystem measurement) { @@ -159,14 +154,12 @@ DistanceLyToStr(double distance, int digits, MeasurementSystem measurement) return fmt::format("{} {}", SigDigitNum(distance, digits), units); } - std::string DistanceKmToStr(double distance, int digits, MeasurementSystem measurement) { return DistanceLyToStr(astro::kilometersToLightYears(distance), digits, measurement); } - void displayRotationPeriod(Overlay& overlay, double days) { @@ -197,7 +190,6 @@ displayRotationPeriod(Overlay& overlay, double days) overlay.print(_("Rotation period: {} {}\n"), n, p); } - void displayMass(Overlay& overlay, float mass, MeasurementSystem measurement) { @@ -214,7 +206,6 @@ displayMass(Overlay& overlay, float mass, MeasurementSystem measurement) overlay.printf(_("Mass: %.2f Me\n"), mass); } - void displaySpeed(Overlay& overlay, float speed, MeasurementSystem measurement) { @@ -265,7 +256,6 @@ displaySpeed(Overlay& overlay, float speed, MeasurementSystem measurement) overlay.print(_("Speed: {} {}\n"), n, u); } - // Display a positive angle as degrees, minutes, and seconds. If the angle is less than one // degree, only minutes and seconds are shown; if the angle is less than one minute, only // seconds are displayed. @@ -290,7 +280,6 @@ angleToStr(double angle) return fmt::format("{:.2f}\"", abs(seconds)); } - void displayApparentDiameter(Overlay& overlay, double radius, double distance) { @@ -305,7 +294,6 @@ displayApparentDiameter(Overlay& overlay, double radius, double distance) overlay.printf(_("Apparent diameter: %s\n"), angleToStr(arcSize)); } - void displayDeclination(Overlay& overlay, double angle) { @@ -318,7 +306,6 @@ displayDeclination(Overlay& overlay, double angle) std::abs(minutes), std::abs(seconds)); } - void displayRightAscension(Overlay& overlay, double angle) { @@ -330,7 +317,6 @@ displayRightAscension(Overlay& overlay, double angle) hours, abs(minutes), abs(seconds)); } - void displayApparentMagnitude(Overlay& overlay, float absMag, @@ -347,7 +333,6 @@ displayApparentMagnitude(Overlay& overlay, } } - void displayRADec(Overlay& overlay, const Eigen::Vector3d& v) { @@ -366,7 +351,6 @@ displayRADec(Overlay& overlay, const Eigen::Vector3d& v) displayDeclination(overlay, celmath::radToDeg(theta)); } - // Display nicely formatted planetocentric/planetographic coordinates. // The latitude and longitude parameters are angles in radians, altitude // is in kilometers. @@ -429,7 +413,6 @@ displayPlanetocentricCoords(Overlay& overlay, overlay.printf(_("%.6f%c %.6f%c %s"), lat, nsHemi, lon, ewHemi, DistanceKmToStr(altitude, 5, measurement)); } - void displayStarInfo(Overlay& overlay, int detail, @@ -504,7 +487,6 @@ displayStarInfo(Overlay& overlay, } } - void displayDSOinfo(Overlay& overlay, const DeepSkyObject& dso, double distance, @@ -535,7 +517,6 @@ void displayDSOinfo(Overlay& overlay, } } - static void displayPlanetInfo(Overlay& overlay, int detail, Body& body, @@ -618,7 +599,6 @@ static void displayPlanetInfo(Overlay& overlay, } } - void displayLocationInfo(Overlay& overlay, Location& location, @@ -637,7 +617,6 @@ displayLocationInfo(Overlay& overlay, lonLatAlt.x(), lonLatAlt.y(), lonLatAlt.z(), false, measurement); } - std::string getSelectionName(const Selection& sel, const Universe& univ) { @@ -656,7 +635,6 @@ getSelectionName(const Selection& sel, const Universe& univ) } } - std::string getBodySelectionNames(const Body& body) { @@ -697,31 +675,26 @@ getBodySelectionNames(const Body& body) } // end unnamed namespace - Hud::~Hud() = default; - int Hud::getDetail() const { return hudDetail; } - void Hud::setDetail(int detail) { hudDetail = detail % 3; } - astro::Date::Format Hud::getDateFormat() const { return dateFormat; } - void Hud::setDateFormat(astro::Date::Format format) { @@ -729,14 +702,12 @@ Hud::setDateFormat(astro::Date::Format format) dateStrWidth = 0; } - TextInput& Hud::textInput() { return m_textInput; } - unsigned int Hud::getTextEnterMode() const { @@ -751,14 +722,12 @@ Hud::setTextEnterMode(unsigned int value) m_textInput.reset(); } - void Hud::setOverlay(std::unique_ptr&& _overlay) { overlay = std::move(_overlay); } - void Hud::setWindowSize(int w, int h) { @@ -766,7 +735,6 @@ Hud::setWindowSize(int w, int h) overlay->setWindowSize(w, h); } - void Hud::setTextAlignment(LayoutDirection dir) { @@ -775,35 +743,30 @@ Hud::setTextAlignment(LayoutDirection dir) : engine::TextLayout::HorizontalAlignment::Left); } - int Hud::getTextWidth(std::string_view text) const { return engine::TextLayout::getTextWidth(text, titleFont.get()); } - const std::shared_ptr& Hud::getFont() const { return font; } - const std::shared_ptr& Hud::getTitleFont() const { return titleFont; } - std::tuple Hud::getTitleMetrics() const { return std::make_tuple(titleEmWidth, titleFontHeight); } - void Hud::renderOverlay(const WindowMetrics& metrics, const Simulation* sim, @@ -884,7 +847,6 @@ Hud::renderOverlay(const WindowMetrics& metrics, setlocale(LC_NUMERIC, "C"); } - void Hud::renderViewBorders(const WindowMetrics& metrics, double currentTime, @@ -916,7 +878,6 @@ Hud::renderViewBorders(const WindowMetrics& metrics, } } - void Hud::renderTimeInfo(const WindowMetrics& metrics, const Simulation* sim, const TimeInfo& timeInfo) { @@ -986,7 +947,6 @@ Hud::renderTimeInfo(const WindowMetrics& metrics, const Simulation* sim, const T overlay->restorePos(); } - void Hud::renderFrameInfo(const WindowMetrics& metrics, const Simulation* sim) { @@ -1059,7 +1019,6 @@ Hud::renderFrameInfo(const WindowMetrics& metrics, const Simulation* sim) overlay->restorePos(); } - void Hud::renderSelectionInfo(const WindowMetrics& metrics, const Simulation* sim, @@ -1181,7 +1140,6 @@ Hud::renderSelectionInfo(const WindowMetrics& metrics, overlay->restorePos(); } - void Hud::renderTextInput(const WindowMetrics& metrics) { @@ -1234,8 +1192,6 @@ Hud::renderTextInput(const WindowMetrics& metrics) overlay->setFont(font); } - - void Hud::renderTextMessages(const WindowMetrics& metrics, double currentTime) { @@ -1263,7 +1219,6 @@ Hud::renderTextMessages(const WindowMetrics& metrics, double currentTime) overlay->setFont(font); } - void Hud::renderMovieCapture(const WindowMetrics& metrics, const MovieCapture& movieCapture) { @@ -1313,7 +1268,6 @@ Hud::renderMovieCapture(const WindowMetrics& metrics, const MovieCapture& movieC overlay->restorePos(); } - std::string_view Hud::getCurrentMessage(double currentTime) const { @@ -1322,7 +1276,6 @@ Hud::getCurrentMessage(double currentTime) const return {}; } - void Hud::setImage(std::unique_ptr&& _image, double currentTime) { @@ -1330,7 +1283,6 @@ Hud::setImage(std::unique_ptr&& _image, double currentTime) image->setStartTime(static_cast(currentTime)); } - bool Hud::setFont(const std::shared_ptr& f) { @@ -1344,7 +1296,6 @@ Hud::setFont(const std::shared_ptr& f) return true; } - bool Hud::setTitleFont(const std::shared_ptr& f) { @@ -1358,7 +1309,6 @@ Hud::setTitleFont(const std::shared_ptr& f) return true; } - void Hud::clearFonts() { diff --git a/src/celestia/hud.h b/src/celestia/hud.h index 9085a9bdede..b87bc53263f 100644 --- a/src/celestia/hud.h +++ b/src/celestia/hud.h @@ -45,14 +45,12 @@ namespace engine class DateFormatter; } - enum class MeasurementSystem { Metric = 0, Imperial = 1, }; - enum class TemperatureScale { Kelvin = 0, @@ -60,7 +58,6 @@ enum class TemperatureScale Fahrenheit = 2, }; - class Hud { public: diff --git a/src/celestia/textinput.cpp b/src/celestia/textinput.cpp index 3e0f6e7d4c7..33498c1b5d3 100644 --- a/src/celestia/textinput.cpp +++ b/src/celestia/textinput.cpp @@ -28,21 +28,18 @@ TextInput::getTypedText() const return m_text; } - util::array_view TextInput::getCompletion() const { return m_completion; } - int TextInput::getCompletionIndex() const { return m_completionIdx; } - CharEnteredResult TextInput::charEntered(const Simulation* sim, std::string_view c_p, bool withLocations) { @@ -86,38 +83,26 @@ TextInput::charEntered(const Simulation* sim, std::string_view c_p, bool withLoc m_completionIdx++; else if ((int) m_completion.size() > 0 && m_completionIdx + 1 == (int) m_completion.size()) m_completionIdx = 0; - if (m_completionIdx >= 0) { - std::string::size_type pos = m_text.rfind('/', m_text.length()); - if (pos != std::string::npos) - { - m_text.resize(pos + 1); - m_text.append(m_completion[m_completionIdx]); - } - else - { - m_text = m_completion[m_completionIdx]; - } + + if (m_completionIdx >= 0) + { + auto pos = m_text.rfind('/'); + m_text.resize(pos == std::string::npos ? 0 : (pos + 1)); + m_text.append(m_completion[m_completionIdx]); } } else if (c == '\177') // BackTab { if (m_completionIdx > 0) m_completionIdx--; - else if (m_completionIdx == 0) + else if (m_completionIdx == 0 || m_completion.size() > 0) m_completionIdx = m_completion.size() - 1; - else if (m_completion.size() > 0) - m_completionIdx = m_completion.size() - 1; - if (m_completionIdx >= 0) { - std::string::size_type pos = m_text.rfind('/', m_text.length()); - if (pos != std::string::npos) - { - m_text.resize(pos + 1); - m_text.append(m_completion[m_completionIdx]); - } - else - { - m_text = m_completion[m_completionIdx]; - } + + if (m_completionIdx >= 0) + { + auto pos = m_text.rfind('/'); + m_text.resize(pos == std::string::npos ? 0 : (pos + 1)); + m_text.append(m_completion[m_completionIdx]); } } else if (c == '\033') // ESC @@ -132,7 +117,6 @@ TextInput::charEntered(const Simulation* sim, std::string_view c_p, bool withLoc return CharEnteredResult::Normal; } - void TextInput::appendText(const Simulation* sim, std::string_view sv, bool withLocations) { @@ -143,21 +127,13 @@ TextInput::appendText(const Simulation* sim, std::string_view sv, bool withLocat #ifdef AUTO_COMPLETION if (m_completion.size() == 1) { - std::string::size_type pos = m_text.rfind('/', m_text.length()); - if (pos != string::npos) - { - m_text.resize(pos + 1); - m_text.append(m_completion[0]); - } - else - { - m_text = m_completion[0]; - } + auto pos = m_text.rfind('/'); + m_text.resize(pos == std::string::npos ? 0 : (pos + 1)); + m_text.append(m_completion.front()); } #endif } - void TextInput::reset() { diff --git a/src/celestia/textinput.h b/src/celestia/textinput.h index ec603d32f55..15fb33a709d 100644 --- a/src/celestia/textinput.h +++ b/src/celestia/textinput.h @@ -30,7 +30,6 @@ enum class CharEnteredResult Cancelled, }; - class TextInput { public: diff --git a/src/celestia/timeinfo.h b/src/celestia/timeinfo.h index 1800175758c..ffad350d012 100644 --- a/src/celestia/timeinfo.h +++ b/src/celestia/timeinfo.h @@ -17,9 +17,9 @@ struct TimeInfo static constexpr double MinimumTimeRate = 1.0e-15; double currentTime{ 0.0 }; - double fps{ 0.0 }; + float fps{ 0.0f }; int timeZoneBias{ 0 }; // Diff in secs between local time and GMT - bool lightTravelFlag { false }; + bool lightTravelFlag{ false }; }; } diff --git a/src/celestia/viewmanager.cpp b/src/celestia/viewmanager.cpp index 409a5e12df5..c7545f9631a 100644 --- a/src/celestia/viewmanager.cpp +++ b/src/celestia/viewmanager.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -26,31 +27,44 @@ namespace celestia namespace { +constexpr float borderSize = 2.0f; + +inline std::pair +metricsSizeFloat(const WindowMetrics& metrics) +{ + return std::make_pair(static_cast(metrics.width), static_cast(metrics.height)); +} + bool -pointOutsideView(const View* view, - const WindowMetrics& metrics, +pointOutsideView(const View& view, + float mwidth, float mheight, float x, float y) { - return x+2 < view->x * metrics.width || - x-2 > (view->x + view->width) * metrics.width || - (metrics.height - y)+2 < view->y * metrics.height || - (metrics.height - y)-2 > (view->y + view->height) * metrics.height; + return x + borderSize < view.x * mwidth || + x - borderSize > (view.x + view.width) * mwidth || + (mheight - y) + borderSize < view.y * mheight || + (mheight - y) - borderSize > (view.y + view.height) * mheight; } - std::tuple -viewBoundaryTestValues(const View* view, - const WindowMetrics& metrics, - float x, - float y) +viewBoundaryTestValues(const View& view, + float mwidth, float mheight, + float x, float y) { - float vx = (x / metrics.width - view->x) / view->width; - float vy = ((1 - y / metrics.height) - view->y ) / view->height; - float vxp = vx * view->width * metrics.width; - float vyp = vy * view->height * metrics.height; + float vx = (x / mwidth - view.x) / view.width; + float vy = ((1 - y / mheight) - view.y ) / view.height; + float vxp = vx * view.width * mwidth; + float vyp = vy * view.height * mheight; return std::make_tuple(vx, vy, vxp, vyp); } +inline bool +testEdge(float vpara, float vperpp, float vperpDim, float mperpDim) +{ + return vpara >= 0.0f && vpara <= 1.0f && + (std::abs(vperpp) <= borderSize || std::abs(vperpp - vperpDim * mperpDim) <= borderSize); +} + } // end unnamed namespace ViewManager::ViewManager(View* view) @@ -65,65 +79,63 @@ ViewManager::views() const return m_views; } - const View* ViewManager::activeView() const { return *m_activeView; } - double ViewManager::flashFrameStart() const { return m_flashFrameStart; } - void ViewManager::flashFrameStart(double currentTime) { m_flashFrameStart = currentTime; } - bool ViewManager::isResizing() const { return m_resizeSplit != nullptr; } - ViewBorderType ViewManager::checkViewBorder(const WindowMetrics& metrics, float x, float y) const { + auto [mwidth, mheight] = metricsSizeFloat(metrics); for (const auto v : m_views) { if (v->type != View::ViewWindow) continue; - auto [vx, vy, vxp, vyp] = viewBoundaryTestValues(v, metrics, x, y); - if (vx >=0 && vx <= 1 && (std::abs(vyp) <= 2 || std::abs(vyp - v->height * metrics.height) <= 2)) + auto [vx, vy, vxp, vyp] = viewBoundaryTestValues(*v, mwidth, mheight, x, y); + if (testEdge(vx, vyp, v->height, mheight)) return ViewBorderType::SizeVertical; - if (vy >=0 && vy <= 1 && (std::abs(vxp) <= 2 || std::abs(vxp - v->width * metrics.width) <= 2)) + if (testEdge(vy, vxp, v->width, mwidth)) return ViewBorderType::SizeHorizontal; } return ViewBorderType::None; } - /// Makes the view under x, y the active view. bool ViewManager::pickView(Simulation* sim, const WindowMetrics& metrics, float x, float y) { - if (!pointOutsideView(*m_activeView, metrics, x, y)) + // Clang does not support capturing structured bindings, so work with the pair here + auto msize = metricsSizeFloat(metrics); + if (!pointOutsideView(**m_activeView, msize.first, msize.second, x, y)) return false; m_activeView = std::find_if(m_views.begin(), m_views.end(), - [&metrics, x, y](const View* view) { - return view->type == View::ViewWindow && !pointOutsideView(view, metrics, x, y); + [&msize, x, y](const View* view) { + return view->type == View::ViewWindow && + !pointOutsideView(*view, msize.first, msize.second, x, y); }); // Make sure that we're left with a valid view @@ -134,7 +146,6 @@ ViewManager::pickView(Simulation* sim, const WindowMetrics& metrics, float x, fl return true; } - void ViewManager::nextView(Simulation* sim) { @@ -147,20 +158,19 @@ ViewManager::nextView(Simulation* sim) sim->setActiveObserver((*m_activeView)->observer); } - void ViewManager::tryStartResizing(const WindowMetrics& metrics, float x, float y) { View* v1 = nullptr; View* v2 = nullptr; + auto [mwidth, mheight] = metricsSizeFloat(metrics); for (View* v : m_views) { if (v->type != View::ViewWindow) continue; - auto [vx, vy, vxp, vyp] = viewBoundaryTestValues(v, metrics, x, y); - if ((vx >=0 && vx <= 1 && (std::abs(vyp) <= 2 || std::abs(vyp - v->height * metrics.height) <= 2)) || - (vy >=0 && vy <= 1 && (std::abs(vxp) <= 2 || std::abs(vxp - v->width * metrics.width) <= 2))) + auto [vx, vy, vxp, vyp] = viewBoundaryTestValues(*v, mwidth, mheight, x, y); + if (testEdge(vx, vyp, v->height, mheight) || testEdge(vy, vxp, v->width, mwidth)) { if (v1 == nullptr) { @@ -177,7 +187,7 @@ ViewManager::tryStartResizing(const WindowMetrics& metrics, float x, float y) if (v2 == nullptr) return; - // Look for common ancestor to v1 & v2 = split being draged. + // Look for common ancestor to v1 & v2 = split being dragged. View *p1 = v1; View *p2 = v2; while ((p1 = p1->parent) != nullptr ) @@ -192,7 +202,6 @@ ViewManager::tryStartResizing(const WindowMetrics& metrics, float x, float y) m_resizeSplit = p1; } - bool ViewManager::resizeViews(const WindowMetrics& metrics, float dx, float dy) { @@ -224,7 +233,6 @@ ViewManager::resizeViews(const WindowMetrics& metrics, float dx, float dy) return true; } - bool ViewManager::stopResizing() { @@ -235,7 +243,6 @@ ViewManager::stopResizing() return true; } - ViewSplitResult ViewManager::splitView(Simulation* sim, View::Type type, View* av, float splitPos) { @@ -248,12 +255,7 @@ ViewManager::splitView(Simulation* sim, View::Type type, View* av, float splitPo if (!av->isSplittable(type)) return ViewSplitResult::NotSplittable; - Observer* o = sim->addObserver(); - - // Make the new observer a copy of the old one - // TODO: This works, but an assignment operator for Observer - // should be defined. - *o = *(sim->getActiveObserver()); + Observer* o = sim->duplicateActiveObserver(); View* split; View* view; @@ -264,40 +266,37 @@ ViewManager::splitView(Simulation* sim, View::Type type, View* av, float splitPo return ViewSplitResult::Ok; } - void -ViewManager::singleView(Simulation* sim, View* av) +ViewManager::singleView(Simulation* sim, const View* av) { if (av == nullptr) av = *m_activeView; - auto it = m_views.begin(); - while(it != m_views.end()) - { - if (*it == av) - { - ++it; - continue; - } + auto start = m_views.begin(); + auto it = std::find(start, m_views.end(), av); + if (it == m_views.end()) + return; - sim->removeObserver((*it)->getObserver()); - delete (*it)->getObserver(); - delete (*it); - it = m_views.erase(it); - } + if (it != start) + std::iter_swap(start, it); - av->reset(); + ++start; + for (auto delIter = start; delIter != m_views.end(); ++delIter) + { + sim->removeObserver((*delIter)->getObserver()); + delete (*delIter)->getObserver(); + delete (*delIter); + } - if (m_views.empty()) - m_views.push_back(av); + m_views.resize(1); m_activeView = m_views.begin(); + (*m_activeView)->reset(); sim->setActiveObserver((*m_activeView)->observer); } - void -ViewManager::setActiveView(Simulation* sim, View* view) +ViewManager::setActiveView(Simulation* sim, const View* view) { auto it = std::find(m_views.begin(), m_views.end(), view); if (it == m_views.end()) @@ -307,7 +306,6 @@ ViewManager::setActiveView(Simulation* sim, View* view) sim->setActiveObserver((*m_activeView)->observer); } - bool ViewManager::deleteView(Simulation* sim, View* v) { @@ -318,13 +316,9 @@ ViewManager::deleteView(Simulation* sim, View* v) return false; //Erase view and parent view from views - for (auto i = m_views.begin(); i != m_views.end(); ) - { - if ((*i == v) || (*i == v->parent)) - i = m_views.erase(i); - else - ++i; - } + m_views.erase(std::remove_if(m_views.begin(), m_views.end(), + [v](const auto mv) { return mv == v || mv == v->parent; }), + m_views.end()); sim->removeObserver(v->getObserver()); delete(v->getObserver()); diff --git a/src/celestia/viewmanager.h b/src/celestia/viewmanager.h index e8fd68b4464..0e3597ee0bc 100644 --- a/src/celestia/viewmanager.h +++ b/src/celestia/viewmanager.h @@ -23,7 +23,6 @@ namespace celestia struct WindowMetrics; - enum class ViewBorderType { None, @@ -31,7 +30,6 @@ enum class ViewBorderType SizeVertical, }; - enum class ViewSplitResult { Ignored, @@ -39,7 +37,6 @@ enum class ViewSplitResult Ok, }; - class ViewManager { public: @@ -61,8 +58,8 @@ class ViewManager bool stopResizing(); ViewSplitResult splitView(Simulation*, View::Type, View*, float); - void singleView(Simulation*, View*); - void setActiveView(Simulation*, View*); + void singleView(Simulation*, const View*); + void setActiveView(Simulation*, const View*); bool deleteView(Simulation*, View*); private: