rename HFCancelEvent to HFBackEvent, fire from joystick

This commit is contained in:
Stephen Birarda 2014-10-27 15:51:59 -07:00
parent 04e7e979aa
commit 8a9f2d172a
5 changed files with 33 additions and 20 deletions

View file

@ -56,7 +56,7 @@
#include <AudioInjector.h> #include <AudioInjector.h>
#include <EntityScriptingInterface.h> #include <EntityScriptingInterface.h>
#include <HFActionEvent.h> #include <HFActionEvent.h>
#include <HFCancelEvent.h> #include <HFBackEvent.h>
#include <LocalVoxelsList.h> #include <LocalVoxelsList.h>
#include <Logging.h> #include <Logging.h>
#include <NetworkAccessManager.h> #include <NetworkAccessManager.h>
@ -1106,8 +1106,8 @@ void Application::keyPressEvent(QKeyEvent* event) {
OculusManager::abandonCalibration(); OculusManager::abandonCalibration();
// this fires the HFCancelEvent // this fires the HFCancelEvent
HFCancelEvent startCancelEvent(HFCancelEvent::startType()); HFBackEvent startBackEvent(HFBackEvent::startType());
sendEvent(this, &startCancelEvent); sendEvent(this, &startBackEvent);
break; break;
} }
@ -1183,8 +1183,8 @@ void Application::keyReleaseEvent(QKeyEvent* event) {
break; break;
case Qt::Key_Escape: { case Qt::Key_Escape: {
// this ends the HFCancelEvent // this ends the HFCancelEvent
HFCancelEvent endCancelEvent(HFCancelEvent::endType()); HFBackEvent endBackEvent(HFBackEvent::endType());
sendEvent(this, &endCancelEvent); sendEvent(this, &endBackEvent);
break; break;
} }

View file

@ -10,7 +10,7 @@
// //
#include <HandData.h> #include <HandData.h>
#include <HFCancelEvent.h> #include <HFBackEvent.h>
#include "Application.h" #include "Application.h"
#include "devices/MotionTracker.h" #include "devices/MotionTracker.h"
@ -31,9 +31,9 @@ void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) {
emit actionStartEvent(static_cast<HFActionEvent&>(*event)); emit actionStartEvent(static_cast<HFActionEvent&>(*event));
} else if (event->type() == HFActionEvent::endType()) { } else if (event->type() == HFActionEvent::endType()) {
emit actionEndEvent(static_cast<HFActionEvent&>(*event)); emit actionEndEvent(static_cast<HFActionEvent&>(*event));
} else if (event->type() == HFCancelEvent::startType()) { } else if (event->type() == HFBackEvent::startType()) {
emit cancelStartEvent(); emit cancelStartEvent();
} else if (event->type() == HFCancelEvent::endType()) { } else if (event->type() == HFBackEvent::endType()) {
emit cancelEndEvent(); emit cancelEndEvent();
} }
} }

View file

@ -9,6 +9,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include <qapplication.h>
#include <QtDebug> #include <QtDebug>
#include <QScriptValue> #include <QScriptValue>
@ -17,6 +18,7 @@
#undef main #undef main
#endif #endif
#include <HFBackEvent.h>
#include <PerfStat.h> #include <PerfStat.h>
#include "JoystickScriptingInterface.h" #include "JoystickScriptingInterface.h"
@ -108,6 +110,17 @@ void JoystickScriptingInterface::update() {
if (joystick) { if (joystick) {
joystick->handleButtonEvent(event.cbutton); 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) { } else if (event.type == SDL_CONTROLLERDEVICEADDED) {
SDL_GameController* controller = SDL_GameControllerOpen(event.cdevice.which); SDL_GameController* controller = SDL_GameControllerOpen(event.cdevice.which);

View file

@ -1,5 +1,5 @@
// //
// HFCancelEvent.cpp // HFBackEvent.cpp
// script-engine/src // script-engine/src
// //
// Created by Stephen Birarda on 2014-10-27. // 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 // 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) HFMetaEvent(type)
{ {
} }
QEvent::Type HFCancelEvent::startType() { QEvent::Type HFBackEvent::startType() {
static QEvent::Type startType = HFMetaEvent::newEventType(); static QEvent::Type startType = HFMetaEvent::newEventType();
return startType; return startType;
} }
QEvent::Type HFCancelEvent::endType() { QEvent::Type HFBackEvent::endType() {
static QEvent::Type endType = HFMetaEvent::newEventType(); static QEvent::Type endType = HFMetaEvent::newEventType();
return endType; return endType;
} }

View file

@ -1,5 +1,5 @@
// //
// HFCancelEvent.h // HFBackEvent.h
// script-engine/src // script-engine/src
// //
// Created by Stephen Birarda on 2014-10-27. // 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 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#ifndef hifi_HFCancelEvent_h #ifndef hifi_HFBackEvent_h
#define hifi_HFCancelEvent_h #define hifi_HFBackEvent_h
#include <qevent.h> #include <qevent.h>
#include <qscriptengine.h> #include <qscriptengine.h>
#include "HFMetaEvent.h" #include "HFMetaEvent.h"
class HFCancelEvent : public HFMetaEvent { class HFBackEvent : public HFMetaEvent {
public: public:
HFCancelEvent() {}; HFBackEvent() {};
HFCancelEvent(QEvent::Type type); HFBackEvent(QEvent::Type type);
static QEvent::Type startType(); static QEvent::Type startType();
static QEvent::Type endType(); static QEvent::Type endType();
}; };
#endif // hifi_HFCancelEvent_h #endif // hifi_HFBackEvent_h