have controller A button fire action at center of screen

This commit is contained in:
Stephen Birarda 2014-10-27 15:58:42 -07:00
parent 8a9f2d172a
commit 8e6b6d5294
2 changed files with 17 additions and 1 deletions

View file

@ -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; }

View file

@ -18,9 +18,12 @@
#undef main
#endif
#include <HFActionEvent.h>
#include <HFBackEvent.h>
#include <PerfStat.h>
#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) {