Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new GuiEvent HoverOnScene #273

Merged
merged 2 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
chapulina marked this conversation as resolved.
Show resolved Hide resolved

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noob question, why -13? Can this be documented in the comments?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to comment it, because it keeps coming up 😅

tl;dr: gazebo::gui:GuiEvents count up, gui::GuiEvents count down.

See context here: #70 (comment)


/// \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