+ multitouch[MAXFINGERS-1][0] = SDL_GetMouseState(&x, &y) ? 11 : 0;
+ multitouch[MAXFINGERS-1][1] = (float)x / vid.width;
+ multitouch[MAXFINGERS-1][2] = (float)y / vid.height;
+ }
+ else
+ {
+ // disable it so it doesn't get stuck, because SDL seems to stop updating it if there are more than 1 finger on screen
+ multitouch[MAXFINGERS-1][0] = 0;
+ }*/
+
+ // TODO: make touchscreen areas controlled by a config file or the VMs. THIS IS A MESS!
+ // TODO: can't just clear buttons[] when entering a new keydest, some keys would remain pressed
+ // SS:BR menuqc has many peculiarities, including that it can't accept more than one command per frame and pressing and releasing on the same frame
+
+ // Tuned for the SGS3, use it's value as a base. CLEAN THIS.
+ xscale = vid_touchscreen_density.value / 2.0f;
+ yscale = vid_touchscreen_density.value / 2.0f;
+ switch(keydest)
+ {
+ case key_console:
+ Vid_ClearAllTouchscreenAreas(14);
+ VID_TouchscreenArea( 0, 0, 160, 64, 64, "gfx/gui/touch_menu_button.tga" , 0.0f, NULL, NULL, &buttons[14], K_ESCAPE, NULL, 0, 0, 0, false);
+ break;
+ case key_game:
+ if (steelstorm_showing_map && steelstorm_showing_map->integer) // FIXME: another hack to be removed when touchscreen areas go to QC
+ {
+ VID_TouchscreenArea( 0, 0, 0, vid_conwidth.value, vid_conheight.value, NULL , 0.0f, NULL, NULL, &buttons[10], (keynum_t)'m', NULL, 0, 0, 0, false);
+ Vid_ClearAllTouchscreenAreas(10);
+ }
+ else if (steelstorm_showing_mousecursor && steelstorm_showing_mousecursor->integer)
+ {
+ // in_windowmouse_x* is in screen resolution coordinates, not console resolution
+ VID_TouchscreenCursor((float)in_windowmouse_x/vid_width.value*vid_conwidth.value, (float)in_windowmouse_y/vid_height.value*vid_conheight.value, 192*xscale, 192*yscale, &buttons[0], K_MOUSE1);
+ Vid_ClearAllTouchscreenAreas(0);
+ }
+ else
+ {
+ VID_TouchscreenCursor(0, 0, 0, 0, &buttons[0], K_MOUSE1);
+
+ VID_TouchscreenArea( 2,16*xscale,-240*yscale, 224*xscale, 224*yscale, "gfx/gui/touch_l_thumb_dpad.tga", 0.0f, NULL, move, &buttons[1], (keynum_t)0, NULL, 0.15, 112*xscale, 112*yscale, false);
+
+ VID_TouchscreenArea( 3,-240*xscale,-160*yscale, 224*xscale, 128*yscale, "gfx/gui/touch_r_thumb_turn_n_shoot.tga" , 0.0f, NULL, NULL, 0, (keynum_t)0, NULL, 0, 56*xscale, 0, false);
+ VID_TouchscreenArea( 3,-240*xscale,-256*yscale, 224*xscale, 224*yscale, NULL , 0.0f, NULL, aim, &buttons[2], (keynum_t)0, NULL, 0.2, 56*xscale, 0, false);
+
+ VID_TouchscreenArea( 2, (vid_conwidth.value / 2) - 128,-80, 256, 80, NULL, 0.0f, NULL, NULL, &buttons[3], K_SHIFT, NULL, 0, 0, 0, true);
+
+ VID_TouchscreenArea( 3,-240*xscale,-256*yscale, 224*xscale, 64*yscale, "gfx/gui/touch_secondary_slide.tga", 0.0f, NULL, NULL, &buttons[4], K_MOUSE2, NULL, 0, 56*xscale, 0, false);
+ VID_TouchscreenArea( 3,-240*xscale,-256*yscale, 224*xscale, 160*yscale, NULL , 0.0f, NULL, NULL, &buttons[9], K_MOUSE3, NULL, 0.2, 56*xscale, 0, false);
+
+ VID_TouchscreenArea( 1,-100, 0, 100, 100, NULL , 0.0f, NULL, NULL, &buttons[10], (keynum_t)'m', NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 1,-100, 120, 100, 100, NULL , 0.0f, NULL, NULL, &buttons[11], (keynum_t)'b', NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 0, 0, 0, 64, 64, NULL , 0.0f, NULL, NULL, &buttons[12], (keynum_t)'q', NULL, 0, 0, 0, true);
+ if (developer.integer)
+ VID_TouchscreenArea( 0, 0, 96, 64, 64, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, true);
+ else
+ VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, false);
+ VID_TouchscreenArea( 0, 0, 160, 64, 64, "gfx/gui/touch_menu_button.tga" , 0.0f, NULL, NULL, &buttons[14], K_ESCAPE, NULL, 0, 0, 0, true);
+ switch(cl.activeweapon)
+ {
+ case 14:
+ VID_TouchscreenArea( 2, 16*xscale,-320*yscale, 224*xscale, 64*yscale, "gfx/gui/touch_booster.tga" , 0.0f, NULL, NULL, &buttons[15], K_SPACE, NULL, 0, 0, 0, true);
+ break;
+ case 12:
+ VID_TouchscreenArea( 2, 16*xscale,-320*yscale, 224*xscale, 64*yscale, "gfx/gui/touch_shockwave.tga" , 0.0f, NULL, NULL, &buttons[15], K_SPACE, NULL, 0, 0, 0, true);
+ break;
+ default:
+ VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[15], K_SPACE, NULL, 0, 0, 0, false);
+ }
+ }
+ break;
+ default:
+ if (!steelstorm_showing_mousecursor || !steelstorm_showing_mousecursor->integer)
+ {
+ Vid_ClearAllTouchscreenAreas(14);
+ // this way we can skip cutscenes
+ VID_TouchscreenArea( 0, 0, 0, vid_conwidth.value, vid_conheight.value, NULL , 0.0f, NULL, NULL, &buttons[14], K_ESCAPE, NULL, 0, 0, 0, false);
+ }
+ else
+ {
+ // in_windowmouse_x* is in screen resolution coordinates, not console resolution
+ VID_TouchscreenCursor((float)in_windowmouse_x/vid_width.value*vid_conwidth.value, (float)in_windowmouse_y/vid_height.value*vid_conheight.value, 192*xscale, 192*yscale, &buttons[0], K_MOUSE1);
+ Vid_ClearAllTouchscreenAreas(0);
+ }
+ break;
+ }
+
+ if (VID_ShowingKeyboard() && (float)in_windowmouse_y > vid_height.value / 2 - 10)
+ in_windowmouse_y = 128;
+
+ cl.cmd.forwardmove -= move[1] * cl_forwardspeed.value;
+ cl.cmd.sidemove += move[0] * cl_sidespeed.value;
+ cl.viewangles[0] += aim[1] * cl_pitchspeed.value * cl.realframetime;
+ cl.viewangles[1] -= aim[0] * cl_yawspeed.value * cl.realframetime;
+}
+
+static void IN_Move_TouchScreen_Quake(void)
+{
+ int x, y;
+ float move[3], aim[3], click[3];
+ static qbool oldbuttons[128];
+ static qbool buttons[128];
+ keydest_t keydest = (key_consoleactive & KEY_CONSOLEACTIVE_USER) ? key_console : key_dest;
+ memcpy(oldbuttons, buttons, sizeof(oldbuttons));
+ memset(multitouchs, 0, sizeof(multitouchs));
+
+ // simple quake controls
+ multitouch[MAXFINGERS-1][0] = SDL_GetMouseState(&x, &y);
+ multitouch[MAXFINGERS-1][1] = x * 32768 / vid.width;
+ multitouch[MAXFINGERS-1][2] = y * 32768 / vid.height;
+
+ // top of screen is toggleconsole and K_ESCAPE
+ switch(keydest)
+ {
+ case key_console:
+ VID_TouchscreenArea( 0, 0, 0, 64, 64, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 0, 64, 0, 64, 64, "gfx/touch_menu.tga" , 0.0f, NULL, NULL, &buttons[14], K_ESCAPE, NULL, 0, 0, 0, true);
+ if (!VID_ShowingKeyboard())
+ {
+ // user entered a command, close the console now
+ Con_ToggleConsole_f(cmd_local);
+ }
+ VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[15], (keynum_t)0, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, move, &buttons[0], K_MOUSE4, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, aim, &buttons[1], K_MOUSE5, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, click,&buttons[2], K_MOUSE1, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[3], K_SPACE, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[4], K_MOUSE2, NULL, 0, 0, 0, true);
+ break;
+ case key_game:
+ VID_TouchscreenArea( 0, 0, 0, 64, 64, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 0, 64, 0, 64, 64, "gfx/touch_menu.tga" , 0.0f, NULL, NULL, &buttons[14], K_ESCAPE, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 2, 0,-128, 128, 128, "gfx/touch_movebutton.tga" , 0.0f, NULL, move, &buttons[0], K_MOUSE4, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 3,-128,-128, 128, 128, "gfx/touch_aimbutton.tga" , 0.0f, NULL, aim, &buttons[1], K_MOUSE5, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 2, 0,-160, 64, 32, "gfx/touch_jumpbutton.tga" , 0.0f, NULL, NULL, &buttons[3], K_SPACE, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 3,-128,-160, 64, 32, "gfx/touch_attackbutton.tga" , 0.0f, NULL, NULL, &buttons[2], K_MOUSE1, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 3, -64,-160, 64, 32, "gfx/touch_attack2button.tga", 0.0f, NULL, NULL, &buttons[4], K_MOUSE2, NULL, 0, 0, 0, true);
+ buttons[15] = false;
+ break;
+ default:
+ VID_TouchscreenArea( 0, 0, 0, 64, 64, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 0, 64, 0, 64, 64, "gfx/touch_menu.tga" , 0.0f, NULL, NULL, &buttons[14], K_ESCAPE, NULL, 0, 0, 0, true);
+ // in menus, an icon in the corner activates keyboard
+ VID_TouchscreenArea( 2, 0, -32, 32, 32, "gfx/touch_keyboard.tga" , 0.0f, NULL, NULL, &buttons[15], (keynum_t)0, NULL, 0, 0, 0, true);
+ if (buttons[15])
+ VID_ShowKeyboard(true);
+ VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, move, &buttons[0], K_MOUSE4, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, aim, &buttons[1], K_MOUSE5, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea(16, -320,-480,640, 960, NULL , 0.0f, NULL, click,&buttons[2], K_MOUSE1, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[3], K_SPACE, NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[4], K_MOUSE2, NULL, 0, 0, 0, true);
+ if (buttons[2])
+ {
+ in_windowmouse_x = x;
+ in_windowmouse_y = y;
+ }
+ break;
+ }
+
+ cl.cmd.forwardmove -= move[1] * cl_forwardspeed.value;
+ cl.cmd.sidemove += move[0] * cl_sidespeed.value;
+ cl.viewangles[0] += aim[1] * cl_pitchspeed.value * cl.realframetime;
+ cl.viewangles[1] -= aim[0] * cl_yawspeed.value * cl.realframetime;
+}
+
+void IN_Move( void )
+{
+ static int old_x = 0, old_y = 0;
+ static int stuck = 0;
+ static keydest_t oldkeydest;
+ static qbool oldshowkeyboard;
+ int x, y;
+ vid_joystate_t joystate;
+ keydest_t keydest = (key_consoleactive & KEY_CONSOLEACTIVE_USER) ? key_console : key_dest;
+
+ scr_numtouchscreenareas = 0;
+
+ // Only apply the new keyboard state if the input changes.
+ if (keydest != oldkeydest || !!vid_touchscreen_showkeyboard.integer != oldshowkeyboard)
+ {
+ switch(keydest)
+ {
+ case key_console: VID_ShowKeyboard(true);break;
+ case key_message: VID_ShowKeyboard(true);break;
+ default: VID_ShowKeyboard(!!vid_touchscreen_showkeyboard.integer); break;
+ }
+ }
+ oldkeydest = keydest;
+ oldshowkeyboard = !!vid_touchscreen_showkeyboard.integer;
+
+ if (vid_touchscreen.integer)
+ {
+ switch(gamemode)
+ {
+ case GAME_STEELSTORM:
+ IN_Move_TouchScreen_SteelStorm();
+ break;
+ default:
+ IN_Move_TouchScreen_Quake();
+ break;
+ }
+ }
+ else
+ {
+ if (vid_usingmouse)
+ {
+ if (vid_stick_mouse.integer || !vid_usingmouse_relativeworks)
+ {
+ // have the mouse stuck in the middle, example use: prevent expose effect of beryl during the game when not using
+ // window grabbing. --blub
+
+ // we need 2 frames to initialize the center position
+ if(!stuck)
+ {
+ SDL_WarpMouseInWindow(window, win_half_width, win_half_height);
+ SDL_GetMouseState(&x, &y);
+ SDL_GetRelativeMouseState(&x, &y);
+ ++stuck;
+ } else {
+ SDL_GetRelativeMouseState(&x, &y);
+ in_mouse_x = x + old_x;
+ in_mouse_y = y + old_y;
+ SDL_GetMouseState(&x, &y);
+ old_x = x - win_half_width;
+ old_y = y - win_half_height;
+ SDL_WarpMouseInWindow(window, win_half_width, win_half_height);
+ }
+ } else {
+ SDL_GetRelativeMouseState( &x, &y );
+ in_mouse_x = x;
+ in_mouse_y = y;
+ }
+ }
+
+ SDL_GetMouseState(&x, &y);
+ in_windowmouse_x = x;
+ in_windowmouse_y = y;