mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 01:30:05 +00:00 
			
		
		
		
	Add cursor position (screen coordinates) to mouse picking
This commit is contained in:
		
							parent
							
								
									f158c4174c
								
							
						
					
					
						commit
						9ebc859756
					
				
					 13 changed files with 55 additions and 23 deletions
				
			
		|  | @ -55,7 +55,9 @@ void DrawItem::Render(const QMapLibreGL::CustomLayerRenderParameters& params, | |||
| 
 | ||||
| bool DrawItem::RunMousePicking( | ||||
|    const QMapLibreGL::CustomLayerRenderParameters& /* params */, | ||||
|    const glm::vec2& /* mousePos */) | ||||
|    const QPointF& /* mouseLocalPos */, | ||||
|    const QPointF& /* mouseGlobalPos */, | ||||
|    const glm::vec2& /* mouseCoords */) | ||||
| { | ||||
|    // By default, the draw item is not picked
 | ||||
|    return false; | ||||
|  |  | |||
|  | @ -38,13 +38,17 @@ public: | |||
|     * @brief Run mouse picking on the draw item. | ||||
|     * | ||||
|     * @param [in] params Custom layer render parameters | ||||
|     * @param [in] mousePos Mouse cursor location in map screen coordinates | ||||
|     * @param [in] mouseLocalPos Mouse cursor widget position | ||||
|     * @param [in] mouseGlobalPos Mouse cursor screen position | ||||
|     * @param [in] mouseCoords Mouse cursor location in map screen coordinates | ||||
|     * | ||||
|     * @return true if the draw item was picked, otherwise false | ||||
|     */ | ||||
|    virtual bool | ||||
|    RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params, | ||||
|                    const glm::vec2&                                mousePos); | ||||
|                    const QPointF&   mouseLocalPos, | ||||
|                    const QPointF&   mouseGlobalPos, | ||||
|                    const glm::vec2& mouseCoords); | ||||
| 
 | ||||
| protected: | ||||
|    void | ||||
|  |  | |||
|  | @ -684,7 +684,9 @@ void PlacefileIcons::Impl::Update(bool textureAtlasChanged) | |||
| 
 | ||||
| bool PlacefileIcons::RunMousePicking( | ||||
|    const QMapLibreGL::CustomLayerRenderParameters& params, | ||||
|    const glm::vec2&                                mousePos) | ||||
|    const QPointF& /* mouseLocalPos */, | ||||
|    const QPointF& /* mouseGlobalPos */, | ||||
|    const glm::vec2& mouseCoords) | ||||
| { | ||||
|    std::unique_lock lock {p->iconMutex_}; | ||||
| 
 | ||||
|  | @ -716,7 +718,7 @@ bool PlacefileIcons::RunMousePicking( | |||
|       std::execution::par_unseq, | ||||
|       p->currentHoverIcons_.crbegin(), | ||||
|       p->currentHoverIcons_.crend(), | ||||
|       [&mapDistance, &selectedTime, &mapMatrix, &mousePos](const auto& icon) | ||||
|       [&mapDistance, &selectedTime, &mapMatrix, &mouseCoords](const auto& icon) | ||||
|       { | ||||
|          if (( | ||||
|                 // Placefile is thresholded
 | ||||
|  | @ -766,7 +768,7 @@ bool PlacefileIcons::RunMousePicking( | |||
|          tr += otr; | ||||
| 
 | ||||
|          // Test point against polygon bounds
 | ||||
|          return util::maplibre::IsPointInPolygon({tl, bl, br, tr}, mousePos); | ||||
|          return util::maplibre::IsPointInPolygon({tl, bl, br, tr}, mouseCoords); | ||||
|       }); | ||||
| 
 | ||||
|    if (it != p->currentHoverIcons_.crend()) | ||||
|  |  | |||
|  | @ -36,7 +36,9 @@ public: | |||
|    void Deinitialize() override; | ||||
| 
 | ||||
|    bool RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params, | ||||
|                         const glm::vec2& mousePos) override; | ||||
|                         const QPointF&   mouseLocalPos, | ||||
|                         const QPointF&   mouseGlobalPos, | ||||
|                         const glm::vec2& mouseCoords) override; | ||||
| 
 | ||||
|    /**
 | ||||
|     * Resets and prepares the draw item for adding a new set of icons. | ||||
|  |  | |||
|  | @ -497,7 +497,9 @@ void PlacefileLines::Impl::Update() | |||
| 
 | ||||
| bool PlacefileLines::RunMousePicking( | ||||
|    const QMapLibreGL::CustomLayerRenderParameters& params, | ||||
|    const glm::vec2&                                mousePos) | ||||
|    const QPointF& /* mouseLocalPos */, | ||||
|    const QPointF& /* mouseGlobalPos */, | ||||
|    const glm::vec2& mouseCoords) | ||||
| { | ||||
|    std::unique_lock lock {p->lineMutex_}; | ||||
| 
 | ||||
|  | @ -529,7 +531,7 @@ bool PlacefileLines::RunMousePicking( | |||
|       std::execution::par_unseq, | ||||
|       p->currentHoverLines_.crbegin(), | ||||
|       p->currentHoverLines_.crend(), | ||||
|       [&mapDistance, &selectedTime, &mapMatrix, &mousePos](const auto& line) | ||||
|       [&mapDistance, &selectedTime, &mapMatrix, &mouseCoords](const auto& line) | ||||
|       { | ||||
|          if (( | ||||
|                 // Placefile is thresholded
 | ||||
|  | @ -581,7 +583,7 @@ bool PlacefileLines::RunMousePicking( | |||
|          // TODO: X/Y offsets
 | ||||
| 
 | ||||
|          // Test point against polygon bounds
 | ||||
|          return util::maplibre::IsPointInPolygon({tl, bl, br, tr}, mousePos); | ||||
|          return util::maplibre::IsPointInPolygon({tl, bl, br, tr}, mouseCoords); | ||||
|       }); | ||||
| 
 | ||||
|    if (it != p->currentHoverLines_.crend()) | ||||
|  |  | |||
|  | @ -33,7 +33,9 @@ public: | |||
|    void Deinitialize() override; | ||||
| 
 | ||||
|    bool RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params, | ||||
|                         const glm::vec2& mousePos) override; | ||||
|                         const QPointF&   mouseLocalPos, | ||||
|                         const QPointF&   mouseGlobalPos, | ||||
|                         const glm::vec2& mouseCoords) override; | ||||
| 
 | ||||
|    /**
 | ||||
|     * Resets and prepares the draw item for adding a new set of lines. | ||||
|  |  | |||
|  | @ -209,7 +209,9 @@ void PlacefileText::Deinitialize() | |||
| 
 | ||||
| bool PlacefileText::RunMousePicking( | ||||
|    const QMapLibreGL::CustomLayerRenderParameters& /* params */, | ||||
|    const glm::vec2& /* mousePos */) | ||||
|    const QPointF& /* mouseLocalPos */, | ||||
|    const QPointF& /* mouseGlobalPos */, | ||||
|    const glm::vec2& /* mouseCoords */) | ||||
| { | ||||
|    bool itemPicked = false; | ||||
| 
 | ||||
|  |  | |||
|  | @ -35,7 +35,9 @@ public: | |||
|    void Deinitialize() override; | ||||
| 
 | ||||
|    bool RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params, | ||||
|                         const glm::vec2& mousePos) override; | ||||
|                         const QPointF&   mouseLocalPos, | ||||
|                         const QPointF&   mouseGlobalPos, | ||||
|                         const glm::vec2& mouseCoords) override; | ||||
| 
 | ||||
|    /**
 | ||||
|     * Resets and prepares the draw item for adding a new set of text. | ||||
|  |  | |||
|  | @ -78,7 +78,9 @@ void DrawLayer::Deinitialize() | |||
| 
 | ||||
| bool DrawLayer::RunMousePicking( | ||||
|    const QMapLibreGL::CustomLayerRenderParameters& params, | ||||
|    const glm::vec2&                                mousePos) | ||||
|    const QPointF&                                  mouseLocalPos, | ||||
|    const QPointF&                                  mouseGlobalPos, | ||||
|    const glm::vec2&                                mouseCoords) | ||||
| { | ||||
|    bool itemPicked = false; | ||||
| 
 | ||||
|  | @ -86,7 +88,8 @@ bool DrawLayer::RunMousePicking( | |||
|    for (auto it = p->drawList_.rbegin(); it != p->drawList_.rend(); ++it) | ||||
|    { | ||||
|       // Run mouse picking on each draw item
 | ||||
|       if ((*it)->RunMousePicking(params, mousePos)) | ||||
|       if ((*it)->RunMousePicking( | ||||
|              params, mouseLocalPos, mouseGlobalPos, mouseCoords)) | ||||
|       { | ||||
|          // If a draw item was picked, don't process additional items
 | ||||
|          itemPicked = true; | ||||
|  |  | |||
|  | @ -25,7 +25,9 @@ public: | |||
| 
 | ||||
|    virtual bool | ||||
|    RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params, | ||||
|                    const glm::vec2& mousePos) override; | ||||
|                    const QPointF&   mouseLocalPos, | ||||
|                    const QPointF&   mouseGlobalPos, | ||||
|                    const glm::vec2& mouseCoords) override; | ||||
| 
 | ||||
| protected: | ||||
|    void AddDrawItem(const std::shared_ptr<gl::draw::DrawItem>& drawItem); | ||||
|  |  | |||
|  | @ -28,6 +28,8 @@ GenericLayer::~GenericLayer() = default; | |||
| 
 | ||||
| bool GenericLayer::RunMousePicking( | ||||
|    const QMapLibreGL::CustomLayerRenderParameters& /* params */, | ||||
|    const QPointF& /* mouseLocalPos */, | ||||
|    const QPointF& /* mouseGlobalPos */, | ||||
|    const glm::vec2& /* mousePos */) | ||||
| { | ||||
|    // By default, the layer has nothing to pick
 | ||||
|  |  | |||
|  | @ -33,13 +33,17 @@ public: | |||
|     * @brief Run mouse picking on the layer. | ||||
|     * | ||||
|     * @param [in] params Custom layer render parameters | ||||
|     * @param [in] mousePos Mouse cursor location in map screen coordinates | ||||
|     * @param [in] mouseLocalPos Mouse cursor widget position | ||||
|     * @param [in] mouseGlobalPos Mouse cursor screen position | ||||
|     * @param [in] mouseCoords Mouse cursor location in map screen coordinates | ||||
|     * | ||||
|     * @return true if a draw item was picked, otherwise false | ||||
|     */ | ||||
|    virtual bool | ||||
|    RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params, | ||||
|                    const glm::vec2&                                mousePos); | ||||
|                    const QPointF&   mouseLocalPos, | ||||
|                    const QPointF&   mouseGlobalPos, | ||||
|                    const glm::vec2& mouseCoords); | ||||
| 
 | ||||
| protected: | ||||
|    std::shared_ptr<MapContext> context() const; | ||||
|  |  | |||
|  | @ -70,7 +70,6 @@ public: | |||
|        autoRefreshEnabled_ {true}, | ||||
|        autoUpdateEnabled_ {true}, | ||||
|        selectedLevel2Product_ {common::Level2Product::Unknown}, | ||||
|        lastPos_(), | ||||
|        currentStyleIndex_ {0}, | ||||
|        currentStyle_ {nullptr}, | ||||
|        frameDraws_(0), | ||||
|  | @ -174,7 +173,8 @@ public: | |||
|    common::Level2Product selectedLevel2Product_; | ||||
| 
 | ||||
|    bool            hasMouse_ {false}; | ||||
|    QPointF         lastPos_; | ||||
|    QPointF         lastPos_ {}; | ||||
|    QPointF         lastGlobalPos_ {}; | ||||
|    std::size_t     currentStyleIndex_; | ||||
|    const MapStyle* currentStyle_; | ||||
|    std::string     initialStyleName_ {}; | ||||
|  | @ -898,7 +898,8 @@ void MapWidget::keyPressEvent(QKeyEvent* ev) | |||
| 
 | ||||
| void MapWidget::mousePressEvent(QMouseEvent* ev) | ||||
| { | ||||
|    p->lastPos_ = ev->position(); | ||||
|    p->lastPos_       = ev->position(); | ||||
|    p->lastGlobalPos_ = ev->globalPosition(); | ||||
| 
 | ||||
|    if (ev->type() == QEvent::MouseButtonPress) | ||||
|    { | ||||
|  | @ -944,7 +945,8 @@ void MapWidget::mouseMoveEvent(QMouseEvent* ev) | |||
|       } | ||||
|    } | ||||
| 
 | ||||
|    p->lastPos_ = ev->position(); | ||||
|    p->lastPos_       = ev->position(); | ||||
|    p->lastGlobalPos_ = ev->globalPosition(); | ||||
|    ev->accept(); | ||||
| } | ||||
| 
 | ||||
|  | @ -1064,7 +1066,8 @@ void MapWidgetImpl::RunMousePicking() | |||
|         ++it) | ||||
|    { | ||||
|       // Run mouse picking for each layer
 | ||||
|       if ((*it)->RunMousePicking(params, mouseScreenCoordinate)) | ||||
|       if ((*it)->RunMousePicking( | ||||
|              params, lastPos_, lastGlobalPos_, mouseScreenCoordinate)) | ||||
|       { | ||||
|          // If a draw item was picked, don't process additional layers
 | ||||
|          break; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat