Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to add touchscreen support to SDL version on a raspberry pi #5693

Open
stash763 opened this issue Sep 20, 2022 · 3 comments
Open

Trying to add touchscreen support to SDL version on a raspberry pi #5693

stash763 opened this issue Sep 20, 2022 · 3 comments

Comments

@stash763
Copy link

Hello,

I'm not sure if this is the right place to post, I'm trying to modify the imgui_impl_sdl.cpp file to add touchscreen support on a raspberry pi. I've added SDL touch events to the event loop and it seems to process them similarly to mouse event. The programs isn't responding to them the same way and I'm not sure why. The following was added to the event->type loop.

SDL_DisplayMode DM;
SDL_GetCurrentDisplayMode(0, &DM);

    case SDL_FINGERDOWN:    
    case SDL_FINGERUP:        
    {
        int mouse_button = 0; // left click

        io.AddMouseButtonEvent(mouse_button, (event->type == SDL_MOUSEBUTTONDOWN));
        bd->MouseButtonsDown = (event->type == SDL_MOUSEBUTTONDOWN) ? (bd->MouseButtonsDown | (1 << mouse_button)) : (bd->MouseButtonsDown & ~(1 << mouse_button));
        printf("Finger Up\n");
        return true;
    }
    case SDL_FINGERMOTION:
    {
        int disp_x = (int)(DM.w * (float)event->tfinger.x);
        int disp_y = (int)(DM.h * (float)event->tfinger.y);

        printf("Finger Motion %d %d\n", disp_x, disp_y);
        io.AddMousePosEvent(disp_x, disp_y);
        return true;
    }

The touch events occur like I would expect them to, however imgui doesn't seem to be responding to the "click" events. The most I can get to occur is it will act like the mouse is hovering over a control in the demo. I feel like I'm missing something with how imgui works.

Thank you

@PathogenDavid
Copy link
Contributor

Your SDL_FINGERDOWN/SDL_FINGERUP code is using SDL_MOUSEBUTTONDOWN when it should be SDL_FINGERDOWN. As a result you're only ever sending mouse release events to Dear ImGui.

If you run into further issues you may find it helpful to look at the IO log. You can access it via the demo window (Tools > Metrics / Debugger and then Tools > Show Debug Log) or by calling ImGui::ShowDebugLogWindow directly. From there just check the IO box and you should see input events come streaming in.

@stash763
Copy link
Author

Thank you I appreciate the input, can't believe I missed that. I can move windows around now but can't interact with the controls. I'll check out the logging window and see if it provides some clues.

@ocornut
Copy link
Owner

ocornut commented Apr 4, 2023

@stash763 Have you got around to investigate this further?

I am surprised that touch events are not emitting Mouse events. On Windows with SDL2 it does that.
I am tempted to say it would be more correct if SDL behave the same on RaspberryPi as on other systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants