mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-30 23:50:05 +00:00 
			
		
		
		
	Radar site buttons, styling and hover
This commit is contained in:
		
							parent
							
								
									798dc479f0
								
							
						
					
					
						commit
						de2e1fea3f
					
				
					 3 changed files with 46 additions and 9 deletions
				
			
		|  | @ -165,6 +165,8 @@ public: | ||||||
|    std::shared_ptr<QMapLibreGL::Map> map_; |    std::shared_ptr<QMapLibreGL::Map> map_; | ||||||
|    std::list<std::string>            layerList_; |    std::list<std::string>            layerList_; | ||||||
| 
 | 
 | ||||||
|  |    std::vector<std::shared_ptr<GenericLayer>> genericLayers_ {}; | ||||||
|  | 
 | ||||||
|    QStringList        styleLayers_; |    QStringList        styleLayers_; | ||||||
|    types::LayerVector customLayers_; |    types::LayerVector customLayers_; | ||||||
| 
 | 
 | ||||||
|  | @ -802,6 +804,7 @@ void MapWidgetImpl::AddLayers() | ||||||
|       map_->removeLayer(id.c_str()); |       map_->removeLayer(id.c_str()); | ||||||
|    } |    } | ||||||
|    layerList_.clear(); |    layerList_.clear(); | ||||||
|  |    genericLayers_.clear(); | ||||||
|    placefileLayers_.clear(); |    placefileLayers_.clear(); | ||||||
| 
 | 
 | ||||||
|    // Update custom layer list from model
 |    // Update custom layer list from model
 | ||||||
|  | @ -961,6 +964,7 @@ void MapWidgetImpl::AddLayer(const std::string&            id, | ||||||
|       map_->addCustomLayer(id.c_str(), std::move(pHost), before.c_str()); |       map_->addCustomLayer(id.c_str(), std::move(pHost), before.c_str()); | ||||||
| 
 | 
 | ||||||
|       layerList_.push_back(id); |       layerList_.push_back(id); | ||||||
|  |       genericLayers_.push_back(layer); | ||||||
|    } |    } | ||||||
|    catch (const std::exception&) |    catch (const std::exception&) | ||||||
|    { |    { | ||||||
|  | @ -1206,10 +1210,8 @@ void MapWidgetImpl::RunMousePicking() | ||||||
|       util::maplibre::LatLongToScreenCoordinate(coordinate); |       util::maplibre::LatLongToScreenCoordinate(coordinate); | ||||||
| 
 | 
 | ||||||
|    // For each layer in reverse
 |    // For each layer in reverse
 | ||||||
|    // TODO: All Generic Layers, not just Placefile Layers
 |  | ||||||
|    bool itemPicked = false; |    bool itemPicked = false; | ||||||
|    for (auto it = placefileLayers_.rbegin(); it != placefileLayers_.rend(); |    for (auto it = genericLayers_.rbegin(); it != genericLayers_.rend(); ++it) | ||||||
|         ++it) |  | ||||||
|    { |    { | ||||||
|       // Run mouse picking for each layer
 |       // Run mouse picking for each layer
 | ||||||
|       if ((*it)->RunMousePicking( |       if ((*it)->RunMousePicking( | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| #include <scwx/qt/map/radar_site_layer.hpp> | #include <scwx/qt/map/radar_site_layer.hpp> | ||||||
| #include <scwx/qt/config/radar_site.hpp> | #include <scwx/qt/config/radar_site.hpp> | ||||||
| #include <scwx/qt/util/maplibre.hpp> | #include <scwx/qt/util/maplibre.hpp> | ||||||
|  | #include <scwx/qt/util/tooltip.hpp> | ||||||
| #include <scwx/common/geographic.hpp> | #include <scwx/common/geographic.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
| 
 | 
 | ||||||
|  | @ -21,12 +22,17 @@ static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||||
| class RadarSiteLayer::Impl | class RadarSiteLayer::Impl | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit Impl(std::shared_ptr<MapContext> context) {} |    explicit Impl(RadarSiteLayer* self, std::shared_ptr<MapContext> context) : | ||||||
|  |        self_ {self} | ||||||
|  |    { | ||||||
|  |    } | ||||||
|    ~Impl() = default; |    ~Impl() = default; | ||||||
| 
 | 
 | ||||||
|    void RenderRadarSite(const QMapLibreGL::CustomLayerRenderParameters& params, |    void RenderRadarSite(const QMapLibreGL::CustomLayerRenderParameters& params, | ||||||
|                         std::shared_ptr<config::RadarSite>& radarSite); |                         std::shared_ptr<config::RadarSite>& radarSite); | ||||||
| 
 | 
 | ||||||
|  |    RadarSiteLayer* self_; | ||||||
|  | 
 | ||||||
|    std::vector<std::shared_ptr<config::RadarSite>> radarSites_ {}; |    std::vector<std::shared_ptr<config::RadarSite>> radarSites_ {}; | ||||||
| 
 | 
 | ||||||
|    glm::vec2 mapScreenCoordLocation_ {}; |    glm::vec2 mapScreenCoordLocation_ {}; | ||||||
|  | @ -35,10 +41,12 @@ public: | ||||||
|    float     mapBearingSin_ {0.0f}; |    float     mapBearingSin_ {0.0f}; | ||||||
|    float     halfWidth_ {}; |    float     halfWidth_ {}; | ||||||
|    float     halfHeight_ {}; |    float     halfHeight_ {}; | ||||||
|  | 
 | ||||||
|  |    std::string hoverText_ {}; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| RadarSiteLayer::RadarSiteLayer(std::shared_ptr<MapContext> context) : | RadarSiteLayer::RadarSiteLayer(std::shared_ptr<MapContext> context) : | ||||||
|     DrawLayer(context), p(std::make_unique<Impl>(context)) |     DrawLayer(context), p(std::make_unique<Impl>(this, context)) | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -68,11 +76,18 @@ void RadarSiteLayer::Render( | ||||||
|    p->halfWidth_     = params.width * 0.5f; |    p->halfWidth_     = params.width * 0.5f; | ||||||
|    p->halfHeight_    = params.height * 0.5f; |    p->halfHeight_    = params.height * 0.5f; | ||||||
| 
 | 
 | ||||||
|  |    p->hoverText_.clear(); | ||||||
|  | 
 | ||||||
|  |    // Radar site ImGui windows shouldn't have padding
 | ||||||
|  |    ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2 {0.0f, 0.0f}); | ||||||
|  | 
 | ||||||
|    for (auto& radarSite : p->radarSites_) |    for (auto& radarSite : p->radarSites_) | ||||||
|    { |    { | ||||||
|       p->RenderRadarSite(params, radarSite); |       p->RenderRadarSite(params, radarSite); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|  |    ImGui::PopStyleVar(); | ||||||
|  | 
 | ||||||
|    SCWX_GL_CHECK_ERROR(); |    SCWX_GL_CHECK_ERROR(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -112,12 +127,21 @@ void RadarSiteLayer::Impl::RenderRadarSite( | ||||||
|                        ImGuiWindowFlags_AlwaysAutoResize)) |                        ImGuiWindowFlags_AlwaysAutoResize)) | ||||||
|    { |    { | ||||||
|       // Render text
 |       // Render text
 | ||||||
|       ImGui::TextUnformatted(radarSite->id().c_str()); |       if (ImGui::Button(radarSite->id().c_str())) | ||||||
|  |       { | ||||||
|  |          Q_EMIT self_->RadarSiteSelected(radarSite->id()); | ||||||
|  |       } | ||||||
| 
 | 
 | ||||||
|       // Store hover text for mouse picking pass
 |       // Store hover text for mouse picking pass
 | ||||||
|       if (ImGui::IsItemHovered()) |       if (ImGui::IsItemHovered()) | ||||||
|       { |       { | ||||||
|          // TODO
 |          hoverText_ = | ||||||
|  |             fmt::format("{} ({})\n{}\n{}, {}", | ||||||
|  |                         radarSite->id(), | ||||||
|  |                         radarSite->type_name(), | ||||||
|  |                         radarSite->location_name(), | ||||||
|  |                         common::GetLatitudeString(radarSite->latitude()), | ||||||
|  |                         common::GetLongitudeString(radarSite->longitude())); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       // End window
 |       // End window
 | ||||||
|  | @ -135,10 +159,15 @@ void RadarSiteLayer::Deinitialize() | ||||||
| bool RadarSiteLayer::RunMousePicking( | bool RadarSiteLayer::RunMousePicking( | ||||||
|    const QMapLibreGL::CustomLayerRenderParameters& /* params */, |    const QMapLibreGL::CustomLayerRenderParameters& /* params */, | ||||||
|    const QPointF& /* mouseLocalPos */, |    const QPointF& /* mouseLocalPos */, | ||||||
|    const QPointF& /* mouseGlobalPos */, |    const QPointF& mouseGlobalPos, | ||||||
|    const glm::vec2& /* mouseCoords */) |    const glm::vec2& /* mouseCoords */) | ||||||
| { | { | ||||||
|    // TODO
 |    if (!p->hoverText_.empty()) | ||||||
|  |    { | ||||||
|  |       util::tooltip::Show(p->hoverText_, mouseGlobalPos); | ||||||
|  |       return true; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|    return false; |    return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -11,6 +11,9 @@ namespace map | ||||||
| 
 | 
 | ||||||
| class RadarSiteLayer : public DrawLayer | class RadarSiteLayer : public DrawLayer | ||||||
| { | { | ||||||
|  |    Q_OBJECT | ||||||
|  |    Q_DISABLE_COPY_MOVE(RadarSiteLayer) | ||||||
|  | 
 | ||||||
| public: | public: | ||||||
|    explicit RadarSiteLayer(std::shared_ptr<MapContext> context); |    explicit RadarSiteLayer(std::shared_ptr<MapContext> context); | ||||||
|    ~RadarSiteLayer(); |    ~RadarSiteLayer(); | ||||||
|  | @ -24,6 +27,9 @@ public: | ||||||
|                         const QPointF&   mouseGlobalPos, |                         const QPointF&   mouseGlobalPos, | ||||||
|                         const glm::vec2& mouseCoords) override final; |                         const glm::vec2& mouseCoords) override final; | ||||||
| 
 | 
 | ||||||
|  | signals: | ||||||
|  |    void RadarSiteSelected(const std::string& id); | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|    class Impl; |    class Impl; | ||||||
|    std::unique_ptr<Impl> p; |    std::unique_ptr<Impl> p; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat