mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 05:10:04 +00:00 
			
		
		
		
	Mouse picking boilerplate
This commit is contained in:
		
							parent
							
								
									c7487281ad
								
							
						
					
					
						commit
						38b56be7c4
					
				
					 10 changed files with 115 additions and 17 deletions
				
			
		|  | @ -76,6 +76,26 @@ void DrawLayer::Deinitialize() | |||
|    } | ||||
| } | ||||
| 
 | ||||
| bool DrawLayer::RunMousePicking( | ||||
|    const QMapLibreGL::CustomLayerRenderParameters& params) | ||||
| { | ||||
|    bool itemPicked = false; | ||||
| 
 | ||||
|    // For each draw item in the draw list in reverse
 | ||||
|    for (auto it = p->drawList_.rbegin(); it != p->drawList_.rend(); ++it) | ||||
|    { | ||||
|       // Run mouse picking on each draw item
 | ||||
|       if ((*it)->RunMousePicking(params)) | ||||
|       { | ||||
|          // If a draw item was picked, don't process additional items
 | ||||
|          itemPicked = true; | ||||
|          break; | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    return itemPicked; | ||||
| } | ||||
| 
 | ||||
| void DrawLayer::AddDrawItem(const std::shared_ptr<gl::draw::DrawItem>& drawItem) | ||||
| { | ||||
|    p->drawList_.push_back(drawItem); | ||||
|  |  | |||
|  | @ -18,9 +18,13 @@ public: | |||
|    explicit DrawLayer(const std::shared_ptr<MapContext>& context); | ||||
|    virtual ~DrawLayer(); | ||||
| 
 | ||||
|    virtual void Initialize(); | ||||
|    virtual void Render(const QMapLibreGL::CustomLayerRenderParameters&); | ||||
|    virtual void Deinitialize(); | ||||
|    virtual void Initialize() override; | ||||
|    virtual void | ||||
|    Render(const QMapLibreGL::CustomLayerRenderParameters&) override; | ||||
|    virtual void Deinitialize() override; | ||||
| 
 | ||||
|    virtual bool RunMousePicking( | ||||
|       const QMapLibreGL::CustomLayerRenderParameters& params) override; | ||||
| 
 | ||||
| protected: | ||||
|    void AddDrawItem(const std::shared_ptr<gl::draw::DrawItem>& drawItem); | ||||
|  |  | |||
|  | @ -26,6 +26,13 @@ GenericLayer::GenericLayer(std::shared_ptr<MapContext> context) : | |||
| } | ||||
| GenericLayer::~GenericLayer() = default; | ||||
| 
 | ||||
| bool GenericLayer::RunMousePicking( | ||||
|    const QMapLibreGL::CustomLayerRenderParameters& /* params */) | ||||
| { | ||||
|    // By default, the layer has nothing to pick
 | ||||
|    return false; | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<MapContext> GenericLayer::context() const | ||||
| { | ||||
|    return p->context_; | ||||
|  |  | |||
|  | @ -28,6 +28,16 @@ public: | |||
|    virtual void Render(const QMapLibreGL::CustomLayerRenderParameters&) = 0; | ||||
|    virtual void Deinitialize()                                          = 0; | ||||
| 
 | ||||
|    /**
 | ||||
|     * @brief Run mouse picking on the layer. | ||||
|     * | ||||
|     * @param [in] params Custom layer render parameters | ||||
|     * | ||||
|     * @return true if a draw item was picked, otherwise false | ||||
|     */ | ||||
|    virtual bool | ||||
|    RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params); | ||||
| 
 | ||||
| protected: | ||||
|    std::shared_ptr<MapContext> context() const; | ||||
| 
 | ||||
|  |  | |||
|  | @ -23,13 +23,14 @@ public: | |||
| 
 | ||||
|    ~Impl() {} | ||||
| 
 | ||||
|    std::weak_ptr<QMapLibreGL::Map>         map_; | ||||
|    MapSettings                             settings_; | ||||
|    float                                   pixelRatio_; | ||||
|    std::shared_ptr<view::RadarProductView> radarProductView_; | ||||
|    common::RadarProductGroup               radarProductGroup_; | ||||
|    std::string                             radarProduct_; | ||||
|    int16_t                                 radarProductCode_; | ||||
|    std::weak_ptr<QMapLibreGL::Map>          map_; | ||||
|    MapSettings                              settings_; | ||||
|    float                                    pixelRatio_; | ||||
|    std::shared_ptr<view::RadarProductView>  radarProductView_; | ||||
|    common::RadarProductGroup                radarProductGroup_; | ||||
|    std::string                              radarProduct_; | ||||
|    int16_t                                  radarProductCode_; | ||||
|    QMapLibreGL::CustomLayerRenderParameters renderParameters_ {}; | ||||
| }; | ||||
| 
 | ||||
| MapContext::MapContext( | ||||
|  | @ -77,6 +78,11 @@ int16_t MapContext::radar_product_code() const | |||
|    return p->radarProductCode_; | ||||
| } | ||||
| 
 | ||||
| QMapLibreGL::CustomLayerRenderParameters MapContext::render_parameters() const | ||||
| { | ||||
|    return p->renderParameters_; | ||||
| } | ||||
| 
 | ||||
| void MapContext::set_map(std::shared_ptr<QMapLibreGL::Map> map) | ||||
| { | ||||
|    p->map_ = map; | ||||
|  | @ -109,6 +115,12 @@ void MapContext::set_radar_product_code(int16_t radarProductCode) | |||
|    p->radarProductCode_ = radarProductCode; | ||||
| } | ||||
| 
 | ||||
| void MapContext::set_render_parameters( | ||||
|    const QMapLibreGL::CustomLayerRenderParameters& params) | ||||
| { | ||||
|    p->renderParameters_ = params; | ||||
| } | ||||
| 
 | ||||
| } // namespace map
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  |  | |||
|  | @ -26,13 +26,14 @@ public: | |||
|    MapContext(MapContext&&) noexcept; | ||||
|    MapContext& operator=(MapContext&&) noexcept; | ||||
| 
 | ||||
|    std::weak_ptr<QMapLibreGL::Map>         map() const; | ||||
|    MapSettings&                            settings(); | ||||
|    float                                   pixel_ratio() const; | ||||
|    std::shared_ptr<view::RadarProductView> radar_product_view() const; | ||||
|    common::RadarProductGroup               radar_product_group() const; | ||||
|    std::string                             radar_product() const; | ||||
|    int16_t                                 radar_product_code() const; | ||||
|    std::weak_ptr<QMapLibreGL::Map>          map() const; | ||||
|    MapSettings&                             settings(); | ||||
|    float                                    pixel_ratio() const; | ||||
|    std::shared_ptr<view::RadarProductView>  radar_product_view() const; | ||||
|    common::RadarProductGroup                radar_product_group() const; | ||||
|    std::string                              radar_product() const; | ||||
|    int16_t                                  radar_product_code() const; | ||||
|    QMapLibreGL::CustomLayerRenderParameters render_parameters() const; | ||||
| 
 | ||||
|    void set_map(std::shared_ptr<QMapLibreGL::Map> map); | ||||
|    void set_pixel_ratio(float pixelRatio); | ||||
|  | @ -41,6 +42,8 @@ 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_render_parameters( | ||||
|       const QMapLibreGL::CustomLayerRenderParameters& params); | ||||
| 
 | ||||
| private: | ||||
|    class Impl; | ||||
|  |  | |||
|  | @ -126,6 +126,7 @@ public: | |||
|    void RadarProductViewConnect(); | ||||
|    void RadarProductViewDisconnect(); | ||||
|    void RemovePlacefileLayer(const std::string& placefileName); | ||||
|    void RunMousePicking(); | ||||
|    void SetRadarSite(const std::string& radarSite); | ||||
|    void UpdatePlacefileLayers(); | ||||
|    bool UpdateStoredMapParameters(); | ||||
|  | @ -1022,6 +1023,9 @@ void MapWidget::paintGL() | |||
|                                  size() * pixelRatio()); | ||||
|    p->map_->render(); | ||||
| 
 | ||||
|    // Perform mouse picking
 | ||||
|    p->RunMousePicking(); | ||||
| 
 | ||||
|    // Render ImGui Frame
 | ||||
|    ImGui::Render(); | ||||
|    ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); | ||||
|  | @ -1030,6 +1034,25 @@ void MapWidget::paintGL() | |||
|    Q_EMIT WidgetPainted(); | ||||
| } | ||||
| 
 | ||||
| void MapWidgetImpl::RunMousePicking() | ||||
| { | ||||
|    const QMapLibreGL::CustomLayerRenderParameters params = | ||||
|       context_->render_parameters(); | ||||
| 
 | ||||
|    // For each layer in reverse
 | ||||
|    // TODO: All Generic Layers, not just Placefile Layers
 | ||||
|    for (auto it = placefileLayers_.rbegin(); it != placefileLayers_.rend(); | ||||
|         ++it) | ||||
|    { | ||||
|       // Run mouse picking for each layer
 | ||||
|       if ((*it)->RunMousePicking(params)) | ||||
|       { | ||||
|          // If a draw item was picked, don't process additional layers
 | ||||
|          break; | ||||
|       } | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| void MapWidget::mapChanged(QMapLibreGL::Map::MapChange mapChange) | ||||
| { | ||||
|    switch (mapChange) | ||||
|  |  | |||
|  | @ -95,6 +95,8 @@ void OverlayLayer::Render( | |||
|    auto&                settings         = context()->settings(); | ||||
|    const float          pixelRatio       = context()->pixel_ratio(); | ||||
| 
 | ||||
|    context()->set_render_parameters(params); | ||||
| 
 | ||||
|    if (p->sweepTimeNeedsUpdate_ && radarProductView != nullptr) | ||||
|    { | ||||
|       const scwx::util::time_zone* currentZone; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat