Skip to content

Commit

Permalink
#5180: First round of cleanup in CamWnd class.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed May 16, 2020
1 parent e37536a commit 2e2bbb4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 126 deletions.
87 changes: 18 additions & 69 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -151,30 +151,29 @@ CamWnd::CamWnd(wxWindow* parent) :
_timer(this),
_timerLock(false)
{
Connect(wxEVT_TIMER, wxTimerEventHandler(CamWnd::onFrame), NULL, this);
Bind(wxEVT_TIMER, &CamWnd::onFrame, this);

constructGUIComponents();

// Deactivate all commands, just to make sure
disableDiscreteMoveEvents();
disableFreeMoveEvents();

// Connect the mouse button events
_wxGLWidget->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(CamWnd::onGLMouseButtonRelease), NULL, this);
_wxGLWidget->Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_RIGHT_DCLICK, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(CamWnd::onGLMouseButtonRelease), NULL, this);
_wxGLWidget->Connect(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_MIDDLE_DCLICK, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_MIDDLE_UP, wxMouseEventHandler(CamWnd::onGLMouseButtonRelease), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX1_DOWN, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX1_DCLICK, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX1_UP, wxMouseEventHandler(CamWnd::onGLMouseButtonRelease), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX2_DOWN, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX2_DCLICK, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX2_UP, wxMouseEventHandler(CamWnd::onGLMouseButtonRelease), NULL, this);
_wxGLWidget->Bind(wxEVT_LEFT_DOWN, &CamWnd::onGLMouseButtonPress, this);
_wxGLWidget->Bind(wxEVT_LEFT_DCLICK, &CamWnd::onGLMouseButtonPress, this);
_wxGLWidget->Bind(wxEVT_LEFT_UP, &CamWnd::onGLMouseButtonRelease, this);
_wxGLWidget->Bind(wxEVT_RIGHT_DOWN, &CamWnd::onGLMouseButtonPress, this);
_wxGLWidget->Bind(wxEVT_RIGHT_DCLICK, &CamWnd::onGLMouseButtonPress, this);
_wxGLWidget->Bind(wxEVT_RIGHT_UP, &CamWnd::onGLMouseButtonRelease, this);
_wxGLWidget->Bind(wxEVT_MIDDLE_DOWN, &CamWnd::onGLMouseButtonPress, this);
_wxGLWidget->Bind(wxEVT_MIDDLE_DCLICK, &CamWnd::onGLMouseButtonPress, this);
_wxGLWidget->Bind(wxEVT_MIDDLE_UP, &CamWnd::onGLMouseButtonRelease, this);
_wxGLWidget->Bind(wxEVT_AUX1_DOWN, &CamWnd::onGLMouseButtonPress, this);
_wxGLWidget->Bind(wxEVT_AUX1_DCLICK, &CamWnd::onGLMouseButtonPress, this);
_wxGLWidget->Bind(wxEVT_AUX1_UP, &CamWnd::onGLMouseButtonRelease, this);
_wxGLWidget->Bind(wxEVT_AUX2_DOWN, &CamWnd::onGLMouseButtonPress, this);
_wxGLWidget->Bind(wxEVT_AUX2_DCLICK, &CamWnd::onGLMouseButtonPress, this);
_wxGLWidget->Bind(wxEVT_AUX2_UP, &CamWnd::onGLMouseButtonRelease, this);

// Now add the handlers for the non-freelook mode, the events are activated by this
addHandlersMove();
Expand Down Expand Up @@ -528,8 +527,6 @@ void CamWnd::enableFreeMove()

removeHandlersMove();

enableFreeMoveEvents();

update();
}

Expand All @@ -539,8 +536,6 @@ void CamWnd::disableFreeMove()
_camera.freeMoveEnabled = false;
_camera.clearMovementFlags(MOVE_ALL);

disableFreeMoveEvents();

addHandlersMove();

update();
Expand Down Expand Up @@ -829,89 +824,43 @@ void CamWnd::onSceneGraphChange()

// ----------------------------------------------------------

void CamWnd::enableFreeMoveEvents()
{
#if 0
GlobalEventManager().enableEvent("CameraFreeMoveForward");
GlobalEventManager().enableEvent("CameraFreeMoveBack");
GlobalEventManager().enableEvent("CameraFreeMoveLeft");
GlobalEventManager().enableEvent("CameraFreeMoveRight");
GlobalEventManager().enableEvent("CameraFreeMoveUp");
GlobalEventManager().enableEvent("CameraFreeMoveDown");
#endif
}

void CamWnd::disableFreeMoveEvents()
{
#if 0
GlobalEventManager().disableEvent("CameraFreeMoveForward");
GlobalEventManager().disableEvent("CameraFreeMoveBack");
GlobalEventManager().disableEvent("CameraFreeMoveLeft");
GlobalEventManager().disableEvent("CameraFreeMoveRight");
GlobalEventManager().disableEvent("CameraFreeMoveUp");
GlobalEventManager().disableEvent("CameraFreeMoveDown");
#endif
}

void CamWnd::enableDiscreteMoveEvents()
{
#if 0
GlobalEventManager().enableEvent("CameraBack");
GlobalEventManager().enableEvent("CameraLeft");
GlobalEventManager().enableEvent("CameraRight");
#endif
GlobalEventManager().enableEvent("CameraStrafeRight");
GlobalEventManager().enableEvent("CameraStrafeLeft");
GlobalEventManager().enableEvent("CameraUp");
GlobalEventManager().enableEvent("CameraDown");
GlobalEventManager().enableEvent("CameraAngleUp");
GlobalEventManager().enableEvent("CameraAngleDown");
}

void CamWnd::disableDiscreteMoveEvents()
{
#if 0
GlobalEventManager().disableEvent("CameraBack");
GlobalEventManager().disableEvent("CameraLeft");
GlobalEventManager().disableEvent("CameraRight");
#endif
GlobalEventManager().disableEvent("CameraStrafeRight");
GlobalEventManager().disableEvent("CameraStrafeLeft");
GlobalEventManager().disableEvent("CameraUp");
GlobalEventManager().disableEvent("CameraDown");
GlobalEventManager().disableEvent("CameraAngleUp");
GlobalEventManager().disableEvent("CameraAngleDown");
}

void CamWnd::addHandlersMove()
{
_wxGLWidget->Connect(wxEVT_MOTION, wxMouseEventHandler(CamWnd::onGLMouseMove), NULL, this);
_wxGLWidget->Bind(wxEVT_MOTION, &CamWnd::onGLMouseMove, this);

// Enable either the free-look movement commands or the discrete ones,
// depending on the selection
if (getCameraSettings()->discreteMovement())
{
enableDiscreteMoveEvents();
}
else
{
enableFreeMoveEvents();
}
}

void CamWnd::removeHandlersMove()
{
_wxGLWidget->Disconnect(wxEVT_MOTION, wxMouseEventHandler(CamWnd::onGLMouseMove), NULL, this);
_wxGLWidget->Unbind(wxEVT_MOTION, &CamWnd::onGLMouseMove, this);

// Disable either the free-look movement commands or the discrete ones, depending on the selection
if (getCameraSettings()->discreteMovement())
{
disableDiscreteMoveEvents();
}
else
{
disableFreeMoveEvents();
}
}

void CamWnd::update()
Expand Down
2 changes: 0 additions & 2 deletions radiant/camera/CamWnd.h
Expand Up @@ -138,9 +138,7 @@ class CamWnd :
void removeHandlersMove();

void enableDiscreteMoveEvents();
void enableFreeMoveEvents();
void disableDiscreteMoveEvents();
void disableFreeMoveEvents();

// Increases/decreases the far clip plane distance
void farClipPlaneIn();
Expand Down
50 changes: 1 addition & 49 deletions radiant/camera/GlobalCamera.cpp
Expand Up @@ -60,15 +60,9 @@ void GlobalCameraManager::registerCommands()
{ cmd::ARGTYPE_STRING, cmd::ARGTYPE_DOUBLE });

// Insert movement commands
//GlobalCommandSystem().addCommand("CameraForward", std::bind(&GlobalCameraManager::moveForwardDiscrete, this, std::placeholders::_1));
//GlobalCommandSystem().addCommand("CameraBack", std::bind(&GlobalCameraManager::moveBackDiscrete, this, std::placeholders::_1));
//GlobalCommandSystem().addCommand("CameraLeft", std::bind(&GlobalCameraManager::rotateLeftDiscrete, this, std::placeholders::_1));
//GlobalCommandSystem().addCommand("CameraRight", std::bind(&GlobalCameraManager::rotateRightDiscrete, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("CameraStrafeRight", std::bind(&GlobalCameraManager::moveRightDiscrete, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("CameraStrafeLeft", std::bind(&GlobalCameraManager::moveLeftDiscrete, this, std::placeholders::_1));

//GlobalCommandSystem().addCommand("CameraUp", std::bind(&GlobalCameraManager::moveUpDiscrete, this, std::placeholders::_1));
//GlobalCommandSystem().addCommand("CameraDown", std::bind(&GlobalCameraManager::moveDownDiscrete, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("CameraAngleUp", std::bind(&GlobalCameraManager::pitchUpDiscrete, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("CameraAngleDown", std::bind(&GlobalCameraManager::pitchDownDiscrete, this, std::placeholders::_1));

Expand Down Expand Up @@ -469,7 +463,7 @@ void GlobalCameraManager::onFreelookMoveDownKey(ui::KeyEventType eventType)
auto camWnd = getActiveCamWnd();
if (!camWnd) return;

camWnd->getCamera().onUpKey(eventType);
camWnd->getCamera().onDownKey(eventType);
#if 0
if (eventType == ui::KeyPressed)
{
Expand All @@ -482,34 +476,6 @@ void GlobalCameraManager::onFreelookMoveDownKey(ui::KeyEventType eventType)
#endif
}

void GlobalCameraManager::moveForwardDiscrete(const cmd::ArgumentList& args) {
CamWndPtr camWnd = getActiveCamWnd();
if (camWnd == NULL) return;

camWnd->getCamera().moveForwardDiscrete(SPEED_MOVE);
}

void GlobalCameraManager::moveBackDiscrete(const cmd::ArgumentList& args) {
CamWndPtr camWnd = getActiveCamWnd();
if (camWnd == NULL) return;

camWnd->getCamera().moveBackDiscrete(SPEED_MOVE);
}

void GlobalCameraManager::moveUpDiscrete(const cmd::ArgumentList& args) {
CamWndPtr camWnd = getActiveCamWnd();
if (camWnd == NULL) return;

camWnd->getCamera().moveUpDiscrete(SPEED_MOVE);
}

void GlobalCameraManager::moveDownDiscrete(const cmd::ArgumentList& args) {
CamWndPtr camWnd = getActiveCamWnd();
if (camWnd == NULL) return;

camWnd->getCamera().moveDownDiscrete(SPEED_MOVE);
}

void GlobalCameraManager::moveLeftDiscrete(const cmd::ArgumentList& args) {
CamWndPtr camWnd = getActiveCamWnd();
if (camWnd == NULL) return;
Expand All @@ -524,20 +490,6 @@ void GlobalCameraManager::moveRightDiscrete(const cmd::ArgumentList& args) {
camWnd->getCamera().moveRightDiscrete(SPEED_MOVE);
}

void GlobalCameraManager::rotateLeftDiscrete(const cmd::ArgumentList& args) {
CamWndPtr camWnd = getActiveCamWnd();
if (camWnd == NULL) return;

camWnd->getCamera().rotateLeftDiscrete();
}

void GlobalCameraManager::rotateRightDiscrete(const cmd::ArgumentList& args) {
CamWndPtr camWnd = getActiveCamWnd();
if (camWnd == NULL) return;

camWnd->getCamera().rotateRightDiscrete();
}

void GlobalCameraManager::pitchUpDiscrete(const cmd::ArgumentList& args) {
CamWndPtr camWnd = getActiveCamWnd();
if (camWnd == NULL) return;
Expand Down
6 changes: 0 additions & 6 deletions radiant/camera/GlobalCamera.h
Expand Up @@ -103,14 +103,8 @@ class GlobalCameraManager :

// Movement commands (the calls are passed on to the Camera class)
void moveCameraCmd(const cmd::ArgumentList& args);
void moveForwardDiscrete(const cmd::ArgumentList& args);
void moveBackDiscrete(const cmd::ArgumentList& args);
void moveUpDiscrete(const cmd::ArgumentList& args);
void moveDownDiscrete(const cmd::ArgumentList& args);
void moveLeftDiscrete(const cmd::ArgumentList& args);
void moveRightDiscrete(const cmd::ArgumentList& args);
void rotateLeftDiscrete(const cmd::ArgumentList& args);
void rotateRightDiscrete(const cmd::ArgumentList& args);
void pitchUpDiscrete(const cmd::ArgumentList& args);
void pitchDownDiscrete(const cmd::ArgumentList& args);

Expand Down

0 comments on commit 2e2bbb4

Please sign in to comment.