From c77b66f88c2a88c8f9aa75d1de618f3beb12702c Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 30 Dec 2015 22:27:33 -0800 Subject: [PATCH] Make navigation directions into axes --- interface/src/Application.cpp | 59 ++++++++++++++----- .../controllers/src/controllers/Actions.cpp | 15 ++--- .../controllers/src/controllers/Actions.h | 9 +-- 3 files changed, 52 insertions(+), 31 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index abd08d6d07..a92f019e34 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -692,34 +692,61 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : if (offscreenUi->navigationFocused()) { auto actionEnum = static_cast(action); int key = Qt::Key_unknown; + bool navAxis = false; + static int lastKey = Qt::Key_unknown; switch (actionEnum) { - case Action::UI_NAV_UP: - key = Qt::Key_Up; + case Action::UI_NAV_VERTICAL: + navAxis = true; + if (state > 0.0f) { + key = Qt::Key_Up; + } else if (state < 0.0f) { + key = Qt::Key_Down; + } break; - case Action::UI_NAV_DOWN: - key = Qt::Key_Down; + + case Action::UI_NAV_LATERAL: + navAxis = true; + if (state > 0.0f) { + key = Qt::Key_Right; + } else if (state < 0.0f) { + key = Qt::Key_Left; + } break; - case Action::UI_NAV_LEFT: - key = Qt::Key_Left; - break; - case Action::UI_NAV_RIGHT: - key = Qt::Key_Right; + + case Action::UI_NAV_GROUP: + navAxis = true; + if (state > 0.0f) { + key = Qt::Key_Tab; + } else if (state < 0.0f) { + key = Qt::Key_Backtab; + } break; + case Action::UI_NAV_BACK: key = Qt::Key_Escape; break; + case Action::UI_NAV_SELECT: key = Qt::Key_Return; break; - case Action::UI_NAV_NEXT_GROUP: - key = Qt::Key_Tab; - break; - case Action::UI_NAV_PREVIOUS_GROUP: - key = Qt::Key_Backtab; - break; } - if (key != Qt::Key_unknown) { + if (navAxis) { + qDebug() << "Axis " << action << " value " << state; + if (lastKey != Qt::Key_unknown) { + qDebug() << "Releasing key " << lastKey; + QKeyEvent event(QEvent::KeyRelease, lastKey, Qt::NoModifier); + sendEvent(offscreenUi->getWindow(), &event); + lastKey = Qt::Key_unknown; + } + + if (key != Qt::Key_unknown) { + qDebug() << "Pressing key " << key; + QKeyEvent event(QEvent::KeyPress, key, Qt::NoModifier); + sendEvent(offscreenUi->getWindow(), &event); + lastKey = key; + } + } else if (key != Qt::Key_unknown) { if (state) { QKeyEvent event(QEvent::KeyPress, key, Qt::NoModifier); sendEvent(offscreenUi->getWindow(), &event); diff --git a/libraries/controllers/src/controllers/Actions.cpp b/libraries/controllers/src/controllers/Actions.cpp index 2ff1b8ce0f..7bee5101b1 100644 --- a/libraries/controllers/src/controllers/Actions.cpp +++ b/libraries/controllers/src/controllers/Actions.cpp @@ -62,15 +62,6 @@ namespace controller { makeButtonPair(Action::TOGGLE_MUTE, "ToggleMute"), makeButtonPair(Action::CYCLE_CAMERA, "CycleCamera"), - makeButtonPair(Action::UI_NAV_UP, "UiNavUp"), - makeButtonPair(Action::UI_NAV_DOWN, "UiNavDown"), - makeButtonPair(Action::UI_NAV_LEFT, "UiNavLeft"), - makeButtonPair(Action::UI_NAV_RIGHT, "UiNavRight"), - makeButtonPair(Action::UI_NAV_SELECT, "UiNavSelect"), - makeButtonPair(Action::UI_NAV_BACK, "UiNavBack"), - makeButtonPair(Action::UI_NAV_NEXT_GROUP, "UiNavNextGroup"), - makeButtonPair(Action::UI_NAV_PREVIOUS_GROUP, "UiNavPreviousGroup"), - makeAxisPair(Action::RETICLE_CLICK, "ReticleClick"), makeAxisPair(Action::RETICLE_X, "ReticleX"), makeAxisPair(Action::RETICLE_Y, "ReticleY"), @@ -79,6 +70,12 @@ namespace controller { makeAxisPair(Action::RETICLE_UP, "ReticleUp"), makeAxisPair(Action::RETICLE_DOWN, "ReticleDown"), + makeAxisPair(Action::UI_NAV_LATERAL, "UiNavLateral"), + makeAxisPair(Action::UI_NAV_VERTICAL, "UiNavVertical"), + makeAxisPair(Action::UI_NAV_GROUP, "UiNavGroup"), + makeAxisPair(Action::UI_NAV_SELECT, "UiNavSelect"), + makeAxisPair(Action::UI_NAV_BACK, "UiNavBack"), + // Aliases and bisected versions makeAxisPair(Action::LONGITUDINAL_BACKWARD, "Backward"), makeAxisPair(Action::LONGITUDINAL_FORWARD, "Forward"), diff --git a/libraries/controllers/src/controllers/Actions.h b/libraries/controllers/src/controllers/Actions.h index d358a7a277..812d3b8df3 100644 --- a/libraries/controllers/src/controllers/Actions.h +++ b/libraries/controllers/src/controllers/Actions.h @@ -55,14 +55,11 @@ enum class Action { SHIFT, - UI_NAV_UP, - UI_NAV_DOWN, - UI_NAV_LEFT, - UI_NAV_RIGHT, + UI_NAV_LATERAL, + UI_NAV_VERTICAL, + UI_NAV_GROUP, UI_NAV_SELECT, UI_NAV_BACK, - UI_NAV_NEXT_GROUP, - UI_NAV_PREVIOUS_GROUP, // Pointer/Reticle control RETICLE_CLICK,