Skip to content

Commit

Permalink
Minor amend 9028088 (#3261)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed May 25, 2020
1 parent 43f79aa commit 9c209d5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Other Changes:
- Backends: Vulkan: Fixed error in if initial frame has no vertices. (#3177)
- Backends: Vulkan: Fixed edge case where render callbacks wouldn't be called if the ImDrawData
structure didn't have any vertices. (#2697) [@kudaba]
- Backends: OSX: Added workaround to avoid fast mouse clicks. (#3261, #1992, #2525) [@nburrus]
- Examples: Apple: Fixed example_apple_metal and example_apple_opengl2 using imgui_impl_osx.mm
not forwarding right and center mouse clicks. (#3260) [@nburrus]

Expand Down
2 changes: 1 addition & 1 deletion examples/imgui_impl_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ enum GlfwClientApi
static GLFWwindow* g_Window = NULL; // Main window
static GlfwClientApi g_ClientApi = GlfwClientApi_Unknown;
static double g_Time = 0.0;
static bool g_MouseJustPressed[5] = { false, false, false, false, false };
static bool g_MouseJustPressed[ImGuiMouseButton_COUNT] = {};
static GLFWcursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {};
static bool g_InstalledCallbacks = false;

Expand Down
15 changes: 6 additions & 9 deletions examples/imgui_impl_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
static CFAbsoluteTime g_Time = 0.0;
static NSCursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {};
static bool g_MouseCursorHidden = false;
static bool g_MouseJustPressed[5] = { false, false, false, false, false };
static bool g_MouseDown[5] = { false, false, false, false, false };
static bool g_MouseJustPressed[ImGuiMouseButton_COUNT] = {};
static bool g_MouseDown[ImGuiMouseButton_COUNT] = {};

// Undocumented methods for creating cursors.
@interface NSCursor()
Expand Down Expand Up @@ -126,9 +126,9 @@ void ImGui_ImplOSX_Shutdown()

static void ImGui_ImplOSX_UpdateMouseCursorAndButtons()
{
// Update buttons
ImGuiIO& io = ImGui::GetIO();

for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown) && i < IM_ARRAYSIZE(g_MouseJustPressed); i++)
for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
{
// If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
io.MouseDown[i] = g_MouseJustPressed[i] || g_MouseDown[i];
Expand Down Expand Up @@ -208,11 +208,8 @@ bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view)
if (event.type == NSEventTypeLeftMouseDown || event.type == NSEventTypeRightMouseDown || event.type == NSEventTypeOtherMouseDown)
{
int button = (int)[event buttonNumber];
if (button >= 0 && button < IM_ARRAYSIZE(g_MouseJustPressed))
{
g_MouseJustPressed[button] = true;
g_MouseDown[button] = true;
}
if (button >= 0 && button < IM_ARRAYSIZE(g_MouseDown))
g_MouseDown[button] = g_MouseJustPressed[button] = true;
return io.WantCaptureMouse;
}

Expand Down
2 changes: 1 addition & 1 deletion imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ struct ImGuiIO
//------------------------------------------------------------------

ImVec2 MousePos; // Mouse position, in pixels. Set to ImVec2(-FLT_MAX,-FLT_MAX) if mouse is unavailable (on another screen, etc.)
bool MouseDown[5]; // Mouse buttons: 0=left, 1=right, 2=middle + extras. ImGui itself mostly only uses left button (BeginPopupContext** are using right button). Others buttons allows us to track if the mouse is being used by your application + available to user as a convenience via IsMouse** API.
bool MouseDown[5]; // Mouse buttons: 0=left, 1=right, 2=middle + extras (ImGuiMouseButton_COUNT == 5). Dear ImGui mostly uses left and right buttons. Others buttons allows us to track if the mouse is being used by your application + available to user as a convenience via IsMouse** API.
float MouseWheel; // Mouse wheel Vertical: 1 unit scrolls about 5 lines text.
float MouseWheelH; // Mouse wheel Horizontal. Most users don't have a mouse with an horizontal wheel, may not be filled by all back-ends.
bool KeyCtrl; // Keyboard modifier pressed: Control
Expand Down

0 comments on commit 9c209d5

Please sign in to comment.