UI: Pass touch/button releases to all screens.

This way, if you go into a menu and release a button, it still gets
noticed.  This also goes for axis centering (and therefore vkeys.)

Also, move TOUCH_RELEASE_ALL to all screen switches.
This commit is contained in:
Unknown W. Brackets 2019-03-03 17:50:54 -08:00
parent 2d5acc83b6
commit 1205753289
4 changed files with 51 additions and 33 deletions

View File

@ -381,10 +381,7 @@ static void AfterStateBoot(SaveState::Status status, const std::string &message,
void EmuScreen::sendMessage(const char *message, const char *value) {
// External commands, like from the Windows UI.
if (!strcmp(message, "pause") && screenManager()->topScreen() == this) {
releaseButtons();
screenManager()->push(new GamePauseScreen(gamePath_));
} else if (!strcmp(message, "lost_focus")) {
releaseButtons();
} else if (!strcmp(message, "stop")) {
// We will push MainScreen in update().
PSP_Shutdown();
@ -420,15 +417,12 @@ void EmuScreen::sendMessage(const char *message, const char *value) {
RecreateViews();
} else if (!strcmp(message, "control mapping") && screenManager()->topScreen() == this) {
UpdateUIState(UISTATE_PAUSEMENU);
releaseButtons();
screenManager()->push(new ControlMappingScreen());
} else if (!strcmp(message, "display layout editor") && screenManager()->topScreen() == this) {
UpdateUIState(UISTATE_PAUSEMENU);
releaseButtons();
screenManager()->push(new DisplayLayoutScreen());
} else if (!strcmp(message, "settings") && screenManager()->topScreen() == this) {
UpdateUIState(UISTATE_PAUSEMENU);
releaseButtons();
screenManager()->push(new GameSettingsScreen(gamePath_));
} else if (!strcmp(message, "gpu dump next frame")) {
if (gpu)
@ -1001,7 +995,6 @@ void EmuScreen::CreateViews() {
}
UI::EventReturn EmuScreen::OnDevTools(UI::EventParams &params) {
releaseButtons();
I18NCategory *dev = GetI18NCategory("Developer");
DevMenu *devMenu = new DevMenu(dev);
if (params.v)
@ -1060,7 +1053,6 @@ void EmuScreen::update() {
// This is here to support the iOS on screen back button.
if (pauseTrigger_) {
pauseTrigger_ = false;
releaseButtons();
screenManager()->push(new GamePauseScreen(gamePath_));
}
@ -1374,15 +1366,6 @@ void EmuScreen::autoLoad() {
}
}
// TODO: Add generic loss-of-focus handling for Screens, use this.
void EmuScreen::releaseButtons() {
TouchInput input;
input.flags = TOUCH_RELEASE_ALL;
input.timestamp = time_now_d();
input.id = 0;
touch(input);
}
void EmuScreen::resized() {
RecreateViews();
}

View File

@ -66,8 +66,6 @@ private:
void setVKeyAnalogX(int stick, int virtualKeyMin, int virtualKeyMax);
void setVKeyAnalogY(int stick, int virtualKeyMin, int virtualKeyMax);
void releaseButtons();
void autoLoad();
void checkPowerDown();

View File

@ -157,8 +157,12 @@ public:
}
} else if (hovering_ && key.deviceId == DEVICE_ID_MOUSE && key.keyCode == NKCODE_EXT_MOUSEBUTTON_2) {
// If it's the right mouse button, and it's not otherwise mapped, show the info also.
if (key.flags & KEY_UP) {
if (key.flags & KEY_DOWN) {
showInfoPressed_ = true;
}
if ((key.flags & KEY_UP) && showInfoPressed_) {
showInfo = true;
showInfoPressed_ = false;
}
}
@ -208,6 +212,7 @@ private:
double holdStart_ = 0.0;
bool holdEnabled_ = true;
bool showInfoPressed_ = false;
bool hovering_ = false;
};

View File

@ -1,5 +1,6 @@
#include "base/display.h"
#include "base/logging.h"
#include "base/timeutil.h"
#include "input/input_state.h"
#include "ui/screen.h"
#include "ui/ui.h"
@ -71,30 +72,46 @@ void ScreenManager::switchToNext() {
bool ScreenManager::touch(const TouchInput &touch) {
std::lock_guard<std::recursive_mutex> guard(inputLock_);
if (!stack_.empty()) {
bool result = false;
// Send release all events to every screen layer.
if (touch.flags & TOUCH_RELEASE_ALL) {
for (auto &layer : stack_) {
Screen *screen = layer.screen;
result = layer.screen->touch(screen->transformTouch(touch));
}
} else if (!stack_.empty()) {
Screen *screen = stack_.back().screen;
return screen->touch(screen->transformTouch(touch));
} else {
return false;
result = stack_.back().screen->touch(screen->transformTouch(touch));
}
return result;
}
bool ScreenManager::key(const KeyInput &key) {
std::lock_guard<std::recursive_mutex> guard(inputLock_);
if (!stack_.empty()) {
return stack_.back().screen->key(key);
} else {
return false;
bool result = false;
// Send key up to every screen layer.
if (key.flags & KEY_UP) {
for (auto &layer : stack_) {
result = layer.screen->key(key);
}
} else if (!stack_.empty()) {
result = stack_.back().screen->key(key);
}
return result;
}
bool ScreenManager::axis(const AxisInput &axis) {
std::lock_guard<std::recursive_mutex> guard(inputLock_);
if (!stack_.empty()) {
return stack_.back().screen->axis(axis);
} else {
return false;
bool result = false;
// Send center axis to every screen layer.
if (axis.value == 0) {
for (auto &layer : stack_) {
result = layer.screen->axis(axis);
}
} else if (!stack_.empty()) {
result = stack_.back().screen->axis(axis);
}
return result;
}
void ScreenManager::deviceLost() {
@ -158,6 +175,13 @@ void ScreenManager::render() {
void ScreenManager::sendMessage(const char *msg, const char *value) {
if (!strcmp(msg, "recreateviews"))
RecreateAllViews();
if (!strcmp(msg, "lost_focus")) {
TouchInput input;
input.flags = TOUCH_RELEASE_ALL;
input.timestamp = time_now_d();
input.id = 0;
touch(input);
}
if (!stack_.empty())
stack_.back().screen->sendMessage(msg, value);
}
@ -188,7 +212,15 @@ void ScreenManager::push(Screen *screen, int layerFlags) {
if (screen->isTransparent()) {
layerFlags |= LAYER_TRANSPARENT;
}
UI::SetFocusedView(0);
// Release touches and unfocus.
UI::SetFocusedView(nullptr);
TouchInput input;
input.flags = TOUCH_RELEASE_ALL;
input.timestamp = time_now_d();
input.id = 0;
touch(input);
Layer layer = {screen, layerFlags};
stack_.push_back(layer);
}