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

Fix large / unexpected camera movements #502

Merged
merged 3 commits into from
Nov 16, 2022
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
35 changes: 23 additions & 12 deletions src/plugins/interactive_view_control/InteractiveViewControl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class ignition::gui::plugins::InteractiveViewControlPrivate
/// \brief Flag to indicate if mouse event is dirty
public: bool mouseDirty = false;

/// \brief Flag to indicate if hover event is dirty
public: bool hoverDirty = false;

/// \brief Flag to indicate if mouse press event is dirty
public: bool mousePressDirty = false;

/// \brief True to block orbiting with the mouse.
public: bool blockOrbit = false;

Expand Down Expand Up @@ -171,10 +177,18 @@ void InteractiveViewControlPrivate::OnRender()
return;
}

if (!this->mouseDirty)
if (!this->camera)
return;

if (!this->camera)
// hover
if (this->hoverDirty)
{
if (this->refVisual)
this->refVisual->SetVisible(false);
this->hoverDirty = false;
}

if (!this->mouseDirty)
return;

std::lock_guard<std::mutex> lock(this->mutex);
Expand Down Expand Up @@ -240,8 +254,10 @@ void InteractiveViewControlPrivate::OnRender()
{
this->target = rendering::screenToScene(
this->mouseEvent.PressPos(), this->camera, this->rayQuery);

this->viewControl->SetTarget(this->target);
this->UpdateReferenceVisual();
this->mousePressDirty = false;
}
else
{
Expand Down Expand Up @@ -272,12 +288,6 @@ void InteractiveViewControlPrivate::OnRender()
this->viewControl->Zoom(amount);
this->UpdateReferenceVisual();
}
// hover
else
{
if (this->refVisual)
this->refVisual->SetVisible(false);
}
}

this->drag = 0;
Expand Down Expand Up @@ -389,12 +399,16 @@ bool InteractiveViewControl::eventFilter(QObject *_obj, QEvent *_event)
auto pressOnScene =
reinterpret_cast<ignition::gui::events::MousePressOnScene *>(_event);
this->dataPtr->mouseDirty = true;
this->dataPtr->mousePressDirty = true;

this->dataPtr->drag = math::Vector2d::Zero;
this->dataPtr->mouseEvent = pressOnScene->Mouse();
}
else if (_event->type() == events::DragOnScene::kType)
{
if (this->dataPtr->mousePressDirty)
return QObject::eventFilter(_obj, _event);

auto dragOnScene =
reinterpret_cast<ignition::gui::events::DragOnScene *>(_event);
this->dataPtr->mouseDirty = true;
Expand Down Expand Up @@ -427,10 +441,7 @@ bool InteractiveViewControl::eventFilter(QObject *_obj, QEvent *_event)
}
else if (_event->type() == gui::events::HoverOnScene::kType)
{
gui::events::HoverOnScene *_e =
static_cast<gui::events::HoverOnScene*>(_event);
this->dataPtr->mouseDirty = true;
this->dataPtr->mouseEvent = _e->Mouse();
this->dataPtr->hoverDirty = true;
}

// Standard event processing
Expand Down
43 changes: 24 additions & 19 deletions src/plugins/minimal_scene/MinimalScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,18 @@ class ignition::gui::plugins::IgnRenderer::Implementation
/// \brief Flag to indicate if drop event is dirty
public: bool dropDirty{false};

/// \brief Mouse event
/// \brief Current mouse event
public: common::MouseEvent mouseEvent;

/// \brief A list of mouse events
public: std::list<common::MouseEvent> mouseEvents;

/// \brief Key event
public: common::KeyEvent keyEvent;

/// \brief Max number of mouse events to process
public: const unsigned int kMaxMouseEventSize = 5u;
nkoenig marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Mutex to protect mouse events
public: std::mutex mutex;

Expand Down Expand Up @@ -329,14 +335,21 @@ void IgnRenderer::Render(RenderSync *_renderSync)
void IgnRenderer::HandleMouseEvent()
{
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
for (const auto &e : this->dataPtr->mouseEvents)
{
this->dataPtr->mouseEvent = e;

this->BroadcastDrag();
this->BroadcastMousePress();
this->BroadcastLeftClick();
this->BroadcastRightClick();
this->BroadcastScroll();
this->BroadcastKeyPress();
this->BroadcastKeyRelease();
}
this->dataPtr->mouseEvents.clear();

this->BroadcastHoverPos();
this->BroadcastDrag();
this->BroadcastMousePress();
this->BroadcastLeftClick();
this->BroadcastRightClick();
this->BroadcastScroll();
this->BroadcastKeyPress();
this->BroadcastKeyRelease();
this->BroadcastDrop();
this->dataPtr->mouseDirty = false;
}
Expand Down Expand Up @@ -410,8 +423,6 @@ void IgnRenderer::BroadcastDrag()

events::DragOnScene dragEvent(this->dataPtr->mouseEvent);
App()->sendEvent(App()->findChild<MainWindow *>(), &dragEvent);

this->dataPtr->mouseDirty = false;
}

/////////////////////////////////////////////////
Expand All @@ -432,8 +443,6 @@ void IgnRenderer::BroadcastLeftClick()

events::LeftClickOnScene leftClickOnSceneEvent(this->dataPtr->mouseEvent);
App()->sendEvent(App()->findChild<MainWindow *>(), &leftClickOnSceneEvent);

this->dataPtr->mouseDirty = false;
}

/////////////////////////////////////////////////
Expand All @@ -454,8 +463,6 @@ void IgnRenderer::BroadcastRightClick()

events::RightClickOnScene rightClickOnSceneEvent(this->dataPtr->mouseEvent);
App()->sendEvent(App()->findChild<MainWindow *>(), &rightClickOnSceneEvent);

this->dataPtr->mouseDirty = false;
}

/////////////////////////////////////////////////
Expand All @@ -469,8 +476,6 @@ void IgnRenderer::BroadcastMousePress()

events::MousePressOnScene event(this->dataPtr->mouseEvent);
App()->sendEvent(App()->findChild<MainWindow *>(), &event);

this->dataPtr->mouseDirty = false;
}

/////////////////////////////////////////////////
Expand All @@ -484,8 +489,6 @@ void IgnRenderer::BroadcastScroll()

events::ScrollOnScene scrollOnSceneEvent(this->dataPtr->mouseEvent);
App()->sendEvent(App()->findChild<MainWindow *>(), &scrollOnSceneEvent);

this->dataPtr->mouseDirty = false;
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -641,7 +644,9 @@ void IgnRenderer::NewDropEvent(const std::string &_dropText,
void IgnRenderer::NewMouseEvent(const common::MouseEvent &_e)
{
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
this->dataPtr->mouseEvent = _e;
if (this->dataPtr->mouseEvents.size() >= this->dataPtr->kMaxMouseEventSize)
this->dataPtr->mouseEvents.pop_front();
this->dataPtr->mouseEvents.push_back(_e);
this->dataPtr->mouseDirty = true;
}

Expand Down