hacking on controller events

This commit is contained in:
ZappoMan 2014-01-28 14:58:08 -08:00
parent 64afd17d14
commit 5addc35cd8
3 changed files with 61 additions and 0 deletions

View file

@ -681,6 +681,9 @@ void Application::controlledBroadcastToNodes(unsigned char* broadcastData, size_
}
void Application::keyPressEvent(QKeyEvent* event) {
_controllerScriptingInterface.emitKeyPressEvent(event); // send events to any registered scripts
if (activeWindow() == _window) {
if (_chatEntryOn) {
if (_chatEntry.keyPressEvent(event)) {
@ -1092,6 +1095,9 @@ void Application::keyPressEvent(QKeyEvent* event) {
}
void Application::keyReleaseEvent(QKeyEvent* event) {
_controllerScriptingInterface.emitKeyReleaseEvent(event); // send events to any registered scripts
if (activeWindow() == _window) {
if (_chatEntryOn) {
_myAvatar.setKeyState(NO_KEY_DOWN);
@ -1154,6 +1160,8 @@ void Application::keyReleaseEvent(QKeyEvent* event) {
}
void Application::mouseMoveEvent(QMouseEvent* event) {
_controllerScriptingInterface.emitMouseMoveEvent(event); // send events to any registered scripts
_lastMouseMove = usecTimestampNow();
if (_mouseHidden) {
getGLWidget()->setCursor(Qt::ArrowCursor);
@ -1200,6 +1208,7 @@ const float HOVER_VOXEL_FREQUENCY = 7040.f;
const float HOVER_VOXEL_DECAY = 0.999f;
void Application::mousePressEvent(QMouseEvent* event) {
_controllerScriptingInterface.emitMousePressEvent(event); // send events to any registered scripts
if (activeWindow() == _window) {
if (event->button() == Qt::LeftButton) {
_mouseX = event->x();
@ -1267,6 +1276,7 @@ void Application::mousePressEvent(QMouseEvent* event) {
}
void Application::mouseReleaseEvent(QMouseEvent* event) {
_controllerScriptingInterface.emitMouseReleaseEvent(event); // send events to any registered scripts
if (activeWindow() == _window) {
if (event->button() == Qt::LeftButton) {
_mouseX = event->x();
@ -1283,6 +1293,7 @@ void Application::mouseReleaseEvent(QMouseEvent* event) {
}
void Application::touchUpdateEvent(QTouchEvent* event) {
_controllerScriptingInterface.emitTouchUpdateEvent(event); // send events to any registered scripts
bool validTouch = false;
if (activeWindow() == _window) {
const QList<QTouchEvent::TouchPoint>& tPoints = event->touchPoints();
@ -1307,12 +1318,15 @@ void Application::touchUpdateEvent(QTouchEvent* event) {
}
void Application::touchBeginEvent(QTouchEvent* event) {
_controllerScriptingInterface.emitTouchBeginEvent(event); // send events to any registered scripts
touchUpdateEvent(event);
_lastTouchAvgX = _touchAvgX;
_lastTouchAvgY = _touchAvgY;
}
void Application::touchEndEvent(QTouchEvent* event) {
_controllerScriptingInterface.emitTouchEndEvent(event); // send events to any registered scripts
_touchDragStartedAvgX = _touchAvgX;
_touchDragStartedAvgY = _touchAvgY;
_isTouchPressed = false;
@ -1320,6 +1334,9 @@ void Application::touchEndEvent(QTouchEvent* event) {
const bool USE_MOUSEWHEEL = false;
void Application::wheelEvent(QWheelEvent* event) {
_controllerScriptingInterface.emitWheelEvent(event); // send events to any registered scripts
// Wheel Events disabled for now because they are also activated by touch look pitch up/down.
if (USE_MOUSEWHEEL && (activeWindow() == _window)) {
if (!Menu::getInstance()->isVoxelModeActionChecked()) {

View file

@ -18,6 +18,25 @@ class PalmData;
class ControllerScriptingInterface : public AbstractControllerScriptingInterface {
Q_OBJECT
public:
void emitKeyPressEvent(QKeyEvent* x) {
KeyEvent event(x);
emit keyPressEvent(event);
}
/**
void emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(*event); }
void emitMouseMoveEvent(QMouseEvent* event) { emit mouseMoveEvent(*event); }
void emitMousePressEvent(QMouseEvent* event) { emit mousePressEvent(*event); }
void emitMouseReleaseEvent(QMouseEvent* event) { emit mouseReleaseEvent(*event); }
void emitTouchBeginEvent(QTouchEvent* event) { emit touchBeginEvent(event); }
void emitTouchEndEvent(QTouchEvent* event) { emit touchEndEvent(event); }
void emitTouchUpdateEvent(QTouchEvent* event) { emit touchUpdateEvent(event); }
void emitWheelEvent(QWheelEvent* event) { emit wheelEvent(event); }
**/
public slots:
virtual bool isPrimaryButtonPressed() const;
virtual glm::vec2 getPrimaryJoystickPosition() const;
@ -36,6 +55,12 @@ public slots:
virtual glm::vec3 getSpatialControlVelocity(int controlIndex) const;
virtual glm::vec3 getSpatialControlNormal(int controlIndex) const;
// The following signals are defined by AbstractControllerScriptingInterface
//
// signals:
// void keyPressEvent();
// void keyPressEvent();
private:
const PalmData* getPrimaryPalm() const;
const PalmData* getPalm(int palmIndex) const;

View file

@ -10,8 +10,12 @@
#define __hifi__AbstractControllerScriptingInterface__
#include <QtCore/QObject>
#include <glm/glm.hpp>
#include "EventTypes.h"
/// handles scripting of input controller commands from JS
class AbstractControllerScriptingInterface : public QObject {
Q_OBJECT
@ -33,6 +37,21 @@ public slots:
virtual glm::vec3 getSpatialControlPosition(int controlIndex) const = 0;
virtual glm::vec3 getSpatialControlVelocity(int controlIndex) const = 0;
virtual glm::vec3 getSpatialControlNormal(int controlIndex) const = 0;
signals:
void keyPressEvent(const KeyEvent& event);
void keyReleaseEvent(const KeyEvent& event);
void mouseMoveEvent(const MouseEvent& event);
void mousePressEvent(const MouseEvent& event);
void mouseReleaseEvent(const MouseEvent& event);
void touchBeginEvent(const TouchEvent& event);
void touchEndEvent(const TouchEvent& event);
void touchUpdateEvent(const TouchEvent& event);
void wheelEvent(const WheelEvent& event);
};
#endif /* defined(__hifi__AbstractControllerScriptingInterface__) */