Merge pull request #3673 from birarda/lobby
initial groundwork for lobby interface
This commit is contained in:
commit
4e7e9641f0
@ -12,7 +12,7 @@ macro(SETUP_HIFI_LIBRARY)
|
|||||||
project(${TARGET_NAME})
|
project(${TARGET_NAME})
|
||||||
|
|
||||||
# grab the implemenation and header files
|
# grab the implemenation and header files
|
||||||
file(GLOB LIB_SRCS src/*.h src/*.cpp)
|
file(GLOB_RECURSE LIB_SRCS "src/*.h" "src/*.cpp")
|
||||||
set(LIB_SRCS ${LIB_SRCS})
|
set(LIB_SRCS ${LIB_SRCS})
|
||||||
|
|
||||||
# create a library and set the property so it can be referenced later
|
# create a library and set the property so it can be referenced later
|
||||||
|
@ -44,11 +44,7 @@ configure_file(InterfaceConfig.h.in "${PROJECT_BINARY_DIR}/includes/InterfaceCon
|
|||||||
configure_file(InterfaceVersion.h.in "${PROJECT_BINARY_DIR}/includes/InterfaceVersion.h")
|
configure_file(InterfaceVersion.h.in "${PROJECT_BINARY_DIR}/includes/InterfaceVersion.h")
|
||||||
|
|
||||||
# grab the implementation and header files from src dirs
|
# grab the implementation and header files from src dirs
|
||||||
file(GLOB INTERFACE_SRCS src/*.cpp src/*.h)
|
file(GLOB_RECURSE INTERFACE_SRCS "src/*.cpp" "src/*.h")
|
||||||
foreach(SUBDIR avatar devices renderer ui starfield location scripting voxels particles entities gpu)
|
|
||||||
file(GLOB_RECURSE SUBDIR_SRCS src/${SUBDIR}/*.cpp src/${SUBDIR}/*.h)
|
|
||||||
set(INTERFACE_SRCS ${INTERFACE_SRCS} "${SUBDIR_SRCS}")
|
|
||||||
endforeach(SUBDIR)
|
|
||||||
|
|
||||||
# Add SpeechRecognizer if on OS X, otherwise remove
|
# Add SpeechRecognizer if on OS X, otherwise remove
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
|
@ -55,6 +55,8 @@
|
|||||||
#include <AccountManager.h>
|
#include <AccountManager.h>
|
||||||
#include <AudioInjector.h>
|
#include <AudioInjector.h>
|
||||||
#include <EntityScriptingInterface.h>
|
#include <EntityScriptingInterface.h>
|
||||||
|
#include <HFActionEvent.h>
|
||||||
|
#include <HFBackEvent.h>
|
||||||
#include <LocalVoxelsList.h>
|
#include <LocalVoxelsList.h>
|
||||||
#include <Logging.h>
|
#include <Logging.h>
|
||||||
#include <NetworkAccessManager.h>
|
#include <NetworkAccessManager.h>
|
||||||
@ -67,14 +69,16 @@
|
|||||||
#include <UUID.h>
|
#include <UUID.h>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "ui/DataWebDialog.h"
|
|
||||||
#include "InterfaceVersion.h"
|
#include "InterfaceVersion.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
#include "ModelUploader.h"
|
#include "ModelUploader.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
|
#include "devices/Leapmotion.h"
|
||||||
#include "devices/MIDIManager.h"
|
#include "devices/MIDIManager.h"
|
||||||
#include "devices/OculusManager.h"
|
#include "devices/OculusManager.h"
|
||||||
#include "devices/TV3DManager.h"
|
#include "devices/TV3DManager.h"
|
||||||
|
|
||||||
#include "renderer/ProgramObject.h"
|
#include "renderer/ProgramObject.h"
|
||||||
|
|
||||||
#include "scripting/AccountScriptingInterface.h"
|
#include "scripting/AccountScriptingInterface.h"
|
||||||
@ -87,12 +91,12 @@
|
|||||||
#include "scripting/SettingsScriptingInterface.h"
|
#include "scripting/SettingsScriptingInterface.h"
|
||||||
#include "scripting/WindowScriptingInterface.h"
|
#include "scripting/WindowScriptingInterface.h"
|
||||||
|
|
||||||
|
#include "ui/DataWebDialog.h"
|
||||||
#include "ui/InfoView.h"
|
#include "ui/InfoView.h"
|
||||||
#include "ui/Snapshot.h"
|
#include "ui/Snapshot.h"
|
||||||
#include "ui/Stats.h"
|
#include "ui/Stats.h"
|
||||||
#include "ui/TextRenderer.h"
|
#include "ui/TextRenderer.h"
|
||||||
|
|
||||||
#include "devices/Leapmotion.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -136,6 +140,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||||||
_glWidget(new GLCanvas()),
|
_glWidget(new GLCanvas()),
|
||||||
_nodeThread(new QThread(this)),
|
_nodeThread(new QThread(this)),
|
||||||
_datagramProcessor(),
|
_datagramProcessor(),
|
||||||
|
_undoStack(),
|
||||||
|
_undoStackScriptingInterface(&_undoStack),
|
||||||
_frameCount(0),
|
_frameCount(0),
|
||||||
_fps(60.0f),
|
_fps(60.0f),
|
||||||
_justStarted(true),
|
_justStarted(true),
|
||||||
@ -172,8 +178,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||||||
_nodeBoundsDisplay(this),
|
_nodeBoundsDisplay(this),
|
||||||
_previousScriptLocation(),
|
_previousScriptLocation(),
|
||||||
_applicationOverlay(),
|
_applicationOverlay(),
|
||||||
_undoStack(),
|
|
||||||
_undoStackScriptingInterface(&_undoStack),
|
|
||||||
_runningScriptsWidget(NULL),
|
_runningScriptsWidget(NULL),
|
||||||
_runningScriptsWidgetWasVisible(false),
|
_runningScriptsWidgetWasVisible(false),
|
||||||
_trayIcon(new QSystemTrayIcon(_window)),
|
_trayIcon(new QSystemTrayIcon(_window)),
|
||||||
@ -835,6 +839,10 @@ bool Application::event(QEvent* event) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (HFActionEvent::types().contains(event->type())) {
|
||||||
|
_controllerScriptingInterface.handleMetaEvent(static_cast<HFMetaEvent*>(event));
|
||||||
|
}
|
||||||
|
|
||||||
return QApplication::event(event);
|
return QApplication::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1109,9 +1117,23 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
|||||||
case Qt::Key_Equal:
|
case Qt::Key_Equal:
|
||||||
_myAvatar->resetSize();
|
_myAvatar->resetSize();
|
||||||
break;
|
break;
|
||||||
case Qt::Key_Escape:
|
case Qt::Key_Space: {
|
||||||
OculusManager::abandonCalibration();
|
// this starts an HFActionEvent
|
||||||
|
HFActionEvent startActionEvent(HFActionEvent::startType(), getViewportCenter());
|
||||||
|
sendEvent(this, &startActionEvent);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
case Qt::Key_Escape: {
|
||||||
|
OculusManager::abandonCalibration();
|
||||||
|
|
||||||
|
// this starts the HFCancelEvent
|
||||||
|
HFBackEvent startBackEvent(HFBackEvent::startType());
|
||||||
|
sendEvent(this, &startBackEvent);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
event->ignore();
|
event->ignore();
|
||||||
break;
|
break;
|
||||||
@ -1182,6 +1204,20 @@ void Application::keyReleaseEvent(QKeyEvent* event) {
|
|||||||
case Qt::Key_Alt:
|
case Qt::Key_Alt:
|
||||||
_myAvatar->clearDriveKeys();
|
_myAvatar->clearDriveKeys();
|
||||||
break;
|
break;
|
||||||
|
case Qt::Key_Space: {
|
||||||
|
// this ends the HFActionEvent
|
||||||
|
HFActionEvent endActionEvent(HFActionEvent::endType(), getViewportCenter());
|
||||||
|
sendEvent(this, &endActionEvent);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Qt::Key_Escape: {
|
||||||
|
// this ends the HFCancelEvent
|
||||||
|
HFBackEvent endBackEvent(HFBackEvent::endType());
|
||||||
|
sendEvent(this, &endBackEvent);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
event->ignore();
|
event->ignore();
|
||||||
break;
|
break;
|
||||||
@ -1254,6 +1290,10 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
|||||||
// stop propagation
|
// stop propagation
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nobody handled this - make it an action event on the _window object
|
||||||
|
HFActionEvent actionEvent(HFActionEvent::startType(), event->localPos());
|
||||||
|
sendEvent(this, &actionEvent);
|
||||||
|
|
||||||
} else if (event->button() == Qt::RightButton) {
|
} else if (event->button() == Qt::RightButton) {
|
||||||
// right click items here
|
// right click items here
|
||||||
@ -1274,12 +1314,17 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
|
|||||||
_mouseX = event->x();
|
_mouseX = event->x();
|
||||||
_mouseY = event->y();
|
_mouseY = event->y();
|
||||||
_mousePressed = false;
|
_mousePressed = false;
|
||||||
|
|
||||||
checkBandwidthMeterClick();
|
checkBandwidthMeterClick();
|
||||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) {
|
if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) {
|
||||||
// let's set horizontal offset to give stats some margin to mirror
|
// let's set horizontal offset to give stats some margin to mirror
|
||||||
int horizontalOffset = MIRROR_VIEW_WIDTH;
|
int horizontalOffset = MIRROR_VIEW_WIDTH;
|
||||||
Stats::getInstance()->checkClick(_mouseX, _mouseY, _mouseDragStartedX, _mouseDragStartedY, horizontalOffset);
|
Stats::getInstance()->checkClick(_mouseX, _mouseY, _mouseDragStartedX, _mouseDragStartedY, horizontalOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fire an action end event
|
||||||
|
HFActionEvent actionEvent(HFActionEvent::endType(), event->localPos());
|
||||||
|
sendEvent(this, &actionEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -284,6 +284,8 @@ public:
|
|||||||
PointShader& getPointShader() { return _pointShader; }
|
PointShader& getPointShader() { return _pointShader; }
|
||||||
FileLogger* getLogger() { return _logger; }
|
FileLogger* getLogger() { return _logger; }
|
||||||
|
|
||||||
|
QPointF getViewportCenter() const
|
||||||
|
{ return QPointF(_glWidget->getDeviceWidth() / 2.0f, _glWidget->getDeviceHeight() / 2.0f); }
|
||||||
glm::vec2 getViewportDimensions() const { return glm::vec2(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); }
|
glm::vec2 getViewportDimensions() const { return glm::vec2(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); }
|
||||||
NodeToJurisdictionMap& getVoxelServerJurisdictions() { return _voxelServerJurisdictions; }
|
NodeToJurisdictionMap& getVoxelServerJurisdictions() { return _voxelServerJurisdictions; }
|
||||||
NodeToJurisdictionMap& getEntityServerJurisdictions() { return _entityServerJurisdictions; }
|
NodeToJurisdictionMap& getEntityServerJurisdictions() { return _entityServerJurisdictions; }
|
||||||
|
@ -612,6 +612,31 @@ void NetworkGeometry::clearLoadPriority(const QPointer<QObject>& owner) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& url) {
|
||||||
|
for (int i = 0; i < _meshes.size(); i++) {
|
||||||
|
NetworkMesh& mesh = _meshes[i];
|
||||||
|
for (int j = 0; j < mesh.parts.size(); j++) {
|
||||||
|
NetworkMeshPart& part = mesh.parts[j];
|
||||||
|
|
||||||
|
QSharedPointer<NetworkTexture> matchingTexture = QSharedPointer<NetworkTexture>();
|
||||||
|
if (part.diffuseTextureName == name) {
|
||||||
|
part.diffuseTexture =
|
||||||
|
Application::getInstance()->getTextureCache()->getTexture(url, DEFAULT_TEXTURE,
|
||||||
|
_geometry.meshes[i].isEye, QByteArray());
|
||||||
|
part.diffuseTexture->setLoadPriorities(_loadPriorities);
|
||||||
|
} else if (part.normalTextureName == name) {
|
||||||
|
part.normalTexture = Application::getInstance()->getTextureCache()->getTexture(url, DEFAULT_TEXTURE,
|
||||||
|
false, QByteArray());
|
||||||
|
part.normalTexture->setLoadPriorities(_loadPriorities);
|
||||||
|
} else if (part.specularTextureName == name) {
|
||||||
|
part.specularTexture = Application::getInstance()->getTextureCache()->getTexture(url, DEFAULT_TEXTURE,
|
||||||
|
false, QByteArray());
|
||||||
|
part.specularTexture->setLoadPriorities(_loadPriorities);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Reads geometry in a worker thread.
|
/// Reads geometry in a worker thread.
|
||||||
class GeometryReader : public QRunnable {
|
class GeometryReader : public QRunnable {
|
||||||
public:
|
public:
|
||||||
@ -727,18 +752,21 @@ void NetworkGeometry::setGeometry(const FBXGeometry& geometry) {
|
|||||||
networkPart.diffuseTexture = Application::getInstance()->getTextureCache()->getTexture(
|
networkPart.diffuseTexture = Application::getInstance()->getTextureCache()->getTexture(
|
||||||
_textureBase.resolved(QUrl(part.diffuseTexture.filename)), DEFAULT_TEXTURE,
|
_textureBase.resolved(QUrl(part.diffuseTexture.filename)), DEFAULT_TEXTURE,
|
||||||
mesh.isEye, part.diffuseTexture.content);
|
mesh.isEye, part.diffuseTexture.content);
|
||||||
|
networkPart.diffuseTextureName = part.diffuseTexture.name;
|
||||||
networkPart.diffuseTexture->setLoadPriorities(_loadPriorities);
|
networkPart.diffuseTexture->setLoadPriorities(_loadPriorities);
|
||||||
}
|
}
|
||||||
if (!part.normalTexture.filename.isEmpty()) {
|
if (!part.normalTexture.filename.isEmpty()) {
|
||||||
networkPart.normalTexture = Application::getInstance()->getTextureCache()->getTexture(
|
networkPart.normalTexture = Application::getInstance()->getTextureCache()->getTexture(
|
||||||
_textureBase.resolved(QUrl(part.normalTexture.filename)), NORMAL_TEXTURE,
|
_textureBase.resolved(QUrl(part.normalTexture.filename)), NORMAL_TEXTURE,
|
||||||
false, part.normalTexture.content);
|
false, part.normalTexture.content);
|
||||||
|
networkPart.normalTextureName = part.normalTexture.name;
|
||||||
networkPart.normalTexture->setLoadPriorities(_loadPriorities);
|
networkPart.normalTexture->setLoadPriorities(_loadPriorities);
|
||||||
}
|
}
|
||||||
if (!part.specularTexture.filename.isEmpty()) {
|
if (!part.specularTexture.filename.isEmpty()) {
|
||||||
networkPart.specularTexture = Application::getInstance()->getTextureCache()->getTexture(
|
networkPart.specularTexture = Application::getInstance()->getTextureCache()->getTexture(
|
||||||
_textureBase.resolved(QUrl(part.specularTexture.filename)), SPECULAR_TEXTURE,
|
_textureBase.resolved(QUrl(part.specularTexture.filename)), SPECULAR_TEXTURE,
|
||||||
false, part.specularTexture.content);
|
false, part.specularTexture.content);
|
||||||
|
networkPart.specularTextureName = part.specularTexture.name;
|
||||||
networkPart.specularTexture->setLoadPriorities(_loadPriorities);
|
networkPart.specularTexture->setLoadPriorities(_loadPriorities);
|
||||||
}
|
}
|
||||||
networkMesh.parts.append(networkPart);
|
networkMesh.parts.append(networkPart);
|
||||||
|
@ -107,6 +107,8 @@ public:
|
|||||||
virtual void setLoadPriorities(const QHash<QPointer<QObject>, float>& priorities);
|
virtual void setLoadPriorities(const QHash<QPointer<QObject>, float>& priorities);
|
||||||
virtual void clearLoadPriority(const QPointer<QObject>& owner);
|
virtual void clearLoadPriority(const QPointer<QObject>& owner);
|
||||||
|
|
||||||
|
void setTextureWithNameToURL(const QString& name, const QUrl& url);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void init();
|
virtual void init();
|
||||||
@ -136,10 +138,13 @@ private:
|
|||||||
|
|
||||||
/// The state associated with a single mesh part.
|
/// The state associated with a single mesh part.
|
||||||
class NetworkMeshPart {
|
class NetworkMeshPart {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
QString diffuseTextureName;
|
||||||
QSharedPointer<NetworkTexture> diffuseTexture;
|
QSharedPointer<NetworkTexture> diffuseTexture;
|
||||||
|
QString normalTextureName;
|
||||||
QSharedPointer<NetworkTexture> normalTexture;
|
QSharedPointer<NetworkTexture> normalTexture;
|
||||||
|
QString specularTextureName;
|
||||||
QSharedPointer<NetworkTexture> specularTexture;
|
QSharedPointer<NetworkTexture> specularTexture;
|
||||||
|
|
||||||
bool isTranslucent() const;
|
bool isTranslucent() const;
|
||||||
|
@ -187,6 +187,9 @@ public:
|
|||||||
|
|
||||||
void inverseKinematics(int jointIndex, glm::vec3 position, const glm::quat& rotation, float priority);
|
void inverseKinematics(int jointIndex, glm::vec3 position, const glm::quat& rotation, float priority);
|
||||||
|
|
||||||
|
Q_INVOKABLE void setTextureWithNameToURL(const QString& name, const QUrl& url)
|
||||||
|
{ _geometry->setTextureWithNameToURL(name, url); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSharedPointer<NetworkGeometry> _geometry;
|
QSharedPointer<NetworkGeometry> _geometry;
|
||||||
|
|
||||||
|
@ -156,7 +156,6 @@ protected:
|
|||||||
virtual void imageLoaded(const QImage& image);
|
virtual void imageLoaded(const QImage& image);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
TextureType _type;
|
TextureType _type;
|
||||||
bool _translucent;
|
bool _translucent;
|
||||||
QColor _averageColor;
|
QColor _averageColor;
|
||||||
|
@ -10,18 +10,33 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <HandData.h>
|
#include <HandData.h>
|
||||||
|
#include <HFBackEvent.h>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
#include "devices/MotionTracker.h"
|
||||||
#include "devices/SixenseManager.h"
|
#include "devices/SixenseManager.h"
|
||||||
#include "ControllerScriptingInterface.h"
|
#include "ControllerScriptingInterface.h"
|
||||||
#include "devices/MotionTracker.h"
|
|
||||||
|
|
||||||
ControllerScriptingInterface::ControllerScriptingInterface() :
|
ControllerScriptingInterface::ControllerScriptingInterface() :
|
||||||
_mouseCaptured(false),
|
_mouseCaptured(false),
|
||||||
_touchCaptured(false),
|
_touchCaptured(false),
|
||||||
_wheelCaptured(false)
|
_wheelCaptured(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) {
|
||||||
|
if (event->type() == HFActionEvent::startType()) {
|
||||||
|
emit actionStartEvent(static_cast<HFActionEvent&>(*event));
|
||||||
|
} else if (event->type() == HFActionEvent::endType()) {
|
||||||
|
emit actionEndEvent(static_cast<HFActionEvent&>(*event));
|
||||||
|
} else if (event->type() == HFBackEvent::startType()) {
|
||||||
|
emit backStartEvent();
|
||||||
|
} else if (event->type() == HFBackEvent::endType()) {
|
||||||
|
emit backEndEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const PalmData* ControllerScriptingInterface::getPrimaryPalm() const {
|
const PalmData* ControllerScriptingInterface::getPrimaryPalm() const {
|
||||||
int leftPalmIndex, rightPalmIndex;
|
int leftPalmIndex, rightPalmIndex;
|
||||||
|
@ -46,7 +46,7 @@ private:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// handles scripting of input controller commands from JS
|
/// handles scripting of input controller commands from JS
|
||||||
class ControllerScriptingInterface : public AbstractControllerScriptingInterface {
|
class ControllerScriptingInterface : public AbstractControllerScriptingInterface {
|
||||||
@ -56,6 +56,8 @@ public:
|
|||||||
ControllerScriptingInterface();
|
ControllerScriptingInterface();
|
||||||
void emitKeyPressEvent(QKeyEvent* event) { emit keyPressEvent(KeyEvent(*event)); }
|
void emitKeyPressEvent(QKeyEvent* event) { emit keyPressEvent(KeyEvent(*event)); }
|
||||||
void emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); }
|
void emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); }
|
||||||
|
|
||||||
|
void handleMetaEvent(HFMetaEvent* event);
|
||||||
|
|
||||||
void emitMouseMoveEvent(QMouseEvent* event, unsigned int deviceID = 0) { emit mouseMoveEvent(MouseEvent(*event, deviceID)); }
|
void emitMouseMoveEvent(QMouseEvent* event, unsigned int deviceID = 0) { emit mouseMoveEvent(MouseEvent(*event, deviceID)); }
|
||||||
void emitMousePressEvent(QMouseEvent* event, unsigned int deviceID = 0) { emit mousePressEvent(MouseEvent(*event, deviceID)); }
|
void emitMousePressEvent(QMouseEvent* event, unsigned int deviceID = 0) { emit mousePressEvent(MouseEvent(*event, deviceID)); }
|
||||||
|
@ -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,8 +18,12 @@
|
|||||||
#undef main
|
#undef main
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <HFActionEvent.h>
|
||||||
|
#include <HFBackEvent.h>
|
||||||
#include <PerfStat.h>
|
#include <PerfStat.h>
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
#include "JoystickScriptingInterface.h"
|
#include "JoystickScriptingInterface.h"
|
||||||
|
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
@ -108,6 +113,28 @@ 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 global back event
|
||||||
|
QEvent::Type backType = (event.type == SDL_CONTROLLERBUTTONDOWN)
|
||||||
|
? HFBackEvent::startType()
|
||||||
|
: HFBackEvent::endType();
|
||||||
|
HFBackEvent backEvent(backType);
|
||||||
|
|
||||||
|
qApp->sendEvent(qApp, &backEvent);
|
||||||
|
} else if (event.cbutton.button == SDL_CONTROLLER_BUTTON_A) {
|
||||||
|
// this will either start or stop a global action event
|
||||||
|
QEvent::Type actionType = (event.type == SDL_CONTROLLERBUTTONDOWN)
|
||||||
|
? HFActionEvent::startType()
|
||||||
|
: HFActionEvent::endType();
|
||||||
|
|
||||||
|
// global action events fire in the center of the screen
|
||||||
|
QPointF centerPoint = Application::getInstance()->getViewportCenter();
|
||||||
|
HFActionEvent actionEvent(actionType, centerPoint);
|
||||||
|
|
||||||
|
qApp->sendEvent(qApp, &actionEvent);
|
||||||
|
}
|
||||||
|
|
||||||
} 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);
|
||||||
|
|
||||||
|
@ -102,6 +102,20 @@ void ModelOverlay::setProperties(const QScriptValue &properties) {
|
|||||||
}
|
}
|
||||||
_updateModel = true;
|
_updateModel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QScriptValue texturesValue = properties.property("textures");
|
||||||
|
if (texturesValue.isValid()) {
|
||||||
|
QVariantMap textureMap = texturesValue.toVariant().toMap();
|
||||||
|
foreach(const QString& key, textureMap.keys()) {
|
||||||
|
|
||||||
|
QUrl newTextureURL = textureMap[key].toUrl();
|
||||||
|
qDebug() << "Updating texture named" << key << "to texture at URL" << newTextureURL;
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(&_model, "setTextureWithNameToURL", Qt::AutoConnection,
|
||||||
|
Q_ARG(const QString&, key),
|
||||||
|
Q_ARG(const QUrl&, newTextureURL));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (properties.property("position").isValid()) {
|
if (properties.property("position").isValid()) {
|
||||||
_updateModel = true;
|
_updateModel = true;
|
||||||
|
@ -984,10 +984,13 @@ public:
|
|||||||
QVector<float> values;
|
QVector<float> values;
|
||||||
};
|
};
|
||||||
|
|
||||||
FBXTexture getTexture(const QString& textureID, const QHash<QString, QByteArray>& textureFilenames,
|
FBXTexture getTexture(const QString& textureID,
|
||||||
const QHash<QByteArray, QByteArray>& textureContent) {
|
const QHash<QString, QString>& textureNames,
|
||||||
|
const QHash<QString, QByteArray>& textureFilenames,
|
||||||
|
const QHash<QByteArray, QByteArray>& textureContent) {
|
||||||
FBXTexture texture;
|
FBXTexture texture;
|
||||||
texture.filename = textureFilenames.value(textureID);
|
texture.filename = textureFilenames.value(textureID);
|
||||||
|
texture.name = textureNames.value(textureID);
|
||||||
texture.content = textureContent.value(texture.filename);
|
texture.content = textureContent.value(texture.filename);
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
@ -1012,6 +1015,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
|||||||
QHash<QString, FBXModel> models;
|
QHash<QString, FBXModel> models;
|
||||||
QHash<QString, Cluster> clusters;
|
QHash<QString, Cluster> clusters;
|
||||||
QHash<QString, AnimationCurve> animationCurves;
|
QHash<QString, AnimationCurve> animationCurves;
|
||||||
|
QHash<QString, QString> textureNames;
|
||||||
QHash<QString, QByteArray> textureFilenames;
|
QHash<QString, QByteArray> textureFilenames;
|
||||||
QHash<QByteArray, QByteArray> textureContent;
|
QHash<QByteArray, QByteArray> textureContent;
|
||||||
QHash<QString, Material> materials;
|
QHash<QString, Material> materials;
|
||||||
@ -1278,6 +1282,11 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
|||||||
QByteArray filename = subobject.properties.at(0).toByteArray();
|
QByteArray filename = subobject.properties.at(0).toByteArray();
|
||||||
filename = filename.mid(qMax(filename.lastIndexOf('\\'), filename.lastIndexOf('/')) + 1);
|
filename = filename.mid(qMax(filename.lastIndexOf('\\'), filename.lastIndexOf('/')) + 1);
|
||||||
textureFilenames.insert(getID(object.properties), filename);
|
textureFilenames.insert(getID(object.properties), filename);
|
||||||
|
} else if (subobject.name == "TextureName") {
|
||||||
|
// trim the name from the timestamp
|
||||||
|
QString name = QString(subobject.properties.at(0).toByteArray());
|
||||||
|
name = name.left(name.indexOf('['));
|
||||||
|
textureNames.insert(getID(object.properties), name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (object.name == "Video") {
|
} else if (object.name == "Video") {
|
||||||
@ -1612,12 +1621,12 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
|||||||
FBXTexture diffuseTexture;
|
FBXTexture diffuseTexture;
|
||||||
QString diffuseTextureID = diffuseTextures.value(childID);
|
QString diffuseTextureID = diffuseTextures.value(childID);
|
||||||
if (!diffuseTextureID.isNull()) {
|
if (!diffuseTextureID.isNull()) {
|
||||||
diffuseTexture = getTexture(diffuseTextureID, textureFilenames, textureContent);
|
diffuseTexture = getTexture(diffuseTextureID, textureNames, textureFilenames, textureContent);
|
||||||
|
|
||||||
// FBX files generated by 3DSMax have an intermediate texture parent, apparently
|
// FBX files generated by 3DSMax have an intermediate texture parent, apparently
|
||||||
foreach (const QString& childTextureID, childMap.values(diffuseTextureID)) {
|
foreach (const QString& childTextureID, childMap.values(diffuseTextureID)) {
|
||||||
if (textureFilenames.contains(childTextureID)) {
|
if (textureFilenames.contains(childTextureID)) {
|
||||||
diffuseTexture = getTexture(diffuseTextureID, textureFilenames, textureContent);
|
diffuseTexture = getTexture(diffuseTextureID, textureNames, textureFilenames, textureContent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1625,14 +1634,14 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
|||||||
FBXTexture normalTexture;
|
FBXTexture normalTexture;
|
||||||
QString bumpTextureID = bumpTextures.value(childID);
|
QString bumpTextureID = bumpTextures.value(childID);
|
||||||
if (!bumpTextureID.isNull()) {
|
if (!bumpTextureID.isNull()) {
|
||||||
normalTexture = getTexture(bumpTextureID, textureFilenames, textureContent);
|
normalTexture = getTexture(bumpTextureID, textureNames, textureFilenames, textureContent);
|
||||||
generateTangents = true;
|
generateTangents = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FBXTexture specularTexture;
|
FBXTexture specularTexture;
|
||||||
QString specularTextureID = specularTextures.value(childID);
|
QString specularTextureID = specularTextures.value(childID);
|
||||||
if (!specularTextureID.isNull()) {
|
if (!specularTextureID.isNull()) {
|
||||||
specularTexture = getTexture(specularTextureID, textureFilenames, textureContent);
|
specularTexture = getTexture(specularTextureID, textureNames, textureFilenames, textureContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < extracted.partMaterialTextures.size(); j++) {
|
for (int j = 0; j < extracted.partMaterialTextures.size(); j++) {
|
||||||
@ -1658,7 +1667,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
|||||||
materialIndex++;
|
materialIndex++;
|
||||||
|
|
||||||
} else if (textureFilenames.contains(childID)) {
|
} else if (textureFilenames.contains(childID)) {
|
||||||
FBXTexture texture = getTexture(childID, textureFilenames, textureContent);
|
FBXTexture texture = getTexture(childID, textureNames, textureFilenames, textureContent);
|
||||||
for (int j = 0; j < extracted.partMaterialTextures.size(); j++) {
|
for (int j = 0; j < extracted.partMaterialTextures.size(); j++) {
|
||||||
int partTexture = extracted.partMaterialTextures.at(j).second;
|
int partTexture = extracted.partMaterialTextures.at(j).second;
|
||||||
if (partTexture == textureIndex && !(partTexture == 0 && materialsHaveTextures)) {
|
if (partTexture == textureIndex && !(partTexture == 0 && materialsHaveTextures)) {
|
||||||
|
@ -95,7 +95,7 @@ public:
|
|||||||
/// A texture map in an FBX document.
|
/// A texture map in an FBX document.
|
||||||
class FBXTexture {
|
class FBXTexture {
|
||||||
public:
|
public:
|
||||||
|
QString name;
|
||||||
QByteArray filename;
|
QByteArray filename;
|
||||||
QByteArray content;
|
QByteArray content;
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,12 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
|
||||||
#include "EventTypes.h"
|
#include "HFActionEvent.h"
|
||||||
|
#include "KeyEvent.h"
|
||||||
|
#include "MouseEvent.h"
|
||||||
|
#include "SpatialEvent.h"
|
||||||
|
#include "TouchEvent.h"
|
||||||
|
#include "WheelEvent.h"
|
||||||
|
|
||||||
class AbstractInputController : public QObject {
|
class AbstractInputController : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -88,6 +93,12 @@ public slots:
|
|||||||
signals:
|
signals:
|
||||||
void keyPressEvent(const KeyEvent& event);
|
void keyPressEvent(const KeyEvent& event);
|
||||||
void keyReleaseEvent(const KeyEvent& event);
|
void keyReleaseEvent(const KeyEvent& event);
|
||||||
|
|
||||||
|
void actionStartEvent(const HFActionEvent& event);
|
||||||
|
void actionEndEvent(const HFActionEvent& event);
|
||||||
|
|
||||||
|
void backStartEvent();
|
||||||
|
void backEndEvent();
|
||||||
|
|
||||||
void mouseMoveEvent(const MouseEvent& event, unsigned int deviceID = 0);
|
void mouseMoveEvent(const MouseEvent& event, unsigned int deviceID = 0);
|
||||||
void mousePressEvent(const MouseEvent& event, unsigned int deviceID = 0);
|
void mousePressEvent(const MouseEvent& event, unsigned int deviceID = 0);
|
||||||
|
@ -9,640 +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 <QDebug>
|
#include "HFActionEvent.h"
|
||||||
#include <RegisteredMetaTypes.h>
|
#include "KeyEvent.h"
|
||||||
|
#include "MouseEvent.h"
|
||||||
|
#include "SpatialEvent.h"
|
||||||
|
#include "TouchEvent.h"
|
||||||
|
#include "WheelEvent.h"
|
||||||
|
|
||||||
#include "EventTypes.h"
|
#include "EventTypes.h"
|
||||||
|
|
||||||
|
|
||||||
void registerEventTypes(QScriptEngine* engine) {
|
void registerEventTypes(QScriptEngine* engine) {
|
||||||
qScriptRegisterMetaType(engine, keyEventToScriptValue, keyEventFromScriptValue);
|
qScriptRegisterMetaType(engine, HFActionEvent::toScriptValue, HFActionEvent::fromScriptValue);
|
||||||
qScriptRegisterMetaType(engine, mouseEventToScriptValue, mouseEventFromScriptValue);
|
qScriptRegisterMetaType(engine, KeyEvent::toScriptValue, KeyEvent::fromScriptValue);
|
||||||
qScriptRegisterMetaType(engine, touchEventToScriptValue, touchEventFromScriptValue);
|
qScriptRegisterMetaType(engine, MouseEvent::toScriptValue, MouseEvent::fromScriptValue);
|
||||||
qScriptRegisterMetaType(engine, wheelEventToScriptValue, wheelEventFromScriptValue);
|
qScriptRegisterMetaType(engine, TouchEvent::toScriptValue, TouchEvent::fromScriptValue);
|
||||||
qScriptRegisterMetaType(engine, spatialEventToScriptValue, spatialEventFromScriptValue);
|
qScriptRegisterMetaType(engine, WheelEvent::toScriptValue, WheelEvent::fromScriptValue);
|
||||||
}
|
qScriptRegisterMetaType(engine, SpatialEvent::toScriptValue, SpatialEvent::fromScriptValue);
|
||||||
|
|
||||||
KeyEvent::KeyEvent() :
|
|
||||||
key(0),
|
|
||||||
text(""),
|
|
||||||
isShifted(false),
|
|
||||||
isControl(false),
|
|
||||||
isMeta(false),
|
|
||||||
isAlt(false),
|
|
||||||
isKeypad(false),
|
|
||||||
isValid(false),
|
|
||||||
isAutoRepeat(false)
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
KeyEvent::KeyEvent(const QKeyEvent& event) {
|
|
||||||
key = event.key();
|
|
||||||
text = event.text();
|
|
||||||
isShifted = event.modifiers().testFlag(Qt::ShiftModifier);
|
|
||||||
isMeta = event.modifiers().testFlag(Qt::MetaModifier);
|
|
||||||
isControl = event.modifiers().testFlag(Qt::ControlModifier);
|
|
||||||
isAlt = event.modifiers().testFlag(Qt::AltModifier);
|
|
||||||
isKeypad = event.modifiers().testFlag(Qt::KeypadModifier);
|
|
||||||
isValid = true;
|
|
||||||
isAutoRepeat = event.isAutoRepeat();
|
|
||||||
|
|
||||||
// handle special text for special characters...
|
|
||||||
if (key == Qt::Key_F1) {
|
|
||||||
text = "F1";
|
|
||||||
} else if (key == Qt::Key_F2) {
|
|
||||||
text = "F2";
|
|
||||||
} else if (key == Qt::Key_F3) {
|
|
||||||
text = "F3";
|
|
||||||
} else if (key == Qt::Key_F4) {
|
|
||||||
text = "F4";
|
|
||||||
} else if (key == Qt::Key_F5) {
|
|
||||||
text = "F5";
|
|
||||||
} else if (key == Qt::Key_F6) {
|
|
||||||
text = "F6";
|
|
||||||
} else if (key == Qt::Key_F7) {
|
|
||||||
text = "F7";
|
|
||||||
} else if (key == Qt::Key_F8) {
|
|
||||||
text = "F8";
|
|
||||||
} else if (key == Qt::Key_F9) {
|
|
||||||
text = "F9";
|
|
||||||
} else if (key == Qt::Key_F10) {
|
|
||||||
text = "F10";
|
|
||||||
} else if (key == Qt::Key_F11) {
|
|
||||||
text = "F11";
|
|
||||||
} else if (key == Qt::Key_F12) {
|
|
||||||
text = "F12";
|
|
||||||
} else if (key == Qt::Key_Up) {
|
|
||||||
text = "UP";
|
|
||||||
} else if (key == Qt::Key_Down) {
|
|
||||||
text = "DOWN";
|
|
||||||
} else if (key == Qt::Key_Left) {
|
|
||||||
text = "LEFT";
|
|
||||||
} else if (key == Qt::Key_Right) {
|
|
||||||
text = "RIGHT";
|
|
||||||
} else if (key == Qt::Key_Space) {
|
|
||||||
text = "SPACE";
|
|
||||||
} else if (key == Qt::Key_Escape) {
|
|
||||||
text = "ESC";
|
|
||||||
} else if (key == Qt::Key_Tab) {
|
|
||||||
text = "TAB";
|
|
||||||
} else if (key == Qt::Key_Delete) {
|
|
||||||
text = "DELETE";
|
|
||||||
} else if (key == Qt::Key_Backspace) {
|
|
||||||
text = "BACKSPACE";
|
|
||||||
} else if (key == Qt::Key_Shift) {
|
|
||||||
text = "SHIFT";
|
|
||||||
} else if (key == Qt::Key_Alt) {
|
|
||||||
text = "ALT";
|
|
||||||
} else if (key == Qt::Key_Control) {
|
|
||||||
text = "CONTROL";
|
|
||||||
} else if (key == Qt::Key_Meta) {
|
|
||||||
text = "META";
|
|
||||||
} else if (key == Qt::Key_PageDown) {
|
|
||||||
text = "PAGE DOWN";
|
|
||||||
} else if (key == Qt::Key_PageUp) {
|
|
||||||
text = "PAGE UP";
|
|
||||||
} else if (key == Qt::Key_Home) {
|
|
||||||
text = "HOME";
|
|
||||||
} else if (key == Qt::Key_End) {
|
|
||||||
text = "END";
|
|
||||||
} else if (key == Qt::Key_Help) {
|
|
||||||
text = "HELP";
|
|
||||||
} else if (key == Qt::Key_CapsLock) {
|
|
||||||
text = "CAPS LOCK";
|
|
||||||
} else if (key >= Qt::Key_A && key <= Qt::Key_Z && (isMeta || isControl || isAlt)) {
|
|
||||||
// this little bit of hackery will fix the text character keys like a-z in cases of control/alt/meta where
|
|
||||||
// qt doesn't always give you the key characters and will sometimes give you crazy non-printable characters
|
|
||||||
const int lowerCaseAdjust = 0x20;
|
|
||||||
QString unicode;
|
|
||||||
if (isShifted) {
|
|
||||||
text = QString(QChar(key));
|
|
||||||
} else {
|
|
||||||
text = QString(QChar(key + lowerCaseAdjust));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KeyEvent::operator==(const KeyEvent& other) const {
|
|
||||||
return other.key == key
|
|
||||||
&& other.isShifted == isShifted
|
|
||||||
&& other.isControl == isControl
|
|
||||||
&& other.isMeta == isMeta
|
|
||||||
&& other.isAlt == isAlt
|
|
||||||
&& other.isKeypad == isKeypad
|
|
||||||
&& other.isAutoRepeat == isAutoRepeat;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
KeyEvent::operator QKeySequence() const {
|
|
||||||
int resultCode = 0;
|
|
||||||
if (text.size() == 1 && text >= "a" && text <= "z") {
|
|
||||||
resultCode = text.toUpper().at(0).unicode();
|
|
||||||
} else {
|
|
||||||
resultCode = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isMeta) {
|
|
||||||
resultCode |= Qt::META;
|
|
||||||
}
|
|
||||||
if (isAlt) {
|
|
||||||
resultCode |= Qt::ALT;
|
|
||||||
}
|
|
||||||
if (isControl) {
|
|
||||||
resultCode |= Qt::CTRL;
|
|
||||||
}
|
|
||||||
if (isShifted) {
|
|
||||||
resultCode |= Qt::SHIFT;
|
|
||||||
}
|
|
||||||
return QKeySequence(resultCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
QScriptValue keyEventToScriptValue(QScriptEngine* engine, const KeyEvent& event) {
|
|
||||||
QScriptValue obj = engine->newObject();
|
|
||||||
obj.setProperty("key", event.key);
|
|
||||||
obj.setProperty("text", event.text);
|
|
||||||
obj.setProperty("isShifted", event.isShifted);
|
|
||||||
obj.setProperty("isMeta", event.isMeta);
|
|
||||||
obj.setProperty("isControl", event.isControl);
|
|
||||||
obj.setProperty("isAlt", event.isAlt);
|
|
||||||
obj.setProperty("isKeypad", event.isKeypad);
|
|
||||||
obj.setProperty("isAutoRepeat", event.isAutoRepeat);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
void keyEventFromScriptValue(const QScriptValue& object, KeyEvent& event) {
|
|
||||||
|
|
||||||
event.isValid = false; // assume the worst
|
|
||||||
event.isMeta = object.property("isMeta").toVariant().toBool();
|
|
||||||
event.isControl = object.property("isControl").toVariant().toBool();
|
|
||||||
event.isAlt = object.property("isAlt").toVariant().toBool();
|
|
||||||
event.isKeypad = object.property("isKeypad").toVariant().toBool();
|
|
||||||
event.isAutoRepeat = object.property("isAutoRepeat").toVariant().toBool();
|
|
||||||
|
|
||||||
QScriptValue key = object.property("key");
|
|
||||||
if (key.isValid()) {
|
|
||||||
event.key = key.toVariant().toInt();
|
|
||||||
event.text = QString(QChar(event.key));
|
|
||||||
event.isValid = true;
|
|
||||||
} else {
|
|
||||||
QScriptValue text = object.property("text");
|
|
||||||
if (text.isValid()) {
|
|
||||||
event.text = object.property("text").toVariant().toString();
|
|
||||||
|
|
||||||
// if the text is a special command, then map it here...
|
|
||||||
// TODO: come up with more elegant solution here, a map? is there a Qt function that gives nice names for keys?
|
|
||||||
if (event.text.toUpper() == "F1") {
|
|
||||||
event.key = Qt::Key_F1;
|
|
||||||
} else if (event.text.toUpper() == "F2") {
|
|
||||||
event.key = Qt::Key_F2;
|
|
||||||
} else if (event.text.toUpper() == "F3") {
|
|
||||||
event.key = Qt::Key_F3;
|
|
||||||
} else if (event.text.toUpper() == "F4") {
|
|
||||||
event.key = Qt::Key_F4;
|
|
||||||
} else if (event.text.toUpper() == "F5") {
|
|
||||||
event.key = Qt::Key_F5;
|
|
||||||
} else if (event.text.toUpper() == "F6") {
|
|
||||||
event.key = Qt::Key_F6;
|
|
||||||
} else if (event.text.toUpper() == "F7") {
|
|
||||||
event.key = Qt::Key_F7;
|
|
||||||
} else if (event.text.toUpper() == "F8") {
|
|
||||||
event.key = Qt::Key_F8;
|
|
||||||
} else if (event.text.toUpper() == "F9") {
|
|
||||||
event.key = Qt::Key_F9;
|
|
||||||
} else if (event.text.toUpper() == "F10") {
|
|
||||||
event.key = Qt::Key_F10;
|
|
||||||
} else if (event.text.toUpper() == "F11") {
|
|
||||||
event.key = Qt::Key_F11;
|
|
||||||
} else if (event.text.toUpper() == "F12") {
|
|
||||||
event.key = Qt::Key_F12;
|
|
||||||
} else if (event.text.toUpper() == "UP") {
|
|
||||||
event.key = Qt::Key_Up;
|
|
||||||
event.isKeypad = true;
|
|
||||||
} else if (event.text.toUpper() == "DOWN") {
|
|
||||||
event.key = Qt::Key_Down;
|
|
||||||
event.isKeypad = true;
|
|
||||||
} else if (event.text.toUpper() == "LEFT") {
|
|
||||||
event.key = Qt::Key_Left;
|
|
||||||
event.isKeypad = true;
|
|
||||||
} else if (event.text.toUpper() == "RIGHT") {
|
|
||||||
event.key = Qt::Key_Right;
|
|
||||||
event.isKeypad = true;
|
|
||||||
} else if (event.text.toUpper() == "SPACE") {
|
|
||||||
event.key = Qt::Key_Space;
|
|
||||||
} else if (event.text.toUpper() == "ESC") {
|
|
||||||
event.key = Qt::Key_Escape;
|
|
||||||
} else if (event.text.toUpper() == "TAB") {
|
|
||||||
event.key = Qt::Key_Tab;
|
|
||||||
} else if (event.text.toUpper() == "DELETE") {
|
|
||||||
event.key = Qt::Key_Delete;
|
|
||||||
} else if (event.text.toUpper() == "BACKSPACE") {
|
|
||||||
event.key = Qt::Key_Backspace;
|
|
||||||
} else if (event.text.toUpper() == "SHIFT") {
|
|
||||||
event.key = Qt::Key_Shift;
|
|
||||||
} else if (event.text.toUpper() == "ALT") {
|
|
||||||
event.key = Qt::Key_Alt;
|
|
||||||
} else if (event.text.toUpper() == "CONTROL") {
|
|
||||||
event.key = Qt::Key_Control;
|
|
||||||
} else if (event.text.toUpper() == "META") {
|
|
||||||
event.key = Qt::Key_Meta;
|
|
||||||
} else if (event.text.toUpper() == "PAGE DOWN") {
|
|
||||||
event.key = Qt::Key_PageDown;
|
|
||||||
} else if (event.text.toUpper() == "PAGE UP") {
|
|
||||||
event.key = Qt::Key_PageUp;
|
|
||||||
} else if (event.text.toUpper() == "HOME") {
|
|
||||||
event.key = Qt::Key_Home;
|
|
||||||
} else if (event.text.toUpper() == "END") {
|
|
||||||
event.key = Qt::Key_End;
|
|
||||||
} else if (event.text.toUpper() == "HELP") {
|
|
||||||
event.key = Qt::Key_Help;
|
|
||||||
} else if (event.text.toUpper() == "CAPS LOCK") {
|
|
||||||
event.key = Qt::Key_CapsLock;
|
|
||||||
} else {
|
|
||||||
// Key values do not distinguish between uppercase and lowercase
|
|
||||||
// and use the uppercase key value.
|
|
||||||
event.key = event.text.toUpper().at(0).unicode();
|
|
||||||
}
|
|
||||||
event.isValid = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QScriptValue isShifted = object.property("isShifted");
|
|
||||||
if (isShifted.isValid()) {
|
|
||||||
event.isShifted = isShifted.toVariant().toBool();
|
|
||||||
} else {
|
|
||||||
// if no isShifted was included, get it from the text
|
|
||||||
QChar character = event.text.at(0);
|
|
||||||
if (character.isLetter() && character.isUpper()) {
|
|
||||||
event.isShifted = true;
|
|
||||||
} else {
|
|
||||||
// if it's a symbol, then attempt to detect shifted-ness
|
|
||||||
if (QString("~!@#$%^&*()_+{}|:\"<>?").contains(character)) {
|
|
||||||
event.isShifted = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const bool wantDebug = false;
|
|
||||||
if (wantDebug) {
|
|
||||||
qDebug() << "event.key=" << event.key
|
|
||||||
<< " event.text=" << event.text
|
|
||||||
<< " event.isShifted=" << event.isShifted
|
|
||||||
<< " event.isControl=" << event.isControl
|
|
||||||
<< " event.isMeta=" << event.isMeta
|
|
||||||
<< " event.isAlt=" << event.isAlt
|
|
||||||
<< " event.isKeypad=" << event.isKeypad
|
|
||||||
<< " event.isAutoRepeat=" << event.isAutoRepeat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseEvent::MouseEvent() :
|
|
||||||
x(0.0f),
|
|
||||||
y(0.0f),
|
|
||||||
isLeftButton(false),
|
|
||||||
isRightButton(false),
|
|
||||||
isMiddleButton(false),
|
|
||||||
isShifted(false),
|
|
||||||
isControl(false),
|
|
||||||
isMeta(false),
|
|
||||||
isAlt(false)
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
MouseEvent::MouseEvent(const QMouseEvent& event, const unsigned int deviceID) :
|
|
||||||
x(event.x()),
|
|
||||||
y(event.y()),
|
|
||||||
deviceID(deviceID),
|
|
||||||
isLeftButton(event.buttons().testFlag(Qt::LeftButton)),
|
|
||||||
isRightButton(event.buttons().testFlag(Qt::RightButton)),
|
|
||||||
isMiddleButton(event.buttons().testFlag(Qt::MiddleButton)),
|
|
||||||
isShifted(event.modifiers().testFlag(Qt::ShiftModifier)),
|
|
||||||
isControl(event.modifiers().testFlag(Qt::ControlModifier)),
|
|
||||||
isMeta(event.modifiers().testFlag(Qt::MetaModifier)),
|
|
||||||
isAlt(event.modifiers().testFlag(Qt::AltModifier))
|
|
||||||
{
|
|
||||||
// single button that caused the event
|
|
||||||
switch (event.button()) {
|
|
||||||
case Qt::LeftButton:
|
|
||||||
button = "LEFT";
|
|
||||||
isLeftButton = true;
|
|
||||||
break;
|
|
||||||
case Qt::RightButton:
|
|
||||||
button = "RIGHT";
|
|
||||||
isRightButton = true;
|
|
||||||
break;
|
|
||||||
case Qt::MiddleButton:
|
|
||||||
button = "MIDDLE";
|
|
||||||
isMiddleButton = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
button = "NONE";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QScriptValue mouseEventToScriptValue(QScriptEngine* engine, const MouseEvent& event) {
|
|
||||||
QScriptValue obj = engine->newObject();
|
|
||||||
obj.setProperty("x", event.x);
|
|
||||||
obj.setProperty("y", event.y);
|
|
||||||
obj.setProperty("button", event.button);
|
|
||||||
obj.setProperty("deviceID", event.deviceID);
|
|
||||||
obj.setProperty("isLeftButton", event.isLeftButton);
|
|
||||||
obj.setProperty("isRightButton", event.isRightButton);
|
|
||||||
obj.setProperty("isMiddleButton", event.isMiddleButton);
|
|
||||||
obj.setProperty("isShifted", event.isShifted);
|
|
||||||
obj.setProperty("isMeta", event.isMeta);
|
|
||||||
obj.setProperty("isControl", event.isControl);
|
|
||||||
obj.setProperty("isAlt", event.isAlt);
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mouseEventFromScriptValue(const QScriptValue& object, MouseEvent& event) {
|
|
||||||
// nothing for now...
|
|
||||||
}
|
|
||||||
|
|
||||||
TouchEvent::TouchEvent() :
|
|
||||||
x(0.0f),
|
|
||||||
y(0.0f),
|
|
||||||
isPressed(false),
|
|
||||||
isMoved(false),
|
|
||||||
isStationary(false),
|
|
||||||
isReleased(false),
|
|
||||||
isShifted(false),
|
|
||||||
isControl(false),
|
|
||||||
isMeta(false),
|
|
||||||
isAlt(false),
|
|
||||||
touchPoints(0),
|
|
||||||
points(),
|
|
||||||
radius(0.0f),
|
|
||||||
isPinching(false),
|
|
||||||
isPinchOpening(false),
|
|
||||||
angles(),
|
|
||||||
angle(0.0f),
|
|
||||||
deltaAngle(0.0f),
|
|
||||||
isRotating(false),
|
|
||||||
rotating("none")
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
TouchEvent::TouchEvent(const QTouchEvent& event) :
|
|
||||||
// these values are not set by initWithQTouchEvent() because they only apply to comparing to other events
|
|
||||||
isPinching(false),
|
|
||||||
isPinchOpening(false),
|
|
||||||
deltaAngle(0.0f),
|
|
||||||
isRotating(false),
|
|
||||||
rotating("none")
|
|
||||||
{
|
|
||||||
initWithQTouchEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
TouchEvent::TouchEvent(const QTouchEvent& event, const TouchEvent& other) {
|
|
||||||
initWithQTouchEvent(event);
|
|
||||||
calculateMetaAttributes(other);
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns the angle (in degrees) between two points (note: 0 degrees is 'east')
|
|
||||||
float angleBetweenPoints(const glm::vec2& a, const glm::vec2& b ) {
|
|
||||||
glm::vec2 length = b - a;
|
|
||||||
float angle = DEGREES_PER_RADIAN * std::atan2(length.y, length.x);
|
|
||||||
if (angle < 0) {
|
|
||||||
angle += 360.0f;
|
|
||||||
};
|
|
||||||
return angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchEvent::initWithQTouchEvent(const QTouchEvent& event) {
|
|
||||||
// convert the touch points into an average
|
|
||||||
const QList<QTouchEvent::TouchPoint>& tPoints = event.touchPoints();
|
|
||||||
float touchAvgX = 0.0f;
|
|
||||||
float touchAvgY = 0.0f;
|
|
||||||
touchPoints = tPoints.count();
|
|
||||||
if (touchPoints > 1) {
|
|
||||||
for (int i = 0; i < touchPoints; ++i) {
|
|
||||||
touchAvgX += tPoints[i].pos().x();
|
|
||||||
touchAvgY += tPoints[i].pos().y();
|
|
||||||
|
|
||||||
// add it to our points vector
|
|
||||||
glm::vec2 thisPoint(tPoints[i].pos().x(), tPoints[i].pos().y());
|
|
||||||
points << thisPoint;
|
|
||||||
}
|
|
||||||
touchAvgX /= (float)(touchPoints);
|
|
||||||
touchAvgY /= (float)(touchPoints);
|
|
||||||
} else {
|
|
||||||
// I'm not sure this should ever happen, why would Qt send us a touch event for only one point?
|
|
||||||
// maybe this happens in the case of a multi-touch where all but the last finger is released?
|
|
||||||
touchAvgX = tPoints[0].pos().x();
|
|
||||||
touchAvgY = tPoints[0].pos().y();
|
|
||||||
}
|
|
||||||
x = touchAvgX;
|
|
||||||
y = touchAvgY;
|
|
||||||
|
|
||||||
// after calculating the center point (average touch point), determine the maximum radius
|
|
||||||
// also calculate the rotation angle for each point
|
|
||||||
float maxRadius = 0.0f;
|
|
||||||
glm::vec2 center(x,y);
|
|
||||||
for (int i = 0; i < touchPoints; ++i) {
|
|
||||||
glm::vec2 touchPoint(tPoints[i].pos().x(), tPoints[i].pos().y());
|
|
||||||
float thisRadius = glm::distance(center,touchPoint);
|
|
||||||
if (thisRadius > maxRadius) {
|
|
||||||
maxRadius = thisRadius;
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate the angle for this point
|
|
||||||
float thisAngle = angleBetweenPoints(center,touchPoint);
|
|
||||||
angles << thisAngle;
|
|
||||||
}
|
|
||||||
radius = maxRadius;
|
|
||||||
|
|
||||||
// after calculating the angles for each touch point, determine the average angle
|
|
||||||
float totalAngle = 0.0f;
|
|
||||||
for (int i = 0; i < touchPoints; ++i) {
|
|
||||||
totalAngle += angles[i];
|
|
||||||
}
|
|
||||||
angle = totalAngle/(float)touchPoints;
|
|
||||||
|
|
||||||
isPressed = event.touchPointStates().testFlag(Qt::TouchPointPressed);
|
|
||||||
isMoved = event.touchPointStates().testFlag(Qt::TouchPointMoved);
|
|
||||||
isStationary = event.touchPointStates().testFlag(Qt::TouchPointStationary);
|
|
||||||
isReleased = event.touchPointStates().testFlag(Qt::TouchPointReleased);
|
|
||||||
|
|
||||||
// keyboard modifiers
|
|
||||||
isShifted = event.modifiers().testFlag(Qt::ShiftModifier);
|
|
||||||
isMeta = event.modifiers().testFlag(Qt::MetaModifier);
|
|
||||||
isControl = event.modifiers().testFlag(Qt::ControlModifier);
|
|
||||||
isAlt = event.modifiers().testFlag(Qt::AltModifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchEvent::calculateMetaAttributes(const TouchEvent& other) {
|
|
||||||
// calculate comparative event attributes...
|
|
||||||
if (other.radius > radius) {
|
|
||||||
isPinching = true;
|
|
||||||
isPinchOpening = false;
|
|
||||||
} else if (other.radius < radius) {
|
|
||||||
isPinchOpening = true;
|
|
||||||
isPinching = false;
|
|
||||||
} else {
|
|
||||||
isPinching = other.isPinching;
|
|
||||||
isPinchOpening = other.isPinchOpening;
|
|
||||||
}
|
|
||||||
|
|
||||||
// determine if the points are rotating...
|
|
||||||
// note: if the number of touch points change between events, then we don't consider ourselves to be rotating
|
|
||||||
if (touchPoints == other.touchPoints) {
|
|
||||||
deltaAngle = angle - other.angle;
|
|
||||||
if (other.angle < angle) {
|
|
||||||
isRotating = true;
|
|
||||||
rotating = "clockwise";
|
|
||||||
} else if (other.angle > angle) {
|
|
||||||
isRotating = true;
|
|
||||||
rotating = "counterClockwise";
|
|
||||||
} else {
|
|
||||||
isRotating = false;
|
|
||||||
rotating = "none";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
deltaAngle = 0.0f;
|
|
||||||
isRotating = false;
|
|
||||||
rotating = "none";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& event) {
|
|
||||||
QScriptValue obj = engine->newObject();
|
|
||||||
obj.setProperty("x", event.x);
|
|
||||||
obj.setProperty("y", event.y);
|
|
||||||
obj.setProperty("isPressed", event.isPressed);
|
|
||||||
obj.setProperty("isMoved", event.isMoved);
|
|
||||||
obj.setProperty("isStationary", event.isStationary);
|
|
||||||
obj.setProperty("isReleased", event.isReleased);
|
|
||||||
obj.setProperty("isShifted", event.isShifted);
|
|
||||||
obj.setProperty("isMeta", event.isMeta);
|
|
||||||
obj.setProperty("isControl", event.isControl);
|
|
||||||
obj.setProperty("isAlt", event.isAlt);
|
|
||||||
obj.setProperty("touchPoints", event.touchPoints);
|
|
||||||
|
|
||||||
QScriptValue pointsObj = engine->newArray();
|
|
||||||
int index = 0;
|
|
||||||
foreach (glm::vec2 point, event.points) {
|
|
||||||
QScriptValue thisPoint = vec2toScriptValue(engine, point);
|
|
||||||
pointsObj.setProperty(index, thisPoint);
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
obj.setProperty("points", pointsObj);
|
|
||||||
obj.setProperty("radius", event.radius);
|
|
||||||
obj.setProperty("isPinching", event.isPinching);
|
|
||||||
obj.setProperty("isPinchOpening", event.isPinchOpening);
|
|
||||||
|
|
||||||
obj.setProperty("angle", event.angle);
|
|
||||||
obj.setProperty("deltaAngle", event.deltaAngle);
|
|
||||||
QScriptValue anglesObj = engine->newArray();
|
|
||||||
index = 0;
|
|
||||||
foreach (float angle, event.angles) {
|
|
||||||
anglesObj.setProperty(index, angle);
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
obj.setProperty("angles", anglesObj);
|
|
||||||
|
|
||||||
obj.setProperty("isRotating", event.isRotating);
|
|
||||||
obj.setProperty("rotating", event.rotating);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
void touchEventFromScriptValue(const QScriptValue& object, TouchEvent& event) {
|
|
||||||
// nothing for now...
|
|
||||||
}
|
|
||||||
|
|
||||||
WheelEvent::WheelEvent() :
|
|
||||||
x(0.0f),
|
|
||||||
y(0.0f),
|
|
||||||
delta(0.0f),
|
|
||||||
orientation("UNKNOwN"),
|
|
||||||
isLeftButton(false),
|
|
||||||
isRightButton(false),
|
|
||||||
isMiddleButton(false),
|
|
||||||
isShifted(false),
|
|
||||||
isControl(false),
|
|
||||||
isMeta(false),
|
|
||||||
isAlt(false)
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
WheelEvent::WheelEvent(const QWheelEvent& event) {
|
|
||||||
x = event.x();
|
|
||||||
y = event.y();
|
|
||||||
|
|
||||||
delta = event.delta();
|
|
||||||
if (event.orientation() == Qt::Horizontal) {
|
|
||||||
orientation = "HORIZONTAL";
|
|
||||||
} else {
|
|
||||||
orientation = "VERTICAL";
|
|
||||||
}
|
|
||||||
|
|
||||||
// button pressed state
|
|
||||||
isLeftButton = (event.buttons().testFlag(Qt::LeftButton));
|
|
||||||
isRightButton = (event.buttons().testFlag(Qt::RightButton));
|
|
||||||
isMiddleButton = (event.buttons().testFlag(Qt::MiddleButton));
|
|
||||||
|
|
||||||
// keyboard modifiers
|
|
||||||
isShifted = event.modifiers().testFlag(Qt::ShiftModifier);
|
|
||||||
isMeta = event.modifiers().testFlag(Qt::MetaModifier);
|
|
||||||
isControl = event.modifiers().testFlag(Qt::ControlModifier);
|
|
||||||
isAlt = event.modifiers().testFlag(Qt::AltModifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QScriptValue wheelEventToScriptValue(QScriptEngine* engine, const WheelEvent& event) {
|
|
||||||
QScriptValue obj = engine->newObject();
|
|
||||||
obj.setProperty("x", event.x);
|
|
||||||
obj.setProperty("y", event.y);
|
|
||||||
obj.setProperty("delta", event.delta);
|
|
||||||
obj.setProperty("orientation", event.orientation);
|
|
||||||
obj.setProperty("isLeftButton", event.isLeftButton);
|
|
||||||
obj.setProperty("isRightButton", event.isRightButton);
|
|
||||||
obj.setProperty("isMiddleButton", event.isMiddleButton);
|
|
||||||
obj.setProperty("isShifted", event.isShifted);
|
|
||||||
obj.setProperty("isMeta", event.isMeta);
|
|
||||||
obj.setProperty("isControl", event.isControl);
|
|
||||||
obj.setProperty("isAlt", event.isAlt);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wheelEventFromScriptValue(const QScriptValue& object, WheelEvent& event) {
|
|
||||||
// nothing for now...
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SpatialEvent::SpatialEvent() :
|
|
||||||
locTranslation(0.0f),
|
|
||||||
locRotation(),
|
|
||||||
absTranslation(0.0f),
|
|
||||||
absRotation()
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
SpatialEvent::SpatialEvent(const SpatialEvent& event) {
|
|
||||||
locTranslation = event.locTranslation;
|
|
||||||
locRotation = event.locRotation;
|
|
||||||
absTranslation = event.absTranslation;
|
|
||||||
absRotation = event.absRotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QScriptValue spatialEventToScriptValue(QScriptEngine* engine, const SpatialEvent& event) {
|
|
||||||
QScriptValue obj = engine->newObject();
|
|
||||||
|
|
||||||
obj.setProperty("locTranslation", vec3toScriptValue(engine, event.locTranslation) );
|
|
||||||
obj.setProperty("locRotation", quatToScriptValue(engine, event.locRotation) );
|
|
||||||
obj.setProperty("absTranslation", vec3toScriptValue(engine, event.absTranslation) );
|
|
||||||
obj.setProperty("absRotation", quatToScriptValue(engine, event.absRotation) );
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
void spatialEventFromScriptValue(const QScriptValue& object,SpatialEvent& event) {
|
|
||||||
// nothing for now...
|
|
||||||
}
|
}
|
||||||
|
@ -12,139 +12,8 @@
|
|||||||
#ifndef hifi_EventTypes_h
|
#ifndef hifi_EventTypes_h
|
||||||
#define hifi_EventTypes_h
|
#define hifi_EventTypes_h
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <qscriptengine.h>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
|
||||||
|
|
||||||
#include <QtScript/QScriptEngine>
|
|
||||||
|
|
||||||
#include <QKeyEvent>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QTouchEvent>
|
|
||||||
#include <QWheelEvent>
|
|
||||||
|
|
||||||
|
|
||||||
class KeyEvent {
|
|
||||||
public:
|
|
||||||
KeyEvent();
|
|
||||||
KeyEvent(const QKeyEvent& event);
|
|
||||||
bool operator==(const KeyEvent& other) const;
|
|
||||||
operator QKeySequence() const;
|
|
||||||
|
|
||||||
int key;
|
|
||||||
QString text;
|
|
||||||
bool isShifted;
|
|
||||||
bool isControl;
|
|
||||||
bool isMeta;
|
|
||||||
bool isAlt;
|
|
||||||
bool isKeypad;
|
|
||||||
bool isValid;
|
|
||||||
bool isAutoRepeat;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class MouseEvent {
|
|
||||||
public:
|
|
||||||
MouseEvent();
|
|
||||||
MouseEvent(const QMouseEvent& event, const unsigned int deviceID = 0);
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
unsigned int deviceID;
|
|
||||||
QString button;
|
|
||||||
bool isLeftButton;
|
|
||||||
bool isRightButton;
|
|
||||||
bool isMiddleButton;
|
|
||||||
bool isShifted;
|
|
||||||
bool isControl;
|
|
||||||
bool isMeta;
|
|
||||||
bool isAlt;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TouchEvent {
|
|
||||||
public:
|
|
||||||
TouchEvent();
|
|
||||||
TouchEvent(const QTouchEvent& event);
|
|
||||||
TouchEvent(const QTouchEvent& event, const TouchEvent& other);
|
|
||||||
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
bool isPressed;
|
|
||||||
bool isMoved;
|
|
||||||
bool isStationary;
|
|
||||||
bool isReleased;
|
|
||||||
bool isShifted;
|
|
||||||
bool isControl;
|
|
||||||
bool isMeta;
|
|
||||||
bool isAlt;
|
|
||||||
int touchPoints;
|
|
||||||
QVector<glm::vec2> points;
|
|
||||||
float radius;
|
|
||||||
bool isPinching;
|
|
||||||
bool isPinchOpening;
|
|
||||||
|
|
||||||
// angles are in degrees
|
|
||||||
QVector<float> angles; // angle from center to each point
|
|
||||||
float angle; // the average of the angles
|
|
||||||
float deltaAngle; // the change in average angle from last event
|
|
||||||
bool isRotating;
|
|
||||||
QString rotating;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void initWithQTouchEvent(const QTouchEvent& event);
|
|
||||||
void calculateMetaAttributes(const TouchEvent& other);
|
|
||||||
};
|
|
||||||
|
|
||||||
class WheelEvent {
|
|
||||||
public:
|
|
||||||
WheelEvent();
|
|
||||||
WheelEvent(const QWheelEvent& event);
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int delta;
|
|
||||||
QString orientation;
|
|
||||||
bool isLeftButton;
|
|
||||||
bool isRightButton;
|
|
||||||
bool isMiddleButton;
|
|
||||||
bool isShifted;
|
|
||||||
bool isControl;
|
|
||||||
bool isMeta;
|
|
||||||
bool isAlt;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SpatialEvent {
|
|
||||||
public:
|
|
||||||
SpatialEvent();
|
|
||||||
SpatialEvent(const SpatialEvent& other);
|
|
||||||
|
|
||||||
glm::vec3 locTranslation;
|
|
||||||
glm::quat locRotation;
|
|
||||||
glm::vec3 absTranslation;
|
|
||||||
glm::quat absRotation;
|
|
||||||
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(KeyEvent)
|
|
||||||
Q_DECLARE_METATYPE(MouseEvent)
|
|
||||||
Q_DECLARE_METATYPE(TouchEvent)
|
|
||||||
Q_DECLARE_METATYPE(WheelEvent)
|
|
||||||
Q_DECLARE_METATYPE(SpatialEvent)
|
|
||||||
|
|
||||||
void registerEventTypes(QScriptEngine* engine);
|
void registerEventTypes(QScriptEngine* engine);
|
||||||
|
|
||||||
QScriptValue keyEventToScriptValue(QScriptEngine* engine, const KeyEvent& event);
|
|
||||||
void keyEventFromScriptValue(const QScriptValue& object, KeyEvent& event);
|
|
||||||
|
|
||||||
QScriptValue mouseEventToScriptValue(QScriptEngine* engine, const MouseEvent& event);
|
|
||||||
void mouseEventFromScriptValue(const QScriptValue& object, MouseEvent& event);
|
|
||||||
|
|
||||||
QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& event);
|
|
||||||
void touchEventFromScriptValue(const QScriptValue& object, TouchEvent& event);
|
|
||||||
|
|
||||||
QScriptValue wheelEventToScriptValue(QScriptEngine* engine, const WheelEvent& event);
|
|
||||||
void wheelEventFromScriptValue(const QScriptValue& object, WheelEvent& event);
|
|
||||||
|
|
||||||
QScriptValue spatialEventToScriptValue(QScriptEngine* engine, const SpatialEvent& event);
|
|
||||||
void spatialEventFromScriptValue(const QScriptValue& object, SpatialEvent& event);
|
|
||||||
|
|
||||||
#endif // hifi_EventTypes_h
|
#endif // hifi_EventTypes_h
|
||||||
|
41
libraries/script-engine/src/HFActionEvent.cpp
Normal file
41
libraries/script-engine/src/HFActionEvent.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
//
|
||||||
|
// HFActionEvent.cpp
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "HFActionEvent.h"
|
||||||
|
|
||||||
|
HFActionEvent::HFActionEvent(QEvent::Type type, const QPointF& localPosition) :
|
||||||
|
HFMetaEvent(type),
|
||||||
|
localPosition(localPosition)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QEvent::Type HFActionEvent::startType() {
|
||||||
|
static QEvent::Type startType = HFMetaEvent::newEventType();
|
||||||
|
return startType;
|
||||||
|
}
|
||||||
|
|
||||||
|
QEvent::Type HFActionEvent::endType() {
|
||||||
|
static QEvent::Type endType = HFMetaEvent::newEventType();
|
||||||
|
return endType;
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue HFActionEvent::toScriptValue(QScriptEngine* engine, const HFActionEvent& event) {
|
||||||
|
QScriptValue obj = engine->newObject();
|
||||||
|
obj.setProperty("x", event.localPosition.x());
|
||||||
|
obj.setProperty("y", event.localPosition.y());
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HFActionEvent::fromScriptValue(const QScriptValue& object, HFActionEvent& event) {
|
||||||
|
// not yet implemented
|
||||||
|
}
|
||||||
|
|
35
libraries/script-engine/src/HFActionEvent.h
Normal file
35
libraries/script-engine/src/HFActionEvent.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
//
|
||||||
|
// HFActionEvent.h
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_HFActionEvent_h
|
||||||
|
#define hifi_HFActionEvent_h
|
||||||
|
|
||||||
|
#include "HFMetaEvent.h"
|
||||||
|
|
||||||
|
#include <qscriptengine.h>
|
||||||
|
|
||||||
|
class HFActionEvent : public HFMetaEvent {
|
||||||
|
public:
|
||||||
|
HFActionEvent() {};
|
||||||
|
HFActionEvent(QEvent::Type type, const QPointF& localPosition);
|
||||||
|
|
||||||
|
static QEvent::Type startType();
|
||||||
|
static QEvent::Type endType();
|
||||||
|
|
||||||
|
static QScriptValue toScriptValue(QScriptEngine* engine, const HFActionEvent& event);
|
||||||
|
static void fromScriptValue(const QScriptValue& object, HFActionEvent& event);
|
||||||
|
|
||||||
|
QPointF localPosition;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(HFActionEvent)
|
||||||
|
|
||||||
|
#endif // hifi_HFActionEvent_h
|
28
libraries/script-engine/src/HFBackEvent.cpp
Normal file
28
libraries/script-engine/src/HFBackEvent.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// HFBackEvent.cpp
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "HFBackEvent.h"
|
||||||
|
|
||||||
|
HFBackEvent::HFBackEvent(QEvent::Type type) :
|
||||||
|
HFMetaEvent(type)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QEvent::Type HFBackEvent::startType() {
|
||||||
|
static QEvent::Type startType = HFMetaEvent::newEventType();
|
||||||
|
return startType;
|
||||||
|
}
|
||||||
|
|
||||||
|
QEvent::Type HFBackEvent::endType() {
|
||||||
|
static QEvent::Type endType = HFMetaEvent::newEventType();
|
||||||
|
return endType;
|
||||||
|
}
|
29
libraries/script-engine/src/HFBackEvent.h
Normal file
29
libraries/script-engine/src/HFBackEvent.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// HFBackEvent.h
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_HFBackEvent_h
|
||||||
|
#define hifi_HFBackEvent_h
|
||||||
|
|
||||||
|
#include <qevent.h>
|
||||||
|
#include <qscriptengine.h>
|
||||||
|
|
||||||
|
#include "HFMetaEvent.h"
|
||||||
|
|
||||||
|
class HFBackEvent : public HFMetaEvent {
|
||||||
|
public:
|
||||||
|
HFBackEvent() {};
|
||||||
|
HFBackEvent(QEvent::Type type);
|
||||||
|
|
||||||
|
static QEvent::Type startType();
|
||||||
|
static QEvent::Type endType();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_HFBackEvent_h
|
20
libraries/script-engine/src/HFMetaEvent.cpp
Normal file
20
libraries/script-engine/src/HFMetaEvent.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
//
|
||||||
|
// HFMetaEvent.cpp
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "HFMetaEvent.h"
|
||||||
|
|
||||||
|
QSet<QEvent::Type> HFMetaEvent::_types = QSet<QEvent::Type>();
|
||||||
|
|
||||||
|
QEvent::Type HFMetaEvent::newEventType() {
|
||||||
|
QEvent::Type newType = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||||
|
_types.insert(newType);
|
||||||
|
return newType;
|
||||||
|
}
|
28
libraries/script-engine/src/HFMetaEvent.h
Normal file
28
libraries/script-engine/src/HFMetaEvent.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// HFMetaEvent.h
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_HFMetaEvent_h
|
||||||
|
#define hifi_HFMetaEvent_h
|
||||||
|
|
||||||
|
#include <qevent.h>
|
||||||
|
|
||||||
|
class HFMetaEvent : public QEvent {
|
||||||
|
public:
|
||||||
|
HFMetaEvent() : QEvent(HFMetaEvent::newEventType()) {};
|
||||||
|
HFMetaEvent(QEvent::Type type) : QEvent(type) {};
|
||||||
|
static const QSet<QEvent::Type>& types() { return HFMetaEvent::_types; }
|
||||||
|
protected:
|
||||||
|
static QEvent::Type newEventType();
|
||||||
|
|
||||||
|
static QSet<QEvent::Type> _types;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_HFMetaEvent_h
|
290
libraries/script-engine/src/KeyEvent.cpp
Normal file
290
libraries/script-engine/src/KeyEvent.cpp
Normal file
@ -0,0 +1,290 @@
|
|||||||
|
//
|
||||||
|
// KeyEvent.cpp
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <qdebug.h>
|
||||||
|
#include <qscriptengine.h>
|
||||||
|
|
||||||
|
#include "KeyEvent.h"
|
||||||
|
|
||||||
|
KeyEvent::KeyEvent() :
|
||||||
|
key(0),
|
||||||
|
text(""),
|
||||||
|
isShifted(false),
|
||||||
|
isControl(false),
|
||||||
|
isMeta(false),
|
||||||
|
isAlt(false),
|
||||||
|
isKeypad(false),
|
||||||
|
isValid(false),
|
||||||
|
isAutoRepeat(false)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyEvent::KeyEvent(const QKeyEvent& event) {
|
||||||
|
key = event.key();
|
||||||
|
text = event.text();
|
||||||
|
isShifted = event.modifiers().testFlag(Qt::ShiftModifier);
|
||||||
|
isMeta = event.modifiers().testFlag(Qt::MetaModifier);
|
||||||
|
isControl = event.modifiers().testFlag(Qt::ControlModifier);
|
||||||
|
isAlt = event.modifiers().testFlag(Qt::AltModifier);
|
||||||
|
isKeypad = event.modifiers().testFlag(Qt::KeypadModifier);
|
||||||
|
isValid = true;
|
||||||
|
isAutoRepeat = event.isAutoRepeat();
|
||||||
|
|
||||||
|
// handle special text for special characters...
|
||||||
|
if (key == Qt::Key_F1) {
|
||||||
|
text = "F1";
|
||||||
|
} else if (key == Qt::Key_F2) {
|
||||||
|
text = "F2";
|
||||||
|
} else if (key == Qt::Key_F3) {
|
||||||
|
text = "F3";
|
||||||
|
} else if (key == Qt::Key_F4) {
|
||||||
|
text = "F4";
|
||||||
|
} else if (key == Qt::Key_F5) {
|
||||||
|
text = "F5";
|
||||||
|
} else if (key == Qt::Key_F6) {
|
||||||
|
text = "F6";
|
||||||
|
} else if (key == Qt::Key_F7) {
|
||||||
|
text = "F7";
|
||||||
|
} else if (key == Qt::Key_F8) {
|
||||||
|
text = "F8";
|
||||||
|
} else if (key == Qt::Key_F9) {
|
||||||
|
text = "F9";
|
||||||
|
} else if (key == Qt::Key_F10) {
|
||||||
|
text = "F10";
|
||||||
|
} else if (key == Qt::Key_F11) {
|
||||||
|
text = "F11";
|
||||||
|
} else if (key == Qt::Key_F12) {
|
||||||
|
text = "F12";
|
||||||
|
} else if (key == Qt::Key_Up) {
|
||||||
|
text = "UP";
|
||||||
|
} else if (key == Qt::Key_Down) {
|
||||||
|
text = "DOWN";
|
||||||
|
} else if (key == Qt::Key_Left) {
|
||||||
|
text = "LEFT";
|
||||||
|
} else if (key == Qt::Key_Right) {
|
||||||
|
text = "RIGHT";
|
||||||
|
} else if (key == Qt::Key_Space) {
|
||||||
|
text = "SPACE";
|
||||||
|
} else if (key == Qt::Key_Escape) {
|
||||||
|
text = "ESC";
|
||||||
|
} else if (key == Qt::Key_Tab) {
|
||||||
|
text = "TAB";
|
||||||
|
} else if (key == Qt::Key_Delete) {
|
||||||
|
text = "DELETE";
|
||||||
|
} else if (key == Qt::Key_Backspace) {
|
||||||
|
text = "BACKSPACE";
|
||||||
|
} else if (key == Qt::Key_Shift) {
|
||||||
|
text = "SHIFT";
|
||||||
|
} else if (key == Qt::Key_Alt) {
|
||||||
|
text = "ALT";
|
||||||
|
} else if (key == Qt::Key_Control) {
|
||||||
|
text = "CONTROL";
|
||||||
|
} else if (key == Qt::Key_Meta) {
|
||||||
|
text = "META";
|
||||||
|
} else if (key == Qt::Key_PageDown) {
|
||||||
|
text = "PAGE DOWN";
|
||||||
|
} else if (key == Qt::Key_PageUp) {
|
||||||
|
text = "PAGE UP";
|
||||||
|
} else if (key == Qt::Key_Home) {
|
||||||
|
text = "HOME";
|
||||||
|
} else if (key == Qt::Key_End) {
|
||||||
|
text = "END";
|
||||||
|
} else if (key == Qt::Key_Help) {
|
||||||
|
text = "HELP";
|
||||||
|
} else if (key == Qt::Key_CapsLock) {
|
||||||
|
text = "CAPS LOCK";
|
||||||
|
} else if (key >= Qt::Key_A && key <= Qt::Key_Z && (isMeta || isControl || isAlt)) {
|
||||||
|
// this little bit of hackery will fix the text character keys like a-z in cases of control/alt/meta where
|
||||||
|
// qt doesn't always give you the key characters and will sometimes give you crazy non-printable characters
|
||||||
|
const int lowerCaseAdjust = 0x20;
|
||||||
|
QString unicode;
|
||||||
|
if (isShifted) {
|
||||||
|
text = QString(QChar(key));
|
||||||
|
} else {
|
||||||
|
text = QString(QChar(key + lowerCaseAdjust));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KeyEvent::operator==(const KeyEvent& other) const {
|
||||||
|
return other.key == key
|
||||||
|
&& other.isShifted == isShifted
|
||||||
|
&& other.isControl == isControl
|
||||||
|
&& other.isMeta == isMeta
|
||||||
|
&& other.isAlt == isAlt
|
||||||
|
&& other.isKeypad == isKeypad
|
||||||
|
&& other.isAutoRepeat == isAutoRepeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
KeyEvent::operator QKeySequence() const {
|
||||||
|
int resultCode = 0;
|
||||||
|
if (text.size() == 1 && text >= "a" && text <= "z") {
|
||||||
|
resultCode = text.toUpper().at(0).unicode();
|
||||||
|
} else {
|
||||||
|
resultCode = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMeta) {
|
||||||
|
resultCode |= Qt::META;
|
||||||
|
}
|
||||||
|
if (isAlt) {
|
||||||
|
resultCode |= Qt::ALT;
|
||||||
|
}
|
||||||
|
if (isControl) {
|
||||||
|
resultCode |= Qt::CTRL;
|
||||||
|
}
|
||||||
|
if (isShifted) {
|
||||||
|
resultCode |= Qt::SHIFT;
|
||||||
|
}
|
||||||
|
return QKeySequence(resultCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue KeyEvent::toScriptValue(QScriptEngine* engine, const KeyEvent& event) {
|
||||||
|
QScriptValue obj = engine->newObject();
|
||||||
|
obj.setProperty("key", event.key);
|
||||||
|
obj.setProperty("text", event.text);
|
||||||
|
obj.setProperty("isShifted", event.isShifted);
|
||||||
|
obj.setProperty("isMeta", event.isMeta);
|
||||||
|
obj.setProperty("isControl", event.isControl);
|
||||||
|
obj.setProperty("isAlt", event.isAlt);
|
||||||
|
obj.setProperty("isKeypad", event.isKeypad);
|
||||||
|
obj.setProperty("isAutoRepeat", event.isAutoRepeat);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyEvent::fromScriptValue(const QScriptValue& object, KeyEvent& event) {
|
||||||
|
|
||||||
|
event.isValid = false; // assume the worst
|
||||||
|
event.isMeta = object.property("isMeta").toVariant().toBool();
|
||||||
|
event.isControl = object.property("isControl").toVariant().toBool();
|
||||||
|
event.isAlt = object.property("isAlt").toVariant().toBool();
|
||||||
|
event.isKeypad = object.property("isKeypad").toVariant().toBool();
|
||||||
|
event.isAutoRepeat = object.property("isAutoRepeat").toVariant().toBool();
|
||||||
|
|
||||||
|
QScriptValue key = object.property("key");
|
||||||
|
if (key.isValid()) {
|
||||||
|
event.key = key.toVariant().toInt();
|
||||||
|
event.text = QString(QChar(event.key));
|
||||||
|
event.isValid = true;
|
||||||
|
} else {
|
||||||
|
QScriptValue text = object.property("text");
|
||||||
|
if (text.isValid()) {
|
||||||
|
event.text = object.property("text").toVariant().toString();
|
||||||
|
|
||||||
|
// if the text is a special command, then map it here...
|
||||||
|
// TODO: come up with more elegant solution here, a map? is there a Qt function that gives nice names for keys?
|
||||||
|
if (event.text.toUpper() == "F1") {
|
||||||
|
event.key = Qt::Key_F1;
|
||||||
|
} else if (event.text.toUpper() == "F2") {
|
||||||
|
event.key = Qt::Key_F2;
|
||||||
|
} else if (event.text.toUpper() == "F3") {
|
||||||
|
event.key = Qt::Key_F3;
|
||||||
|
} else if (event.text.toUpper() == "F4") {
|
||||||
|
event.key = Qt::Key_F4;
|
||||||
|
} else if (event.text.toUpper() == "F5") {
|
||||||
|
event.key = Qt::Key_F5;
|
||||||
|
} else if (event.text.toUpper() == "F6") {
|
||||||
|
event.key = Qt::Key_F6;
|
||||||
|
} else if (event.text.toUpper() == "F7") {
|
||||||
|
event.key = Qt::Key_F7;
|
||||||
|
} else if (event.text.toUpper() == "F8") {
|
||||||
|
event.key = Qt::Key_F8;
|
||||||
|
} else if (event.text.toUpper() == "F9") {
|
||||||
|
event.key = Qt::Key_F9;
|
||||||
|
} else if (event.text.toUpper() == "F10") {
|
||||||
|
event.key = Qt::Key_F10;
|
||||||
|
} else if (event.text.toUpper() == "F11") {
|
||||||
|
event.key = Qt::Key_F11;
|
||||||
|
} else if (event.text.toUpper() == "F12") {
|
||||||
|
event.key = Qt::Key_F12;
|
||||||
|
} else if (event.text.toUpper() == "UP") {
|
||||||
|
event.key = Qt::Key_Up;
|
||||||
|
event.isKeypad = true;
|
||||||
|
} else if (event.text.toUpper() == "DOWN") {
|
||||||
|
event.key = Qt::Key_Down;
|
||||||
|
event.isKeypad = true;
|
||||||
|
} else if (event.text.toUpper() == "LEFT") {
|
||||||
|
event.key = Qt::Key_Left;
|
||||||
|
event.isKeypad = true;
|
||||||
|
} else if (event.text.toUpper() == "RIGHT") {
|
||||||
|
event.key = Qt::Key_Right;
|
||||||
|
event.isKeypad = true;
|
||||||
|
} else if (event.text.toUpper() == "SPACE") {
|
||||||
|
event.key = Qt::Key_Space;
|
||||||
|
} else if (event.text.toUpper() == "ESC") {
|
||||||
|
event.key = Qt::Key_Escape;
|
||||||
|
} else if (event.text.toUpper() == "TAB") {
|
||||||
|
event.key = Qt::Key_Tab;
|
||||||
|
} else if (event.text.toUpper() == "DELETE") {
|
||||||
|
event.key = Qt::Key_Delete;
|
||||||
|
} else if (event.text.toUpper() == "BACKSPACE") {
|
||||||
|
event.key = Qt::Key_Backspace;
|
||||||
|
} else if (event.text.toUpper() == "SHIFT") {
|
||||||
|
event.key = Qt::Key_Shift;
|
||||||
|
} else if (event.text.toUpper() == "ALT") {
|
||||||
|
event.key = Qt::Key_Alt;
|
||||||
|
} else if (event.text.toUpper() == "CONTROL") {
|
||||||
|
event.key = Qt::Key_Control;
|
||||||
|
} else if (event.text.toUpper() == "META") {
|
||||||
|
event.key = Qt::Key_Meta;
|
||||||
|
} else if (event.text.toUpper() == "PAGE DOWN") {
|
||||||
|
event.key = Qt::Key_PageDown;
|
||||||
|
} else if (event.text.toUpper() == "PAGE UP") {
|
||||||
|
event.key = Qt::Key_PageUp;
|
||||||
|
} else if (event.text.toUpper() == "HOME") {
|
||||||
|
event.key = Qt::Key_Home;
|
||||||
|
} else if (event.text.toUpper() == "END") {
|
||||||
|
event.key = Qt::Key_End;
|
||||||
|
} else if (event.text.toUpper() == "HELP") {
|
||||||
|
event.key = Qt::Key_Help;
|
||||||
|
} else if (event.text.toUpper() == "CAPS LOCK") {
|
||||||
|
event.key = Qt::Key_CapsLock;
|
||||||
|
} else {
|
||||||
|
// Key values do not distinguish between uppercase and lowercase
|
||||||
|
// and use the uppercase key value.
|
||||||
|
event.key = event.text.toUpper().at(0).unicode();
|
||||||
|
}
|
||||||
|
event.isValid = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue isShifted = object.property("isShifted");
|
||||||
|
if (isShifted.isValid()) {
|
||||||
|
event.isShifted = isShifted.toVariant().toBool();
|
||||||
|
} else {
|
||||||
|
// if no isShifted was included, get it from the text
|
||||||
|
QChar character = event.text.at(0);
|
||||||
|
if (character.isLetter() && character.isUpper()) {
|
||||||
|
event.isShifted = true;
|
||||||
|
} else {
|
||||||
|
// if it's a symbol, then attempt to detect shifted-ness
|
||||||
|
if (QString("~!@#$%^&*()_+{}|:\"<>?").contains(character)) {
|
||||||
|
event.isShifted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const bool wantDebug = false;
|
||||||
|
if (wantDebug) {
|
||||||
|
qDebug() << "event.key=" << event.key
|
||||||
|
<< " event.text=" << event.text
|
||||||
|
<< " event.isShifted=" << event.isShifted
|
||||||
|
<< " event.isControl=" << event.isControl
|
||||||
|
<< " event.isMeta=" << event.isMeta
|
||||||
|
<< " event.isAlt=" << event.isAlt
|
||||||
|
<< " event.isKeypad=" << event.isKeypad
|
||||||
|
<< " event.isAutoRepeat=" << event.isAutoRepeat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
41
libraries/script-engine/src/KeyEvent.h
Normal file
41
libraries/script-engine/src/KeyEvent.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
//
|
||||||
|
// KeyEvent.h
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_KeyEvent_h
|
||||||
|
#define hifi_KeyEvent_h
|
||||||
|
|
||||||
|
#include <QKeyEvent>
|
||||||
|
#include <qscriptvalue.h>
|
||||||
|
|
||||||
|
class KeyEvent {
|
||||||
|
public:
|
||||||
|
KeyEvent();
|
||||||
|
KeyEvent(const QKeyEvent& event);
|
||||||
|
bool operator==(const KeyEvent& other) const;
|
||||||
|
operator QKeySequence() const;
|
||||||
|
|
||||||
|
static QScriptValue toScriptValue(QScriptEngine* engine, const KeyEvent& event);
|
||||||
|
static void fromScriptValue(const QScriptValue& object, KeyEvent& event);
|
||||||
|
|
||||||
|
int key;
|
||||||
|
QString text;
|
||||||
|
bool isShifted;
|
||||||
|
bool isControl;
|
||||||
|
bool isMeta;
|
||||||
|
bool isAlt;
|
||||||
|
bool isKeypad;
|
||||||
|
bool isValid;
|
||||||
|
bool isAutoRepeat;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(KeyEvent)
|
||||||
|
|
||||||
|
#endif // hifi_KeyEvent_h
|
@ -82,7 +82,7 @@ void menuItemPropertiesFromScriptValue(const QScriptValue& object, MenuItemPrope
|
|||||||
} else {
|
} else {
|
||||||
QScriptValue shortcutKeyEventValue = object.property("shortcutKeyEvent");
|
QScriptValue shortcutKeyEventValue = object.property("shortcutKeyEvent");
|
||||||
if (shortcutKeyEventValue.isValid()) {
|
if (shortcutKeyEventValue.isValid()) {
|
||||||
keyEventFromScriptValue(shortcutKeyEventValue, properties.shortcutKeyEvent);
|
KeyEvent::fromScriptValue(shortcutKeyEventValue, properties.shortcutKeyEvent);
|
||||||
properties.shortcutKeySequence = properties.shortcutKeyEvent;
|
properties.shortcutKeySequence = properties.shortcutKeyEvent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include <QtScript/QScriptEngine>
|
#include <QtScript/QScriptEngine>
|
||||||
|
|
||||||
#include "EventTypes.h"
|
#include "KeyEvent.h"
|
||||||
|
|
||||||
const int UNSPECIFIED_POSITION = -1;
|
const int UNSPECIFIED_POSITION = -1;
|
||||||
|
|
||||||
|
83
libraries/script-engine/src/MouseEvent.cpp
Normal file
83
libraries/script-engine/src/MouseEvent.cpp
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
//
|
||||||
|
// MouseEvent.cpp
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <qscriptengine.h>
|
||||||
|
#include <qscriptvalue.h>
|
||||||
|
|
||||||
|
#include "MouseEvent.h"
|
||||||
|
|
||||||
|
MouseEvent::MouseEvent() :
|
||||||
|
x(0.0f),
|
||||||
|
y(0.0f),
|
||||||
|
isLeftButton(false),
|
||||||
|
isRightButton(false),
|
||||||
|
isMiddleButton(false),
|
||||||
|
isShifted(false),
|
||||||
|
isControl(false),
|
||||||
|
isMeta(false),
|
||||||
|
isAlt(false)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MouseEvent::MouseEvent(const QMouseEvent& event, const unsigned int deviceID) :
|
||||||
|
x(event.x()),
|
||||||
|
y(event.y()),
|
||||||
|
deviceID(deviceID),
|
||||||
|
isLeftButton(event.buttons().testFlag(Qt::LeftButton)),
|
||||||
|
isRightButton(event.buttons().testFlag(Qt::RightButton)),
|
||||||
|
isMiddleButton(event.buttons().testFlag(Qt::MiddleButton)),
|
||||||
|
isShifted(event.modifiers().testFlag(Qt::ShiftModifier)),
|
||||||
|
isControl(event.modifiers().testFlag(Qt::ControlModifier)),
|
||||||
|
isMeta(event.modifiers().testFlag(Qt::MetaModifier)),
|
||||||
|
isAlt(event.modifiers().testFlag(Qt::AltModifier))
|
||||||
|
{
|
||||||
|
// single button that caused the event
|
||||||
|
switch (event.button()) {
|
||||||
|
case Qt::LeftButton:
|
||||||
|
button = "LEFT";
|
||||||
|
isLeftButton = true;
|
||||||
|
break;
|
||||||
|
case Qt::RightButton:
|
||||||
|
button = "RIGHT";
|
||||||
|
isRightButton = true;
|
||||||
|
break;
|
||||||
|
case Qt::MiddleButton:
|
||||||
|
button = "MIDDLE";
|
||||||
|
isMiddleButton = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
button = "NONE";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue MouseEvent::toScriptValue(QScriptEngine* engine, const MouseEvent& event) {
|
||||||
|
QScriptValue obj = engine->newObject();
|
||||||
|
obj.setProperty("x", event.x);
|
||||||
|
obj.setProperty("y", event.y);
|
||||||
|
obj.setProperty("button", event.button);
|
||||||
|
obj.setProperty("deviceID", event.deviceID);
|
||||||
|
obj.setProperty("isLeftButton", event.isLeftButton);
|
||||||
|
obj.setProperty("isRightButton", event.isRightButton);
|
||||||
|
obj.setProperty("isMiddleButton", event.isMiddleButton);
|
||||||
|
obj.setProperty("isShifted", event.isShifted);
|
||||||
|
obj.setProperty("isMeta", event.isMeta);
|
||||||
|
obj.setProperty("isControl", event.isControl);
|
||||||
|
obj.setProperty("isAlt", event.isAlt);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MouseEvent::fromScriptValue(const QScriptValue& object, MouseEvent& event) {
|
||||||
|
// nothing for now...
|
||||||
|
}
|
40
libraries/script-engine/src/MouseEvent.h
Normal file
40
libraries/script-engine/src/MouseEvent.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
//
|
||||||
|
// MouseEvent.h
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_MouseEvent_h
|
||||||
|
#define hifi_MouseEvent_h
|
||||||
|
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
class MouseEvent {
|
||||||
|
public:
|
||||||
|
MouseEvent();
|
||||||
|
MouseEvent(const QMouseEvent& event, const unsigned int deviceID = 0);
|
||||||
|
|
||||||
|
static QScriptValue toScriptValue(QScriptEngine* engine, const MouseEvent& event);
|
||||||
|
static void fromScriptValue(const QScriptValue& object, MouseEvent& event);
|
||||||
|
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
unsigned int deviceID;
|
||||||
|
QString button;
|
||||||
|
bool isLeftButton;
|
||||||
|
bool isRightButton;
|
||||||
|
bool isMiddleButton;
|
||||||
|
bool isShifted;
|
||||||
|
bool isControl;
|
||||||
|
bool isMeta;
|
||||||
|
bool isAlt;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(MouseEvent)
|
||||||
|
|
||||||
|
#endif // hifi_MouseEvent_h
|
@ -35,13 +35,15 @@
|
|||||||
#include "AnimationObject.h"
|
#include "AnimationObject.h"
|
||||||
#include "ArrayBufferViewClass.h"
|
#include "ArrayBufferViewClass.h"
|
||||||
#include "DataViewClass.h"
|
#include "DataViewClass.h"
|
||||||
|
#include "EventTypes.h"
|
||||||
#include "MenuItemProperties.h"
|
#include "MenuItemProperties.h"
|
||||||
#include "MIDIEvent.h"
|
|
||||||
#include "LocalVoxels.h"
|
#include "LocalVoxels.h"
|
||||||
#include "ScriptEngine.h"
|
#include "ScriptEngine.h"
|
||||||
#include "TypedArrays.h"
|
#include "TypedArrays.h"
|
||||||
#include "XMLHttpRequestClass.h"
|
#include "XMLHttpRequestClass.h"
|
||||||
|
|
||||||
|
#include "MIDIEvent.h"
|
||||||
|
|
||||||
VoxelsScriptingInterface ScriptEngine::_voxelsScriptingInterface;
|
VoxelsScriptingInterface ScriptEngine::_voxelsScriptingInterface;
|
||||||
EntityScriptingInterface ScriptEngine::_entityScriptingInterface;
|
EntityScriptingInterface ScriptEngine::_entityScriptingInterface;
|
||||||
|
|
||||||
|
46
libraries/script-engine/src/SpatialEvent.cpp
Normal file
46
libraries/script-engine/src/SpatialEvent.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
//
|
||||||
|
// SpatialEvent.cpp
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <RegisteredMetaTypes.h>
|
||||||
|
|
||||||
|
#include "SpatialEvent.h"
|
||||||
|
|
||||||
|
SpatialEvent::SpatialEvent() :
|
||||||
|
locTranslation(0.0f),
|
||||||
|
locRotation(),
|
||||||
|
absTranslation(0.0f),
|
||||||
|
absRotation()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SpatialEvent::SpatialEvent(const SpatialEvent& event) {
|
||||||
|
locTranslation = event.locTranslation;
|
||||||
|
locRotation = event.locRotation;
|
||||||
|
absTranslation = event.absTranslation;
|
||||||
|
absRotation = event.absRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QScriptValue SpatialEvent::toScriptValue(QScriptEngine* engine, const SpatialEvent& event) {
|
||||||
|
QScriptValue obj = engine->newObject();
|
||||||
|
|
||||||
|
obj.setProperty("locTranslation", vec3toScriptValue(engine, event.locTranslation) );
|
||||||
|
obj.setProperty("locRotation", quatToScriptValue(engine, event.locRotation) );
|
||||||
|
obj.setProperty("absTranslation", vec3toScriptValue(engine, event.absTranslation) );
|
||||||
|
obj.setProperty("absRotation", quatToScriptValue(engine, event.absRotation) );
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpatialEvent::fromScriptValue(const QScriptValue& object,SpatialEvent& event) {
|
||||||
|
// nothing for now...
|
||||||
|
}
|
36
libraries/script-engine/src/SpatialEvent.h
Normal file
36
libraries/script-engine/src/SpatialEvent.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
//
|
||||||
|
// SpatialEvent.h
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_SpatialEvent_h
|
||||||
|
#define hifi_SpatialEvent_h
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
|
||||||
|
#include <qscriptengine.h>
|
||||||
|
|
||||||
|
class SpatialEvent {
|
||||||
|
public:
|
||||||
|
SpatialEvent();
|
||||||
|
SpatialEvent(const SpatialEvent& other);
|
||||||
|
|
||||||
|
static QScriptValue toScriptValue(QScriptEngine* engine, const SpatialEvent& event);
|
||||||
|
static void fromScriptValue(const QScriptValue& object, SpatialEvent& event);
|
||||||
|
|
||||||
|
glm::vec3 locTranslation;
|
||||||
|
glm::quat locRotation;
|
||||||
|
glm::vec3 absTranslation;
|
||||||
|
glm::quat absRotation;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(SpatialEvent)
|
||||||
|
|
||||||
|
#endif // hifi_SpatialEvent_h
|
211
libraries/script-engine/src/TouchEvent.cpp
Normal file
211
libraries/script-engine/src/TouchEvent.cpp
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
//
|
||||||
|
// TouchEvent.cpp
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <qscriptengine.h>
|
||||||
|
#include <qscriptvalue.h>
|
||||||
|
#include <QTouchEvent>
|
||||||
|
|
||||||
|
#include <RegisteredMetaTypes.h>
|
||||||
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
|
#include "TouchEvent.h"
|
||||||
|
|
||||||
|
TouchEvent::TouchEvent() :
|
||||||
|
x(0.0f),
|
||||||
|
y(0.0f),
|
||||||
|
isPressed(false),
|
||||||
|
isMoved(false),
|
||||||
|
isStationary(false),
|
||||||
|
isReleased(false),
|
||||||
|
isShifted(false),
|
||||||
|
isControl(false),
|
||||||
|
isMeta(false),
|
||||||
|
isAlt(false),
|
||||||
|
touchPoints(0),
|
||||||
|
points(),
|
||||||
|
radius(0.0f),
|
||||||
|
isPinching(false),
|
||||||
|
isPinchOpening(false),
|
||||||
|
angles(),
|
||||||
|
angle(0.0f),
|
||||||
|
deltaAngle(0.0f),
|
||||||
|
isRotating(false),
|
||||||
|
rotating("none")
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TouchEvent::TouchEvent(const QTouchEvent& event) :
|
||||||
|
// these values are not set by initWithQTouchEvent() because they only apply to comparing to other events
|
||||||
|
isPinching(false),
|
||||||
|
isPinchOpening(false),
|
||||||
|
deltaAngle(0.0f),
|
||||||
|
isRotating(false),
|
||||||
|
rotating("none")
|
||||||
|
{
|
||||||
|
initWithQTouchEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
TouchEvent::TouchEvent(const QTouchEvent& event, const TouchEvent& other) {
|
||||||
|
initWithQTouchEvent(event);
|
||||||
|
calculateMetaAttributes(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the angle (in degrees) between two points (note: 0 degrees is 'east')
|
||||||
|
float angleBetweenPoints(const glm::vec2& a, const glm::vec2& b ) {
|
||||||
|
glm::vec2 length = b - a;
|
||||||
|
float angle = DEGREES_PER_RADIAN * std::atan2(length.y, length.x);
|
||||||
|
if (angle < 0) {
|
||||||
|
angle += 360.0f;
|
||||||
|
};
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchEvent::initWithQTouchEvent(const QTouchEvent& event) {
|
||||||
|
// convert the touch points into an average
|
||||||
|
const QList<QTouchEvent::TouchPoint>& tPoints = event.touchPoints();
|
||||||
|
float touchAvgX = 0.0f;
|
||||||
|
float touchAvgY = 0.0f;
|
||||||
|
touchPoints = tPoints.count();
|
||||||
|
if (touchPoints > 1) {
|
||||||
|
for (int i = 0; i < touchPoints; ++i) {
|
||||||
|
touchAvgX += tPoints[i].pos().x();
|
||||||
|
touchAvgY += tPoints[i].pos().y();
|
||||||
|
|
||||||
|
// add it to our points vector
|
||||||
|
glm::vec2 thisPoint(tPoints[i].pos().x(), tPoints[i].pos().y());
|
||||||
|
points << thisPoint;
|
||||||
|
}
|
||||||
|
touchAvgX /= (float)(touchPoints);
|
||||||
|
touchAvgY /= (float)(touchPoints);
|
||||||
|
} else {
|
||||||
|
// I'm not sure this should ever happen, why would Qt send us a touch event for only one point?
|
||||||
|
// maybe this happens in the case of a multi-touch where all but the last finger is released?
|
||||||
|
touchAvgX = tPoints[0].pos().x();
|
||||||
|
touchAvgY = tPoints[0].pos().y();
|
||||||
|
}
|
||||||
|
x = touchAvgX;
|
||||||
|
y = touchAvgY;
|
||||||
|
|
||||||
|
// after calculating the center point (average touch point), determine the maximum radius
|
||||||
|
// also calculate the rotation angle for each point
|
||||||
|
float maxRadius = 0.0f;
|
||||||
|
glm::vec2 center(x,y);
|
||||||
|
for (int i = 0; i < touchPoints; ++i) {
|
||||||
|
glm::vec2 touchPoint(tPoints[i].pos().x(), tPoints[i].pos().y());
|
||||||
|
float thisRadius = glm::distance(center,touchPoint);
|
||||||
|
if (thisRadius > maxRadius) {
|
||||||
|
maxRadius = thisRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate the angle for this point
|
||||||
|
float thisAngle = angleBetweenPoints(center,touchPoint);
|
||||||
|
angles << thisAngle;
|
||||||
|
}
|
||||||
|
radius = maxRadius;
|
||||||
|
|
||||||
|
// after calculating the angles for each touch point, determine the average angle
|
||||||
|
float totalAngle = 0.0f;
|
||||||
|
for (int i = 0; i < touchPoints; ++i) {
|
||||||
|
totalAngle += angles[i];
|
||||||
|
}
|
||||||
|
angle = totalAngle/(float)touchPoints;
|
||||||
|
|
||||||
|
isPressed = event.touchPointStates().testFlag(Qt::TouchPointPressed);
|
||||||
|
isMoved = event.touchPointStates().testFlag(Qt::TouchPointMoved);
|
||||||
|
isStationary = event.touchPointStates().testFlag(Qt::TouchPointStationary);
|
||||||
|
isReleased = event.touchPointStates().testFlag(Qt::TouchPointReleased);
|
||||||
|
|
||||||
|
// keyboard modifiers
|
||||||
|
isShifted = event.modifiers().testFlag(Qt::ShiftModifier);
|
||||||
|
isMeta = event.modifiers().testFlag(Qt::MetaModifier);
|
||||||
|
isControl = event.modifiers().testFlag(Qt::ControlModifier);
|
||||||
|
isAlt = event.modifiers().testFlag(Qt::AltModifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchEvent::calculateMetaAttributes(const TouchEvent& other) {
|
||||||
|
// calculate comparative event attributes...
|
||||||
|
if (other.radius > radius) {
|
||||||
|
isPinching = true;
|
||||||
|
isPinchOpening = false;
|
||||||
|
} else if (other.radius < radius) {
|
||||||
|
isPinchOpening = true;
|
||||||
|
isPinching = false;
|
||||||
|
} else {
|
||||||
|
isPinching = other.isPinching;
|
||||||
|
isPinchOpening = other.isPinchOpening;
|
||||||
|
}
|
||||||
|
|
||||||
|
// determine if the points are rotating...
|
||||||
|
// note: if the number of touch points change between events, then we don't consider ourselves to be rotating
|
||||||
|
if (touchPoints == other.touchPoints) {
|
||||||
|
deltaAngle = angle - other.angle;
|
||||||
|
if (other.angle < angle) {
|
||||||
|
isRotating = true;
|
||||||
|
rotating = "clockwise";
|
||||||
|
} else if (other.angle > angle) {
|
||||||
|
isRotating = true;
|
||||||
|
rotating = "counterClockwise";
|
||||||
|
} else {
|
||||||
|
isRotating = false;
|
||||||
|
rotating = "none";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
deltaAngle = 0.0f;
|
||||||
|
isRotating = false;
|
||||||
|
rotating = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue TouchEvent::toScriptValue(QScriptEngine* engine, const TouchEvent& event) {
|
||||||
|
QScriptValue obj = engine->newObject();
|
||||||
|
obj.setProperty("x", event.x);
|
||||||
|
obj.setProperty("y", event.y);
|
||||||
|
obj.setProperty("isPressed", event.isPressed);
|
||||||
|
obj.setProperty("isMoved", event.isMoved);
|
||||||
|
obj.setProperty("isStationary", event.isStationary);
|
||||||
|
obj.setProperty("isReleased", event.isReleased);
|
||||||
|
obj.setProperty("isShifted", event.isShifted);
|
||||||
|
obj.setProperty("isMeta", event.isMeta);
|
||||||
|
obj.setProperty("isControl", event.isControl);
|
||||||
|
obj.setProperty("isAlt", event.isAlt);
|
||||||
|
obj.setProperty("touchPoints", event.touchPoints);
|
||||||
|
|
||||||
|
QScriptValue pointsObj = engine->newArray();
|
||||||
|
int index = 0;
|
||||||
|
foreach (glm::vec2 point, event.points) {
|
||||||
|
QScriptValue thisPoint = vec2toScriptValue(engine, point);
|
||||||
|
pointsObj.setProperty(index, thisPoint);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
obj.setProperty("points", pointsObj);
|
||||||
|
obj.setProperty("radius", event.radius);
|
||||||
|
obj.setProperty("isPinching", event.isPinching);
|
||||||
|
obj.setProperty("isPinchOpening", event.isPinchOpening);
|
||||||
|
|
||||||
|
obj.setProperty("angle", event.angle);
|
||||||
|
obj.setProperty("deltaAngle", event.deltaAngle);
|
||||||
|
QScriptValue anglesObj = engine->newArray();
|
||||||
|
index = 0;
|
||||||
|
foreach (float angle, event.angles) {
|
||||||
|
anglesObj.setProperty(index, angle);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
obj.setProperty("angles", anglesObj);
|
||||||
|
|
||||||
|
obj.setProperty("isRotating", event.isRotating);
|
||||||
|
obj.setProperty("rotating", event.rotating);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchEvent::fromScriptValue(const QScriptValue& object, TouchEvent& event) {
|
||||||
|
// nothing for now...
|
||||||
|
}
|
56
libraries/script-engine/src/TouchEvent.h
Normal file
56
libraries/script-engine/src/TouchEvent.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
//
|
||||||
|
// TouchEvent.h
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_TouchEvent_h
|
||||||
|
#define hifi_TouchEvent_h
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
class TouchEvent {
|
||||||
|
public:
|
||||||
|
TouchEvent();
|
||||||
|
TouchEvent(const QTouchEvent& event);
|
||||||
|
TouchEvent(const QTouchEvent& event, const TouchEvent& other);
|
||||||
|
|
||||||
|
static QScriptValue toScriptValue(QScriptEngine* engine, const TouchEvent& event);
|
||||||
|
static void fromScriptValue(const QScriptValue& object, TouchEvent& event);
|
||||||
|
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
bool isPressed;
|
||||||
|
bool isMoved;
|
||||||
|
bool isStationary;
|
||||||
|
bool isReleased;
|
||||||
|
bool isShifted;
|
||||||
|
bool isControl;
|
||||||
|
bool isMeta;
|
||||||
|
bool isAlt;
|
||||||
|
int touchPoints;
|
||||||
|
QVector<glm::vec2> points;
|
||||||
|
float radius;
|
||||||
|
bool isPinching;
|
||||||
|
bool isPinchOpening;
|
||||||
|
|
||||||
|
// angles are in degrees
|
||||||
|
QVector<float> angles; // angle from center to each point
|
||||||
|
float angle; // the average of the angles
|
||||||
|
float deltaAngle; // the change in average angle from last event
|
||||||
|
bool isRotating;
|
||||||
|
QString rotating;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initWithQTouchEvent(const QTouchEvent& event);
|
||||||
|
void calculateMetaAttributes(const TouchEvent& other);
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(TouchEvent)
|
||||||
|
|
||||||
|
#endif // hifi_TouchEvent_h
|
75
libraries/script-engine/src/WheelEvent.cpp
Normal file
75
libraries/script-engine/src/WheelEvent.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
//
|
||||||
|
// WheelEvent.cpp
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <qscriptengine.h>
|
||||||
|
#include <qscriptvalue.h>
|
||||||
|
|
||||||
|
#include "WheelEvent.h"
|
||||||
|
|
||||||
|
WheelEvent::WheelEvent() :
|
||||||
|
x(0.0f),
|
||||||
|
y(0.0f),
|
||||||
|
delta(0.0f),
|
||||||
|
orientation("UNKNOwN"),
|
||||||
|
isLeftButton(false),
|
||||||
|
isRightButton(false),
|
||||||
|
isMiddleButton(false),
|
||||||
|
isShifted(false),
|
||||||
|
isControl(false),
|
||||||
|
isMeta(false),
|
||||||
|
isAlt(false)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
WheelEvent::WheelEvent(const QWheelEvent& event) {
|
||||||
|
x = event.x();
|
||||||
|
y = event.y();
|
||||||
|
|
||||||
|
delta = event.delta();
|
||||||
|
if (event.orientation() == Qt::Horizontal) {
|
||||||
|
orientation = "HORIZONTAL";
|
||||||
|
} else {
|
||||||
|
orientation = "VERTICAL";
|
||||||
|
}
|
||||||
|
|
||||||
|
// button pressed state
|
||||||
|
isLeftButton = (event.buttons().testFlag(Qt::LeftButton));
|
||||||
|
isRightButton = (event.buttons().testFlag(Qt::RightButton));
|
||||||
|
isMiddleButton = (event.buttons().testFlag(Qt::MiddleButton));
|
||||||
|
|
||||||
|
// keyboard modifiers
|
||||||
|
isShifted = event.modifiers().testFlag(Qt::ShiftModifier);
|
||||||
|
isMeta = event.modifiers().testFlag(Qt::MetaModifier);
|
||||||
|
isControl = event.modifiers().testFlag(Qt::ControlModifier);
|
||||||
|
isAlt = event.modifiers().testFlag(Qt::AltModifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QScriptValue WheelEvent::toScriptValue(QScriptEngine* engine, const WheelEvent& event) {
|
||||||
|
QScriptValue obj = engine->newObject();
|
||||||
|
obj.setProperty("x", event.x);
|
||||||
|
obj.setProperty("y", event.y);
|
||||||
|
obj.setProperty("delta", event.delta);
|
||||||
|
obj.setProperty("orientation", event.orientation);
|
||||||
|
obj.setProperty("isLeftButton", event.isLeftButton);
|
||||||
|
obj.setProperty("isRightButton", event.isRightButton);
|
||||||
|
obj.setProperty("isMiddleButton", event.isMiddleButton);
|
||||||
|
obj.setProperty("isShifted", event.isShifted);
|
||||||
|
obj.setProperty("isMeta", event.isMeta);
|
||||||
|
obj.setProperty("isControl", event.isControl);
|
||||||
|
obj.setProperty("isAlt", event.isAlt);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WheelEvent::fromScriptValue(const QScriptValue& object, WheelEvent& event) {
|
||||||
|
// nothing for now...
|
||||||
|
}
|
40
libraries/script-engine/src/WheelEvent.h
Normal file
40
libraries/script-engine/src/WheelEvent.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
//
|
||||||
|
// WheelEvent.h
|
||||||
|
// script-engine/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2014-10-27.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_WheelEvent_h
|
||||||
|
#define hifi_WheelEvent_h
|
||||||
|
|
||||||
|
#include <QWheelEvent>
|
||||||
|
|
||||||
|
class WheelEvent {
|
||||||
|
public:
|
||||||
|
WheelEvent();
|
||||||
|
WheelEvent(const QWheelEvent& event);
|
||||||
|
|
||||||
|
static QScriptValue toScriptValue(QScriptEngine* engine, const WheelEvent& event);
|
||||||
|
static void fromScriptValue(const QScriptValue& object, WheelEvent& event);
|
||||||
|
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int delta;
|
||||||
|
QString orientation;
|
||||||
|
bool isLeftButton;
|
||||||
|
bool isRightButton;
|
||||||
|
bool isMiddleButton;
|
||||||
|
bool isShifted;
|
||||||
|
bool isControl;
|
||||||
|
bool isMeta;
|
||||||
|
bool isAlt;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(WheelEvent)
|
||||||
|
|
||||||
|
#endif // hifi_WheelEvent_h
|
Loading…
x
Reference in New Issue
Block a user