Hide the cursor only when capturing the mouse

Clean up mouse cursor code to use ImGuiMouseCursor_None
Ignore Pi::DrawGUI as it doesn't make sense for cursors
master
Webster Sheets 2020-03-24 12:33:11 -04:00
parent 8990fbeb96
commit 03e297dd61
4 changed files with 20 additions and 17 deletions

View File

@ -290,6 +290,10 @@ float Input::JoystickAxisState(int joystick, int axis)
void Input::SetCapturingMouse(bool grabbed)
{
// early-out to avoid changing (possibly) expensive WM state
if (grabbed == m_capturingMouse)
return;
SDL_SetWindowGrab(Pi::renderer->GetSDLWindow(), SDL_bool(grabbed));
SDL_SetRelativeMouseMode(SDL_bool(grabbed));
m_capturingMouse = grabbed;

View File

@ -132,7 +132,14 @@ public:
memcpy(motion, mouseMotion, sizeof(int) * 2);
}
// Capturing the mouse hides the cursor, puts the mouse into relative mode,
// and passes all mouse inputs to the input system, regardless of whether
// ImGui is using them or not.
bool IsCapturingMouse() const { return m_capturingMouse; }
// Set whether the application would like to capture the mouse.
// To avoid contention between different classes, please only call this when the state
// has actually changed.
void SetCapturingMouse(bool enabled);
sigc::signal<void, SDL_Keysym *> onKeyPress;

View File

@ -885,7 +885,8 @@ void Pi::HandleEvents()
Pi::pigui->ProcessEvent(&event);
if (Pi::pigui->WantCaptureMouse()) {
// Input system takes priority over mouse events when capturing the mouse
if (Pi::pigui->WantCaptureMouse() && !Pi::input.IsCapturingMouse()) {
// don't process mouse event any further, imgui already handled it
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:

View File

@ -4,6 +4,7 @@
#include "PiGui.h"
#include "Pi.h"
#include "graphics/opengl/TextureGL.h" // nasty, usage of GL is implementation specific
#include "imgui/imgui.h"
// Use GLEW instead of GL3W.
#define IMGUI_IMPL_OPENGL_LOADER_GLEW 1
#include "imgui/examples/imgui_impl_opengl3.h"
@ -375,15 +376,13 @@ void *PiGui::makeTexture(unsigned char *pixels, int width, int height)
void PiGui::NewFrame(SDL_Window *window)
{
PROFILE_SCOPED()
// Ask ImGui to hide OS cursor if GUI is not being drawn:
// it will do this if MouseDrawCursor is true. After the frame
// is created, we set the actual cursor draw state.
#if 0 // Mouse cursors are set via the OS facilities.
// See also below.
if (!Pi::DrawGUI) {
ImGui::GetIO().MouseDrawCursor = true;
// Ask ImGui to hide OS cursor if we're capturing it for input:
// it will do this if GetMouseCursor == ImGuiMouseCursor_None.
if (Pi::input.IsCapturingMouse()) {
ImGui::SetMouseCursor(ImGuiMouseCursor_None);
}
#endif
switch (Pi::renderer->GetRendererType()) {
default:
case Graphics::RENDERER_DUMMY:
@ -398,14 +397,6 @@ void PiGui::NewFrame(SDL_Window *window)
Pi::renderer->CheckRenderErrors(__FUNCTION__, __LINE__);
ImGui::SetMouseCursor(ImGuiMouseCursor_Arrow);
#if 0 // Mouse cursors are set via the OS facilities.
// We may want to revisit this at a later date.
if(Pi::DoingMouseGrab() || !Pi::DrawGUI) {
ImGui::GetIO().MouseDrawCursor = false;
} else {
ImGui::GetIO().MouseDrawCursor = true;
}
#endif
}
void PiGui::RunHandler(double delta, std::string handler)