ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
59.11k stars 10.09k forks source link

Support for Windows Pointer Events? #3453

Open acidicoala opened 3 years ago

acidicoala commented 3 years ago

Config/Build Information

Dear ImGui 1.78 (17800)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1927
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx11
io.ConfigFlags: 0x00000000
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigWindowsMemoryCompactTimer = 60.0f
io.BackendFlags: 0x0000000E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
--------------------------------
io.Fonts: 2 fonts, Flags: 0x00000000, TexSize: 512,1024
io.DisplaySize: 1262.00,753.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

My Issue/Question:

Hello there. Some windows instead of sending typical mouse input messages that ImGui expects (MS docs reference), send pointer event messages (MS docs reference). Therefore mouse input does not get processed with ImGui_ImplWin32_WndProcHandler. On my end I am using a hacky fix in which I substitute pointer events with mouse input messages that ImGui expects. For example:

LRESULT __stdcall WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    // ...
    switch(uMsg)
    {
        case WM_POINTERDOWN:
            uMsg = WM_LBUTTONDOWN;
            break;
        case WM_POINTERUP:
            uMsg = WM_LBUTTONUP;
            break;
        case WM_POINTERWHEEL:
            uMsg = WM_MOUSEWHEEL;
            break;
        case WM_POINTERUPDATE:
            uMsg = WM_SETCURSOR;
            break;
    }
    ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam);
    // ...
}

I was wondering if there are any plans to support such pointer event messages in the future? Or does it already exist and I've just missed it?

ocornut commented 3 years ago

Hello,

I was wondering if there are any plans to support such pointer event messages in the future? Or does it already exist and I've just missed it?

It's not supported yet. I don't have such device and wouldn't be able to test for it. Pull requests would be appreciated but I think they would need to be mindful of things discussed e.g. in #2334, #2372, #2729, #2650.

-Omar

ocornut commented 1 year ago

Hello there. Some windows instead of sending typical mouse input messages that ImGui expects

Could you elaborate on "some windows" ? AFAIK the behavior is documented here: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enablemouseinpointer

Can you confirm your setup and if you are calling EnableMouseInPointer() and what is the result of IsMouseInPointerEnabled()?

If you have mouse-in-pointer enabled then I guess it means you are handling WM_POINTER events and you can convert them to mouse events.

This is wrong:

    switch(uMsg)
    {
        case WM_POINTERDOWN:
            uMsg = WM_LBUTTONDOWN;
            break;
        case WM_POINTERUP:
            uMsg = WM_LBUTTONUP;
            break;
        case WM_POINTERWHEEL:
            uMsg = WM_MOUSEWHEEL;
            break;
        case WM_POINTERUPDATE:
            uMsg = WM_SETCURSOR;
            break;
    }
    ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam);

Because the meaning of wParam and lParam is different between WM_POINTER messages and Mouse equivalent, so this need so be remapped.

If there is a confirmation that you are using EnableMouseInPointer = TRUE; I am curious why. We could consider adding that support in imgui_impl_win32 but it seems like a edge case for something you would normally already be able to do if EnableMouseInPointer = TRUE.