Make navigation directions into axes

This commit is contained in:
Brad Davis 2015-12-30 22:27:33 -08:00
parent 3eddf8d4a4
commit c77b66f88c
3 changed files with 52 additions and 31 deletions

View file

@ -692,34 +692,61 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
if (offscreenUi->navigationFocused()) {
auto actionEnum = static_cast<Action>(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);

View file

@ -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"),

View file

@ -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,