From 5addc35cd8a7f68e82229c5b2635e7aaa8a3575f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 28 Jan 2014 14:58:08 -0800 Subject: [PATCH] hacking on controller events --- interface/src/Application.cpp | 17 +++++++++++++ interface/src/ControllerScriptingInterface.h | 25 +++++++++++++++++++ .../AbstractControllerScriptingInterface.h | 19 ++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 228a8bdd2f..fd365d67e8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -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& 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()) { diff --git a/interface/src/ControllerScriptingInterface.h b/interface/src/ControllerScriptingInterface.h index 69daefa3fb..ca14729151 100644 --- a/interface/src/ControllerScriptingInterface.h +++ b/interface/src/ControllerScriptingInterface.h @@ -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; diff --git a/libraries/script-engine/src/AbstractControllerScriptingInterface.h b/libraries/script-engine/src/AbstractControllerScriptingInterface.h index 5c791af0a4..b3f482c74e 100644 --- a/libraries/script-engine/src/AbstractControllerScriptingInterface.h +++ b/libraries/script-engine/src/AbstractControllerScriptingInterface.h @@ -10,8 +10,12 @@ #define __hifi__AbstractControllerScriptingInterface__ #include + #include +#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__) */