mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:37:48 +02:00
hacking on controller events
This commit is contained in:
parent
5addc35cd8
commit
7882d50c5f
2 changed files with 148 additions and 0 deletions
86
libraries/script-engine/src/EventTypes.cpp
Normal file
86
libraries/script-engine/src/EventTypes.cpp
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
//
|
||||||
|
// EventTypes.cpp
|
||||||
|
// hifi
|
||||||
|
//
|
||||||
|
// Created by Brad Hefta-Gaub on 1/28/14.
|
||||||
|
// Copyright (c) 2014 HighFidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Used to register meta-types with Qt for very various event types so that they can be exposed to our
|
||||||
|
// scripting engine
|
||||||
|
|
||||||
|
#include "EventTypes.h"
|
||||||
|
|
||||||
|
void registerEventTypes(QScriptEngine* engine) {
|
||||||
|
qScriptRegisterMetaType(engine, keyEventToScriptValue, keyEventFromScriptValue);
|
||||||
|
qScriptRegisterMetaType(engine, mouseEventToScriptValue, mouseEventFromScriptValue);
|
||||||
|
qScriptRegisterMetaType(engine, touchEventToScriptValue, touchEventFromScriptValue);
|
||||||
|
qScriptRegisterMetaType(engine, wheelEventToScriptValue, wheelEventFromScriptValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue keyEventToScriptValue(QScriptEngine* engine, const KeyEvent& event) {
|
||||||
|
QScriptValue obj = engine->newObject();
|
||||||
|
/*
|
||||||
|
obj.setProperty("key", event.key());
|
||||||
|
obj.setProperty("isAutoRepeat", event.isAutoRepeat());
|
||||||
|
|
||||||
|
bool isShifted = event.modifiers().testFlag(Qt::ShiftModifier);
|
||||||
|
bool isMeta = event.modifiers().testFlag(Qt::ControlModifier);
|
||||||
|
|
||||||
|
obj.setProperty("isShifted", isShifted);
|
||||||
|
obj.setProperty("isMeta", isMeta);
|
||||||
|
*/
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void keyEventFromScriptValue(const QScriptValue &object, KeyEvent& event) {
|
||||||
|
// nothing for now...
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue mouseEventToScriptValue(QScriptEngine* engine, const MouseEvent& event) {
|
||||||
|
QScriptValue obj = engine->newObject();
|
||||||
|
obj.setProperty("x", event.x());
|
||||||
|
obj.setProperty("y", event.y());
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mouseEventFromScriptValue(const QScriptValue &object, MouseEvent& event) {
|
||||||
|
// nothing for now...
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& event) {
|
||||||
|
QScriptValue obj = engine->newObject();
|
||||||
|
|
||||||
|
// convert the touch points into an average
|
||||||
|
const QList<QTouchEvent::TouchPoint>& tPoints = event.touchPoints();
|
||||||
|
float touchAvgX = 0.0f;
|
||||||
|
float touchAvgY = 0.0f;
|
||||||
|
int numTouches = tPoints.count();
|
||||||
|
if (numTouches > 1) {
|
||||||
|
for (int i = 0; i < numTouches; ++i) {
|
||||||
|
touchAvgX += tPoints[i].pos().x();
|
||||||
|
touchAvgY += tPoints[i].pos().y();
|
||||||
|
}
|
||||||
|
touchAvgX /= (float)(numTouches);
|
||||||
|
touchAvgY /= (float)(numTouches);
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.setProperty("averageX", touchAvgX);
|
||||||
|
obj.setProperty("averageY", touchAvgY);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void touchEventFromScriptValue(const QScriptValue &object, TouchEvent& event) {
|
||||||
|
// nothing for now...
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue wheelEventToScriptValue(QScriptEngine* engine, const WheelEvent& event) {
|
||||||
|
QScriptValue obj = engine->newObject();
|
||||||
|
obj.setProperty("x", event.x());
|
||||||
|
obj.setProperty("y", event.y());
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wheelEventFromScriptValue(const QScriptValue &object, WheelEvent& event) {
|
||||||
|
// nothing for now...
|
||||||
|
}
|
62
libraries/script-engine/src/EventTypes.h
Normal file
62
libraries/script-engine/src/EventTypes.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
//
|
||||||
|
// EventTypes.h
|
||||||
|
// hifi
|
||||||
|
//
|
||||||
|
// Created by Brad Hefta-Gaub on 1/28/14.
|
||||||
|
// Copyright (c) 2014 HighFidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __hifi_EventTypes_h__
|
||||||
|
#define __hifi_EventTypes_h__
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
#include <QtScript/QScriptEngine>
|
||||||
|
|
||||||
|
#include <QKeyEvent>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QTouchEvent>
|
||||||
|
#include <QWheelEvent>
|
||||||
|
|
||||||
|
class KeyEvent {
|
||||||
|
public:
|
||||||
|
KeyEvent() { };
|
||||||
|
KeyEvent(QKeyEvent* other) { };
|
||||||
|
};
|
||||||
|
|
||||||
|
class MouseEvent {
|
||||||
|
public:
|
||||||
|
MouseEvent() { };
|
||||||
|
};
|
||||||
|
|
||||||
|
class TouchEvent {
|
||||||
|
public:
|
||||||
|
TouchEvent() { };
|
||||||
|
};
|
||||||
|
|
||||||
|
class WheelEvent {
|
||||||
|
public:
|
||||||
|
WheelEvent() { };
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(KeyEvent)
|
||||||
|
Q_DECLARE_METATYPE(MouseEvent)
|
||||||
|
Q_DECLARE_METATYPE(TouchEvent)
|
||||||
|
Q_DECLARE_METATYPE(WheelEvent)
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
#endif // __hifi_EventTypes_h__
|
Loading…
Reference in a new issue