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 <EntityScriptingInterface.h>
#include <HFActionEvent.h>
#include <HFCancelEvent.h>
#include <HFBackEvent.h>
#include <LocalVoxelsList.h>
#include <Logging.h>
#include <NetworkAccessManager.h>
@ -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;
}

View file

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

View file

@ -9,6 +9,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <qapplication.h>
#include <QtDebug>
#include <QScriptValue>
@ -17,6 +18,7 @@
#undef main
#endif
#include <HFBackEvent.h>
#include <PerfStat.h>
#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);

View file

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

View file

@ -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 <qevent.h>
#include <qscriptengine.h>
#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
#endif // hifi_HFBackEvent_h