Skip to content

Commit

Permalink
Create new GuiEvent HoverOnScene
Browse files Browse the repository at this point in the history
Signed-off-by: ahcorde <[email protected]>
  • Loading branch information
ahcorde committed Aug 18, 2021
1 parent db6b225 commit 5d689c7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
23 changes: 23 additions & 0 deletions include/ignition/gui/GuiEvents.hh
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,29 @@ namespace ignition
/// \brief Private data pointer
IGN_UTILS_IMPL_PTR(dataPtr)
};

/// \brief Event which is called to broadcast the 2D coordinates of a
/// user's mouse hover within the scene.
class IGNITION_GUI_VISIBLE HoverOnScene : public QEvent
{
/// \brief Constructor
/// \param[in] _point The point at which the mouse is hovering within
/// the scene
public: explicit HoverOnScene(const math::Vector2i &_point);

/// \brief Unique type for this event.
static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 13);

/// \brief Get the point within the scene over which the user is
/// hovering.
/// \return The 2D point
public: math::Vector2i Point() const;

/// \internal
/// \brief Private data pointer
IGN_UTILS_IMPL_PTR(dataPtr)
};

}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/GuiEvents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class ignition::gui::events::HoverToScene::Implementation
public: math::Vector3d point;
};

class ignition::gui::events::HoverOnScene::Implementation
{
/// \brief The 2D point over which the user is hovering.
public: math::Vector2i point;
};

class ignition::gui::events::LeftClickToScene::Implementation
{
/// \brief The 3D point that the user clicked within the scene.
Expand Down Expand Up @@ -170,6 +176,19 @@ math::Vector3d HoverToScene::Point() const
return this->dataPtr->point;
}

/////////////////////////////////////////////////
HoverOnScene::HoverOnScene(const math::Vector2i &_point)
: QEvent(kType), dataPtr(utils::MakeImpl<Implementation>())
{
this->dataPtr->point = _point;
}

/////////////////////////////////////////////////
math::Vector2i HoverOnScene::Point() const
{
return this->dataPtr->point;
}

/////////////////////////////////////////////////
LeftClickToScene::LeftClickToScene(const math::Vector3d &_point)
: QEvent(kType), dataPtr(utils::MakeImpl<Implementation>())
Expand Down
9 changes: 9 additions & 0 deletions src/GuiEvents_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ TEST(GuiEventsTest, HoverToScene)
EXPECT_EQ(math::Vector3d(1, 2, 3), event.Point());
}

/////////////////////////////////////////////////
TEST(GuiEventsTest, HoverOnScene)
{
events::HoverOnScene event({1, 2});

EXPECT_LT(QEvent::User, event.type());
EXPECT_EQ(math::Vector2i(1, 2), event.Point());
}

/////////////////////////////////////////////////
TEST(GuiEventsTest, LeftClickToScene)
{
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/minimal_scene/MinimalScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ void IgnRenderer::BroadcastHoverPos()

events::HoverToScene hoverToSceneEvent(pos);
App()->sendEvent(App()->findChild<MainWindow *>(), &hoverToSceneEvent);
events::HoverOnScene hoverOnSceneEvent(this->dataPtr->mouseHoverPos);
App()->sendEvent(App()->findChild<MainWindow *>(), &hoverOnSceneEvent);
}

/////////////////////////////////////////////////
Expand Down

0 comments on commit 5d689c7

Please sign in to comment.