diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index 67b41da6..01ba5517 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -86,6 +86,7 @@ set(HDR_MAP source/scwx/qt/map/alert_layer.hpp source/scwx/qt/map/map_settings.hpp source/scwx/qt/map/map_widget.hpp source/scwx/qt/map/overlay_layer.hpp + source/scwx/qt/map/placefile_layer.hpp source/scwx/qt/map/radar_product_layer.hpp source/scwx/qt/map/radar_range_layer.hpp) set(SRC_MAP source/scwx/qt/map/alert_layer.cpp @@ -97,6 +98,7 @@ set(SRC_MAP source/scwx/qt/map/alert_layer.cpp source/scwx/qt/map/map_provider.cpp source/scwx/qt/map/map_widget.cpp source/scwx/qt/map/overlay_layer.cpp + source/scwx/qt/map/placefile_layer.cpp source/scwx/qt/map/radar_product_layer.cpp source/scwx/qt/map/radar_range_layer.cpp) set(HDR_MODEL source/scwx/qt/model/alert_model.hpp diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index cc35ef85..a59de3d5 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,7 @@ public: radarProductLayer_ {nullptr}, alertLayer_ {std::make_shared(context_)}, overlayLayer_ {nullptr}, + placefileLayer_ {nullptr}, colorTableLayer_ {nullptr}, autoRefreshEnabled_ {true}, autoUpdateEnabled_ {true}, @@ -147,6 +149,7 @@ public: std::shared_ptr radarProductLayer_; std::shared_ptr alertLayer_; std::shared_ptr overlayLayer_; + std::shared_ptr placefileLayer_; std::shared_ptr colorTableLayer_; bool autoRefreshEnabled_; @@ -698,6 +701,10 @@ void MapWidget::AddLayers() } p->alertLayer_->AddLayers("colorTable"); + + p->placefileLayer_ = std::make_shared(p->context_); + p->AddLayer("placefile", p->placefileLayer_); + p->overlayLayer_ = std::make_shared(p->context_); p->AddLayer("overlay", p->overlayLayer_); } diff --git a/scwx-qt/source/scwx/qt/map/placefile_layer.cpp b/scwx-qt/source/scwx/qt/map/placefile_layer.cpp new file mode 100644 index 00000000..76578e66 --- /dev/null +++ b/scwx-qt/source/scwx/qt/map/placefile_layer.cpp @@ -0,0 +1,104 @@ +#include +#include + +#include +#include + +namespace scwx +{ +namespace qt +{ +namespace map +{ + +static const std::string logPrefix_ = "scwx::qt::map::placefile_layer"; +static const auto logger_ = scwx::util::Logger::Create(logPrefix_); + +class PlacefileLayer::Impl +{ +public: + explicit Impl(std::shared_ptr context) {}; + ~Impl() = default; + + void RenderText(const std::string& text, + const std::string& hoverText, + boost::gil::rgba8_pixel_t color, + float x, + float y); + + std::uint32_t textId_ {}; +}; + +PlacefileLayer::PlacefileLayer(std::shared_ptr context) : + DrawLayer(context), p(std::make_unique(context)) +{ +} + +PlacefileLayer::~PlacefileLayer() = default; + +void PlacefileLayer::Initialize() +{ + logger_->debug("Initialize()"); + + DrawLayer::Initialize(); +} + +void PlacefileLayer::Impl::RenderText(const std::string& text, + const std::string& hoverText, + boost::gil::rgba8_pixel_t color, + float x, + float y) +{ + const std::string windowName {fmt::format("PlacefileText-{}", ++textId_)}; + + // Setup "window" to hold text + ImGui::SetNextWindowPos( + ImVec2 {x, y}, ImGuiCond_Always, ImVec2 {0.5f, 0.5f}); + ImGui::Begin(windowName.c_str(), + nullptr, + ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoNav | + ImGuiWindowFlags_NoBackground); + + // Render text + ImGui::PushStyleColor(ImGuiCol_Text, + IM_COL32(color[0], color[1], color[2], color[3])); + ImGui::TextUnformatted(text.c_str()); + ImGui::PopStyleColor(); + + // Create tooltip for hover text + if (!hoverText.empty() && ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::TextUnformatted(hoverText.c_str()); + ImGui::EndTooltip(); + } + + // End window + ImGui::End(); +} + +void PlacefileLayer::Render( + const QMapLibreGL::CustomLayerRenderParameters& params) +{ + gl::OpenGLFunctions& gl = context()->gl(); + + DrawLayer::Render(params); + + // Reset text ID per frame + p->textId_ = 0; + + // Render text + + SCWX_GL_CHECK_ERROR(); +} + +void PlacefileLayer::Deinitialize() +{ + logger_->debug("Deinitialize()"); + + DrawLayer::Deinitialize(); +} + +} // namespace map +} // namespace qt +} // namespace scwx diff --git a/scwx-qt/source/scwx/qt/map/placefile_layer.hpp b/scwx-qt/source/scwx/qt/map/placefile_layer.hpp new file mode 100644 index 00000000..9a293d38 --- /dev/null +++ b/scwx-qt/source/scwx/qt/map/placefile_layer.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include + +namespace scwx +{ +namespace qt +{ +namespace map +{ + +class PlacefileLayer : public DrawLayer +{ +public: + explicit PlacefileLayer(std::shared_ptr context); + ~PlacefileLayer(); + + void Initialize() override final; + void Render(const QMapLibreGL::CustomLayerRenderParameters&) override final; + void Deinitialize() override final; + +private: + class Impl; + std::unique_ptr p; +}; + +} // namespace map +} // namespace qt +} // namespace scwx