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

Pen motion could be more precise (Windows) #12084

Open
FullPtrDereference opened this issue Jan 25, 2025 · 0 comments
Open

Pen motion could be more precise (Windows) #12084

FullPtrDereference opened this issue Jan 25, 2025 · 0 comments
Assignees
Milestone

Comments

@FullPtrDereference
Copy link

I would have made a PR instead, but I never use github and I didn't wanna screw something up.

I saw how pen motion coordinates are basically just ints, but other programs like Krita manage to get more precision somehow, and I figured out how to do that, as without it a tablet is basically just a mouse with pressure, which affects your lines.

After this from SDL_windowsevents.c:

    case WM_POINTERDOWN:
    case WM_POINTERUP: {
        ...
        ScreenToClient(data->hwnd, &position);

I added this:

        const POINTER_INFO pointerInfo = pen_info.pointerInfo;
        
        SDL_FPoint tabletPos = {
            pointerInfo.ptHimetricLocationRaw.x,
            pointerInfo.ptHimetricLocationRaw.y
        };
        
        RECT tabletBounds  = {0};
        RECT tabletMapping = {0};
        
        float outX, outY;
        
        // should cache this somewhere?
        if(!GetPointerDeviceRects(pointerInfo.sourceDevice, &tabletBounds, &tabletMapping)) {
            outX = (float) position.x;
            outY = (float) position.y;
        } else {
            SDL_FPoint windowPos;
            
            {
                int x, y;
                
                SDL_GetWindowPosition(window, &x, &y);
                windowPos.x = x;
                windowPos.y = y;
            }
            
            const float facX = tabletPos.x / (float) (tabletBounds.right );
            const float facY = tabletPos.y / (float) (tabletBounds.bottom);
            
            const float w = tabletMapping.right  - tabletMapping.left;
            const float h = tabletMapping.bottom - tabletMapping.top;
            
            outX = (tabletMapping.left + (facX * w)) - windowPos.x;
            outY = (tabletMapping.top  + (facY * h)) - windowPos.y;
        }
        
        SDL_SendPenMotion(timestamp, pen, window, outX, outY);
        // SDL_SendPenMotion(timestamp, pen, window, (float) position.x, (float) position.y);

I couldn't test this on HiDPI, and you might wanna cache the result of GetPointerDeviceRects but I don't know where, but otherwise this worked for me at least, using 1 and 2 monitors.

@slouken slouken added this to the 3.2.2 milestone Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants