Add option to require double click to move

This commit is contained in:
Robin Appelman
2018-07-08 18:08:09 +02:00
parent a66cded56d
commit 837a91f920
3 changed files with 83 additions and 24 deletions
+13
View File
@@ -278,6 +278,7 @@ MyStackViewPage {
border.color: "#ffffff" border.color: "#ffffff"
radius: 8 radius: 8
} }
ColumnLayout {
RowLayout { RowLayout {
anchors.fill: parent anchors.fill: parent
@@ -296,6 +297,15 @@ MyStackViewPage {
MoveCenterTabController.moveShortcutRight = this.checked MoveCenterTabController.moveShortcutRight = this.checked
} }
} }
MyToggleButton {
id: requireDoubleClick
text: "Require double click"
onCheckedChanged: {
MoveCenterTabController.requireDoubleClick = this.checked
}
}
}
} }
} }
@@ -366,6 +376,9 @@ MyStackViewPage {
onMoveShortcutLeftChanged: { onMoveShortcutLeftChanged: {
moveShortcutLeft.checked = MoveCenterTabController.moveShortcutLeft moveShortcutLeft.checked = MoveCenterTabController.moveShortcutLeft
} }
onRequireDoubleClickChanged: {
requireDoubleClick.checked = MoveCenterTabController.requireDoubleClick
}
onTrackingUniverseChanged: { onTrackingUniverseChanged: {
if (MoveCenterTabController.trackingUniverse === 0) { if (MoveCenterTabController.trackingUniverse === 0) {
playspaceModeText.text = "Sitting" playspaceModeText.text = "Sitting"
@@ -17,6 +17,10 @@ void rotateCoordinates(float coordinates[3], float angle) {
// application namespace // application namespace
namespace advsettings { namespace advsettings {
using std::chrono::duration_cast;
using std::chrono::milliseconds;
typedef std::chrono::system_clock clock;
void MoveCenterTabController::initStage1() { void MoveCenterTabController::initStage1() {
setTrackingUniverse(vr::VRCompositor()->GetTrackingSpace()); setTrackingUniverse(vr::VRCompositor()->GetTrackingSpace());
auto settings = OverlayController::appSettings(); auto settings = OverlayController::appSettings();
@@ -33,7 +37,12 @@ void MoveCenterTabController::initStage1() {
if (value.isValid() && !value.isNull()) { if (value.isValid() && !value.isNull()) {
m_moveShortcutLeftEnabled = value.toBool(); m_moveShortcutLeftEnabled = value.toBool();
} }
value = settings->value("requireDoubleClick", m_requireDoubleClick);
if (value.isValid() && !value.isNull()) {
m_requireDoubleClick = value.toBool();
}
settings->endGroup(); settings->endGroup();
lastMoveButtonClick[0] = lastMoveButtonClick[0] = clock::now();
} }
void MoveCenterTabController::initStage2(OverlayController * parent, QQuickWindow * widget) { void MoveCenterTabController::initStage2(OverlayController * parent, QQuickWindow * widget) {
@@ -164,6 +173,22 @@ void MoveCenterTabController::setMoveShortcutLeft(bool value, bool notify) {
} }
} }
bool MoveCenterTabController::requireDoubleClick() const {
return m_requireDoubleClick;
}
void MoveCenterTabController::setRequireDoubleClick(bool value, bool notify) {
m_requireDoubleClick = value;
auto settings = OverlayController::appSettings();
settings->beginGroup("playspaceSettings");
settings->setValue("requireDoubleClick", m_requireDoubleClick);
settings->endGroup();
settings->sync();
if (notify) {
emit requireDoubleClickChanged(m_requireDoubleClick);
}
}
void MoveCenterTabController::modOffsetX(float value, bool notify) { void MoveCenterTabController::modOffsetX(float value, bool notify) {
auto angle = m_rotation * 2 * M_PI / 360.0; auto angle = m_rotation * 2 * M_PI / 360.0;
float offset[3] = { value, 0, 0 }; float offset[3] = { value, 0, 0 };
@@ -233,14 +258,24 @@ vr::ETrackedControllerRole MoveCenterTabController::getMoveShortcutHand() {
bool rightPressed = m_moveShortcutRightEnabled && isMoveShortCutPressed(vr::TrackedControllerRole_RightHand); bool rightPressed = m_moveShortcutRightEnabled && isMoveShortCutPressed(vr::TrackedControllerRole_RightHand);
bool leftPressed = m_moveShortcutLeftEnabled && isMoveShortCutPressed(vr::TrackedControllerRole_LeftHand); bool leftPressed = m_moveShortcutLeftEnabled && isMoveShortCutPressed(vr::TrackedControllerRole_LeftHand);
bool checkDoubleClick = m_requireDoubleClick && activeHand == vr::TrackedControllerRole_Invalid;
auto now = clock::now();
// if we start pressing the shortcut on a controller we set the active one to it // if we start pressing the shortcut on a controller we set the active one to it
if (rightPressed && !m_moveShortcutRightPressed) { if (rightPressed && !m_moveShortcutRightPressed) {
auto elapsed = duration_cast<milliseconds>(now - lastMoveButtonClick[0]).count();
if (!checkDoubleClick || elapsed < 250) {
activeHand = vr::TrackedControllerRole_RightHand; activeHand = vr::TrackedControllerRole_RightHand;
} }
lastMoveButtonClick[0] = now;
}
if (leftPressed && !m_moveShortcutLeftPressed) { if (leftPressed && !m_moveShortcutLeftPressed) {
auto elapsed = duration_cast<milliseconds>(now - lastMoveButtonClick[1]).count();
if (!checkDoubleClick || elapsed < 250) {
activeHand = vr::TrackedControllerRole_LeftHand; activeHand = vr::TrackedControllerRole_LeftHand;
} }
lastMoveButtonClick[1] = now;
}
// if we let down of a shortcut we set the active hand to any remaining pressed down hand // if we let down of a shortcut we set the active hand to any remaining pressed down hand
if (!rightPressed && m_moveShortcutRightPressed) { if (!rightPressed && m_moveShortcutRightPressed) {
@@ -252,6 +287,10 @@ vr::ETrackedControllerRole MoveCenterTabController::getMoveShortcutHand() {
if (!leftPressed && !rightPressed) { if (!leftPressed && !rightPressed) {
activeHand = vr::TrackedControllerRole_Invalid; activeHand = vr::TrackedControllerRole_Invalid;
if (m_activeMoveController != vr::TrackedControllerRole_Invalid) {
// grace period while switching hands
lastMoveButtonClick[0] = lastMoveButtonClick[1] = now;
}
} }
m_activeMoveController = activeHand; m_activeMoveController = activeHand;
@@ -3,6 +3,7 @@
#include <QObject> #include <QObject>
#include <openvr.h> #include <openvr.h>
#include <chrono>
class QQuickWindow; class QQuickWindow;
// application namespace // application namespace
@@ -22,6 +23,7 @@ class MoveCenterTabController : public QObject {
Q_PROPERTY(bool adjustChaperone READ adjustChaperone WRITE setAdjustChaperone NOTIFY adjustChaperoneChanged) Q_PROPERTY(bool adjustChaperone READ adjustChaperone WRITE setAdjustChaperone NOTIFY adjustChaperoneChanged)
Q_PROPERTY(bool moveShortcutRight READ moveShortcutRight WRITE setMoveShortcutRight NOTIFY moveShortcutRightChanged) Q_PROPERTY(bool moveShortcutRight READ moveShortcutRight WRITE setMoveShortcutRight NOTIFY moveShortcutRightChanged)
Q_PROPERTY(bool moveShortcutLeft READ moveShortcutLeft WRITE setMoveShortcutLeft NOTIFY moveShortcutLeftChanged) Q_PROPERTY(bool moveShortcutLeft READ moveShortcutLeft WRITE setMoveShortcutLeft NOTIFY moveShortcutLeftChanged)
Q_PROPERTY(bool requireDoubleClick READ requireDoubleClick WRITE setRequireDoubleClick NOTIFY requireDoubleClickChanged)
private: private:
OverlayController* parent; OverlayController* parent;
@@ -39,6 +41,8 @@ private:
float m_lastControllerPosition[3]; float m_lastControllerPosition[3];
bool m_moveShortcutRightEnabled = false; bool m_moveShortcutRightEnabled = false;
bool m_moveShortcutLeftEnabled = false; bool m_moveShortcutLeftEnabled = false;
bool m_requireDoubleClick = false;
std::chrono::system_clock::time_point lastMoveButtonClick[2];
unsigned settingsUpdateCounter = 0; unsigned settingsUpdateCounter = 0;
@@ -57,6 +61,7 @@ public:
bool adjustChaperone() const; bool adjustChaperone() const;
bool moveShortcutRight() const; bool moveShortcutRight() const;
bool moveShortcutLeft() const; bool moveShortcutLeft() const;
bool requireDoubleClick() const;
public slots: public slots:
int trackingUniverse() const; int trackingUniverse() const;
@@ -72,6 +77,7 @@ public slots:
void setMoveShortcutRight(bool value, bool notify = true); void setMoveShortcutRight(bool value, bool notify = true);
void setMoveShortcutLeft(bool value, bool notify = true); void setMoveShortcutLeft(bool value, bool notify = true);
void setRequireDoubleClick(bool value, bool notify = true);
void modOffsetX(float value, bool notify = true); void modOffsetX(float value, bool notify = true);
void modOffsetY(float value, bool notify = true); void modOffsetY(float value, bool notify = true);
@@ -87,6 +93,7 @@ signals:
void adjustChaperoneChanged(bool value); void adjustChaperoneChanged(bool value);
void moveShortcutRightChanged(bool value); void moveShortcutRightChanged(bool value);
void moveShortcutLeftChanged(bool value); void moveShortcutLeftChanged(bool value);
void requireDoubleClickChanged(bool value);
}; };
} // namespace advsettings } // namespace advsettings