From 8e6b6d529439ec21d15f8ca6cc0b6638baab630d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 27 Oct 2014 15:58:42 -0700 Subject: [PATCH] have controller A button fire action at center of screen --- interface/src/Application.h | 2 ++ .../src/scripting/JoystickScriptingInterface.cpp | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.h b/interface/src/Application.h index e85c4f4db5..9930f5debc 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -283,6 +283,8 @@ public: PointShader& getPointShader() { return _pointShader; } FileLogger* getLogger() { return _logger; } + QPointF getViewportCenter() const + { return QPointF(_glWidget->getDeviceWidth() / 2.0f, _glWidget->getDeviceHeight() / 2.0f); } glm::vec2 getViewportDimensions() const { return glm::vec2(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); } NodeToJurisdictionMap& getVoxelServerJurisdictions() { return _voxelServerJurisdictions; } NodeToJurisdictionMap& getEntityServerJurisdictions() { return _entityServerJurisdictions; } diff --git a/interface/src/scripting/JoystickScriptingInterface.cpp b/interface/src/scripting/JoystickScriptingInterface.cpp index 9375f80045..f2c7ef4579 100644 --- a/interface/src/scripting/JoystickScriptingInterface.cpp +++ b/interface/src/scripting/JoystickScriptingInterface.cpp @@ -18,9 +18,12 @@ #undef main #endif +#include #include #include +#include "Application.h" + #include "JoystickScriptingInterface.h" #ifdef HAVE_SDL2 @@ -112,13 +115,24 @@ void JoystickScriptingInterface::update() { } if (event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) { - // this will either start or stop a cancel event + // this will either start or stop a global back event QEvent::Type backType = (event.type == SDL_CONTROLLERBUTTONDOWN) ? HFBackEvent::startType() : HFBackEvent::endType(); HFBackEvent backEvent(backType); qApp->sendEvent(qApp, &backEvent); + } else if (event.cbutton.button == SDL_CONTROLLER_BUTTON_A) { + // this will either start or stop a global action event + QEvent::Type actionType = (event.type == SDL_CONTROLLERBUTTONDOWN) + ? HFActionEvent::startType() + : HFActionEvent::endType(); + + // global action events fire in the center of the screen + QPointF centerPoint = Application::getInstance()->getViewportCenter(); + HFActionEvent actionEvent(actionType, centerPoint); + + qApp->sendEvent(qApp, &actionEvent); } } else if (event.type == SDL_CONTROLLERDEVICEADDED) {