mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 16:32:39 +00:00
sdl window: mouse capture var
This commit is contained in:
parent
015550384c
commit
03d24d0fd5
@ -83,7 +83,7 @@ void Initialize(const ::Vulkan::Instance& instance, const Frontend::WindowSDL& w
|
|||||||
StyleColorsDark();
|
StyleColorsDark();
|
||||||
|
|
||||||
::Core::Devtools::Layer::SetupSettings();
|
::Core::Devtools::Layer::SetupSettings();
|
||||||
Sdl::Init(window.GetSdlWindow());
|
Sdl::Init(&window);
|
||||||
|
|
||||||
const Vulkan::InitInfo vk_info{
|
const Vulkan::InitInfo vk_info{
|
||||||
.instance = instance.GetInstance(),
|
.instance = instance.GetInstance(),
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
|
|
||||||
// SDL
|
// SDL
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
#include "sdl_window.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_instance.h"
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#include <TargetConditionals.h>
|
#include <TargetConditionals.h>
|
||||||
#endif
|
#endif
|
||||||
@ -23,6 +26,9 @@ namespace ImGui::Sdl {
|
|||||||
|
|
||||||
// SDL Data
|
// SDL Data
|
||||||
struct SdlData {
|
struct SdlData {
|
||||||
|
// SDL Wrapper
|
||||||
|
const Frontend::WindowSDL* wrapper{};
|
||||||
|
|
||||||
SDL_Window* window{};
|
SDL_Window* window{};
|
||||||
SDL_WindowID window_id{};
|
SDL_WindowID window_id{};
|
||||||
Uint64 time{};
|
Uint64 time{};
|
||||||
@ -501,7 +507,7 @@ static void SetupPlatformHandles(ImGuiViewport* viewport, SDL_Window* window) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Init(SDL_Window* window) {
|
bool Init(const Frontend::WindowSDL* wrapper) {
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
|
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
|
||||||
@ -514,8 +520,9 @@ bool Init(SDL_Window* window) {
|
|||||||
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests
|
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests
|
||||||
// (optional, rarely used)
|
// (optional, rarely used)
|
||||||
|
|
||||||
bd->window = window;
|
bd->wrapper = wrapper;
|
||||||
bd->window_id = SDL_GetWindowID(window);
|
bd->window = wrapper->GetSdlWindow();
|
||||||
|
bd->window_id = SDL_GetWindowID(bd->window);
|
||||||
|
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
platform_io.Platform_SetClipboardTextFn = SetClipboardText;
|
platform_io.Platform_SetClipboardTextFn = SetClipboardText;
|
||||||
@ -543,7 +550,7 @@ bool Init(SDL_Window* window) {
|
|||||||
// Set platform dependent data in viewport
|
// Set platform dependent data in viewport
|
||||||
// Our mouse update function expect PlatformHandle to be filled for the main viewport
|
// Our mouse update function expect PlatformHandle to be filled for the main viewport
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
SetupPlatformHandles(main_viewport, window);
|
SetupPlatformHandles(main_viewport, bd->window);
|
||||||
|
|
||||||
// From 2.0.5: Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't
|
// From 2.0.5: Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't
|
||||||
// emit the event. Without this, when clicking to gain focus, our widgets wouldn't activate even
|
// emit the event. Without this, when clicking to gain focus, our widgets wouldn't activate even
|
||||||
@ -593,7 +600,6 @@ static void UpdateMouseData() {
|
|||||||
// (below)
|
// (below)
|
||||||
// SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries
|
// SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries
|
||||||
// shouldn't e.g. trigger other operations outside
|
// shouldn't e.g. trigger other operations outside
|
||||||
SDL_CaptureMouse((bd->mouse_buttons_down != 0) ? true : false);
|
|
||||||
SDL_Window* focused_window = SDL_GetKeyboardFocus();
|
SDL_Window* focused_window = SDL_GetKeyboardFocus();
|
||||||
const bool is_app_focused = (bd->window == focused_window);
|
const bool is_app_focused = (bd->window == focused_window);
|
||||||
|
|
||||||
@ -662,7 +668,9 @@ static void UpdateMouseCursor() {
|
|||||||
SDL_SetCursor(expected_cursor); // SDL function doesn't have an early out (see #6113)
|
SDL_SetCursor(expected_cursor); // SDL function doesn't have an early out (see #6113)
|
||||||
bd->mouse_last_cursor = expected_cursor;
|
bd->mouse_last_cursor = expected_cursor;
|
||||||
}
|
}
|
||||||
SDL_ShowCursor();
|
if (!bd->wrapper->isCapturingMouse()) {
|
||||||
|
SDL_ShowCursor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,9 +10,13 @@ struct SDL_Renderer;
|
|||||||
struct SDL_Gamepad;
|
struct SDL_Gamepad;
|
||||||
typedef union SDL_Event SDL_Event;
|
typedef union SDL_Event SDL_Event;
|
||||||
|
|
||||||
|
namespace Frontend {
|
||||||
|
class WindowSDL;
|
||||||
|
}
|
||||||
|
|
||||||
namespace ImGui::Sdl {
|
namespace ImGui::Sdl {
|
||||||
|
|
||||||
bool Init(SDL_Window* window);
|
bool Init(const Frontend::WindowSDL* window);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
void NewFrame();
|
void NewFrame();
|
||||||
bool ProcessEvent(const SDL_Event* event);
|
bool ProcessEvent(const SDL_Event* event);
|
||||||
|
@ -58,6 +58,10 @@ public:
|
|||||||
return is_open;
|
return is_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isCapturingMouse() const {
|
||||||
|
return is_capturing_mouse;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] SDL_Window* GetSdlWindow() const {
|
[[nodiscard]] SDL_Window* GetSdlWindow() const {
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
@ -83,6 +87,8 @@ private:
|
|||||||
SDL_Window* window{};
|
SDL_Window* window{};
|
||||||
bool is_shown{};
|
bool is_shown{};
|
||||||
bool is_open{true};
|
bool is_open{true};
|
||||||
|
|
||||||
|
bool is_capturing_mouse{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Frontend
|
} // namespace Frontend
|
||||||
|
Loading…
Reference in New Issue
Block a user