mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 20:10:04 +00:00 
			
		
		
		
	Add placefile layer with text rendering
This commit is contained in:
		
							parent
							
								
									bfe62301b2
								
							
						
					
					
						commit
						1a411af3bc
					
				
					 4 changed files with 142 additions and 0 deletions
				
			
		|  | @ -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 | ||||
|  |  | |||
|  | @ -7,6 +7,7 @@ | |||
| #include <scwx/qt/map/layer_wrapper.hpp> | ||||
| #include <scwx/qt/map/map_provider.hpp> | ||||
| #include <scwx/qt/map/overlay_layer.hpp> | ||||
| #include <scwx/qt/map/placefile_layer.hpp> | ||||
| #include <scwx/qt/map/radar_product_layer.hpp> | ||||
| #include <scwx/qt/map/radar_range_layer.hpp> | ||||
| #include <scwx/qt/model/imgui_context_model.hpp> | ||||
|  | @ -61,6 +62,7 @@ public: | |||
|        radarProductLayer_ {nullptr}, | ||||
|        alertLayer_ {std::make_shared<AlertLayer>(context_)}, | ||||
|        overlayLayer_ {nullptr}, | ||||
|        placefileLayer_ {nullptr}, | ||||
|        colorTableLayer_ {nullptr}, | ||||
|        autoRefreshEnabled_ {true}, | ||||
|        autoUpdateEnabled_ {true}, | ||||
|  | @ -147,6 +149,7 @@ public: | |||
|    std::shared_ptr<RadarProductLayer> radarProductLayer_; | ||||
|    std::shared_ptr<AlertLayer>        alertLayer_; | ||||
|    std::shared_ptr<OverlayLayer>      overlayLayer_; | ||||
|    std::shared_ptr<PlacefileLayer>    placefileLayer_; | ||||
|    std::shared_ptr<ColorTableLayer>   colorTableLayer_; | ||||
| 
 | ||||
|    bool autoRefreshEnabled_; | ||||
|  | @ -698,6 +701,10 @@ void MapWidget::AddLayers() | |||
|    } | ||||
| 
 | ||||
|    p->alertLayer_->AddLayers("colorTable"); | ||||
| 
 | ||||
|    p->placefileLayer_ = std::make_shared<PlacefileLayer>(p->context_); | ||||
|    p->AddLayer("placefile", p->placefileLayer_); | ||||
| 
 | ||||
|    p->overlayLayer_ = std::make_shared<OverlayLayer>(p->context_); | ||||
|    p->AddLayer("overlay", p->overlayLayer_); | ||||
| } | ||||
|  |  | |||
							
								
								
									
										104
									
								
								scwx-qt/source/scwx/qt/map/placefile_layer.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								scwx-qt/source/scwx/qt/map/placefile_layer.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,104 @@ | |||
| #include <scwx/qt/map/placefile_layer.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <fmt/format.h> | ||||
| #include <imgui.h> | ||||
| 
 | ||||
| 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<MapContext> 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<MapContext> context) : | ||||
|     DrawLayer(context), p(std::make_unique<PlacefileLayer::Impl>(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
 | ||||
							
								
								
									
										29
									
								
								scwx-qt/source/scwx/qt/map/placefile_layer.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								scwx-qt/source/scwx/qt/map/placefile_layer.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,29 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <scwx/qt/map/draw_layer.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace map | ||||
| { | ||||
| 
 | ||||
| class PlacefileLayer : public DrawLayer | ||||
| { | ||||
| public: | ||||
|    explicit PlacefileLayer(std::shared_ptr<MapContext> context); | ||||
|    ~PlacefileLayer(); | ||||
| 
 | ||||
|    void Initialize() override final; | ||||
|    void Render(const QMapLibreGL::CustomLayerRenderParameters&) override final; | ||||
|    void Deinitialize() override final; | ||||
| 
 | ||||
| private: | ||||
|    class Impl; | ||||
|    std::unique_ptr<Impl> p; | ||||
| }; | ||||
| 
 | ||||
| } // namespace map
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat