fgsfdsfgs / ioq3

Nintendo Switch port of ioquake3
https://www.ioquake3.org/
GNU General Public License v2.0
21 stars 4 forks source link

Touch sceen support for menus? #16

Open mrdude2478 opened 1 year ago

mrdude2478 commented 1 year ago

Can you please let me know in sdl_input_nx. I am trying to add mouse touchsceen for navigating menu's. I have already innitialised touchscreen in a different function: hidInitializeTouchScreen(); In this function, the cursor moves around the screen, but for some reason the calculations are wrong and the more you drag the cursor to the right edge of the screen the further out of sink it goes.

void IN_ProcessTouch( void )
{
    HidTouchScreenState state={0};
    if (hidGetTouchScreenStates(&state, 1)) {
        if (state.count != prev_touchcount)
        {
            prev_touchcount = state.count;
        }
        for(s32 i=0; i<state.count; i++)
        {
            //get pixel location of where we touched the sceen
            int touchscreenx = state.touches[i].x;
            int touchscreeny = state.touches[i].y;

            //get the current window resolution
            int Width, Height;
            SDL_GetWindowSize(SDL_window, &Width, &Height); //This shows as 1280/720

            SDL_WarpMouseInWindow(SDL_window, touchscreenx, touchscreeny);
        }
    }
}

Can you see what I have done wrong in this code?

mrdude2478 commented 1 year ago

Never Mind, I found the problem - this fixes it and now touchscreen works with this modded code:

void IN_Touch( void ) {
    //set up touchscreen
  hidInitializeTouchScreen();
}

void IN_ProcessTouch( void )
{   
    HidTouchScreenState state={0};

    if (hidGetTouchScreenStates(&state, 1)) {
        if (state.count != prev_touchcount)
        {
            prev_touchcount = state.count;
        }

        for(int i=0; i<state.count; i++)
        {
            SDL_WarpMouseInWindow(SDL_window, (state.touches[i].x/3)*2, (state.touches[i].y/3)*2);
        }
    }
}

Thanks anyway.