Showing the changes to interface/src/Application.cpp (1 of 20 files). Show all
Unified · Split
| @@ -64,6 +64,7 @@ · 63 unmodified lines | |||
| 64 | #include <DeferredLightingEffect.h> | 64 | #include <DeferredLightingEffect.h> |
| 65 | #include <DependencyManager.h> | 65 | #include <DependencyManager.h> |
| 66 | #include <display-plugins/DisplayPlugin.h> | 66 | #include <display-plugins/DisplayPlugin.h> |
| 67 | |||
| 67 | #include <EntityScriptingInterface.h> | 68 | #include <EntityScriptingInterface.h> |
| 68 | #include <ErrorDialog.h> | 69 | #include <ErrorDialog.h> |
| 69 | #include <GlowEffect.h> | 70 | #include <GlowEffect.h> |
| @@ -74,6 +75,9 @@ · 4 unmodified lines | |||
| 74 | #include <HFActionEvent.h> | 75 | #include <HFActionEvent.h> |
| 75 | #include <HFBackEvent.h> | 76 | #include <HFBackEvent.h> |
| 76 | #include <InfoView.h> | 77 | #include <InfoView.h> |
| 78 | #include <input-plugins/InputPlugin.h> | ||
| 79 | #include <input-plugins/Joystick.h> // this should probably be removed | ||
| 80 | #include <input-plugins/SixenseManager.h> // this definitely should be removed | ||
| 77 | #include <LogHandler.h> | 81 | #include <LogHandler.h> |
| 78 | #include <MainWindow.h> | 82 | #include <MainWindow.h> |
| 79 | #include <MessageDialog.h> | 83 | #include <MessageDialog.h> |
| @@ -123,9 +127,6 @@ · 43 unmodified lines | |||
| 123 | #include "devices/Leapmotion.h" | 127 | #include "devices/Leapmotion.h" |
| 124 | #include "devices/RealSense.h" | 128 | #include "devices/RealSense.h" |
| 125 | #include "devices/MIDIManager.h" | 129 | #include "devices/MIDIManager.h" |
| 126 | #include <input-plugins/SDL2Manager.h> | ||
| 127 | #include <input-plugins/SixenseManager.h> | ||
| 128 | #include <input-plugins/ViveControllerManager.h> | ||
| 129 | #include "RenderDeferredTask.h" | 130 | #include "RenderDeferredTask.h" |
| 130 | #include "scripting/AccountScriptingInterface.h" | 131 | #include "scripting/AccountScriptingInterface.h" |
| 131 | #include "scripting/AudioDeviceScriptingInterface.h" | 132 | #include "scripting/AudioDeviceScriptingInterface.h" |
| @@ -621,9 +622,19 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 489 unmodified lines | |||
| 621 | auto userInputMapper = DependencyManager::get<UserInputMapper>(); | 622 | auto userInputMapper = DependencyManager::get<UserInputMapper>(); |
| 622 | connect(userInputMapper.data(), &UserInputMapper::actionEvent, &_controllerScriptingInterface, &AbstractControllerScriptingInterface::actionEvent); | 623 | connect(userInputMapper.data(), &UserInputMapper::actionEvent, &_controllerScriptingInterface, &AbstractControllerScriptingInterface::actionEvent); |
| 623 | 624 | ||
| 625 | auto inputPlugins = getInputPlugins(); | ||
| 626 | foreach(auto inputPlugin, inputPlugins) { | ||
| 627 | QString name = inputPlugin->getName(); | ||
| 628 | if (name == KeyboardMouseDevice::NAME) { | ||
| 629 | _keyboardMouseDevice = static_cast<KeyboardMouseDevice*>(inputPlugin.data()); // TODO: this seems super hacky | ||
| 630 | } | ||
| 631 | } | ||
| 632 | |||
| 633 | //updateInputModes(); // TODO: shouldn't have to call this explicitly | ||
| 634 | |||
| 624 | // Setup the keyboardMouseDevice and the user input mapper with the default bindings | 635 | // Setup the keyboardMouseDevice and the user input mapper with the default bindings |
| 625 | _keyboardMouseDevice.registerToUserInputMapper(*userInputMapper); | 636 | _keyboardMouseDevice->registerToUserInputMapper(*userInputMapper); |
| 626 | _keyboardMouseDevice.assignDefaultInputMapping(*userInputMapper); | 637 | _keyboardMouseDevice->assignDefaultInputMapping(*userInputMapper); |
| 627 | 638 | ||
| 628 | // check first run... | 639 | // check first run... |
| 629 | if (_firstRun.get()) { | 640 | if (_firstRun.get()) { |
| @@ -676,11 +687,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 46 unmodified lines | |||
| 676 | connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled); | 687 | connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled); |
| 677 | #endif | 688 | #endif |
| 678 | 689 | ||
| 679 | if (ViveControllerManager::getInstance().isSupported()) { | ||
| 680 | ViveControllerManager::getInstance().init(); | ||
| 681 | ViveControllerManager::getInstance().activate(NULL); | ||
| 682 | } | ||
| 683 | |||
| 684 | _oldHandMouseX[0] = -1; | 690 | _oldHandMouseX[0] = -1; |
| 685 | _oldHandMouseY[0] = -1; | 691 | _oldHandMouseY[0] = -1; |
| 686 | _oldHandMouseX[1] = -1; | 692 | _oldHandMouseX[1] = -1; |
| @@ -771,6 +777,15 @@ Application::~Application() { · 84 unmodified lines | |||
| 771 | 777 | ||
| 772 | getActiveDisplayPlugin()->deactivate(); | 778 | getActiveDisplayPlugin()->deactivate(); |
| 773 | 779 | ||
| 780 | auto inputPlugins = getInputPlugins(); | ||
| 781 | foreach(auto inputPlugin, inputPlugins) { | ||
| 782 | QString name = inputPlugin->getName(); | ||
| 783 | QAction* action = Menu::getInstance()->getActionForOption(name); | ||
| 784 | if (action->isChecked()) { | ||
| 785 | inputPlugin->deactivate(); | ||
| 786 | } | ||
| 787 | } | ||
| 788 | |||
| 774 | // remove avatars from physics engine | 789 | // remove avatars from physics engine |
| 775 | DependencyManager::get<AvatarManager>()->clearOtherAvatars(); | 790 | DependencyManager::get<AvatarManager>()->clearOtherAvatars(); |
| 776 | _physicsEngine.deleteObjects(DependencyManager::get<AvatarManager>()->getObjectsToDelete()); | 791 | _physicsEngine.deleteObjects(DependencyManager::get<AvatarManager>()->getObjectsToDelete()); |
| @@ -1344,7 +1359,9 @@ void Application::keyPressEvent(QKeyEvent* event) { · 567 unmodified lines | |||
| 1344 | } | 1359 | } |
| 1345 | 1360 | ||
| 1346 | if (hasFocus()) { | 1361 | if (hasFocus()) { |
| 1347 | _keyboardMouseDevice.keyPressEvent(event); | 1362 | if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) { |
| 1363 | _keyboardMouseDevice->keyPressEvent(event); | ||
| 1364 | } | ||
| 1348 | 1365 | ||
| 1349 | bool isShifted = event->modifiers().testFlag(Qt::ShiftModifier); | 1366 | bool isShifted = event->modifiers().testFlag(Qt::ShiftModifier); |
| 1350 | bool isMeta = event->modifiers().testFlag(Qt::ControlModifier); | 1367 | bool isMeta = event->modifiers().testFlag(Qt::ControlModifier); |
| @@ -1614,7 +1631,9 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 263 unmodified lines | |||
| 1614 | return; | 1631 | return; |
| 1615 | } | 1632 | } |
| 1616 | 1633 | ||
| 1617 | _keyboardMouseDevice.keyReleaseEvent(event); | 1634 | if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) { |
| 1635 | _keyboardMouseDevice->keyReleaseEvent(event); | ||
| 1636 | } | ||
| 1618 | 1637 | ||
| 1619 | switch (event->key()) { | 1638 | switch (event->key()) { |
| 1620 | case Qt::Key_Space: { | 1639 | case Qt::Key_Space: { |
| @@ -1641,10 +1660,14 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 20 unmodified lines | |||
| 1641 | } | 1660 | } |
| 1642 | 1661 | ||
| 1643 | void Application::focusOutEvent(QFocusEvent* event) { | 1662 | void Application::focusOutEvent(QFocusEvent* event) { |
| 1644 | _keyboardMouseDevice.pluginFocusOutEvent(); | 1663 | auto inputPlugins = getInputPlugins(); |
| 1645 | SixenseManager::getInstance().pluginFocusOutEvent(); | 1664 | foreach(auto inputPlugin, inputPlugins) { |
| 1646 | SDL2Manager::getInstance()->pluginFocusOutEvent(); | 1665 | QString name = inputPlugin->getName(); |
| 1647 | ViveControllerManager::getInstance().pluginFocusOutEvent(); | 1666 | QAction* action = Menu::getInstance()->getActionForOption(name); |
| 1667 | if (action->isChecked()) { | ||
| 1668 | inputPlugin->pluginFocusOutEvent(); | ||
| 1669 | } | ||
| 1670 | } | ||
| 1648 | 1671 | ||
| 1649 | // synthesize events for keys currently pressed, since we may not get their release events | 1672 | // synthesize events for keys currently pressed, since we may not get their release events |
| 1650 | foreach (int key, _keysPressed) { | 1673 | foreach (int key, _keysPressed) { |
| @@ -1687,7 +1710,9 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { · 36 unmodified lines | |||
| 1687 | return; | 1710 | return; |
| 1688 | } | 1711 | } |
| 1689 | 1712 | ||
| 1690 | _keyboardMouseDevice.mouseMoveEvent(event, deviceID); | 1713 | if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) { |
| 1714 | _keyboardMouseDevice->mouseMoveEvent(event, deviceID); | ||
| 1715 | } | ||
| 1691 | 1716 | ||
| 1692 | } | 1717 | } |
| 1693 | 1718 | ||
| @@ -1708,7 +1733,9 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { · 14 unmodified lines | |||
| 1708 | 1733 | ||
| 1709 | 1734 | ||
| 1710 | if (hasFocus()) { | 1735 | if (hasFocus()) { |
| 1711 | _keyboardMouseDevice.mousePressEvent(event); | 1736 | if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) { |
| 1737 | _keyboardMouseDevice->mousePressEvent(event); | ||
| 1738 | } | ||
| 1712 | 1739 | ||
| 1713 | if (event->button() == Qt::LeftButton) { | 1740 | if (event->button() == Qt::LeftButton) { |
| 1714 | _mouseDragStarted = getTrueMouse(); | 1741 | _mouseDragStarted = getTrueMouse(); |
| @@ -1748,7 +1775,9 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { · 33 unmodified lines | |||
| 1748 | } | 1775 | } |
| 1749 | 1776 | ||
| 1750 | if (hasFocus()) { | 1777 | if (hasFocus()) { |
| 1751 | _keyboardMouseDevice.mouseReleaseEvent(event); | 1778 | if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) { |
| 1779 | _keyboardMouseDevice->mouseReleaseEvent(event); | ||
| 1780 | } | ||
| 1752 | 1781 | ||
| 1753 | if (event->button() == Qt::LeftButton) { | 1782 | if (event->button() == Qt::LeftButton) { |
| 1754 | _mousePressed = false; | 1783 | _mousePressed = false; |
| @@ -1775,7 +1804,9 @@ void Application::touchUpdateEvent(QTouchEvent* event) { · 20 unmodified lines | |||
| 1775 | return; | 1804 | return; |
| 1776 | } | 1805 | } |
| 1777 | 1806 | ||
| 1778 | _keyboardMouseDevice.touchUpdateEvent(event); | 1807 | if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) { |
| 1808 | _keyboardMouseDevice->touchUpdateEvent(event); | ||
| 1809 | } | ||
| 1779 | 1810 | ||
| 1780 | bool validTouch = false; | 1811 | bool validTouch = false; |
| 1781 | if (hasFocus()) { | 1812 | if (hasFocus()) { |
| @@ -1809,7 +1840,9 @@ void Application::touchBeginEvent(QTouchEvent* event) { · 27 unmodified lines | |||
| 1809 | return; | 1840 | return; |
| 1810 | } | 1841 | } |
| 1811 | 1842 | ||
| 1812 | _keyboardMouseDevice.touchBeginEvent(event); | 1843 | if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) { |
| 1844 | _keyboardMouseDevice->touchBeginEvent(event); | ||
| 1845 | } | ||
| 1813 | 1846 | ||
| 1814 | } | 1847 | } |
| 1815 | 1848 | ||
| @@ -1824,7 +1857,9 @@ void Application::touchEndEvent(QTouchEvent* event) { · 8 unmodified lines | |||
| 1824 | return; | 1857 | return; |
| 1825 | } | 1858 | } |
| 1826 | 1859 | ||
| 1827 | _keyboardMouseDevice.touchEndEvent(event); | 1860 | if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) { |
| 1861 | _keyboardMouseDevice->touchEndEvent(event); | ||
| 1862 | } | ||
| 1828 | 1863 | ||
| 1829 | // put any application specific touch behavior below here.. | 1864 | // put any application specific touch behavior below here.. |
| 1830 | _touchDragStartedAvg = _touchAvg; | 1865 | _touchDragStartedAvg = _touchAvg; |
| @@ -1840,8 +1875,10 @@ void Application::wheelEvent(QWheelEvent* event) { · 9 unmodified lines | |||
| 1840 | if (_controllerScriptingInterface.isWheelCaptured()) { | 1875 | if (_controllerScriptingInterface.isWheelCaptured()) { |
| 1841 | return; | 1876 | return; |
| 1842 | } | 1877 | } |
| 1843 | 1878 | ||
| 1844 | _keyboardMouseDevice.wheelEvent(event); | 1879 | if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) { |
| 1880 | _keyboardMouseDevice->wheelEvent(event); | ||
| 1881 | } | ||
| 1845 | } | 1882 | } |
| 1846 | 1883 | ||
| 1847 | void Application::dropEvent(QDropEvent *event) { | 1884 | void Application::dropEvent(QDropEvent *event) { |
| @@ -1964,6 +2001,14 @@ void Application::idle() { · 116 unmodified lines | |||
| 1964 | PerformanceTimer perfTimer("updateGL"); | 2001 | PerformanceTimer perfTimer("updateGL"); |
| 1965 | PerformanceWarning warn(showWarnings, "Application::idle()... updateGL()"); | 2002 | PerformanceWarning warn(showWarnings, "Application::idle()... updateGL()"); |
| 1966 | getActiveDisplayPlugin()->idle(); | 2003 | getActiveDisplayPlugin()->idle(); |
| 2004 | auto inputPlugins = getInputPlugins(); | ||
| 2005 | foreach(auto inputPlugin, inputPlugins) { | ||
| 2006 | QString name = inputPlugin->getName(); | ||
| 2007 | QAction* action = Menu::getInstance()->getActionForOption(name); | ||
| 2008 | if (action->isChecked()) { | ||
| 2009 | inputPlugin->idle(); | ||
| 2010 | } | ||
| 2011 | } | ||
| 1967 | } | 2012 | } |
| 1968 | { | 2013 | { |
| 1969 | PerformanceTimer perfTimer("rest"); | 2014 | PerformanceTimer perfTimer("rest"); |
| @@ -2625,10 +2670,14 @@ void Application::update(float deltaTime) { · 655 unmodified lines | |||
| 2625 | userInputMapper->setSensorToWorldMat(_myAvatar->getSensorToWorldMatrix()); | 2670 | userInputMapper->setSensorToWorldMat(_myAvatar->getSensorToWorldMatrix()); |
| 2626 | userInputMapper->update(deltaTime); | 2671 | userInputMapper->update(deltaTime); |
| 2627 | 2672 | ||
| 2628 | _keyboardMouseDevice.pluginUpdate(deltaTime); | 2673 | auto inputPlugins = getInputPlugins(); |
| 2629 | SixenseManager::getInstance().pluginUpdate(deltaTime); | 2674 | foreach(auto inputPlugin, inputPlugins) { |
| 2630 | SDL2Manager::getInstance()->pluginUpdate(deltaTime); | 2675 | QString name = inputPlugin->getName(); |
| 2631 | ViveControllerManager::getInstance().pluginUpdate(deltaTime); | 2676 | QAction* action = Menu::getInstance()->getActionForOption(name); |
| 2677 | if (action->isChecked()) { | ||
| 2678 | inputPlugin->pluginUpdate(deltaTime); // add flag to prevent multiple devices from modifying joints | ||
| 2679 | } | ||
| 2680 | } | ||
| 2632 | 2681 | ||
| 2633 | // Dispatch input events | 2682 | // Dispatch input events |
| 2634 | _controllerScriptingInterface.updateInputControllers(); | 2683 | _controllerScriptingInterface.updateInputControllers(); |
| @@ -2826,7 +2875,7 @@ void Application::setPalmData(Hand* hand, UserInputMapper::PoseValue pose, int i · 191 unmodified lines | |||
| 2826 | 2875 | ||
| 2827 | palm->setActive(pose.isValid()); | 2876 | palm->setActive(pose.isValid()); |
| 2828 | 2877 | ||
| 2829 | // TODO: velocity filters, tip velocities, et.c | 2878 | // TODO: velocity filters, tip velocities, etc. |
| 2830 | // see SixenseManager | 2879 | // see SixenseManager |
| 2831 | 2880 | ||
| 2832 | // transform from sensor space, to world space, to avatar model space. | 2881 | // transform from sensor space, to world space, to avatar model space. |
| @@ -2872,8 +2921,7 @@ void Application::emulateMouse(Hand* hand, float click, float shift, int index) · 39 unmodified lines | |||
| 2872 | float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)M_PI_2)); | 2921 | float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)M_PI_2)); |
| 2873 | auto canvasSize = qApp->getCanvasSize(); | 2922 | auto canvasSize = qApp->getCanvasSize(); |
| 2874 | // Get the pixel range over which the xAngle and yAngle are scaled | 2923 | // Get the pixel range over which the xAngle and yAngle are scaled |
| 2875 | // TODO: move this from SixenseManager | 2924 | float cursorRange = canvasSize.x * InputDevice::getCursorPixelRangeMult(); |
| 2876 | float cursorRange = canvasSize.x * SixenseManager::getInstance().getCursorPixelRangeMult(); | ||
| 2877 | 2925 | ||
| 2878 | pos.setX(canvasSize.x / 2.0f + cursorRange * xAngle); | 2926 | pos.setX(canvasSize.x / 2.0f + cursorRange * xAngle); |
| 2879 | pos.setY(canvasSize.y / 2.0f + cursorRange * yAngle); | 2927 | pos.setY(canvasSize.y / 2.0f + cursorRange * yAngle); |
| @@ -5128,6 +5176,51 @@ void Application::updateDisplayMode() { · 2248 unmodified lines | |||
| 5128 | Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); | 5176 | Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); |
| 5129 | } | 5177 | } |
| 5130 | 5178 | ||
| 5179 | static QVector<QPair<QString, QString>> _currentInputPluginActions; | ||
| 5180 | |||
| 5181 | void Application::updateInputModes() { | ||
| 5182 | auto menu = Menu::getInstance(); | ||
| 5183 | auto inputPlugins = getInputPlugins(); | ||
| 5184 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); | ||
| 5185 | |||
| 5186 | InputPluginPointer newInputPlugin = InputPluginPointer(nullptr); | ||
| 5187 | InputPluginPointer removedInputPlugin = InputPluginPointer(nullptr); | ||
| 5188 | foreach(InputPluginPointer inputPlugin, inputPlugins) { | ||
| 5189 | QString name = inputPlugin->getName(); | ||
| 5190 | QAction* action = menu->getActionForOption(name); | ||
| 5191 | if (action->isChecked() && !_activeInputPlugins.contains(inputPlugin)) { | ||
| 5192 | _activeInputPlugins.append(inputPlugin); | ||
| 5193 | newInputPlugin = inputPlugin; | ||
| 5194 | break; | ||
| 5195 | } else if (!action->isChecked() && _activeInputPlugins.contains(inputPlugin)) { | ||
| 5196 | _activeInputPlugins.removeOne(inputPlugin); | ||
| 5197 | removedInputPlugin = inputPlugin; | ||
| 5198 | break; | ||
| 5199 | } | ||
| 5200 | } | ||
| 5201 | |||
| 5202 | // A plugin was checked | ||
| 5203 | if (newInputPlugin) { | ||
| 5204 | newInputPlugin->activate(this); | ||
| 5205 | newInputPlugin->installEventFilter(qApp); | ||
| 5206 | newInputPlugin->installEventFilter(offscreenUi.data()); | ||
| 5207 | } else if (removedInputPlugin) { // A plugin was unchecked | ||
| 5208 | removedInputPlugin->deactivate(); | ||
| 5209 | removedInputPlugin->removeEventFilter(qApp); | ||
| 5210 | removedInputPlugin->removeEventFilter(offscreenUi.data()); | ||
| 5211 | } | ||
| 5212 | |||
| 5213 | if (newInputPlugin || removedInputPlugin) { | ||
| 5214 | if (!_currentInputPluginActions.isEmpty()) { | ||
| 5215 | auto menu = Menu::getInstance(); | ||
| 5216 | foreach(auto itemInfo, _currentInputPluginActions) { | ||
| 5217 | menu->removeMenuItem(itemInfo.first, itemInfo.second); | ||
| 5218 | } | ||
| 5219 | _currentInputPluginActions.clear(); | ||
| 5220 | } | ||
| 5221 | } | ||
| 5222 | } | ||
| 5223 | |||
| 5131 | void Application::addMenuItem(const QString& path, const QString& name, std::function<void()> onClicked, bool checkable, bool checked, const QString& groupName) { | 5224 | void Application::addMenuItem(const QString& path, const QString& name, std::function<void()> onClicked, bool checkable, bool checked, const QString& groupName) { |
| 5132 | auto menu = Menu::getInstance(); | 5225 | auto menu = Menu::getInstance(); |
| 5133 | MenuWrapper* parentItem = menu->getMenu(path); | 5226 | MenuWrapper* parentItem = menu->getMenu(path); |
| @@ -5136,6 +5229,7 @@ void Application::addMenuItem(const QString& path, const QString& name, std::fun · 2 unmodified lines | |||
| 5136 | onClicked(); | 5229 | onClicked(); |
| 5137 | }); | 5230 | }); |
| 5138 | _currentDisplayPluginActions.push_back({ path, name }); | 5231 | _currentDisplayPluginActions.push_back({ path, name }); |
| 5232 | _currentInputPluginActions.push_back({ path, name }); | ||
| 5139 | } | 5233 | } |
| 5140 | 5234 | ||
| 5141 | GlWindow* Application::getVisibleWindow() { | 5235 | GlWindow* Application::getVisibleWindow() { |