imgui: rework gamepad navigation

This commit is contained in:
Vinicius Rangel 2024-09-19 21:43:58 -03:00
commit dd65ee3683
No known key found for this signature in database
GPG key ID: A5B154D904B761D9
7 changed files with 9 additions and 37 deletions

View file

@ -31,10 +31,6 @@ public:
void Finish(); void Finish();
void Draw() override; void Draw() override;
bool ShouldGrabGamepad() override {
return false;
}
}; };
}; // namespace Libraries::NpTrophy }; // namespace Libraries::NpTrophy

View file

@ -39,11 +39,6 @@ Error PS4_SYSV_ABI sceMsgDialogGetResult(DialogResult* result) {
if (result == nullptr) { if (result == nullptr) {
return Error::ARG_NULL; return Error::ARG_NULL;
} }
for (const auto v : result->reserved) {
if (v != 0) {
return Error::PARAM_INVALID;
}
}
*result = g_result; *result = g_result;
return Error::OK; return Error::OK;
} }

View file

@ -266,11 +266,13 @@ void MsgDialogUi::Draw() {
CentralizeWindow(); CentralizeWindow();
SetNextWindowSize(window_size); SetNextWindowSize(window_size);
SetNextWindowFocus();
SetNextWindowCollapsed(false); SetNextWindowCollapsed(false);
if (first_render || !io.NavActive) {
SetNextWindowFocus();
}
KeepNavHighlight(); KeepNavHighlight();
// Hack to allow every dialog to have a unique window if (Begin("Message Dialog##MessageDialog", nullptr,
if (Begin("Message Dialog##MessageDialog", nullptr, ImGuiWindowFlags_NoSavedSettings)) { ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings)) {
switch (state->GetMode()) { switch (state->GetMode()) {
case MsgDialogMode::USER_MSG: case MsgDialogMode::USER_MSG:
DrawUser(); DrawUser();

View file

@ -174,10 +174,6 @@ public:
void SetProgressBarValue(u32 value, bool increment); void SetProgressBarValue(u32 value, bool increment);
void Draw() override; void Draw() override;
bool ShouldGrabGamepad() override {
return true;
}
}; };
// Utility function to show a message dialog // Utility function to show a message dialog

View file

@ -12,10 +12,6 @@ public:
static void RemoveLayer(Layer* layer); static void RemoveLayer(Layer* layer);
virtual void Draw() = 0; virtual void Draw() = 0;
virtual bool ShouldGrabGamepad() {
return false;
}
}; };
} // namespace ImGui } // namespace ImGui

View file

@ -10,7 +10,7 @@ void ImGui::Layers::VideoInfo::Draw() {
m_show = IsKeyPressed(ImGuiKey_F10, false) ^ m_show; m_show = IsKeyPressed(ImGuiKey_F10, false) ^ m_show;
if (m_show) { if (m_show) {
if (Begin("Video Info")) { if (Begin("Video Info", 0, ImGuiWindowFlags_NoNav)) {
Text("Frame time: %.3f ms (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); Text("Frame time: %.3f ms (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
} }
End(); End();

View file

@ -9,6 +9,7 @@
#include "imgui_core.h" #include "imgui_core.h"
#include "imgui_impl_sdl3.h" #include "imgui_impl_sdl3.h"
#include "imgui_impl_vulkan.h" #include "imgui_impl_vulkan.h"
#include "imgui_internal.h"
#include "sdl_window.h" #include "sdl_window.h"
#include "texture_manager.h" #include "texture_manager.h"
#include "video_core/renderer_vulkan/renderer_vulkan.h" #include "video_core/renderer_vulkan/renderer_vulkan.h"
@ -97,24 +98,19 @@ void Shutdown(const vk::Device& device) {
bool ProcessEvent(SDL_Event* event) { bool ProcessEvent(SDL_Event* event) {
Sdl::ProcessEvent(event); Sdl::ProcessEvent(event);
switch (event->type) { switch (event->type) {
// Don't block release/up events
case SDL_EVENT_MOUSE_MOTION: case SDL_EVENT_MOUSE_MOTION:
case SDL_EVENT_MOUSE_WHEEL: case SDL_EVENT_MOUSE_WHEEL:
case SDL_EVENT_MOUSE_BUTTON_DOWN: case SDL_EVENT_MOUSE_BUTTON_DOWN:
case SDL_EVENT_MOUSE_BUTTON_UP:
return GetIO().WantCaptureMouse; return GetIO().WantCaptureMouse;
case SDL_EVENT_TEXT_INPUT: case SDL_EVENT_TEXT_INPUT:
case SDL_EVENT_KEY_DOWN: case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
return GetIO().WantCaptureKeyboard; return GetIO().WantCaptureKeyboard;
case SDL_EVENT_GAMEPAD_BUTTON_DOWN: case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_EVENT_GAMEPAD_BUTTON_UP:
case SDL_EVENT_GAMEPAD_AXIS_MOTION: 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_DOWN:
case SDL_EVENT_GAMEPAD_TOUCHPAD_UP:
case SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION: case SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION:
return (GetIO().BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; return GetIO().NavActive;
default: default:
return false; return false;
} }
@ -138,17 +134,8 @@ void NewFrame() {
Sdl::NewFrame(); Sdl::NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
bool capture_gamepad = false;
for (auto* layer : layers) { for (auto* layer : layers) {
layer->Draw(); layer->Draw();
if (layer->ShouldGrabGamepad()) {
capture_gamepad = true;
}
}
if (capture_gamepad) {
GetIO().BackendFlags |= ImGuiBackendFlags_HasGamepad;
} else {
GetIO().BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
} }
} }