mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 23:40:06 +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
|
|
@ -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