Browse Source

Backends: OSX: Fixed mouse inputs on flipped views. (#5756)

ocornut 2 years ago
parent
commit
dfa1bb0ac7
2 changed files with 7 additions and 2 deletions
  1. 6 2
      backends/imgui_impl_osx.mm
  2. 1 0
      docs/CHANGELOG.txt

+ 6 - 2
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;
     }

+ 1 - 0
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]