From 8a9f2d172a638affb774f923c23c853d6a776a63 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 27 Oct 2014 15:51:59 -0700 Subject: [PATCH] rename HFCancelEvent to HFBackEvent, fire from joystick --- interface/src/Application.cpp | 10 +++++----- .../src/scripting/ControllerScriptingInterface.cpp | 6 +++--- .../src/scripting/JoystickScriptingInterface.cpp | 13 +++++++++++++ .../src/{HFCancelEvent.cpp => HFBackEvent.cpp} | 10 +++++----- .../src/{HFCancelEvent.h => HFBackEvent.h} | 14 +++++++------- 5 files changed, 33 insertions(+), 20 deletions(-) rename libraries/script-engine/src/{HFCancelEvent.cpp => HFBackEvent.cpp} (72%) rename libraries/script-engine/src/{HFCancelEvent.h => HFBackEvent.h} (66%) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9b83e6211c..b1f694671e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -56,7 +56,7 @@ #include #include #include -#include +#include #include #include #include @@ -1106,8 +1106,8 @@ void Application::keyPressEvent(QKeyEvent* event) { OculusManager::abandonCalibration(); // this fires the HFCancelEvent - HFCancelEvent startCancelEvent(HFCancelEvent::startType()); - sendEvent(this, &startCancelEvent); + HFBackEvent startBackEvent(HFBackEvent::startType()); + sendEvent(this, &startBackEvent); break; } @@ -1183,8 +1183,8 @@ void Application::keyReleaseEvent(QKeyEvent* event) { break; case Qt::Key_Escape: { // this ends the HFCancelEvent - HFCancelEvent endCancelEvent(HFCancelEvent::endType()); - sendEvent(this, &endCancelEvent); + HFBackEvent endBackEvent(HFBackEvent::endType()); + sendEvent(this, &endBackEvent); break; } diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 090bbea66e..d2cc847ab5 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -10,7 +10,7 @@ // #include -#include +#include #include "Application.h" #include "devices/MotionTracker.h" @@ -31,9 +31,9 @@ void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) { emit actionStartEvent(static_cast(*event)); } else if (event->type() == HFActionEvent::endType()) { emit actionEndEvent(static_cast(*event)); - } else if (event->type() == HFCancelEvent::startType()) { + } else if (event->type() == HFBackEvent::startType()) { emit cancelStartEvent(); - } else if (event->type() == HFCancelEvent::endType()) { + } else if (event->type() == HFBackEvent::endType()) { emit cancelEndEvent(); } } diff --git a/interface/src/scripting/JoystickScriptingInterface.cpp b/interface/src/scripting/JoystickScriptingInterface.cpp index ced063c8fe..9375f80045 100644 --- a/interface/src/scripting/JoystickScriptingInterface.cpp +++ b/interface/src/scripting/JoystickScriptingInterface.cpp @@ -9,6 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include #include @@ -17,6 +18,7 @@ #undef main #endif +#include #include #include "JoystickScriptingInterface.h" @@ -108,6 +110,17 @@ void JoystickScriptingInterface::update() { if (joystick) { joystick->handleButtonEvent(event.cbutton); } + + if (event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) { + // this will either start or stop a cancel event + QEvent::Type backType = (event.type == SDL_CONTROLLERBUTTONDOWN) + ? HFBackEvent::startType() + : HFBackEvent::endType(); + HFBackEvent backEvent(backType); + + qApp->sendEvent(qApp, &backEvent); + } + } else if (event.type == SDL_CONTROLLERDEVICEADDED) { SDL_GameController* controller = SDL_GameControllerOpen(event.cdevice.which); diff --git a/libraries/script-engine/src/HFCancelEvent.cpp b/libraries/script-engine/src/HFBackEvent.cpp similarity index 72% rename from libraries/script-engine/src/HFCancelEvent.cpp rename to libraries/script-engine/src/HFBackEvent.cpp index f6462eea49..c67b2e3431 100644 --- a/libraries/script-engine/src/HFCancelEvent.cpp +++ b/libraries/script-engine/src/HFBackEvent.cpp @@ -1,5 +1,5 @@ // -// HFCancelEvent.cpp +// HFBackEvent.cpp // script-engine/src // // Created by Stephen Birarda on 2014-10-27. @@ -9,20 +9,20 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "HFCancelEvent.h" +#include "HFBackEvent.h" -HFCancelEvent::HFCancelEvent(QEvent::Type type) : +HFBackEvent::HFBackEvent(QEvent::Type type) : HFMetaEvent(type) { } -QEvent::Type HFCancelEvent::startType() { +QEvent::Type HFBackEvent::startType() { static QEvent::Type startType = HFMetaEvent::newEventType(); return startType; } -QEvent::Type HFCancelEvent::endType() { +QEvent::Type HFBackEvent::endType() { static QEvent::Type endType = HFMetaEvent::newEventType(); return endType; } diff --git a/libraries/script-engine/src/HFCancelEvent.h b/libraries/script-engine/src/HFBackEvent.h similarity index 66% rename from libraries/script-engine/src/HFCancelEvent.h rename to libraries/script-engine/src/HFBackEvent.h index 8e3a761296..bb7b348ea7 100644 --- a/libraries/script-engine/src/HFCancelEvent.h +++ b/libraries/script-engine/src/HFBackEvent.h @@ -1,5 +1,5 @@ // -// HFCancelEvent.h +// HFBackEvent.h // script-engine/src // // Created by Stephen Birarda on 2014-10-27. @@ -9,21 +9,21 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_HFCancelEvent_h -#define hifi_HFCancelEvent_h +#ifndef hifi_HFBackEvent_h +#define hifi_HFBackEvent_h #include #include #include "HFMetaEvent.h" -class HFCancelEvent : public HFMetaEvent { +class HFBackEvent : public HFMetaEvent { public: - HFCancelEvent() {}; - HFCancelEvent(QEvent::Type type); + HFBackEvent() {}; + HFBackEvent(QEvent::Type type); static QEvent::Type startType(); static QEvent::Type endType(); }; -#endif // hifi_HFCancelEvent_h \ No newline at end of file +#endif // hifi_HFBackEvent_h \ No newline at end of file