From dfa1bb0ac782e9e9d88f2e42981b50f84282fc94 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 6 Oct 2022 14:27:27 +0200 Subject: [PATCH] Backends: OSX: Fixed mouse inputs on flipped views. (#5756) --- backends/imgui_impl_osx.mm | 8 ++++++-- docs/CHANGELOG.txt | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backends/imgui_impl_osx.mm b/backends/imgui_impl_osx.mm index 63d7d06d..054776ff 100644 --- a/backends/imgui_impl_osx.mm +++ b/backends/imgui_impl_osx.mm @@ -23,12 +23,13 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2022-10-06: Fixed mouse inputs on flipped views. // 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported). // 2022-05-03: Inputs: Removed ImGui_ImplOSX_HandleEvent() from backend API in favor of backend automatically handling event capture. // 2022-04-27: Misc: Store backend data in a per-context struct, allowing to use this backend with multiple contexts. // 2022-03-22: Inputs: Monitor NSKeyUp events to catch missing keyUp for key when user press Cmd + key // 2022-02-07: Inputs: Forward keyDown/keyUp events to OS when unused by dear imgui. -// 2022-01-31: Fix building with old Xcode versions that are missing gamepad features. +// 2022-01-31: Fixed building with old Xcode versions that are missing gamepad features. // 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. // 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[]. // 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+). @@ -631,7 +632,10 @@ static bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view) { NSPoint mousePoint = event.locationInWindow; mousePoint = [view convertPoint:mousePoint fromView:nil]; - mousePoint = NSMakePoint(mousePoint.x, view.bounds.size.height - mousePoint.y); + if ([view isFlipped]) + mousePoint = NSMakePoint(mousePoint.x, mousePoint.y); + else + mousePoint = NSMakePoint(mousePoint.x, view.bounds.size.height - mousePoint.y); io.AddMousePosEvent((float)mousePoint.x, (float)mousePoint.y); return io.WantCaptureMouse; } diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 552b2610..6b97dcdf 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -176,6 +176,7 @@ Other Changes: - Backends: Metal: Add dispatch synchronization. (#5447) [@luigifcruz] - Backends: Metal: Update deprecated property 'sampleCount'->'rasterSampleCount'. (#5603) [@dcvz] - Backends: Vulkan: Added experimental ImGui_ImplVulkan_RemoveTexture() for api symetry. (#914, #5738). +- Backends: OSX: Fixed mouse inputs on flipped views. (#5756) [@Nemirtingas] - Backends: OSX: Fixes to support full app creation in C++. (#5403) [@stack]