Improve input event handling. Can now map volume keys on Android without issues.
This commit is contained in:
parent
7febcd5d91
commit
e3bbf26731
14 changed files with 80 additions and 58 deletions
|
@ -287,12 +287,12 @@ void KeyMappingNewKeyDialog::CreatePopupContents(UI::ViewGroup *parent) {
|
|||
parent->Add(new TextView(std::string(keyI18N->T("Map a new key for")) + " " + pspButtonName, new LinearLayoutParams(Margins(10,0))));
|
||||
}
|
||||
|
||||
void KeyMappingNewKeyDialog::key(const KeyInput &key) {
|
||||
bool KeyMappingNewKeyDialog::key(const KeyInput &key) {
|
||||
if (mapped_)
|
||||
return;
|
||||
return false;
|
||||
if (key.flags & KEY_DOWN) {
|
||||
if (key.keyCode == NKCODE_EXT_MOUSEBUTTON_1) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
mapped_ = true;
|
||||
|
@ -301,24 +301,25 @@ void KeyMappingNewKeyDialog::key(const KeyInput &key) {
|
|||
if (callback_)
|
||||
callback_(kdf);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
|
||||
bool KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
|
||||
if (mapped_)
|
||||
return;
|
||||
return false;
|
||||
switch (axis.axisId) {
|
||||
// Ignore the accelerometer for mapping for now.
|
||||
case JOYSTICK_AXIS_ACCELEROMETER_X:
|
||||
case JOYSTICK_AXIS_ACCELEROMETER_Y:
|
||||
case JOYSTICK_AXIS_ACCELEROMETER_Z:
|
||||
return;
|
||||
return false;
|
||||
|
||||
// Also ignore some weird axis events we get on Ouya.
|
||||
case JOYSTICK_AXIS_OUYA_UNKNOWN1:
|
||||
case JOYSTICK_AXIS_OUYA_UNKNOWN2:
|
||||
case JOYSTICK_AXIS_OUYA_UNKNOWN3:
|
||||
case JOYSTICK_AXIS_OUYA_UNKNOWN4:
|
||||
return;
|
||||
return false;
|
||||
|
||||
default:
|
||||
;
|
||||
|
@ -339,4 +340,5 @@ void KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
|
|||
if (callback_)
|
||||
callback_(kdf);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ public:
|
|||
ControlMappingScreen() {}
|
||||
void KeyMapped(int pspkey); // Notification to let us refocus the same one after recreating views.
|
||||
protected:
|
||||
virtual void CreateViews();
|
||||
virtual void sendMessage(const char *message, const char *value);
|
||||
virtual void CreateViews() override;
|
||||
virtual void sendMessage(const char *message, const char *value) override;
|
||||
private:
|
||||
UI::EventReturn OnDefaultMapping(UI::EventParams ¶ms);
|
||||
UI::EventReturn OnClearMapping(UI::EventParams ¶ms);
|
||||
|
@ -51,15 +51,15 @@ public:
|
|||
pspBtn_ = btn;
|
||||
}
|
||||
|
||||
void key(const KeyInput &key);
|
||||
void axis(const AxisInput &axis);
|
||||
virtual bool key(const KeyInput &key) override;
|
||||
virtual bool axis(const AxisInput &axis) override;
|
||||
|
||||
protected:
|
||||
void CreatePopupContents(UI::ViewGroup *parent);
|
||||
void CreatePopupContents(UI::ViewGroup *parent) override;
|
||||
|
||||
virtual bool FillVertical() const { return false; }
|
||||
virtual bool ShowButtons() const { return true; }
|
||||
virtual void OnCompleted(DialogResult result) {}
|
||||
virtual bool FillVertical() const override { return false; }
|
||||
virtual bool ShowButtons() const override { return true; }
|
||||
virtual void OnCompleted(DialogResult result) override {}
|
||||
|
||||
private:
|
||||
int pspBtn_;
|
||||
|
|
|
@ -344,7 +344,7 @@ void AddressPromptScreen::UpdatePreviewDigits() {
|
|||
}
|
||||
}
|
||||
|
||||
void AddressPromptScreen::key(const KeyInput &key) {
|
||||
bool AddressPromptScreen::key(const KeyInput &key) {
|
||||
if (key.flags & KEY_DOWN) {
|
||||
if (key.keyCode >= NKCODE_0 && key.keyCode <= NKCODE_9) {
|
||||
AddDigit(key.keyCode - NKCODE_0);
|
||||
|
@ -356,13 +356,13 @@ void AddressPromptScreen::key(const KeyInput &key) {
|
|||
} else if (key.keyCode == NKCODE_ENTER) {
|
||||
OnCompleted(DR_OK);
|
||||
screenManager()->finishDialog(this, DR_OK);
|
||||
return;
|
||||
} else {
|
||||
UIDialogScreen::key(key);
|
||||
return UIDialogScreen::key(key);
|
||||
}
|
||||
} else {
|
||||
UIDialogScreen::key(key);
|
||||
return UIDialogScreen::key(key);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Three panes: Block chooser, MIPS view, ARM/x86 view
|
||||
|
|
|
@ -75,12 +75,12 @@ public:
|
|||
memset(buttons_, 0, sizeof(buttons_));
|
||||
}
|
||||
|
||||
virtual void key(const KeyInput &key);
|
||||
virtual bool key(const KeyInput &key) override;
|
||||
|
||||
UI::Event OnChoice;
|
||||
|
||||
protected:
|
||||
void CreatePopupContents(UI::ViewGroup *parent);
|
||||
virtual void CreatePopupContents(UI::ViewGroup *parent) override;
|
||||
virtual void OnCompleted(DialogResult result);
|
||||
UI::EventReturn OnDigitButton(UI::EventParams &e);
|
||||
UI::EventReturn OnBackspace(UI::EventParams &e);
|
||||
|
|
|
@ -252,9 +252,13 @@ inline float clamp1(float x) {
|
|||
return x;
|
||||
}
|
||||
|
||||
void EmuScreen::touch(const TouchInput &touch) {
|
||||
if (root_)
|
||||
bool EmuScreen::touch(const TouchInput &touch) {
|
||||
if (root_) {
|
||||
root_->Touch(touch);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void EmuScreen::onVKeyDown(int virtualKeyCode) {
|
||||
|
@ -386,16 +390,23 @@ inline void EmuScreen::setVKeyAnalogY(int stick, int virtualKeyMin, int virtualK
|
|||
__CtrlSetAnalogY(axis, stick);
|
||||
}
|
||||
|
||||
void EmuScreen::key(const KeyInput &key) {
|
||||
bool EmuScreen::key(const KeyInput &key) {
|
||||
if ((key.flags & KEY_DOWN) && key.keyCode == NKCODE_BACK) {
|
||||
pauseTrigger_ = true;
|
||||
}
|
||||
|
||||
std::vector<int> pspKeys;
|
||||
KeyMap::KeyToPspButton(key.deviceId, key.keyCode, &pspKeys);
|
||||
|
||||
if (pspKeys.size() && (key.flags & KEY_IS_REPEAT)) {
|
||||
// Claim that we handled this. Prevents volume key repeats from popping up the volume control on Android.
|
||||
return true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < pspKeys.size(); i++) {
|
||||
pspKey(pspKeys[i], key.flags);
|
||||
}
|
||||
return pspKeys.size() > 0;
|
||||
}
|
||||
|
||||
void EmuScreen::pspKey(int pspKeyCode, int flags) {
|
||||
|
@ -418,16 +429,20 @@ void EmuScreen::pspKey(int pspKeyCode, int flags) {
|
|||
}
|
||||
}
|
||||
|
||||
void EmuScreen::axis(const AxisInput &axis) {
|
||||
bool EmuScreen::axis(const AxisInput &axis) {
|
||||
if (axis.value > 0) {
|
||||
processAxis(axis, 1);
|
||||
return true;
|
||||
} else if (axis.value < 0) {
|
||||
processAxis(axis, -1);
|
||||
return true;
|
||||
} else if (axis.value == 0) {
|
||||
// Both directions! Prevents sticking for digital input devices that are axises (like HAT)
|
||||
processAxis(axis, 1);
|
||||
processAxis(axis, -1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void EmuScreen::processAxis(const AxisInput &axis, int direction) {
|
||||
|
|
|
@ -32,15 +32,15 @@ public:
|
|||
EmuScreen(const std::string &filename);
|
||||
~EmuScreen();
|
||||
|
||||
virtual void update(InputState &input);
|
||||
virtual void render();
|
||||
virtual void deviceLost();
|
||||
virtual void dialogFinished(const Screen *dialog, DialogResult result);
|
||||
virtual void sendMessage(const char *msg, const char *value);
|
||||
virtual void update(InputState &input) override;
|
||||
virtual void render() override;
|
||||
virtual void deviceLost() override;
|
||||
virtual void dialogFinished(const Screen *dialog, DialogResult result) override;
|
||||
virtual void sendMessage(const char *msg, const char *value) override;
|
||||
|
||||
virtual void touch(const TouchInput &touch);
|
||||
virtual void key(const KeyInput &key);
|
||||
virtual void axis(const AxisInput &axis);
|
||||
virtual bool touch(const TouchInput &touch) override;
|
||||
virtual bool key(const KeyInput &key) override;
|
||||
virtual bool axis(const AxisInput &axis) override;
|
||||
|
||||
protected:
|
||||
virtual void CreateViews();
|
||||
|
|
|
@ -60,11 +60,12 @@ void InstallZipScreen::CreateViews() {
|
|||
rightColumnItems->Add(new CheckBox(&deleteZipFile_, iz->T("Delete ZIP file")));
|
||||
}
|
||||
|
||||
void InstallZipScreen::key(const KeyInput &key) {
|
||||
bool InstallZipScreen::key(const KeyInput &key) {
|
||||
// Ignore all key presses during installation to avoid user escape
|
||||
if (!g_GameManager.IsInstallInProgress()) {
|
||||
UIScreen::key(key);
|
||||
return UIScreen::key(key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
UI::EventReturn InstallZipScreen::OnInstall(UI::EventParams ¶ms) {
|
||||
|
|
|
@ -26,11 +26,11 @@
|
|||
class InstallZipScreen : public UIDialogScreenWithBackground {
|
||||
public:
|
||||
InstallZipScreen(std::string zipPath) : installChoice_(0), doneView_(0), zipPath_(zipPath), installStarted_(false), deleteZipFile_(false) {}
|
||||
virtual void update(InputState &input);
|
||||
virtual void key(const KeyInput &key);
|
||||
virtual void update(InputState &input) override;
|
||||
virtual bool key(const KeyInput &key) override;
|
||||
|
||||
protected:
|
||||
virtual void CreateViews();
|
||||
virtual void CreateViews() override;
|
||||
|
||||
private:
|
||||
UI::EventReturn OnInstall(UI::EventParams ¶ms);
|
||||
|
|
|
@ -376,10 +376,12 @@ void LogoScreen::sendMessage(const char *message, const char *value) {
|
|||
}
|
||||
}
|
||||
|
||||
void LogoScreen::key(const KeyInput &key) {
|
||||
bool LogoScreen::key(const KeyInput &key) {
|
||||
if (key.deviceId != DEVICE_ID_MOUSE) {
|
||||
Next();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void LogoScreen::render() {
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
UIScreenWithBackground() : UIScreen() {}
|
||||
protected:
|
||||
virtual void DrawBackground(UIContext &dc);
|
||||
virtual void sendMessage(const char *message, const char *value);
|
||||
virtual void sendMessage(const char *message, const char *value) override;
|
||||
virtual UI::EventReturn OnLanguageChange(UI::EventParams &e);
|
||||
};
|
||||
|
||||
|
@ -53,7 +53,7 @@ public:
|
|||
UIDialogScreenWithBackground() : UIDialogScreen() {}
|
||||
protected:
|
||||
virtual void DrawBackground(UIContext &dc);
|
||||
virtual void sendMessage(const char *message, const char *value);
|
||||
virtual void sendMessage(const char *message, const char *value) override;
|
||||
virtual UI::EventReturn OnLanguageChange(UI::EventParams &e);
|
||||
};
|
||||
|
||||
|
@ -71,7 +71,7 @@ public:
|
|||
PromptScreen(std::string message, std::string yesButtonText, std::string noButtonText,
|
||||
std::function<void(bool)> callback = &NoOpVoidBool);
|
||||
|
||||
virtual void CreateViews();
|
||||
virtual void CreateViews() override;
|
||||
|
||||
private:
|
||||
UI::EventReturn OnYes(UI::EventParams &e);
|
||||
|
@ -89,7 +89,7 @@ public:
|
|||
|
||||
private:
|
||||
virtual void OnCompleted(DialogResult result);
|
||||
virtual bool ShowButtons() const { return true; }
|
||||
virtual bool ShowButtons() const override { return true; }
|
||||
std::map<std::string, std::pair<std::string, int>> langValuesMapping;
|
||||
std::map<std::string, std::string> titleCodeMapping;
|
||||
std::vector<FileInfo> langs_;
|
||||
|
@ -101,7 +101,7 @@ public:
|
|||
|
||||
private:
|
||||
virtual void OnCompleted(DialogResult result);
|
||||
virtual bool ShowButtons() const { return true; }
|
||||
virtual bool ShowButtons() const override { return true; }
|
||||
std::vector<ShaderInfo> shaders_;
|
||||
};
|
||||
|
||||
|
@ -109,10 +109,10 @@ class LogoScreen : public UIScreen {
|
|||
public:
|
||||
LogoScreen()
|
||||
: frames_(0), switched_(false) {}
|
||||
void key(const KeyInput &key);
|
||||
void update(InputState &input);
|
||||
void render();
|
||||
void sendMessage(const char *message, const char *value);
|
||||
bool key(const KeyInput &key) override;
|
||||
virtual void update(InputState &input) override;
|
||||
virtual void render() override;
|
||||
virtual void sendMessage(const char *message, const char *value) override;
|
||||
virtual void CreateViews() {}
|
||||
|
||||
private:
|
||||
|
@ -124,8 +124,8 @@ private:
|
|||
class CreditsScreen : public UIDialogScreenWithBackground {
|
||||
public:
|
||||
CreditsScreen() : frames_(0) {}
|
||||
void update(InputState &input);
|
||||
void render();
|
||||
virtual void update(InputState &input) override;
|
||||
virtual void render() override;
|
||||
|
||||
virtual void CreateViews();
|
||||
|
||||
|
|
|
@ -721,9 +721,10 @@ bool NativeKey(const KeyInput &key) {
|
|||
}
|
||||
#endif
|
||||
g_buttonTracker.Process(key);
|
||||
bool retval = false;
|
||||
if (screenManager)
|
||||
screenManager->key(key);
|
||||
return true;
|
||||
retval = screenManager->key(key);
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool NativeAxis(const AxisInput &key) {
|
||||
|
|
|
@ -214,7 +214,7 @@ TouchControlLayoutScreen::TouchControlLayoutScreen() {
|
|||
pickedControl_ = 0;
|
||||
};
|
||||
|
||||
void TouchControlLayoutScreen::touch(const TouchInput &touch) {
|
||||
bool TouchControlLayoutScreen::touch(const TouchInput &touch) {
|
||||
UIScreen::touch(touch);
|
||||
|
||||
using namespace UI;
|
||||
|
@ -275,6 +275,7 @@ void TouchControlLayoutScreen::touch(const TouchInput &touch) {
|
|||
pickedControl_->SavePosition();
|
||||
pickedControl_ = 0;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
void TouchControlLayoutScreen::onFinish(DialogResult reason) {
|
||||
|
|
|
@ -29,10 +29,10 @@ class TouchControlLayoutScreen : public UIDialogScreenWithBackground {
|
|||
public:
|
||||
TouchControlLayoutScreen();
|
||||
|
||||
virtual void CreateViews();
|
||||
virtual void touch(const TouchInput &touch);
|
||||
virtual void dialogFinished(const Screen *dialog, DialogResult result);
|
||||
virtual void onFinish(DialogResult reason);
|
||||
virtual void CreateViews() override;
|
||||
virtual bool touch(const TouchInput &touch) override;
|
||||
virtual void dialogFinished(const Screen *dialog, DialogResult result) override;
|
||||
virtual void onFinish(DialogResult reason) override;
|
||||
|
||||
protected:
|
||||
virtual UI::EventReturn OnReset(UI::EventParams &e);
|
||||
|
|
2
native
2
native
|
@ -1 +1 @@
|
|||
Subproject commit 6739fc565464ec4cb830ad16ca73605519ab3223
|
||||
Subproject commit a3e23f0ac6266507ecf24a5f4d59087a089ceda3
|
Loading…
Add table
Add a link
Reference in a new issue