From 6d107f6c2d57da163e1b93ee971362ce830dd284 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sat, 4 Jan 2025 13:49:31 -0500 Subject: [PATCH 1/8] Inital code for per map layer ImGui contexts --- scwx-qt/source/scwx/qt/map/draw_layer.cpp | 106 +++++++++++++++++- scwx-qt/source/scwx/qt/map/draw_layer.hpp | 5 + scwx-qt/source/scwx/qt/map/map_context.cpp | 20 ++++ scwx-qt/source/scwx/qt/map/map_context.hpp | 2 + scwx-qt/source/scwx/qt/map/map_widget.cpp | 25 +++-- scwx-qt/source/scwx/qt/map/overlay_layer.cpp | 6 +- .../source/scwx/qt/map/radar_site_layer.cpp | 4 + 7 files changed, 153 insertions(+), 15 deletions(-) diff --git a/scwx-qt/source/scwx/qt/map/draw_layer.cpp b/scwx-qt/source/scwx/qt/map/draw_layer.cpp index 7d03d13a..4dc24f89 100644 --- a/scwx-qt/source/scwx/qt/map/draw_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/draw_layer.cpp @@ -1,7 +1,14 @@ +#include #include +#include #include #include +#include +#include +#include +#include + namespace scwx { namespace qt @@ -16,18 +23,65 @@ class DrawLayerImpl { public: explicit DrawLayerImpl(std::shared_ptr context) : - context_ {context}, drawList_ {}, textureAtlas_ {GL_INVALID_INDEX} + context_ {context}, + drawList_ {}, + textureAtlas_ {GL_INVALID_INDEX}, + imGuiRendererInitialized_ {false} { + static size_t currentMapId_ {0u}; + imGuiContextName_ = fmt::format("Layer {}", ++currentMapId_); + imGuiContext_ = + model::ImGuiContextModel::Instance().CreateContext(imGuiContextName_); + + // Initialize ImGui Qt backend + ImGui_ImplQt_Init(); } - ~DrawLayerImpl() {} + ~DrawLayerImpl() + { + // Set ImGui Context + ImGui::SetCurrentContext(imGuiContext_); + + // Shutdown ImGui Context + if (imGuiRendererInitialized_) + { + ImGui_ImplOpenGL3_Shutdown(); + } + ImGui_ImplQt_Shutdown(); + + // Destroy ImGui Context + model::ImGuiContextModel::Instance().DestroyContext(imGuiContextName_); + } + + void ImGuiCheckFonts(); std::shared_ptr context_; std::vector> drawList_; GLuint textureAtlas_; std::uint64_t textureAtlasBuildCount_ {}; + + std::string imGuiContextName_; + ImGuiContext* imGuiContext_; + bool imGuiRendererInitialized_; + std::uint64_t imGuiFontsBuildCount_ {}; }; +void DrawLayerImpl::ImGuiCheckFonts() +{ + // Update ImGui Fonts if required + std::uint64_t currentImGuiFontsBuildCount = + manager::FontManager::Instance().imgui_fonts_build_count(); + + if (imGuiFontsBuildCount_ != currentImGuiFontsBuildCount || + !model::ImGuiContextModel::Instance().font_atlas()->IsBuilt()) + { + ImGui_ImplOpenGL3_DestroyFontsTexture(); + ImGui_ImplOpenGL3_CreateFontsTexture(); + } + + imGuiFontsBuildCount_ = currentImGuiFontsBuildCount; +} + DrawLayer::DrawLayer(const std::shared_ptr& context) : GenericLayer(context), p(std::make_unique(context)) { @@ -42,9 +96,48 @@ void DrawLayer::Initialize() { item->Initialize(); } + + ImGuiInitialize(); } -void DrawLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) +void DrawLayer::StartImGuiFrame() +{ + auto defaultFont = manager::FontManager::Instance().GetImGuiFont( + types::FontCategory::Default); + + // Setup ImGui Frame + ImGui::SetCurrentContext(p->imGuiContext_); + + // Start ImGui Frame + ImGui_ImplQt_NewFrame(p->context_->widget()); + ImGui_ImplOpenGL3_NewFrame(); + p->ImGuiCheckFonts(); + ImGui::NewFrame(); + ImGui::PushFont(defaultFont->font()); +} + +void DrawLayer::EndImGuiFrame() +{ + // Pop default font + ImGui::PopFont(); + + // Render ImGui Frame + ImGui::Render(); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); +} + +void DrawLayer::ImGuiInitialize() +{ + ImGui::SetCurrentContext(p->imGuiContext_); + ImGui_ImplQt_RegisterWidget(p->context_->widget()); + ImGui_ImplOpenGL3_Init(); + p->imGuiFontsBuildCount_ = + manager::FontManager::Instance().imgui_fonts_build_count(); + p->imGuiRendererInitialized_ = true; +} + +void DrawLayer::RenderWithoutImGui( + const QMapLibre::CustomLayerRenderParameters& params) { gl::OpenGLFunctions& gl = p->context_->gl(); p->textureAtlas_ = p->context_->GetTextureAtlas(); @@ -69,6 +162,13 @@ void DrawLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) p->textureAtlasBuildCount_ = newTextureAtlasBuildCount; } + void DrawLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) +{ + StartImGuiFrame(); + RenderWithoutImGui(params); + EndImGuiFrame(); +} + void DrawLayer::Deinitialize() { p->textureAtlas_ = GL_INVALID_INDEX; diff --git a/scwx-qt/source/scwx/qt/map/draw_layer.hpp b/scwx-qt/source/scwx/qt/map/draw_layer.hpp index 22dfa76c..416c4e7f 100644 --- a/scwx-qt/source/scwx/qt/map/draw_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/draw_layer.hpp @@ -32,6 +32,11 @@ public: protected: void AddDrawItem(const std::shared_ptr& drawItem); + void StartImGuiFrame(); + void EndImGuiFrame(); + void ImGuiInitialize(); + void + RenderWithoutImGui(const QMapLibre::CustomLayerRenderParameters& params); private: std::unique_ptr p; diff --git a/scwx-qt/source/scwx/qt/map/map_context.cpp b/scwx-qt/source/scwx/qt/map/map_context.cpp index 38a41e1f..7c0683d4 100644 --- a/scwx-qt/source/scwx/qt/map/map_context.cpp +++ b/scwx-qt/source/scwx/qt/map/map_context.cpp @@ -36,6 +36,8 @@ public: std::shared_ptr overlayProductView_ {nullptr}; std::shared_ptr radarProductView_; + + QWidget* widget_; }; MapContext::MapContext( @@ -109,6 +111,19 @@ int16_t MapContext::radar_product_code() const return p->radarProductCode_; } +<<<<<<< HEAD +======= +QMapLibre::CustomLayerRenderParameters MapContext::render_parameters() const +{ + return p->renderParameters_; +} + +QWidget* MapContext::widget() const +{ + return p->widget_; +} + +>>>>>>> 513a41d3 (Inital code for per map layer ImGui contexts) void MapContext::set_map(const std::shared_ptr& map) { p->map_ = map; @@ -167,6 +182,11 @@ void MapContext::set_radar_product_code(int16_t radarProductCode) p->radarProductCode_ = radarProductCode; } +void MapContext::set_widget(QWidget* widget) +{ + p->widget_ = widget; +} + } // namespace map } // namespace qt } // namespace scwx diff --git a/scwx-qt/source/scwx/qt/map/map_context.hpp b/scwx-qt/source/scwx/qt/map/map_context.hpp index 59fb8a5b..8e79b028 100644 --- a/scwx-qt/source/scwx/qt/map/map_context.hpp +++ b/scwx-qt/source/scwx/qt/map/map_context.hpp @@ -50,6 +50,7 @@ public: common::RadarProductGroup radar_product_group() const; std::string radar_product() const; int16_t radar_product_code() const; + QWidget* widget() const; void set_map(const std::shared_ptr& map); void set_map_copyrights(const std::string& copyrights); @@ -64,6 +65,7 @@ public: void set_radar_product_group(common::RadarProductGroup radarProductGroup); void set_radar_product(const std::string& radarProduct); void set_radar_product_code(int16_t radarProductCode); + void set_widget(QWidget* widget); private: class Impl; diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index 466a03fe..2f801f00 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -114,6 +114,7 @@ public: context_->set_map_provider( GetMapProvider(generalSettings.map_provider().GetValue())); context_->set_overlay_product_view(overlayProductView); + context_->set_widget(widget); // Initialize map data SetRadarSite(generalSettings.default_radar_site().GetValue()); @@ -1571,21 +1572,10 @@ void MapWidget::paintGL() // Handle hotkey updates p->HandleHotkeyUpdates(); - // Setup ImGui Frame - ImGui::SetCurrentContext(p->imGuiContext_); - // Lock ImGui font atlas prior to new ImGui frame std::shared_lock imguiFontAtlasLock { manager::FontManager::Instance().imgui_font_atlas_mutex()}; - // Start ImGui Frame - ImGui_ImplQt_NewFrame(this); - ImGui_ImplOpenGL3_NewFrame(); - p->ImGuiCheckFonts(); - ImGui::NewFrame(); - - // Set default font - ImGui::PushFont(defaultFont->font()); // Update pixel ratio p->context_->set_pixel_ratio(pixelRatio()); @@ -1596,6 +1586,19 @@ void MapWidget::paintGL() size() * pixelRatio()); p->map_->render(); + // ImGui tool tip code + // Setup ImGui Frame + ImGui::SetCurrentContext(p->imGuiContext_); + + // Start ImGui Frame + ImGui_ImplQt_NewFrame(this); + ImGui_ImplOpenGL3_NewFrame(); + p->ImGuiCheckFonts(); + ImGui::NewFrame(); + + // Set default font + ImGui::PushFont(defaultFont->font()); + // Perform mouse picking if (p->hasMouse_) { diff --git a/scwx-qt/source/scwx/qt/map/overlay_layer.cpp b/scwx-qt/source/scwx/qt/map/overlay_layer.cpp index da82ef7f..1f7110a2 100644 --- a/scwx-qt/source/scwx/qt/map/overlay_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/overlay_layer.cpp @@ -292,6 +292,8 @@ void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) auto& settings = context()->settings(); const float pixelRatio = context()->pixel_ratio(); + StartImGuiFrame(); + p->sweepTimePicked_ = false; if (radarProductView != nullptr) @@ -457,7 +459,7 @@ void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) p->icons_->SetIconVisible(p->mapLogoIcon_, generalSettings.show_map_logo().GetValue()); - DrawLayer::Render(params); + DrawLayer::RenderWithoutImGui(params); auto mapCopyrights = context()->map_copyrights(); if (mapCopyrights.length() > 0 && @@ -491,6 +493,8 @@ void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) p->lastFontSize_ = ImGui::GetFontSize(); p->lastColorTableMargins_ = colorTableMargins; + EndImGuiFrame(); + SCWX_GL_CHECK_ERROR(); } diff --git a/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp b/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp index d2fd7547..431af597 100644 --- a/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp @@ -55,6 +55,8 @@ void RadarSiteLayer::Initialize() logger_->debug("Initialize()"); p->radarSites_ = config::RadarSite::GetAll(); + + ImGuiInitialize(); } void RadarSiteLayer::Render( @@ -84,6 +86,7 @@ void RadarSiteLayer::Render( p->halfWidth_ = params.width * 0.5f; p->halfHeight_ = params.height * 0.5f; + StartImGuiFrame(); // Radar site ImGui windows shouldn't have padding ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2 {0.0f, 0.0f}); @@ -93,6 +96,7 @@ void RadarSiteLayer::Render( } ImGui::PopStyleVar(); + EndImGuiFrame(); SCWX_GL_CHECK_ERROR(); } From 9bd5af03f9dff370a34bbc919efd78a4f36a242f Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Mon, 6 Jan 2025 08:57:55 -0500 Subject: [PATCH 2/8] fix crash when selecting radar site with new ImGui contexts --- scwx-qt/source/scwx/qt/map/draw_layer.cpp | 6 +++++- scwx-qt/source/scwx/qt/map/draw_layer.hpp | 1 + scwx-qt/source/scwx/qt/map/radar_site_layer.cpp | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/scwx-qt/source/scwx/qt/map/draw_layer.cpp b/scwx-qt/source/scwx/qt/map/draw_layer.cpp index 4dc24f89..9588a160 100644 --- a/scwx-qt/source/scwx/qt/map/draw_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/draw_layer.cpp @@ -161,8 +161,12 @@ void DrawLayer::RenderWithoutImGui( p->textureAtlasBuildCount_ = newTextureAtlasBuildCount; } +void DrawLayer::ImGuiSelectContext() +{ + ImGui::SetCurrentContext(p->imGuiContext_); +} - void DrawLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) +void DrawLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) { StartImGuiFrame(); RenderWithoutImGui(params); diff --git a/scwx-qt/source/scwx/qt/map/draw_layer.hpp b/scwx-qt/source/scwx/qt/map/draw_layer.hpp index 416c4e7f..a6fd685a 100644 --- a/scwx-qt/source/scwx/qt/map/draw_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/draw_layer.hpp @@ -37,6 +37,7 @@ protected: void ImGuiInitialize(); void RenderWithoutImGui(const QMapLibre::CustomLayerRenderParameters& params); + void ImGuiSelectContext(); private: std::unique_ptr p; diff --git a/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp b/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp index 431af597..7398ab36 100644 --- a/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp @@ -140,6 +140,7 @@ void RadarSiteLayer::Impl::RenderRadarSite( if (ImGui::Button(radarSite->id().c_str())) { Q_EMIT self_->RadarSiteSelected(radarSite->id()); + self_->ImGuiSelectContext(); } // Store hover text for mouse picking pass From c6596b3e7d287e58bafdfa03afae2a9220daf7e7 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Sat, 18 Jan 2025 09:45:24 -0500 Subject: [PATCH 3/8] Move ImGuiCheckFonts back to only being called in map_widget (lock makes this safe) --- scwx-qt/source/scwx/qt/map/draw_layer.cpp | 29 +++-------------------- scwx-qt/source/scwx/qt/map/map_widget.cpp | 4 +++- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/scwx-qt/source/scwx/qt/map/draw_layer.cpp b/scwx-qt/source/scwx/qt/map/draw_layer.cpp index 9588a160..a0ad64e6 100644 --- a/scwx-qt/source/scwx/qt/map/draw_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/draw_layer.cpp @@ -25,8 +25,7 @@ public: explicit DrawLayerImpl(std::shared_ptr context) : context_ {context}, drawList_ {}, - textureAtlas_ {GL_INVALID_INDEX}, - imGuiRendererInitialized_ {false} + textureAtlas_ {GL_INVALID_INDEX} { static size_t currentMapId_ {0u}; imGuiContextName_ = fmt::format("Layer {}", ++currentMapId_); @@ -52,36 +51,17 @@ public: model::ImGuiContextModel::Instance().DestroyContext(imGuiContextName_); } - void ImGuiCheckFonts(); - std::shared_ptr context_; std::vector> drawList_; GLuint textureAtlas_; std::uint64_t textureAtlasBuildCount_ {}; - std::string imGuiContextName_; + std::string imGuiContextName_; ImGuiContext* imGuiContext_; - bool imGuiRendererInitialized_; - std::uint64_t imGuiFontsBuildCount_ {}; + bool imGuiRendererInitialized_{}; }; -void DrawLayerImpl::ImGuiCheckFonts() -{ - // Update ImGui Fonts if required - std::uint64_t currentImGuiFontsBuildCount = - manager::FontManager::Instance().imgui_fonts_build_count(); - - if (imGuiFontsBuildCount_ != currentImGuiFontsBuildCount || - !model::ImGuiContextModel::Instance().font_atlas()->IsBuilt()) - { - ImGui_ImplOpenGL3_DestroyFontsTexture(); - ImGui_ImplOpenGL3_CreateFontsTexture(); - } - - imGuiFontsBuildCount_ = currentImGuiFontsBuildCount; -} - DrawLayer::DrawLayer(const std::shared_ptr& context) : GenericLayer(context), p(std::make_unique(context)) { @@ -111,7 +91,6 @@ void DrawLayer::StartImGuiFrame() // Start ImGui Frame ImGui_ImplQt_NewFrame(p->context_->widget()); ImGui_ImplOpenGL3_NewFrame(); - p->ImGuiCheckFonts(); ImGui::NewFrame(); ImGui::PushFont(defaultFont->font()); } @@ -131,8 +110,6 @@ void DrawLayer::ImGuiInitialize() ImGui::SetCurrentContext(p->imGuiContext_); ImGui_ImplQt_RegisterWidget(p->context_->widget()); ImGui_ImplOpenGL3_Init(); - p->imGuiFontsBuildCount_ = - manager::FontManager::Instance().imgui_fonts_build_count(); p->imGuiRendererInitialized_ = true; } diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index 2f801f00..f2599579 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -1576,6 +1576,9 @@ void MapWidget::paintGL() std::shared_lock imguiFontAtlasLock { manager::FontManager::Instance().imgui_font_atlas_mutex()}; + // Check ImGui fonts + ImGui::SetCurrentContext(p->imGuiContext_); + p->ImGuiCheckFonts(); // Update pixel ratio p->context_->set_pixel_ratio(pixelRatio()); @@ -1593,7 +1596,6 @@ void MapWidget::paintGL() // Start ImGui Frame ImGui_ImplQt_NewFrame(this); ImGui_ImplOpenGL3_NewFrame(); - p->ImGuiCheckFonts(); ImGui::NewFrame(); // Set default font From a9daf47741c8e26617202af7b0ebd64645ca0685 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Tue, 21 Jan 2025 10:56:43 -0500 Subject: [PATCH 4/8] add support for opentype fonts --- .../source/scwx/qt/manager/font_manager.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/scwx-qt/source/scwx/qt/manager/font_manager.cpp b/scwx-qt/source/scwx/qt/manager/font_manager.cpp index 89a1643f..4f5ad99f 100644 --- a/scwx-qt/source/scwx/qt/manager/font_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/font_manager.cpp @@ -29,6 +29,7 @@ static const std::string logPrefix_ = "scwx::qt::manager::font_manager"; static const auto logger_ = scwx::util::Logger::Create(logPrefix_); static const std::string kFcTrueType_ {"TrueType"}; +static const std::string kFcOpenType_ {"CFF"}; struct FontRecord { @@ -70,6 +71,7 @@ public: const std::vector& GetRawFontData(const std::string& filename); + static bool CheckFontFormat(const FcChar8* format); static FontRecord MatchFontFile(const std::string& family, const std::vector& styles); @@ -457,6 +459,13 @@ void FontManager::Impl::FinalizeFontconfig() FcFini(); } +bool FontManager::Impl::CheckFontFormat(const FcChar8* format) +{ + const std::string stdFormat = reinterpret_cast(format); + + return stdFormat == kFcTrueType_ || stdFormat == kFcOpenType_; +} + FontRecord FontManager::Impl::MatchFontFile(const std::string& family, const std::vector& styles) @@ -469,9 +478,6 @@ FontManager::Impl::MatchFontFile(const std::string& family, FcPatternAddString( pattern, FC_FAMILY, reinterpret_cast(family.c_str())); - FcPatternAddString(pattern, - FC_FONTFORMAT, - reinterpret_cast(kFcTrueType_.c_str())); FcPatternAddBool(pattern, FC_SYMBOL, FcFalse); if (!styles.empty()) @@ -505,6 +511,7 @@ FontManager::Impl::MatchFontFile(const std::string& family, FcChar8* fcFamily = nullptr; FcChar8* fcStyle = nullptr; FcChar8* fcFile = nullptr; + FcChar8* fcFormat = nullptr; FcBool fcSymbol = FcFalse; // Match was found, get properties @@ -515,7 +522,10 @@ FontManager::Impl::MatchFontFile(const std::string& family, FcPatternGetString(match, FC_FILE, 0, &fcFile) == FcResultMatch && FcPatternGetBool(match, FC_SYMBOL, 0, &fcSymbol) == FcResultMatch && - fcSymbol == FcFalse /*Must check fcSymbol manually*/) + FcPatternGetString(match, FC_FONTFORMAT, 0, &fcFormat) == + FcResultMatch && + fcSymbol == FcFalse /*Must check fcSymbol manually*/ && + CheckFontFormat(fcFormat)) { record.family_ = reinterpret_cast(fcFamily); record.style_ = reinterpret_cast(fcStyle); From c139b156ee73defa472d6804d3f437d683002d39 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Fri, 24 Jan 2025 12:37:44 -0500 Subject: [PATCH 5/8] Make naming more consistent for some ImGui DrawLayer Functions --- scwx-qt/source/scwx/qt/map/draw_layer.cpp | 8 ++++---- scwx-qt/source/scwx/qt/map/draw_layer.hpp | 4 ++-- scwx-qt/source/scwx/qt/map/overlay_layer.cpp | 4 ++-- scwx-qt/source/scwx/qt/map/radar_site_layer.cpp | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scwx-qt/source/scwx/qt/map/draw_layer.cpp b/scwx-qt/source/scwx/qt/map/draw_layer.cpp index a0ad64e6..91dace1c 100644 --- a/scwx-qt/source/scwx/qt/map/draw_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/draw_layer.cpp @@ -80,7 +80,7 @@ void DrawLayer::Initialize() ImGuiInitialize(); } -void DrawLayer::StartImGuiFrame() +void DrawLayer::ImGuiFrameStart() { auto defaultFont = manager::FontManager::Instance().GetImGuiFont( types::FontCategory::Default); @@ -95,7 +95,7 @@ void DrawLayer::StartImGuiFrame() ImGui::PushFont(defaultFont->font()); } -void DrawLayer::EndImGuiFrame() +void DrawLayer::ImGuiFrameEnd() { // Pop default font ImGui::PopFont(); @@ -145,9 +145,9 @@ void DrawLayer::ImGuiSelectContext() void DrawLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) { - StartImGuiFrame(); + ImGuiFrameStart(); RenderWithoutImGui(params); - EndImGuiFrame(); + ImGuiFrameEnd(); } void DrawLayer::Deinitialize() diff --git a/scwx-qt/source/scwx/qt/map/draw_layer.hpp b/scwx-qt/source/scwx/qt/map/draw_layer.hpp index a6fd685a..8bfe8a5d 100644 --- a/scwx-qt/source/scwx/qt/map/draw_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/draw_layer.hpp @@ -32,8 +32,8 @@ public: protected: void AddDrawItem(const std::shared_ptr& drawItem); - void StartImGuiFrame(); - void EndImGuiFrame(); + void ImGuiFrameStart(); + void ImGuiFrameEnd(); void ImGuiInitialize(); void RenderWithoutImGui(const QMapLibre::CustomLayerRenderParameters& params); diff --git a/scwx-qt/source/scwx/qt/map/overlay_layer.cpp b/scwx-qt/source/scwx/qt/map/overlay_layer.cpp index 1f7110a2..53557222 100644 --- a/scwx-qt/source/scwx/qt/map/overlay_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/overlay_layer.cpp @@ -292,7 +292,7 @@ void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) auto& settings = context()->settings(); const float pixelRatio = context()->pixel_ratio(); - StartImGuiFrame(); + ImGuiFrameStart(); p->sweepTimePicked_ = false; @@ -493,7 +493,7 @@ void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) p->lastFontSize_ = ImGui::GetFontSize(); p->lastColorTableMargins_ = colorTableMargins; - EndImGuiFrame(); + ImGuiFrameEnd(); SCWX_GL_CHECK_ERROR(); } diff --git a/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp b/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp index 7398ab36..1cb5e222 100644 --- a/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp @@ -86,7 +86,7 @@ void RadarSiteLayer::Render( p->halfWidth_ = params.width * 0.5f; p->halfHeight_ = params.height * 0.5f; - StartImGuiFrame(); + ImGuiFrameStart(); // Radar site ImGui windows shouldn't have padding ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2 {0.0f, 0.0f}); @@ -96,7 +96,7 @@ void RadarSiteLayer::Render( } ImGui::PopStyleVar(); - EndImGuiFrame(); + ImGuiFrameEnd(); SCWX_GL_CHECK_ERROR(); } From ab682567c69a4788524ae0ab605a62473283cce5 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Mon, 3 Mar 2025 10:24:41 -0500 Subject: [PATCH 6/8] Fix merge conflict during rebasing of rework_layer_text --- scwx-qt/source/scwx/qt/map/map_context.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/scwx-qt/source/scwx/qt/map/map_context.cpp b/scwx-qt/source/scwx/qt/map/map_context.cpp index 7c0683d4..46c2b6fa 100644 --- a/scwx-qt/source/scwx/qt/map/map_context.cpp +++ b/scwx-qt/source/scwx/qt/map/map_context.cpp @@ -111,19 +111,11 @@ int16_t MapContext::radar_product_code() const return p->radarProductCode_; } -<<<<<<< HEAD -======= -QMapLibre::CustomLayerRenderParameters MapContext::render_parameters() const -{ - return p->renderParameters_; -} - QWidget* MapContext::widget() const { return p->widget_; } ->>>>>>> 513a41d3 (Inital code for per map layer ImGui contexts) void MapContext::set_map(const std::shared_ptr& map) { p->map_ = map; From ec296d98eb1d3e313bdc4b48ba19a2f4ddf86035 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Mon, 3 Mar 2025 10:52:39 -0500 Subject: [PATCH 7/8] clang format/tidy fixes for rework_layer_text --- .../source/scwx/qt/manager/font_manager.cpp | 4 +- scwx-qt/source/scwx/qt/map/draw_layer.cpp | 43 ++++++++++--------- scwx-qt/source/scwx/qt/map/map_context.hpp | 2 +- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/scwx-qt/source/scwx/qt/manager/font_manager.cpp b/scwx-qt/source/scwx/qt/manager/font_manager.cpp index 4f5ad99f..d92d3bd7 100644 --- a/scwx-qt/source/scwx/qt/manager/font_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/font_manager.cpp @@ -71,7 +71,7 @@ public: const std::vector& GetRawFontData(const std::string& filename); - static bool CheckFontFormat(const FcChar8* format); + static bool CheckFontFormat(const FcChar8* format); static FontRecord MatchFontFile(const std::string& family, const std::vector& styles); @@ -461,7 +461,7 @@ void FontManager::Impl::FinalizeFontconfig() bool FontManager::Impl::CheckFontFormat(const FcChar8* format) { - const std::string stdFormat = reinterpret_cast(format); + const std::string stdFormat = reinterpret_cast(format); return stdFormat == kFcTrueType_ || stdFormat == kFcOpenType_; } diff --git a/scwx-qt/source/scwx/qt/map/draw_layer.cpp b/scwx-qt/source/scwx/qt/map/draw_layer.cpp index 91dace1c..c39b9f4c 100644 --- a/scwx-qt/source/scwx/qt/map/draw_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/draw_layer.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -6,14 +7,11 @@ #include #include +#include #include #include -namespace scwx -{ -namespace qt -{ -namespace map +namespace scwx::qt::map { static const std::string logPrefix_ = "scwx::qt::map::draw_layer"; @@ -23,13 +21,13 @@ class DrawLayerImpl { public: explicit DrawLayerImpl(std::shared_ptr context) : - context_ {context}, - drawList_ {}, - textureAtlas_ {GL_INVALID_INDEX} + context_ {std::move(context)}, drawList_ {} { static size_t currentMapId_ {0u}; imGuiContextName_ = fmt::format("Layer {}", ++currentMapId_); - imGuiContext_ = + // This must be initialized after the last line + // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer) + imGuiContext_ = model::ImGuiContextModel::Instance().CreateContext(imGuiContextName_); // Initialize ImGui Qt backend @@ -51,15 +49,20 @@ public: model::ImGuiContextModel::Instance().DestroyContext(imGuiContextName_); } + DrawLayerImpl(const DrawLayerImpl&) = delete; + DrawLayerImpl& operator=(const DrawLayerImpl&) = delete; + DrawLayerImpl(const DrawLayerImpl&&) = delete; + DrawLayerImpl& operator=(const DrawLayerImpl&&) = delete; + std::shared_ptr context_; std::vector> drawList_; - GLuint textureAtlas_; + GLuint textureAtlas_ {GL_INVALID_INDEX}; std::uint64_t textureAtlasBuildCount_ {}; std::string imGuiContextName_; ImGuiContext* imGuiContext_; - bool imGuiRendererInitialized_{}; + bool imGuiRendererInitialized_ {}; }; DrawLayer::DrawLayer(const std::shared_ptr& context) : @@ -171,15 +174,15 @@ bool DrawLayer::RunMousePicking( bool itemPicked = false; // For each draw item in the draw list in reverse - for (auto it = p->drawList_.rbegin(); it != p->drawList_.rend(); ++it) + for (auto& it : std::ranges::reverse_view(p->drawList_)) { // Run mouse picking on each draw item - if ((*it)->RunMousePicking(params, - mouseLocalPos, - mouseGlobalPos, - mouseCoords, - mouseGeoCoords, - eventHandler)) + if (it->RunMousePicking(params, + mouseLocalPos, + mouseGlobalPos, + mouseCoords, + mouseGeoCoords, + eventHandler)) { // If a draw item was picked, don't process additional items itemPicked = true; @@ -195,6 +198,4 @@ void DrawLayer::AddDrawItem(const std::shared_ptr& drawItem) p->drawList_.push_back(drawItem); } -} // namespace map -} // namespace qt -} // namespace scwx +} // namespace scwx::qt::map diff --git a/scwx-qt/source/scwx/qt/map/map_context.hpp b/scwx-qt/source/scwx/qt/map/map_context.hpp index 8e79b028..57640263 100644 --- a/scwx-qt/source/scwx/qt/map/map_context.hpp +++ b/scwx-qt/source/scwx/qt/map/map_context.hpp @@ -50,7 +50,7 @@ public: common::RadarProductGroup radar_product_group() const; std::string radar_product() const; int16_t radar_product_code() const; - QWidget* widget() const; + [[nodiscard]] QWidget* widget() const; void set_map(const std::shared_ptr& map); void set_map_copyrights(const std::string& copyrights); From 2be140d29117ec9da09382396fc6cead61ee43f5 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Wed, 19 Mar 2025 14:14:43 -0400 Subject: [PATCH 8/8] Use layer names in ImGui Context names --- scwx-qt/source/scwx/qt/map/alert_layer.cpp | 5 +++- scwx-qt/source/scwx/qt/map/draw_layer.cpp | 14 ++++++---- scwx-qt/source/scwx/qt/map/draw_layer.hpp | 3 +- scwx-qt/source/scwx/qt/map/map_context.hpp | 28 ++++++++++--------- scwx-qt/source/scwx/qt/map/marker_layer.cpp | 3 +- scwx-qt/source/scwx/qt/map/overlay_layer.cpp | 3 +- .../scwx/qt/map/overlay_product_layer.cpp | 3 +- .../source/scwx/qt/map/placefile_layer.cpp | 2 +- .../source/scwx/qt/map/radar_site_layer.cpp | 2 +- 9 files changed, 38 insertions(+), 25 deletions(-) diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.cpp b/scwx-qt/source/scwx/qt/map/alert_layer.cpp index c88f6220..7c5c9db2 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.cpp @@ -229,7 +229,10 @@ public: AlertLayer::AlertLayer(std::shared_ptr context, awips::Phenomenon phenomenon) : - DrawLayer(context), p(std::make_unique(this, context, phenomenon)) + DrawLayer( + context, + fmt::format("AlertLayer {}", awips::GetPhenomenonText(phenomenon))), + p(std::make_unique(this, context, phenomenon)) { for (auto alertActive : {false, true}) { diff --git a/scwx-qt/source/scwx/qt/map/draw_layer.cpp b/scwx-qt/source/scwx/qt/map/draw_layer.cpp index c39b9f4c..13d06780 100644 --- a/scwx-qt/source/scwx/qt/map/draw_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/draw_layer.cpp @@ -20,11 +20,13 @@ static const auto logger_ = scwx::util::Logger::Create(logPrefix_); class DrawLayerImpl { public: - explicit DrawLayerImpl(std::shared_ptr context) : + explicit DrawLayerImpl(std::shared_ptr context, + const std::string& imGuiContextName) : context_ {std::move(context)}, drawList_ {} { - static size_t currentMapId_ {0u}; - imGuiContextName_ = fmt::format("Layer {}", ++currentMapId_); + static size_t currentLayerId_ {0u}; + imGuiContextName_ = + fmt::format("{} {}", imGuiContextName, ++currentLayerId_); // This must be initialized after the last line // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer) imGuiContext_ = @@ -65,8 +67,10 @@ public: bool imGuiRendererInitialized_ {}; }; -DrawLayer::DrawLayer(const std::shared_ptr& context) : - GenericLayer(context), p(std::make_unique(context)) +DrawLayer::DrawLayer(const std::shared_ptr& context, + const std::string& imGuiContextName) : + GenericLayer(context), + p(std::make_unique(context, imGuiContextName)) { } DrawLayer::~DrawLayer() = default; diff --git a/scwx-qt/source/scwx/qt/map/draw_layer.hpp b/scwx-qt/source/scwx/qt/map/draw_layer.hpp index 8bfe8a5d..6cfa5aae 100644 --- a/scwx-qt/source/scwx/qt/map/draw_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/draw_layer.hpp @@ -15,7 +15,8 @@ class DrawLayerImpl; class DrawLayer : public GenericLayer { public: - explicit DrawLayer(const std::shared_ptr& context); + explicit DrawLayer(const std::shared_ptr& context, + const std::string& imGuiContextName); virtual ~DrawLayer(); virtual void Initialize() override; diff --git a/scwx-qt/source/scwx/qt/map/map_context.hpp b/scwx-qt/source/scwx/qt/map/map_context.hpp index 57640263..680f9ddd 100644 --- a/scwx-qt/source/scwx/qt/map/map_context.hpp +++ b/scwx-qt/source/scwx/qt/map/map_context.hpp @@ -38,19 +38,21 @@ public: MapContext(MapContext&&) noexcept; MapContext& operator=(MapContext&&) noexcept; - std::weak_ptr map() const; - std::string map_copyrights() const; - MapProvider map_provider() const; - MapSettings& settings(); - QMargins color_table_margins() const; - float pixel_ratio() const; - common::Coordinate mouse_coordinate() const; - std::shared_ptr overlay_product_view() const; - std::shared_ptr radar_product_view() const; - common::RadarProductGroup radar_product_group() const; - std::string radar_product() const; - int16_t radar_product_code() const; - [[nodiscard]] QWidget* widget() const; + [[nodiscard]] std::weak_ptr map() const; + [[nodiscard]] std::string map_copyrights() const; + [[nodiscard]] MapProvider map_provider() const; + [[nodiscard]] MapSettings& settings(); + [[nodiscard]] QMargins color_table_margins() const; + [[nodiscard]] float pixel_ratio() const; + [[nodiscard]] common::Coordinate mouse_coordinate() const; + [[nodiscard]] std::shared_ptr + overlay_product_view() const; + [[nodiscard]] std::shared_ptr + radar_product_view() const; + [[nodiscard]] common::RadarProductGroup radar_product_group() const; + [[nodiscard]] std::string radar_product() const; + [[nodiscard]] int16_t radar_product_code() const; + [[nodiscard]] QWidget* widget() const; void set_map(const std::shared_ptr& map); void set_map_copyrights(const std::string& copyrights); diff --git a/scwx-qt/source/scwx/qt/map/marker_layer.cpp b/scwx-qt/source/scwx/qt/map/marker_layer.cpp index 39e43a57..aec23f84 100644 --- a/scwx-qt/source/scwx/qt/map/marker_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/marker_layer.cpp @@ -129,7 +129,8 @@ void MarkerLayer::Impl::ReloadMarkers() } MarkerLayer::MarkerLayer(const std::shared_ptr& context) : - DrawLayer(context), p(std::make_unique(this, context)) + DrawLayer(context, "MarkerLayer"), + p(std::make_unique(this, context)) { AddDrawItem(p->geoIcons_); } diff --git a/scwx-qt/source/scwx/qt/map/overlay_layer.cpp b/scwx-qt/source/scwx/qt/map/overlay_layer.cpp index 53557222..3522ba40 100644 --- a/scwx-qt/source/scwx/qt/map/overlay_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/overlay_layer.cpp @@ -143,7 +143,8 @@ public: }; OverlayLayer::OverlayLayer(std::shared_ptr context) : - DrawLayer(context), p(std::make_unique(this, context)) + DrawLayer(context, "OverlayLayer"), + p(std::make_unique(this, context)) { AddDrawItem(p->activeBoxOuter_); AddDrawItem(p->activeBoxInner_); diff --git a/scwx-qt/source/scwx/qt/map/overlay_product_layer.cpp b/scwx-qt/source/scwx/qt/map/overlay_product_layer.cpp index 64745fd5..76eeaa8b 100644 --- a/scwx-qt/source/scwx/qt/map/overlay_product_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/overlay_product_layer.cpp @@ -109,7 +109,8 @@ public: }; OverlayProductLayer::OverlayProductLayer(std::shared_ptr context) : - DrawLayer(context), p(std::make_unique(this, context)) + DrawLayer(context, "OverlayProductLayer"), + p(std::make_unique(this, context)) { auto overlayProductView = context->overlay_product_view(); connect(overlayProductView.get(), diff --git a/scwx-qt/source/scwx/qt/map/placefile_layer.cpp b/scwx-qt/source/scwx/qt/map/placefile_layer.cpp index be2d9a18..df9828eb 100644 --- a/scwx-qt/source/scwx/qt/map/placefile_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/placefile_layer.cpp @@ -66,7 +66,7 @@ public: PlacefileLayer::PlacefileLayer(const std::shared_ptr& context, const std::string& placefileName) : - DrawLayer(context), + DrawLayer(context, fmt::format("PlacefileLayer {}", placefileName)), p(std::make_unique(this, context, placefileName)) { AddDrawItem(p->placefileImages_); diff --git a/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp b/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp index 1cb5e222..65b53f14 100644 --- a/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/radar_site_layer.cpp @@ -44,7 +44,7 @@ public: }; RadarSiteLayer::RadarSiteLayer(std::shared_ptr context) : - DrawLayer(context), p(std::make_unique(this)) + DrawLayer(context, "RadarSiteLayer"), p(std::make_unique(this)) { }