History

Merging old and new controller interfaces

Brad Davis committed 11 years ago

Commit 0063f9a1 parent 619fce043 files · +1088 −1103Browse files

Showing the changes to interface/src/scripting/ControllerScriptingInterface.cpp (1 of 43 files). Show all

Unified · Split

interface/src/scripting/ControllerScriptingInterface.cpp+52−92
@@ -9,21 +9,19 @@ · 8 unmodified lines
99 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
1010 //
1111
12+#include "ControllerScriptingInterface.h"
13+
1214 #include <avatar/AvatarManager.h>
1315 #include <avatar/MyAvatar.h>
1416 #include <HandData.h>
1517 #include <HFBackEvent.h>
1618
17−#include <controllers/NewControllerScriptingInterface.h>
18−
1919 #include "Application.h"
2020 #include "devices/MotionTracker.h"
21−#include "ControllerScriptingInterface.h"
2221
2322 // TODO: this needs to be removed, as well as any related controller-specific information
2423 #include <input-plugins/SixenseManager.h>
2524
26−
2725 ControllerScriptingInterface::ControllerScriptingInterface() :
2826 _mouseCaptured(false),
2927 _touchCaptured(false),
@@ -34,7 +32,6 @@ ControllerScriptingInterface::ControllerScriptingInterface() : · 4 unmodified lines
3432 }
3533
3634 ControllerScriptingInterface::~ControllerScriptingInterface() {
37− delete _newControllerScriptingInterface;
3835 }
3936
4037
@@ -126,13 +123,6 @@ void ControllerScriptingInterface::registerControllerTypes(ScriptEngine* engine) · 85 unmodified lines
126123 qScriptRegisterMetaType(engine, inputChannelToScriptValue, inputChannelFromScriptValue);
127124 qScriptRegisterMetaType(engine, inputToScriptValue, inputFromScriptValue);
128125 qScriptRegisterMetaType(engine, inputPairToScriptValue, inputPairFromScriptValue);
129−
130− wireUpControllers(engine);
131−
132− // hack in the new controller scripting interface...
133− _newControllerScriptingInterface = new controller::NewControllerScriptingInterface();
134− engine->registerGlobalObject("NewControllers", _newControllerScriptingInterface);
135−
136126 }
137127
138128 void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) {
@@ -192,6 +182,7 @@ const PalmData* ControllerScriptingInterface::getActivePalm(int palmIndex) const · 53 unmodified lines
192182 return NULL;
193183 }
194184
185+/*
195186 bool ControllerScriptingInterface::isPrimaryButtonPressed() const {
196187 const PalmData* primaryPalm = getPrimaryPalm();
197188 if (primaryPalm) {
@@ -345,6 +336,7 @@ glm::vec3 ControllerScriptingInterface::getSpatialControlNormal(int controlIndex · 147 unmodified lines
345336 }
346337 return glm::vec3(0); // bad index
347338 }
339+*/
348340
349341 bool ControllerScriptingInterface::isKeyCaptured(QKeyEvent* event) const {
350342 return isKeyCaptured(KeyEvent(*event));
@@ -395,96 +387,49 @@ glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { · 44 unmodified lines
395387 return qApp->getUiSize();
396388 }
397389
398−QString ControllerScriptingInterface::sanatizeName(const QString& name) {
399− QString cleanName { name };
400− cleanName.remove(QRegularExpression{"[\\(\\)\\.\\s]"});
401− return cleanName;
402−}
403−
404−void ControllerScriptingInterface::wireUpControllers(ScriptEngine* engine) {
405−
406− // Controller.Standard.*
407− auto standardDevice = DependencyManager::get<UserInputMapper>()->getStandardDevice();
408− if (standardDevice) {
409− auto deviceName = sanatizeName(standardDevice->getName());
410− auto deviceInputs = standardDevice->getAvailabeInputs();
411− for (const auto& inputMapping : deviceInputs) {
412− auto input = inputMapping.first;
413− auto inputName = sanatizeName(inputMapping.second);
414− QString deviceInputName{ "Controller." + deviceName + "." + inputName };
415− engine->registerValue(deviceInputName, input.getID());
416− }
417− }
418−
419− // Controller.Hardware.*
420− auto devices = DependencyManager::get<UserInputMapper>()->getDevices();
421− for(const auto& deviceMapping : devices) {
422− auto device = deviceMapping.second.get();
423− auto deviceName = sanatizeName(device->getName());
424− auto deviceInputs = device->getAvailabeInputs();
425− for (const auto& inputMapping : deviceInputs) {
426− auto input = inputMapping.first;
427− auto inputName = sanatizeName(inputMapping.second);
428− QString deviceInputName { "Controller.Hardware." + deviceName + "." + inputName };
429− engine->registerValue(deviceInputName, input.getID());
430− }
431− }
432−
433− // Controller.Actions.*
434− auto actionNames = DependencyManager::get<UserInputMapper>()->getActionNames();
435− int actionNumber = 0;
436− for (const auto& actionName : actionNames) {
437− QString safeActionName { "Controller.Actions." + sanatizeName(actionName) };
438− engine->registerValue(safeActionName, actionNumber);
439− actionNumber++;
440− }
441−}
442−
443−AbstractInputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) {
390+controller::InputController::Pointer ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) {
444391 // This is where we retreive the Device Tracker category and then the sub tracker within it
445− //TODO C++11 auto icIt = _inputControllers.find(0);
446− InputControllerMap::iterator icIt = _inputControllers.find(0);
447−
392+ auto icIt = _inputControllers.find(0);
448393 if (icIt != _inputControllers.end()) {
449394 return (*icIt).second;
450− } else {
395+ }
451396
452− // Look for device
453− DeviceTracker::ID deviceID = DeviceTracker::getDeviceID(deviceName.toStdString());
454− if (deviceID < 0) {
455− deviceID = 0;
456− }
457− // TODO in this current implementation, we just pick the device assuming there is one (normally the Leapmotion)
458− // in the near future we need to change that to a real mapping between the devices and the deviceName
459− // ALso we need to expand the spec so we can fall back on the "default" controller per categories
460−
461− if (deviceID >= 0) {
462− // TODO here again the assumption it's the LeapMotion and so it's a MOtionTracker, this would need to be changed to support different types of devices
463− MotionTracker* motionTracker = dynamic_cast< MotionTracker* > (DeviceTracker::getDevice(deviceID));
464− if (motionTracker) {
465− MotionTracker::Index trackerID = motionTracker->findJointIndex(tracker.toStdString());
466− if (trackerID >= 0) {
467− AbstractInputController* inputController = new InputController(deviceID, trackerID, this);
468−
469− _inputControllers.insert(InputControllerMap::value_type(inputController->getKey(), inputController));
470−
471− return inputController;
472− }
397+
398+ // Look for device
399+ DeviceTracker::ID deviceID = DeviceTracker::getDeviceID(deviceName.toStdString());
400+ if (deviceID < 0) {
401+ deviceID = 0;
402+ }
403+ // TODO in this current implementation, we just pick the device assuming there is one (normally the Leapmotion)
404+ // in the near future we need to change that to a real mapping between the devices and the deviceName
405+ // ALso we need to expand the spec so we can fall back on the "default" controller per categories
406+
407+ if (deviceID >= 0) {
408+ // TODO here again the assumption it's the LeapMotion and so it's a MOtionTracker, this would need to be changed to support different types of devices
409+ MotionTracker* motionTracker = dynamic_cast< MotionTracker* > (DeviceTracker::getDevice(deviceID));
410+ if (motionTracker) {
411+ MotionTracker::Index trackerID = motionTracker->findJointIndex(tracker.toStdString());
412+ if (trackerID >= 0) {
413+ controller::InputController::Pointer inputController = std::make_shared<InputController>(deviceID, trackerID, this);
414+ controller::InputController::Key key = inputController->getKey();
415+ _inputControllers.insert(InputControllerMap::value_type(inputController->getKey(), inputController));
416+ return inputController;
473417 }
474418 }
475−
476− return 0;
477419 }
420+
421+ return controller::InputController::Pointer();
478422 }
479423
480−void ControllerScriptingInterface::releaseInputController(AbstractInputController* input) {
424+void ControllerScriptingInterface::releaseInputController(controller::InputController::Pointer input) {
481425 _inputControllers.erase(input->getKey());
482426 }
483427
484−void ControllerScriptingInterface::updateInputControllers() {
485− //TODO C++11 for (auto it = _inputControllers.begin(); it != _inputControllers.end(); it++) {
486− for (InputControllerMap::iterator it = _inputControllers.begin(); it != _inputControllers.end(); it++) {
487− (*it).second->update();
428+void ControllerScriptingInterface::update() {
429+ controller::ScriptingInterface::update();
430+
431+ for (auto entry : _inputControllers) {
432+ entry.second->update();
488433 }
489434 }
490435
@@ -545,7 +490,6 @@ QVector<QString> ControllerScriptingInterface::getActionNames() const { · 54 unmodified lines
545490 }
546491
547492 InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) :
548− AbstractInputController(),
549493 _deviceTrackerId(deviceTrackerId),
550494 _subTrackerId(subTrackerId),
551495 _isActive(false)
@@ -568,7 +512,7 @@ void InputController::update() { · 16 unmodified lines
568512 joint->getLocFrame().getRotation(_eventCache.locRotation);
569513
570514 _isActive = true;
571− emit spatialEvent(_eventCache);
515+ //emit spatialEvent(_eventCache);
572516 }
573517 }
574518 }
@@ -580,3 +524,19 @@ const unsigned int INPUTCONTROLLER_KEY_DEVICE_MASK = 16; · 5 unmodified lines
580524 InputController::Key InputController::getKey() const {
581525 return (((_deviceTrackerId & INPUTCONTROLLER_KEY_DEVICE_MASK) << INPUTCONTROLLER_KEY_DEVICE_OFFSET) | _subTrackerId);
582526 }
527+
528+
529+void ControllerScriptingInterface::emitKeyPressEvent(QKeyEvent* event) { emit keyPressEvent(KeyEvent(*event)); }
530+void ControllerScriptingInterface::emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); }
531+
532+void ControllerScriptingInterface::emitMouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { emit mouseMoveEvent(MouseEvent(*event, deviceID)); }
533+void ControllerScriptingInterface::emitMousePressEvent(QMouseEvent* event, unsigned int deviceID) { emit mousePressEvent(MouseEvent(*event, deviceID)); }
534+void ControllerScriptingInterface::emitMouseDoublePressEvent(QMouseEvent* event, unsigned int deviceID) { emit mouseDoublePressEvent(MouseEvent(*event, deviceID)); }
535+void ControllerScriptingInterface::emitMouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { emit mouseReleaseEvent(MouseEvent(*event, deviceID)); }
536+
537+void ControllerScriptingInterface::emitTouchBeginEvent(const TouchEvent& event) { emit touchBeginEvent(event); }
538+void ControllerScriptingInterface::emitTouchEndEvent(const TouchEvent& event) { emit touchEndEvent(event); }
539+void ControllerScriptingInterface::emitTouchUpdateEvent(const TouchEvent& event) { emit touchUpdateEvent(event); }
540+
541+void ControllerScriptingInterface::emitWheelEvent(QWheelEvent* event) { emit wheelEvent(*event); }
542+