From 37d751774d237f7309ba303043cd5a76d20e790d Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sun, 27 Aug 2023 08:51:04 -0500 Subject: [PATCH] Move placefile text hover to mouse picking pass --- .../source/scwx/qt/gl/draw/placefile_text.cpp | 30 +++++++++++++++---- .../source/scwx/qt/gl/draw/placefile_text.hpp | 3 ++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp b/scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp index 082ee88e..99de2e87 100644 --- a/scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp +++ b/scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp @@ -55,6 +55,7 @@ public: float halfWidth_ {}; float halfHeight_ {}; ImFont* monospaceFont_ {}; + std::string hoverText_ {}; units::length::nautical_miles mapDistance_ {}; @@ -94,6 +95,7 @@ void PlacefileText::Render( { // Reset text ID per frame p->textId_ = 0; + p->hoverText_.clear(); // Update map screen coordinate and scale information p->mapScreenCoordLocation_ = util::maplibre::LatLongToScreenCoordinate( @@ -189,14 +191,10 @@ void PlacefileText::Impl::RenderText( ImGui::TextUnformatted(text.c_str()); ImGui::PopStyleColor(); - // Create tooltip for hover text + // Store hover text for mouse picking pass if (!hoverText.empty() && ImGui::IsItemHovered()) { - ImGui::BeginTooltip(); - ImGui::PushFont(monospaceFont_); - ImGui::TextUnformatted(hoverText.c_str()); - ImGui::PopFont(); - ImGui::EndTooltip(); + hoverText_ = hoverText; } // End window @@ -211,6 +209,26 @@ void PlacefileText::Deinitialize() p->textList_.clear(); } +bool PlacefileText::RunMousePicking( + const QMapLibreGL::CustomLayerRenderParameters& /* params */) +{ + bool itemPicked = false; + + // Create tooltip for hover text + if (!p->hoverText_.empty()) + { + itemPicked = true; + + ImGui::BeginTooltip(); + ImGui::PushFont(p->monospaceFont_); + ImGui::TextUnformatted(p->hoverText_.c_str()); + ImGui::PopFont(); + ImGui::EndTooltip(); + } + + return itemPicked; +} + void PlacefileText::StartText() { // Clear the new list diff --git a/scwx-qt/source/scwx/qt/gl/draw/placefile_text.hpp b/scwx-qt/source/scwx/qt/gl/draw/placefile_text.hpp index 58e22929..65c05905 100644 --- a/scwx-qt/source/scwx/qt/gl/draw/placefile_text.hpp +++ b/scwx-qt/source/scwx/qt/gl/draw/placefile_text.hpp @@ -33,6 +33,9 @@ public: void Render(const QMapLibreGL::CustomLayerRenderParameters& params) override; void Deinitialize() override; + bool RunMousePicking( + const QMapLibreGL::CustomLayerRenderParameters& params) override; + /** * Resets and prepares the draw item for adding a new set of text. */