mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-01 22:30:42 -07:00
overlay: fix mouse cursor getting stuck in wrong shape when leaving and coming back to window (#283)
## Link to GitHub Issue, if one exists Fixes #27 ## Description of change In standalone configurator mode, when a mouse cursor moves outside the window and comes back, it may get stuck in the wrong cursor type (e.g., get stuck in horizontal resize mode). This is a side effect of software rendering we do that doesn't deal nicely with mouse events (i.e., not at all). ## Compiling Should be fine. ## Testing Testing spicecfg, spice -cfg, spice64 -cfg, and in-game overlay.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include "cfg/configurator.h"
|
||||||
#include "games/io.h"
|
#include "games/io.h"
|
||||||
#include "launcher/launcher.h"
|
#include "launcher/launcher.h"
|
||||||
#include "launcher/superexit.h"
|
#include "launcher/superexit.h"
|
||||||
@@ -378,10 +379,27 @@ void ImGui_ImplSpice_NewFrame() {
|
|||||||
// update OS mouse position
|
// update OS mouse position
|
||||||
ImGui_ImplSpice_UpdateMousePos();
|
ImGui_ImplSpice_UpdateMousePos();
|
||||||
|
|
||||||
// update OS mouse cursor with the cursor requested by imgui
|
if (cfg::CONFIGURATOR_STANDALONE) {
|
||||||
ImGuiMouseCursor mouse_cursor = io.MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor();
|
// if cursor is inside the client area, always set the OS cursor to what ImGui wants
|
||||||
if (g_LastMouseCursor != mouse_cursor) {
|
// this is to deal with cases where mouse cursor changes outside the client rect and comes
|
||||||
g_LastMouseCursor = mouse_cursor;
|
// back into the window
|
||||||
ImGui_ImplSpice_UpdateMouseCursor();
|
// i'm sure there might be better ways to deal with this but this works so whatever, right?
|
||||||
|
RECT client_rect;
|
||||||
|
if (GetClientRect(g_hWnd, &client_rect)) {
|
||||||
|
POINT cursor;
|
||||||
|
if (GetCursorPos(&cursor) && ScreenToClient(g_hWnd, &cursor)) {
|
||||||
|
if (client_rect.left < cursor.x && cursor.x < client_rect.right &&
|
||||||
|
client_rect.top < cursor.y && cursor.y < client_rect.bottom) {
|
||||||
|
ImGui_ImplSpice_UpdateMouseCursor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// update OS mouse cursor with the cursor requested by imgui
|
||||||
|
ImGuiMouseCursor mouse_cursor = io.MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor();
|
||||||
|
if (g_LastMouseCursor != mouse_cursor) {
|
||||||
|
g_LastMouseCursor = mouse_cursor;
|
||||||
|
ImGui_ImplSpice_UpdateMouseCursor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user