git repos / sago_multi_scrambler_puzzle2

commit 34993164

Poul Sander · 2024-09-29 14:25
3499316435e75f4f32c07463af0b33ce9c43748f patch · browse files
parent 853c582c03baceb8903169a490bb5b87500f6abd

Make the ImGUI work with scaling. It might not look good but the mouse is now over what it sees.

Changed files

M src/Libs/imgui/backends/imgui_impl_sdl2.cpp before
diff --git a/src/Libs/imgui/backends/imgui_impl_sdl2.cpp b/src/Libs/imgui/backends/imgui_impl_sdl2.cpp index a18c013..c3332b4 100644 --- a/src/Libs/imgui/backends/imgui_impl_sdl2.cpp +++ b/src/Libs/imgui/backends/imgui_impl_sdl2.cpp
@@ -125,6 +125,14 @@ struct ImGui_ImplSDL2_Data
ImGui_ImplSDL2_Data() { memset((void*)this, 0, sizeof(*this)); }
};
+static ImVec2 RenderScale(SDL_Renderer* Renderer) {
+ ImVec2 res;
+ res.x = 1.0f;
+ res.y = 1.0f;
+ SDL_RenderGetScale(Renderer, &res.x, &res.y);
+ return res;
+}
+
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
@@ -568,7 +576,8 @@ static void ImGui_ImplSDL2_UpdateMouseData()
int window_x, window_y, mouse_x_global, mouse_y_global;
SDL_GetGlobalMouseState(&mouse_x_global, &mouse_y_global);
SDL_GetWindowPosition(bd->Window, &window_x, &window_y);
- io.AddMousePosEvent((float)(mouse_x_global - window_x), (float)(mouse_y_global - window_y));
+ ImVec2 scale = RenderScale(bd->Renderer);
+ io.AddMousePosEvent((float)(mouse_x_global - window_x)/scale.x, (float)(mouse_y_global - window_y)/scale.y);
}
}
}