History

have controller A button fire action at center of screen

Stephen Birarda committed 12 years ago

Commit 8e6b6d51 parent 8a9f2d12 files · +17 −1Browse files

Showing the changes to interface/src/scripting/JoystickScriptingInterface.cpp (1 of 2 files). Show all

Unified · Split

interface/src/scripting/JoystickScriptingInterface.cpp+15−1
@@ -18,9 +18,12 @@ · 17 unmodified lines
1818 #undef main
1919 #endif
2020
21+#include <HFActionEvent.h>
2122 #include <HFBackEvent.h>
2223 #include <PerfStat.h>
2324
25+#include "Application.h"
26+
2427 #include "JoystickScriptingInterface.h"
2528
2629 #ifdef HAVE_SDL2
@@ -112,13 +115,24 @@ void JoystickScriptingInterface::update() { · 85 unmodified lines
112115 }
113116
114117 if (event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) {
115− // this will either start or stop a cancel event
118+ // this will either start or stop a global back event
116119 QEvent::Type backType = (event.type == SDL_CONTROLLERBUTTONDOWN)
117120 ? HFBackEvent::startType()
118121 : HFBackEvent::endType();
119122 HFBackEvent backEvent(backType);
120123
121124 qApp->sendEvent(qApp, &backEvent);
125+ } else if (event.cbutton.button == SDL_CONTROLLER_BUTTON_A) {
126+ // this will either start or stop a global action event
127+ QEvent::Type actionType = (event.type == SDL_CONTROLLERBUTTONDOWN)
128+ ? HFActionEvent::startType()
129+ : HFActionEvent::endType();
130+
131+ // global action events fire in the center of the screen
132+ QPointF centerPoint = Application::getInstance()->getViewportCenter();
133+ HFActionEvent actionEvent(actionType, centerPoint);
134+
135+ qApp->sendEvent(qApp, &actionEvent);
122136 }
123137
124138 } else if (event.type == SDL_CONTROLLERDEVICEADDED) {