From 5d689c7240efa1f38bf511c32a1431831380d00c Mon Sep 17 00:00:00 2001 From: ahcorde Date: Wed, 18 Aug 2021 14:29:31 +0200 Subject: [PATCH 1/2] Create new GuiEvent HoverOnScene Signed-off-by: ahcorde --- include/ignition/gui/GuiEvents.hh | 23 +++++++++++++++++++++++ src/GuiEvents.cc | 19 +++++++++++++++++++ src/GuiEvents_TEST.cc | 9 +++++++++ src/plugins/minimal_scene/MinimalScene.cc | 2 ++ 4 files changed, 53 insertions(+) diff --git a/include/ignition/gui/GuiEvents.hh b/include/ignition/gui/GuiEvents.hh index 057035cdc..d8326a308 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 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) + }; + } } } diff --git a/src/GuiEvents.cc b/src/GuiEvents.cc index 8138c02f3..00c2bbaa8 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: math::Vector2i point; +}; + 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 math::Vector2i &_point) + : QEvent(kType), dataPtr(utils::MakeImpl()) +{ + this->dataPtr->point = _point; +} + +///////////////////////////////////////////////// +math::Vector2i HoverOnScene::Point() const +{ + return this->dataPtr->point; +} + ///////////////////////////////////////////////// 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..8ffefb95c 100644 --- a/src/GuiEvents_TEST.cc +++ b/src/GuiEvents_TEST.cc @@ -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) { diff --git a/src/plugins/minimal_scene/MinimalScene.cc b/src/plugins/minimal_scene/MinimalScene.cc index 50bd0fd47..e3fbfd611 100644 --- a/src/plugins/minimal_scene/MinimalScene.cc +++ b/src/plugins/minimal_scene/MinimalScene.cc @@ -203,6 +203,8 @@ void IgnRenderer::BroadcastHoverPos() events::HoverToScene hoverToSceneEvent(pos); App()->sendEvent(App()->findChild(), &hoverToSceneEvent); + events::HoverOnScene hoverOnSceneEvent(this->dataPtr->mouseHoverPos); + App()->sendEvent(App()->findChild(), &hoverOnSceneEvent); } ///////////////////////////////////////////////// From f929e7e0225ac60754796ab4419e3e726b8d7096 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 19 Aug 2021 20:12:26 +0200 Subject: [PATCH 2/2] Use MouseEvent instead of vector2i in HoverOnScene Signed-off-by: ahcorde --- include/ignition/gui/GuiEvents.hh | 4 ++-- src/GuiEvents.cc | 10 +++++----- src/GuiEvents_TEST.cc | 14 ++++++++++++-- src/plugins/minimal_scene/MinimalScene.cc | 7 ++++++- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/include/ignition/gui/GuiEvents.hh b/include/ignition/gui/GuiEvents.hh index d8326a308..1dc0ba227 100644 --- a/include/ignition/gui/GuiEvents.hh +++ b/include/ignition/gui/GuiEvents.hh @@ -331,7 +331,7 @@ namespace ignition /// \brief Constructor /// \param[in] _point The point at which the mouse is hovering within /// the scene - public: explicit HoverOnScene(const math::Vector2i &_point); + public: explicit HoverOnScene(const common::MouseEvent &_mouse); /// \brief Unique type for this event. static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 13); @@ -339,7 +339,7 @@ namespace ignition /// \brief Get the point within the scene over which the user is /// hovering. /// \return The 2D point - public: math::Vector2i Point() const; + public: common::MouseEvent Mouse() const; /// \internal /// \brief Private data pointer diff --git a/src/GuiEvents.cc b/src/GuiEvents.cc index 00c2bbaa8..9cd1322d2 100644 --- a/src/GuiEvents.cc +++ b/src/GuiEvents.cc @@ -52,7 +52,7 @@ class ignition::gui::events::HoverToScene::Implementation class ignition::gui::events::HoverOnScene::Implementation { /// \brief The 2D point over which the user is hovering. - public: math::Vector2i point; + public: common::MouseEvent mouse; }; class ignition::gui::events::LeftClickToScene::Implementation @@ -177,16 +177,16 @@ math::Vector3d HoverToScene::Point() const } ///////////////////////////////////////////////// -HoverOnScene::HoverOnScene(const math::Vector2i &_point) +HoverOnScene::HoverOnScene(const common::MouseEvent &_mouse) : QEvent(kType), dataPtr(utils::MakeImpl()) { - this->dataPtr->point = _point; + this->dataPtr->mouse = _mouse; } ///////////////////////////////////////////////// -math::Vector2i HoverOnScene::Point() const +common::MouseEvent HoverOnScene::Mouse() const { - return this->dataPtr->point; + return this->dataPtr->mouse; } ///////////////////////////////////////////////// diff --git a/src/GuiEvents_TEST.cc b/src/GuiEvents_TEST.cc index 8ffefb95c..dde569693 100644 --- a/src/GuiEvents_TEST.cc +++ b/src/GuiEvents_TEST.cc @@ -72,10 +72,20 @@ TEST(GuiEventsTest, HoverToScene) ///////////////////////////////////////////////// TEST(GuiEventsTest, HoverOnScene) { - events::HoverOnScene event({1, 2}); + + 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_EQ(math::Vector2i(1, 2), event.Point()); + 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()); } ///////////////////////////////////////////////// diff --git a/src/plugins/minimal_scene/MinimalScene.cc b/src/plugins/minimal_scene/MinimalScene.cc index e3fbfd611..76347c2f7 100644 --- a/src/plugins/minimal_scene/MinimalScene.cc +++ b/src/plugins/minimal_scene/MinimalScene.cc @@ -203,7 +203,12 @@ void IgnRenderer::BroadcastHoverPos() events::HoverToScene hoverToSceneEvent(pos); App()->sendEvent(App()->findChild(), &hoverToSceneEvent); - events::HoverOnScene hoverOnSceneEvent(this->dataPtr->mouseHoverPos); + + 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); }