diff --git a/include/ignition/gui/GuiEvents.hh b/include/ignition/gui/GuiEvents.hh index 057035cdc..1dc0ba227 100644 --- a/include/ignition/gui/GuiEvents.hh +++ b/include/ignition/gui/GuiEvents.hh @@ -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 common::MouseEvent &_mouse); + + /// \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: common::MouseEvent Mouse() const; + + /// \internal + /// \brief Private data pointer + IGN_UTILS_IMPL_PTR(dataPtr) + }; + } } } diff --git a/src/GuiEvents.cc b/src/GuiEvents.cc index 8138c02f3..9cd1322d2 100644 --- a/src/GuiEvents.cc +++ b/src/GuiEvents.cc @@ -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: common::MouseEvent mouse; +}; + class ignition::gui::events::LeftClickToScene::Implementation { /// \brief The 3D point that the user clicked within the scene. @@ -170,6 +176,19 @@ math::Vector3d HoverToScene::Point() const return this->dataPtr->point; } +///////////////////////////////////////////////// +HoverOnScene::HoverOnScene(const common::MouseEvent &_mouse) + : QEvent(kType), dataPtr(utils::MakeImpl()) +{ + this->dataPtr->mouse = _mouse; +} + +///////////////////////////////////////////////// +common::MouseEvent HoverOnScene::Mouse() const +{ + return this->dataPtr->mouse; +} + ///////////////////////////////////////////////// LeftClickToScene::LeftClickToScene(const math::Vector3d &_point) : QEvent(kType), dataPtr(utils::MakeImpl()) diff --git a/src/GuiEvents_TEST.cc b/src/GuiEvents_TEST.cc index 4574c5239..dde569693 100644 --- a/src/GuiEvents_TEST.cc +++ b/src/GuiEvents_TEST.cc @@ -69,6 +69,25 @@ TEST(GuiEventsTest, HoverToScene) EXPECT_EQ(math::Vector3d(1, 2, 3), event.Point()); } +///////////////////////////////////////////////// +TEST(GuiEventsTest, HoverOnScene) +{ + + ignition::common::MouseEvent mouse; + mouse.SetAlt(true); + mouse.SetShift(true); + mouse.SetDragging(false); + mouse.SetType(common::MouseEvent::MOVE); + events::HoverOnScene event(mouse); + + EXPECT_LT(QEvent::User, event.type()); + EXPECT_FALSE(event.Mouse().Control()); + EXPECT_FALSE(event.Mouse().Dragging()); + EXPECT_EQ(event.Mouse().Type(), common::MouseEvent::MOVE); + EXPECT_TRUE(event.Mouse().Alt()); + EXPECT_TRUE(event.Mouse().Shift()); +} + ///////////////////////////////////////////////// TEST(GuiEventsTest, LeftClickToScene) { diff --git a/src/plugins/minimal_scene/MinimalScene.cc b/src/plugins/minimal_scene/MinimalScene.cc index 50bd0fd47..76347c2f7 100644 --- a/src/plugins/minimal_scene/MinimalScene.cc +++ b/src/plugins/minimal_scene/MinimalScene.cc @@ -203,6 +203,13 @@ void IgnRenderer::BroadcastHoverPos() events::HoverToScene hoverToSceneEvent(pos); App()->sendEvent(App()->findChild(), &hoverToSceneEvent); + + common::MouseEvent hoverMouseEvent = this->dataPtr->mouseEvent; + hoverMouseEvent.SetPos(this->dataPtr->mouseHoverPos); + hoverMouseEvent.SetDragging(false); + hoverMouseEvent.SetType(common::MouseEvent::MOVE); + events::HoverOnScene hoverOnSceneEvent(hoverMouseEvent); + App()->sendEvent(App()->findChild(), &hoverOnSceneEvent); } /////////////////////////////////////////////////