Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions UI/ChatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ void ChatMenu::CreatePopupContents(UI::ViewGroup *parent) {
chatEdit_ = bottom->Add(new TextEdit("", n->T("Chat Here"), new LinearLayoutParams(1.0)));
#if defined(USING_WIN_UI)
//freeze the ui when using ctrl + C hotkey need workaround
if (g_Config.bBypassOSKWithKeyboard && !g_Config.bFullScreen)
{
if (g_Config.bBypassOSKWithKeyboard && !g_Config.bFullScreen) {
std::wstring titleText = ConvertUTF8ToWString(n->T("Chat"));
std::wstring defaultText = ConvertUTF8ToWString(n->T("Chat Here"));
std::wstring inputChars;
Expand Down
59 changes: 59 additions & 0 deletions ext/native/ui/root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,65 @@ bool TouchEvent(const TouchInput &touch, ViewGroup *root) {
}

bool AxisEvent(const AxisInput &axis, ViewGroup *root) {
enum {
DIR_POS = 1,
DIR_NEG = 2,
};

static uint32_t x_state = 0;
static uint32_t y_state = 0;

const float THRESHOLD = 0.75;

// Cannot use the remapper since this is for the menu, so we provide our own
// axis->button emulation here.
auto GenerateKeyFromAxis = [&](uint32_t old, uint32_t cur, keycode_t neg_key, keycode_t pos_key) {
if (old == cur)
return;
if (old == DIR_POS) {
KeyEvent(KeyInput{ DEVICE_ID_KEYBOARD, pos_key, KEY_UP }, root);
} else if (old == DIR_NEG) {
KeyEvent(KeyInput{ DEVICE_ID_KEYBOARD, neg_key, KEY_UP }, root);
}
if (cur == DIR_POS) {
KeyEvent(KeyInput{ DEVICE_ID_KEYBOARD, pos_key, KEY_DOWN }, root);
} else if (cur == DIR_NEG) {
KeyEvent(KeyInput{ DEVICE_ID_KEYBOARD, neg_key, KEY_DOWN }, root);
}
};

switch (axis.deviceId) {
case DEVICE_ID_PAD_0:
case DEVICE_ID_PAD_1:
case DEVICE_ID_PAD_2:
case DEVICE_ID_PAD_3:
case DEVICE_ID_X360_0:
case DEVICE_ID_X360_1:
case DEVICE_ID_X360_2:
case DEVICE_ID_X360_3:
{
uint32_t dir = 0;
if (axis.axisId == JOYSTICK_AXIS_X) {
if (axis.value < -THRESHOLD)
dir = DIR_NEG;
else if (axis.value > THRESHOLD)
dir = DIR_POS;
GenerateKeyFromAxis(x_state, dir, NKCODE_DPAD_LEFT, NKCODE_DPAD_RIGHT);
x_state = dir;
}
if (axis.axisId == JOYSTICK_AXIS_Y) {
if (axis.value < -THRESHOLD)
dir = DIR_NEG;
else if (axis.value > THRESHOLD)
dir = DIR_POS;
// TODO: What do we do with devices that are reversed... ?
GenerateKeyFromAxis(y_state, dir, NKCODE_DPAD_DOWN, NKCODE_DPAD_UP);
y_state = dir;
}
break;
}
}

root->Axis(axis);
return true;
}
Expand Down