History

Merge remote-tracking branch 'upstream/master' into update

HifiExperiments committed 6 years ago

Commit 7bfbf3c2 parents ccd5ef8 66ccfab161 files · +2251 −895Browse files

Showing the changes to interface/src/Application.cpp (1 of 161 files). Show all

Unified · Split

interface/src/Application.cpp+40−4
@@ -681,6 +681,9 @@ private: · 680 unmodified lines
681681 * <tr><td><code>CameraIndependent</code></td><td>number</td><td>number</td><td>The camera is in independent mode.</td></tr>
682682 * <tr><td><code>CameraEntity</code></td><td>number</td><td>number</td><td>The camera is in entity mode.</td></tr>
683683 * <tr><td><code>InHMD</code></td><td>number</td><td>number</td><td>The user is in HMD mode.</td></tr>
684+ * <tr><td><code>CaptureMouse</code></td><td>number</td><td>number</td><td>The mouse is captured. In this mode,
685+ * the mouse is invisible and cannot leave the bounds of Interface, as long as Interface is the active window and
686+ * no menu item is selected.</td></tr>
684687 * <tr><td><code>AdvancedMovement</code></td><td>number</td><td>number</td><td>Advanced movement (walking) controls are
685688 * enabled.</td></tr>
686689 * <tr><td><code>StrafeEnabled</code></td><td>number</td><td>number</td><td>Strafing is enabled</td></tr>
@@ -716,6 +719,7 @@ static const QString STATE_PLATFORM_ANDROID = "PlatformAndroid"; · 29 unmodified lines
716719 static const QString STATE_LEFT_HAND_DOMINANT = "LeftHandDominant";
717720 static const QString STATE_RIGHT_HAND_DOMINANT = "RightHandDominant";
718721 static const QString STATE_STRAFE_ENABLED = "StrafeEnabled";
722+static const QString STATE_CAPTURE_MOUSE = "CaptureMouse";
719723
720724 // Statically provided display and input plugins
721725 extern DisplayPluginList getDisplayPlugins();
@@ -919,7 +923,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { · 197 unmodified lines
919923 DependencyManager::set<MessagesClient>();
920924 controller::StateController::setStateVariables({ { STATE_IN_HMD, STATE_CAMERA_FULL_SCREEN_MIRROR,
921925 STATE_CAMERA_FIRST_PERSON, STATE_CAMERA_FIRST_PERSON_LOOK_AT, STATE_CAMERA_THIRD_PERSON,
922− STATE_CAMERA_ENTITY, STATE_CAMERA_INDEPENDENT, STATE_CAMERA_LOOK_AT, STATE_CAMERA_SELFIE,
926+ STATE_CAMERA_ENTITY, STATE_CAMERA_INDEPENDENT, STATE_CAMERA_LOOK_AT, STATE_CAMERA_SELFIE, STATE_CAPTURE_MOUSE,
923927 STATE_SNAP_TURN, STATE_ADVANCED_MOVEMENT_CONTROLS, STATE_GROUNDED, STATE_NAV_FOCUSED,
924928 STATE_PLATFORM_WINDOWS, STATE_PLATFORM_MAC, STATE_PLATFORM_ANDROID, STATE_LEFT_HAND_DOMINANT, STATE_RIGHT_HAND_DOMINANT, STATE_STRAFE_ENABLED } });
925929 DependencyManager::set<UserInputMapper>();
@@ -1892,6 +1896,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 966 unmodified lines
18921896 _applicationStateDevice->setInputVariant(STATE_CAMERA_INDEPENDENT, []() -> float {
18931897 return qApp->getCamera().getMode() == CAMERA_MODE_INDEPENDENT ? 1 : 0;
18941898 });
1899+ _applicationStateDevice->setInputVariant(STATE_CAPTURE_MOUSE, []() -> float {
1900+ return qApp->getCamera().getCaptureMouse() ? 1 : 0;
1901+ });
18951902 _applicationStateDevice->setInputVariant(STATE_SNAP_TURN, []() -> float {
18961903 return qApp->getMyAvatar()->getSnapTurn() ? 1 : 0;
18971904 });
@@ -2407,6 +2414,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 509 unmodified lines
24072414 updateSystemTabletMode();
24082415
24092416 connect(&_myCamera, &Camera::modeUpdated, this, &Application::cameraModeChanged);
2417+ connect(&_myCamera, &Camera::captureMouseChanged, this, &Application::captureMouseChanged);
24102418
24112419 DependencyManager::get<PickManager>()->setShouldPickHUDOperator([]() { return DependencyManager::get<HMDScriptingInterface>()->isHMDMode(); });
24122420 DependencyManager::get<PickManager>()->setCalculatePos2DFromHUDOperator([this](const glm::vec3& intersection) {
@@ -4704,6 +4712,11 @@ void Application::maybeToggleMenuVisible(QMouseEvent* event) const { · 2291 unmodified lines
47044712 void Application::mouseMoveEvent(QMouseEvent* event) {
47054713 PROFILE_RANGE(app_input_mouse, __FUNCTION__);
47064714
4715+ if (_ignoreMouseMove) {
4716+ _ignoreMouseMove = false;
4717+ return;
4718+ }
4719+
47074720 maybeToggleMenuVisible(event);
47084721
47094722 auto& compositor = getApplicationCompositor();
@@ -4749,7 +4762,7 @@ void Application::mouseMoveEvent(QMouseEvent* event) { · 39 unmodified lines
47494762 }
47504763
47514764 if (_keyboardMouseDevice->isActive()) {
4752− _keyboardMouseDevice->mouseMoveEvent(event);
4765+ _keyboardMouseDevice->mouseMoveEvent(event, _captureMouse, _mouseCaptureTarget);
47534766 }
47544767 }
47554768
@@ -5950,6 +5963,20 @@ void Application::cameraModeChanged() { · 1194 unmodified lines
59505963 cameraMenuChanged();
59515964 }
59525965
5966+bool Application::shouldCaptureMouse() const {
5967+ return _captureMouse && _glWidget->isActiveWindow() && !ui::Menu::isSomeSubmenuShown();
5968+}
5969+
5970+void Application::captureMouseChanged(bool captureMouse) {
5971+ _captureMouse = captureMouse;
5972+ if (_captureMouse) {
5973+ _glWidget->setCursor(QCursor(Qt::BlankCursor));
5974+ } else {
5975+ _mouseCaptureTarget = QPointF(NAN, NAN);
5976+ _glWidget->unsetCursor();
5977+ }
5978+}
5979+
59535980 void Application::changeViewAsNeeded(float boomLength) {
59545981 // Switch between first and third person views as needed
59555982 // This is called when the boom length has changed
@@ -6300,6 +6327,15 @@ void Application::update(float deltaTime) { · 344 unmodified lines
63006327 PROFILE_ASYNC_END(app, "Scene Loading", "");
63016328 }
63026329
6330+ if (shouldCaptureMouse()) {
6331+ QPoint point = _glWidget->mapToGlobal(_glWidget->geometry().center());
6332+ if (QCursor::pos() != point) {
6333+ _mouseCaptureTarget = point;
6334+ _ignoreMouseMove = true;
6335+ QCursor::setPos(point);
6336+ }
6337+ }
6338+
63036339 auto myAvatar = getMyAvatar();
63046340 {
63056341 PerformanceTimer perfTimer("devices");
@@ -6355,8 +6391,8 @@ void Application::update(float deltaTime) { · 49 unmodified lines
63556391 if (deltaTime > FLT_EPSILON && userInputMapper->getActionState(controller::Action::TRANSLATE_CAMERA_Z) == 0.0f) {
63566392 myAvatar->setDriveKey(MyAvatar::PITCH, -1.0f * userInputMapper->getActionState(controller::Action::PITCH));
63576393 myAvatar->setDriveKey(MyAvatar::YAW, -1.0f * userInputMapper->getActionState(controller::Action::YAW));
6358− myAvatar->setDriveKey(MyAvatar::DELTA_PITCH, -1.0f * userInputMapper->getActionState(controller::Action::DELTA_PITCH));
6359− myAvatar->setDriveKey(MyAvatar::DELTA_YAW, -1.0f * userInputMapper->getActionState(controller::Action::DELTA_YAW));
6394+ myAvatar->setDriveKey(MyAvatar::DELTA_PITCH, -_myCamera.getSensitivity() * userInputMapper->getActionState(controller::Action::DELTA_PITCH));
6395+ myAvatar->setDriveKey(MyAvatar::DELTA_YAW, -_myCamera.getSensitivity() * userInputMapper->getActionState(controller::Action::DELTA_YAW));
63606396 myAvatar->setDriveKey(MyAvatar::STEP_YAW, -1.0f * userInputMapper->getActionState(controller::Action::STEP_YAW));
63616397 }
63626398 }