History

consolidate all calls to QCursor::pos() and QCursor.setPosition() to use common ControllerScriptingInterface

Brad Hefta-Gaub committed 10 years ago

Commit 0d873c71 parent bf52d305 files · +11 −67Browse files

Showing the changes to interface/src/Application.cpp (1 of 5 files). Show all

Unified · Split

interface/src/Application.cpp+11−33
@@ -806,39 +806,14 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 805 unmodified lines
806806 } else if (action == controller::toInt(controller::Action::CYCLE_CAMERA)) {
807807 cycleCamera();
808808 } else if (action == controller::toInt(controller::Action::CONTEXT_MENU)) {
809− offscreenUi->toggleMenu(_glWidget->mapFromGlobal(QCursor::pos()));
809+ auto reticlePosition = _controllerScriptingInterface->getReticlePosition();
810+ offscreenUi->toggleMenu(_glWidget->mapFromGlobal(QPoint(reticlePosition.x, reticlePosition.y)));
810811 } else if (action == controller::toInt(controller::Action::RETICLE_X)) {
811− auto oldPos = QCursor::pos();
812− auto newPos = oldPos;
813− newPos.setX(oldPos.x() + state);
814− QCursor::setPos(newPos);
815−
816−
817− // NOTE: This is some debugging code we will leave in while debugging various reticle movement strategies,
818− // remove it after we're done
819− const float REASONABLE_CHANGE = 50.0f;
820− glm::vec2 oldPosG = { oldPos.x(), oldPos.y() };
821− glm::vec2 newPosG = { newPos.x(), newPos.y() };
822− auto distance = glm::distance(oldPosG, newPosG);
823− if (distance > REASONABLE_CHANGE) {
824− qDebug() << "Action::RETICLE_X... UNREASONABLE CHANGE! distance:" << distance << " oldPos:" << oldPosG << " newPos:" << newPosG;
825− }
826−
812+ auto oldPos = _controllerScriptingInterface->getReticlePosition();
813+ _controllerScriptingInterface->setReticlePosition({ oldPos.x + state, oldPos.y });
827814 } else if (action == controller::toInt(controller::Action::RETICLE_Y)) {
828− auto oldPos = QCursor::pos();
829− auto newPos = oldPos;
830− newPos.setY(oldPos.y() + state);
831− QCursor::setPos(newPos);
832−
833− // NOTE: This is some debugging code we will leave in while debugging various reticle movement strategies,
834− // remove it after we're done
835− const float REASONABLE_CHANGE = 50.0f;
836− glm::vec2 oldPosG = { oldPos.x(), oldPos.y() };
837− glm::vec2 newPosG = { newPos.x(), newPos.y() };
838− auto distance = glm::distance(oldPosG, newPosG);
839− if (distance > REASONABLE_CHANGE) {
840− qDebug() << "Action::RETICLE_Y... UNREASONABLE CHANGE! distance:" << distance << " oldPos:" << oldPosG << " newPos:" << newPosG;
841− }
815+ auto oldPos = _controllerScriptingInterface->getReticlePosition();
816+ _controllerScriptingInterface->setReticlePosition({ oldPos.x, oldPos.y + state });
842817 }
843818 }
844819 });
@@ -2110,7 +2085,8 @@ void Application::keyPressEvent(QKeyEvent* event) { · 1265 unmodified lines
21102085 void Application::keyReleaseEvent(QKeyEvent* event) {
21112086 if (event->key() == Qt::Key_Alt && _altPressed && hasFocus()) {
21122087 auto offscreenUi = DependencyManager::get<OffscreenUi>();
2113− offscreenUi->toggleMenu(_glWidget->mapFromGlobal(QCursor::pos()));
2088+ auto reticlePosition = _controllerScriptingInterface->getReticlePosition();
2089+ offscreenUi->toggleMenu(_glWidget->mapFromGlobal(QPoint(reticlePosition.x, reticlePosition.y)));
21142090 }
21152091
21162092 _keysPressed.remove(event->key());
@@ -4727,8 +4703,10 @@ bool Application::isThrottleRendering() const { · 2610 unmodified lines
47274703 return getActiveDisplayPlugin()->isThrottled();
47284704 }
47294705
4706+// FIXME -- consolidate users of getTrueMouse() controllerScriptingInterface->getReticlePosition()
47304707 ivec2 Application::getTrueMouse() const {
4731− return toGlm(_glWidget->mapFromGlobal(QCursor::pos()));
4708+ auto reticlePosition = _controllerScriptingInterface->getReticlePosition();
4709+ return toGlm(_glWidget->mapFromGlobal(QPoint(reticlePosition.x, reticlePosition.y)));
47324710 }
47334711
47344712 bool Application::hasFocus() const {