From 430cd2712992313cfd1ad6259620687e987bd731 Mon Sep 17 00:00:00 2001 From: codereader Date: Sat, 26 Sep 2020 06:33:34 +0200 Subject: [PATCH] #5338: Move Deferred motion handling to CamWnd --- radiant/camera/CamWnd.cpp | 14 +++++++++++--- radiant/camera/CamWnd.h | 5 +++++ radiant/camera/Camera.cpp | 6 ------ radiant/camera/Camera.h | 6 ------ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/radiant/camera/CamWnd.cpp b/radiant/camera/CamWnd.cpp index d062bd7716..5bdcc1d6fc 100644 --- a/radiant/camera/CamWnd.cpp +++ b/radiant/camera/CamWnd.cpp @@ -151,7 +151,8 @@ CamWnd::CamWnd(wxWindow* parent) : _timer(this), _timerLock(false), _freeMoveFlags(0), - _freeMoveTimer(this) + _freeMoveTimer(this), + _deferredMotionDelta(std::bind(&CamWnd::onDeferredMotionDelta, this, std::placeholders::_1, std::placeholders::_2)) { Bind(wxEVT_TIMER, &CamWnd::onFrame, this, _timer.GetId()); Bind(wxEVT_TIMER, &CamWnd::onFreeMoveTimer, this, _freeMoveTimer.GetId()); @@ -577,7 +578,7 @@ void CamWnd::handleFreeMovement(float timePassed) void CamWnd::onFreeMoveTimer(wxTimerEvent& ev) { - _camera.m_mouseMove.flush(); + _deferredMotionDelta.flush(); float time_seconds = _keyControlTimer.Time() / static_cast(1000); @@ -621,6 +622,13 @@ bool CamWnd::freeMoveEnabled() const return _camera.freeMoveEnabled; } +void CamWnd::onDeferredMotionDelta(int x, int y) +{ + _camera.freeMove(-x, -y); + queueDraw(); + GlobalCamera().movedNotify(); +} + void CamWnd::Cam_Draw() { wxSize glSize = _wxGLWidget->GetSize(); @@ -1152,7 +1160,7 @@ void CamWnd::onGLMouseMove(wxMouseEvent& ev) void CamWnd::handleGLMouseMoveFreeMoveDelta(int x, int y, unsigned int state) { - _camera.m_mouseMove.onMouseMotionDelta(x, y, state); + _deferredMotionDelta.onMouseMotionDelta(x, y, state); unsigned int strafeFlags = GlobalCamera().getStrafeModifierFlags(); diff --git a/radiant/camera/CamWnd.h b/radiant/camera/CamWnd.h index 78caa422d0..0920a4d73a 100644 --- a/radiant/camera/CamWnd.h +++ b/radiant/camera/CamWnd.h @@ -11,6 +11,7 @@ #include "wxutil/XmlResourceBasedWidget.h" #include "wxutil/event/KeyEventFilter.h" #include "wxutil/MouseToolHandler.h" +#include "wxutil/DeferredMotionDelta.h" #include #include @@ -83,6 +84,8 @@ class CamWnd : wxTimer _freeMoveTimer; wxStopWatch _keyControlTimer; + wxutil::DeferredMotionDelta _deferredMotionDelta; + public: // Constructor and destructor CamWnd(wxWindow* parent); @@ -204,6 +207,8 @@ class CamWnd : void handleFreeMovement(float timePassed); void setFreeMoveFlags(unsigned int mask); void clearFreeMoveFlags(unsigned int mask); + // Gets called with the accumulated delta values, as buffered by wxutil::DeferredMotionDelta + void onDeferredMotionDelta(int x, int y); }; /** diff --git a/radiant/camera/Camera.cpp b/radiant/camera/Camera.cpp index d78712bfaa..8cec7bbff6 100644 --- a/radiant/camera/Camera.cpp +++ b/radiant/camera/Camera.cpp @@ -60,7 +60,6 @@ Camera::Camera(render::View& view, const Callback& queueDraw, const Callback& fo modelview(Matrix4::getIdentity()), freeMoveEnabled(false), fieldOfView(75.0f), - m_mouseMove(std::bind(&Camera::onMotionDelta, this, std::placeholders::_1, std::placeholders::_2)), _view(view) {} @@ -284,11 +283,6 @@ void Camera::updateProjection() _view.Construct(projection, modelview, width, height); } -void Camera::onMotionDelta(int x, int y) -{ - mouseMove(x, y); -} - void Camera::pitchUpDiscrete() { Vector3 angles = getCameraAngles(); diff --git a/radiant/camera/Camera.h b/radiant/camera/Camera.h index 4120382d8c..87d5efa6b4 100644 --- a/radiant/camera/Camera.h +++ b/radiant/camera/Camera.h @@ -3,7 +3,6 @@ #include "icameraview.h" #include "math/Vector3.h" #include "math/Matrix4.h" -#include "wxutil/DeferredMotionDelta.h" #include "generic/callback.h" #include "render/View.h" @@ -58,11 +57,6 @@ class Camera : float fieldOfView; - wxutil::DeferredMotionDelta m_mouseMove; - - // Gets called with the accumulated delta values, as buffered by wxutil::DeferredMotionDelta - void onMotionDelta(int x, int y); - render::View& _view; Camera(render::View& view, const Callback& queueDraw, const Callback& forceRedraw);