mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-21 20:14:45 +00:00
imgui: gamepad capture, stopping propagation
This commit is contained in:
parent
752e4032c6
commit
d6c0943720
2 changed files with 23 additions and 4 deletions
|
@ -12,6 +12,10 @@ public:
|
|||
static void RemoveLayer(Layer* layer);
|
||||
|
||||
virtual void Draw() = 0;
|
||||
|
||||
virtual bool ShouldGrabGamepad() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ImGui
|
|
@ -71,10 +71,7 @@ void Shutdown(const vk::Device& device) {
|
|||
}
|
||||
|
||||
bool ProcessEvent(SDL_Event* event) {
|
||||
const bool used = Sdl::ProcessEvent(event);
|
||||
if (!used) {
|
||||
return false;
|
||||
}
|
||||
Sdl::ProcessEvent(event);
|
||||
switch (event->type) {
|
||||
case SDL_EVENT_MOUSE_MOTION:
|
||||
case SDL_EVENT_MOUSE_WHEEL:
|
||||
|
@ -85,6 +82,15 @@ bool ProcessEvent(SDL_Event* event) {
|
|||
case SDL_EVENT_KEY_DOWN:
|
||||
case SDL_EVENT_KEY_UP:
|
||||
return GetIO().WantCaptureKeyboard;
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_UP:
|
||||
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
|
||||
case SDL_EVENT_GAMEPAD_ADDED:
|
||||
case SDL_EVENT_GAMEPAD_REMOVED:
|
||||
case SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN:
|
||||
case SDL_EVENT_GAMEPAD_TOUCHPAD_UP:
|
||||
case SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION:
|
||||
return (GetIO().BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -109,8 +115,17 @@ void NewFrame() {
|
|||
Sdl::NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
bool capture_gamepad = false;
|
||||
for (auto* layer : layers) {
|
||||
layer->Draw();
|
||||
if (layer->ShouldGrabGamepad()) {
|
||||
capture_gamepad = true;
|
||||
}
|
||||
}
|
||||
if (capture_gamepad) {
|
||||
GetIO().BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||
} else {
|
||||
GetIO().BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue