Skip to content

Commit

Permalink
Use MouseEvent instead of vector2i in HoverOnScene
Browse files Browse the repository at this point in the history
Signed-off-by: ahcorde <[email protected]>
  • Loading branch information
ahcorde committed Aug 19, 2021
1 parent 5d689c7 commit f929e7e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions include/ignition/gui/GuiEvents.hh
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,15 @@ 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);

/// \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
Expand Down
10 changes: 5 additions & 5 deletions src/GuiEvents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Implementation>())
{
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;
}

/////////////////////////////////////////////////
Expand Down
14 changes: 12 additions & 2 deletions src/GuiEvents_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/////////////////////////////////////////////////
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/minimal_scene/MinimalScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ void IgnRenderer::BroadcastHoverPos()

events::HoverToScene hoverToSceneEvent(pos);
App()->sendEvent(App()->findChild<MainWindow *>(), &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<MainWindow *>(), &hoverOnSceneEvent);
}

Expand Down

0 comments on commit f929e7e

Please sign in to comment.