Skip to content

Commit

Permalink
#5338: Move Deferred motion handling to CamWnd
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 26, 2020
1 parent 9bb4559 commit 430cd27
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
14 changes: 11 additions & 3 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -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());
Expand Down Expand Up @@ -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<float>(1000);

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
5 changes: 5 additions & 0 deletions radiant/camera/CamWnd.h
Expand Up @@ -11,6 +11,7 @@
#include "wxutil/XmlResourceBasedWidget.h"
#include "wxutil/event/KeyEventFilter.h"
#include "wxutil/MouseToolHandler.h"
#include "wxutil/DeferredMotionDelta.h"

#include <wx/wxprec.h>
#include <wx/glcanvas.h>
Expand Down Expand Up @@ -83,6 +84,8 @@ class CamWnd :
wxTimer _freeMoveTimer;
wxStopWatch _keyControlTimer;

wxutil::DeferredMotionDelta _deferredMotionDelta;

public:
// Constructor and destructor
CamWnd(wxWindow* parent);
Expand Down Expand Up @@ -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);
};

/**
Expand Down
6 changes: 0 additions & 6 deletions radiant/camera/Camera.cpp
Expand Up @@ -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)
{}

Expand Down Expand Up @@ -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();
Expand Down
6 changes: 0 additions & 6 deletions radiant/camera/Camera.h
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 430cd27

Please sign in to comment.