| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#undef WIN32_LEAN_AND_MEAN //hush a warning, SDL.h redefines this |
| 20 |
#include <SDL.h> |
| 21 |
#include <stdio.h> |
| 22 |
|
| 23 |
#include "quakedef.h" |
| 24 |
#include "image.h" |
| 25 |
#include "utf8lib.h" |
| 26 |
|
| 27 |
#ifndef __IPHONEOS__ |
| 28 |
#ifdef MACOSX |
| 29 |
#include <Carbon/Carbon.h> |
| 30 |
#include <IOKit/hidsystem/IOHIDLib.h> |
| 31 |
#include <IOKit/hidsystem/IOHIDParameter.h> |
| 32 |
#include <IOKit/hidsystem/event_status_driver.h> |
| 33 |
static cvar_t apple_mouse_noaccel = {CVAR_SAVE, "apple_mouse_noaccel", "1", "disables mouse acceleration while DarkPlaces is active"}; |
| 34 |
static qboolean vid_usingnoaccel; |
| 35 |
static double originalMouseSpeed = -1.0; |
| 36 |
io_connect_t IN_GetIOHandle(void) |
| 37 |
{ |
| 38 |
io_connect_t iohandle = MACH_PORT_NULL; |
| 39 |
kern_return_t status; |
| 40 |
io_service_t iohidsystem = MACH_PORT_NULL; |
| 41 |
mach_port_t masterport; |
| 42 |
|
| 43 |
status = IOMasterPort(MACH_PORT_NULL, &masterport); |
| 44 |
if(status != KERN_SUCCESS) |
| 45 |
return 0; |
| 46 |
|
| 47 |
iohidsystem = IORegistryEntryFromPath(masterport, kIOServicePlane ":/IOResources/IOHIDSystem"); |
| 48 |
if(!iohidsystem) |
| 49 |
return 0; |
| 50 |
|
| 51 |
status = IOServiceOpen(iohidsystem, mach_task_self(), kIOHIDParamConnectType, &iohandle); |
| 52 |
IOObjectRelease(iohidsystem); |
| 53 |
|
| 54 |
return iohandle; |
| 55 |
} |
| 56 |
#endif |
| 57 |
#endif |
| 58 |
|
| 59 |
#ifdef WIN32 |
| 60 |
#define SDL_R_RESTART |
| 61 |
#endif |
| 62 |
|
| 63 |
|
| 64 |
int cl_available = true; |
| 65 |
|
| 66 |
qboolean vid_supportrefreshrate = false; |
| 67 |
|
| 68 |
static qboolean vid_usingmouse = false; |
| 69 |
static qboolean vid_usingmouse_relativeworks = false; |
| 70 |
static qboolean vid_usinghidecursor = false; |
| 71 |
static qboolean vid_hasfocus = false; |
| 72 |
static qboolean vid_isfullscreen; |
| 73 |
static qboolean vid_usingvsync = false; |
| 74 |
static SDL_Joystick *vid_sdljoystick = NULL; |
| 75 |
|
| 76 |
static cvar_t *steelstorm_showing_map = NULL; |
| 77 |
static cvar_t *steelstorm_showing_mousecursor = NULL; |
| 78 |
|
| 79 |
static int win_half_width = 50; |
| 80 |
static int win_half_height = 50; |
| 81 |
static int video_bpp; |
| 82 |
|
| 83 |
static SDL_GLContext context; |
| 84 |
static SDL_Window *window; |
| 85 |
static int window_flags; |
| 86 |
static vid_mode_t desktop_mode; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
#ifndef SDLK_PERCENT |
| 91 |
#define SDLK_PERCENT '%' |
| 92 |
#endif |
| 93 |
|
| 94 |
static int MapKey( unsigned int sdlkey ) |
| 95 |
{ |
| 96 |
switch(sdlkey) |
| 97 |
{ |
| 98 |
default: return 0; |
| 99 |
|
| 100 |
case SDLK_RETURN: return K_ENTER; |
| 101 |
case SDLK_ESCAPE: return K_ESCAPE; |
| 102 |
case SDLK_BACKSPACE: return K_BACKSPACE; |
| 103 |
case SDLK_TAB: return K_TAB; |
| 104 |
case SDLK_SPACE: return K_SPACE; |
| 105 |
case SDLK_EXCLAIM: return '!'; |
| 106 |
case SDLK_QUOTEDBL: return '"'; |
| 107 |
case SDLK_HASH: return '#'; |
| 108 |
case SDLK_PERCENT: return '%'; |
| 109 |
case SDLK_DOLLAR: return '$'; |
| 110 |
case SDLK_AMPERSAND: return '&'; |
| 111 |
case SDLK_QUOTE: return '\''; |
| 112 |
case SDLK_LEFTPAREN: return '('; |
| 113 |
case SDLK_RIGHTPAREN: return ')'; |
| 114 |
case SDLK_ASTERISK: return '*'; |
| 115 |
case SDLK_PLUS: return '+'; |
| 116 |
case SDLK_COMMA: return ','; |
| 117 |
case SDLK_MINUS: return '-'; |
| 118 |
case SDLK_PERIOD: return '.'; |
| 119 |
case SDLK_SLASH: return '/'; |
| 120 |
case SDLK_0: return '0'; |
| 121 |
case SDLK_1: return '1'; |
| 122 |
case SDLK_2: return '2'; |
| 123 |
case SDLK_3: return '3'; |
| 124 |
case SDLK_4: return '4'; |
| 125 |
case SDLK_5: return '5'; |
| 126 |
case SDLK_6: return '6'; |
| 127 |
case SDLK_7: return '7'; |
| 128 |
case SDLK_8: return '8'; |
| 129 |
case SDLK_9: return '9'; |
| 130 |
case SDLK_COLON: return ':'; |
| 131 |
case SDLK_SEMICOLON: return ';'; |
| 132 |
case SDLK_LESS: return '<'; |
| 133 |
case SDLK_EQUALS: return '='; |
| 134 |
case SDLK_GREATER: return '>'; |
| 135 |
case SDLK_QUESTION: return '?'; |
| 136 |
case SDLK_AT: return '@'; |
| 137 |
case SDLK_LEFTBRACKET: return '['; |
| 138 |
case SDLK_BACKSLASH: return '\\'; |
| 139 |
case SDLK_RIGHTBRACKET: return ']'; |
| 140 |
case SDLK_CARET: return '^'; |
| 141 |
case SDLK_UNDERSCORE: return '_'; |
| 142 |
case SDLK_BACKQUOTE: return '`'; |
| 143 |
case SDLK_a: return 'a'; |
| 144 |
case SDLK_b: return 'b'; |
| 145 |
case SDLK_c: return 'c'; |
| 146 |
case SDLK_d: return 'd'; |
| 147 |
case SDLK_e: return 'e'; |
| 148 |
case SDLK_f: return 'f'; |
| 149 |
case SDLK_g: return 'g'; |
| 150 |
case SDLK_h: return 'h'; |
| 151 |
case SDLK_i: return 'i'; |
| 152 |
case SDLK_j: return 'j'; |
| 153 |
case SDLK_k: return 'k'; |
| 154 |
case SDLK_l: return 'l'; |
| 155 |
case SDLK_m: return 'm'; |
| 156 |
case SDLK_n: return 'n'; |
| 157 |
case SDLK_o: return 'o'; |
| 158 |
case SDLK_p: return 'p'; |
| 159 |
case SDLK_q: return 'q'; |
| 160 |
case SDLK_r: return 'r'; |
| 161 |
case SDLK_s: return 's'; |
| 162 |
case SDLK_t: return 't'; |
| 163 |
case SDLK_u: return 'u'; |
| 164 |
case SDLK_v: return 'v'; |
| 165 |
case SDLK_w: return 'w'; |
| 166 |
case SDLK_x: return 'x'; |
| 167 |
case SDLK_y: return 'y'; |
| 168 |
case SDLK_z: return 'z'; |
| 169 |
case SDLK_CAPSLOCK: return K_CAPSLOCK; |
| 170 |
case SDLK_F1: return K_F1; |
| 171 |
case SDLK_F2: return K_F2; |
| 172 |
case SDLK_F3: return K_F3; |
| 173 |
case SDLK_F4: return K_F4; |
| 174 |
case SDLK_F5: return K_F5; |
| 175 |
case SDLK_F6: return K_F6; |
| 176 |
case SDLK_F7: return K_F7; |
| 177 |
case SDLK_F8: return K_F8; |
| 178 |
case SDLK_F9: return K_F9; |
| 179 |
case SDLK_F10: return K_F10; |
| 180 |
case SDLK_F11: return K_F11; |
| 181 |
case SDLK_F12: return K_F12; |
| 182 |
case SDLK_PRINTSCREEN: return K_PRINTSCREEN; |
| 183 |
case SDLK_SCROLLLOCK: return K_SCROLLOCK; |
| 184 |
case SDLK_PAUSE: return K_PAUSE; |
| 185 |
case SDLK_INSERT: return K_INS; |
| 186 |
case SDLK_HOME: return K_HOME; |
| 187 |
case SDLK_PAGEUP: return K_PGUP; |
| 188 |
#ifdef __IPHONEOS__ |
| 189 |
case SDLK_DELETE: return K_BACKSPACE; |
| 190 |
#else |
| 191 |
case SDLK_DELETE: return K_DEL; |
| 192 |
#endif |
| 193 |
case SDLK_END: return K_END; |
| 194 |
case SDLK_PAGEDOWN: return K_PGDN; |
| 195 |
case SDLK_RIGHT: return K_RIGHTARROW; |
| 196 |
case SDLK_LEFT: return K_LEFTARROW; |
| 197 |
case SDLK_DOWN: return K_DOWNARROW; |
| 198 |
case SDLK_UP: return K_UPARROW; |
| 199 |
case SDLK_NUMLOCKCLEAR: return K_NUMLOCK; |
| 200 |
case SDLK_KP_DIVIDE: return K_KP_DIVIDE; |
| 201 |
case SDLK_KP_MULTIPLY: return K_KP_MULTIPLY; |
| 202 |
case SDLK_KP_MINUS: return K_KP_MINUS; |
| 203 |
case SDLK_KP_PLUS: return K_KP_PLUS; |
| 204 |
case SDLK_KP_ENTER: return K_KP_ENTER; |
| 205 |
case SDLK_KP_1: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_1 : K_END); |
| 206 |
case SDLK_KP_2: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_2 : K_DOWNARROW); |
| 207 |
case SDLK_KP_3: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_3 : K_PGDN); |
| 208 |
case SDLK_KP_4: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_4 : K_LEFTARROW); |
| 209 |
case SDLK_KP_5: return K_KP_5; |
| 210 |
case SDLK_KP_6: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_6 : K_RIGHTARROW); |
| 211 |
case SDLK_KP_7: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_7 : K_HOME); |
| 212 |
case SDLK_KP_8: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_8 : K_UPARROW); |
| 213 |
case SDLK_KP_9: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_9 : K_PGUP); |
| 214 |
case SDLK_KP_0: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_0 : K_INS); |
| 215 |
case SDLK_KP_PERIOD: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_PERIOD : K_DEL); |
| 216 |
|
| 217 |
|
| 218 |
case SDLK_KP_EQUALS: return K_KP_EQUALS; |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
case SDLK_LCTRL: return K_CTRL; |
| 306 |
case SDLK_LSHIFT: return K_SHIFT; |
| 307 |
case SDLK_LALT: return K_ALT; |
| 308 |
|
| 309 |
case SDLK_RCTRL: return K_CTRL; |
| 310 |
case SDLK_RSHIFT: return K_SHIFT; |
| 311 |
case SDLK_RALT: return K_ALT; |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
case SDLK_AC_BACK: return K_ESCAPE; |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
qboolean VID_HasScreenKeyboardSupport(void) |
| 343 |
{ |
| 344 |
return SDL_HasScreenKeyboardSupport() != SDL_FALSE; |
| 345 |
} |
| 346 |
|
| 347 |
void VID_ShowKeyboard(qboolean show) |
| 348 |
{ |
| 349 |
if (!SDL_HasScreenKeyboardSupport()) |
| 350 |
return; |
| 351 |
|
| 352 |
if (show) |
| 353 |
{ |
| 354 |
if (!SDL_IsTextInputActive()) |
| 355 |
SDL_StartTextInput(); |
| 356 |
} |
| 357 |
else |
| 358 |
{ |
| 359 |
if (SDL_IsTextInputActive()) |
| 360 |
SDL_StopTextInput(); |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
qboolean VID_ShowingKeyboard(void) |
| 365 |
{ |
| 366 |
return SDL_IsTextInputActive() != 0; |
| 367 |
} |
| 368 |
|
| 369 |
void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor) |
| 370 |
{ |
| 371 |
#ifndef DP_MOBILETOUCH |
| 372 |
#ifdef MACOSX |
| 373 |
if(relative) |
| 374 |
if(vid_usingmouse && (vid_usingnoaccel != !!apple_mouse_noaccel.integer)) |
| 375 |
VID_SetMouse(false, false, false); |
| 376 |
#endif |
| 377 |
if (vid_usingmouse != relative) |
| 378 |
{ |
| 379 |
vid_usingmouse = relative; |
| 380 |
cl_ignoremousemoves = 2; |
| 381 |
vid_usingmouse_relativeworks = SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE) == 0; |
| 382 |
|
| 383 |
#ifdef MACOSX |
| 384 |
if(relative) |
| 385 |
{ |
| 386 |
|
| 387 |
originalMouseSpeed = -1.0; |
| 388 |
if(apple_mouse_noaccel.integer) |
| 389 |
{ |
| 390 |
io_connect_t mouseDev = IN_GetIOHandle(); |
| 391 |
if(mouseDev != 0) |
| 392 |
{ |
| 393 |
if(IOHIDGetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &originalMouseSpeed) == kIOReturnSuccess) |
| 394 |
{ |
| 395 |
Con_DPrintf("previous mouse acceleration: %f\n", originalMouseSpeed); |
| 396 |
if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), -1.0) != kIOReturnSuccess) |
| 397 |
{ |
| 398 |
Con_Print("Could not disable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); |
| 399 |
Cvar_SetValueQuick(&apple_mouse_noaccel, 0); |
| 400 |
} |
| 401 |
} |
| 402 |
else |
| 403 |
{ |
| 404 |
Con_Print("Could not disable mouse acceleration (failed at IOHIDGetAccelerationWithKey).\n"); |
| 405 |
Cvar_SetValueQuick(&apple_mouse_noaccel, 0); |
| 406 |
} |
| 407 |
IOServiceClose(mouseDev); |
| 408 |
} |
| 409 |
else |
| 410 |
{ |
| 411 |
Con_Print("Could not disable mouse acceleration (failed at IO_GetIOHandle).\n"); |
| 412 |
Cvar_SetValueQuick(&apple_mouse_noaccel, 0); |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
vid_usingnoaccel = !!apple_mouse_noaccel.integer; |
| 417 |
} |
| 418 |
else |
| 419 |
{ |
| 420 |
if(originalMouseSpeed != -1.0) |
| 421 |
{ |
| 422 |
io_connect_t mouseDev = IN_GetIOHandle(); |
| 423 |
if(mouseDev != 0) |
| 424 |
{ |
| 425 |
Con_DPrintf("restoring mouse acceleration to: %f\n", originalMouseSpeed); |
| 426 |
if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess) |
| 427 |
Con_Print("Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); |
| 428 |
IOServiceClose(mouseDev); |
| 429 |
} |
| 430 |
else |
| 431 |
Con_Print("Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n"); |
| 432 |
} |
| 433 |
} |
| 434 |
#endif |
| 435 |
} |
| 436 |
if (vid_usinghidecursor != hidecursor) |
| 437 |
{ |
| 438 |
vid_usinghidecursor = hidecursor; |
| 439 |
SDL_ShowCursor( hidecursor ? SDL_DISABLE : SDL_ENABLE); |
| 440 |
} |
| 441 |
#endif |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
#define MAXFINGERS 11 |
| 450 |
float multitouch[MAXFINGERS][3]; |
| 451 |
|
| 452 |
|
| 453 |
int multitouchs[MAXFINGERS]; |
| 454 |
|
| 455 |
|
| 456 |
static qboolean VID_TouchscreenArea(int corner, float px, float py, float pwidth, float pheight, const char *icon, float textheight, const char *text, float *resultmove, qboolean *resultbutton, keynum_t key, const char *typedtext, float deadzone, float oversizepixels_x, float oversizepixels_y, qboolean iamexclusive) |
| 457 |
{ |
| 458 |
int finger; |
| 459 |
float fx, fy, fwidth, fheight; |
| 460 |
float overfx, overfy, overfwidth, overfheight; |
| 461 |
float rel[3]; |
| 462 |
float sqsum; |
| 463 |
qboolean button = false; |
| 464 |
VectorClear(rel); |
| 465 |
if (pwidth > 0 && pheight > 0) |
| 466 |
{ |
| 467 |
if (corner & 1) px += vid_conwidth.value; |
| 468 |
if (corner & 2) py += vid_conheight.value; |
| 469 |
if (corner & 4) px += vid_conwidth.value * 0.5f; |
| 470 |
if (corner & 8) py += vid_conheight.value * 0.5f; |
| 471 |
if (corner & 16) {px *= vid_conwidth.value * (1.0f / 640.0f);py *= vid_conheight.value * (1.0f / 480.0f);pwidth *= vid_conwidth.value * (1.0f / 640.0f);pheight *= vid_conheight.value * (1.0f / 480.0f);} |
| 472 |
fx = px / vid_conwidth.value; |
| 473 |
fy = py / vid_conheight.value; |
| 474 |
fwidth = pwidth / vid_conwidth.value; |
| 475 |
fheight = pheight / vid_conheight.value; |
| 476 |
|
| 477 |
|
| 478 |
if (resultbutton) |
| 479 |
if (!(*resultbutton)) |
| 480 |
{ |
| 481 |
oversizepixels_x *= 0.2; |
| 482 |
oversizepixels_y *= 0.2; |
| 483 |
} |
| 484 |
|
| 485 |
oversizepixels_x /= vid_conwidth.value; |
| 486 |
oversizepixels_y /= vid_conheight.value; |
| 487 |
|
| 488 |
overfx = fx - oversizepixels_x; |
| 489 |
overfy = fy - oversizepixels_y; |
| 490 |
overfwidth = fwidth + 2*oversizepixels_x; |
| 491 |
overfheight = fheight + 2*oversizepixels_y; |
| 492 |
|
| 493 |
for (finger = 0;finger < MAXFINGERS;finger++) |
| 494 |
{ |
| 495 |
if (multitouchs[finger] && iamexclusive) |
| 496 |
continue; |
| 497 |
|
| 498 |
if (multitouch[finger][0] && multitouch[finger][1] >= overfx && multitouch[finger][2] >= overfy && multitouch[finger][1] < overfx + overfwidth && multitouch[finger][2] < overfy + overfheight) |
| 499 |
{ |
| 500 |
multitouchs[finger]++; |
| 501 |
|
| 502 |
rel[0] = bound(-1, (multitouch[finger][1] - (fx + 0.5f * fwidth)) * (2.0f / fwidth), 1); |
| 503 |
rel[1] = bound(-1, (multitouch[finger][2] - (fy + 0.5f * fheight)) * (2.0f / fheight), 1); |
| 504 |
rel[2] = 0; |
| 505 |
|
| 506 |
sqsum = rel[0]*rel[0] + rel[1]*rel[1]; |
| 507 |
|
| 508 |
if (sqsum < deadzone*deadzone) |
| 509 |
{ |
| 510 |
rel[0] = 0; |
| 511 |
rel[1] = 0; |
| 512 |
} |
| 513 |
else if (sqsum > 1) |
| 514 |
{ |
| 515 |
|
| 516 |
Vector2Normalize2(rel, rel); |
| 517 |
} |
| 518 |
button = true; |
| 519 |
break; |
| 520 |
} |
| 521 |
} |
| 522 |
if (scr_numtouchscreenareas < 128) |
| 523 |
{ |
| 524 |
scr_touchscreenareas[scr_numtouchscreenareas].pic = icon; |
| 525 |
scr_touchscreenareas[scr_numtouchscreenareas].text = text; |
| 526 |
scr_touchscreenareas[scr_numtouchscreenareas].textheight = textheight; |
| 527 |
scr_touchscreenareas[scr_numtouchscreenareas].rect[0] = px; |
| 528 |
scr_touchscreenareas[scr_numtouchscreenareas].rect[1] = py; |
| 529 |
scr_touchscreenareas[scr_numtouchscreenareas].rect[2] = pwidth; |
| 530 |
scr_touchscreenareas[scr_numtouchscreenareas].rect[3] = pheight; |
| 531 |
scr_touchscreenareas[scr_numtouchscreenareas].active = button; |
| 532 |
|
| 533 |
scr_touchscreenareas[scr_numtouchscreenareas].activealpha = 1.f; |
| 534 |
scr_touchscreenareas[scr_numtouchscreenareas].inactivealpha = 0.95f; |
| 535 |
scr_numtouchscreenareas++; |
| 536 |
} |
| 537 |
} |
| 538 |
if (resultmove) |
| 539 |
{ |
| 540 |
if (button) |
| 541 |
VectorCopy(rel, resultmove); |
| 542 |
else |
| 543 |
VectorClear(resultmove); |
| 544 |
} |
| 545 |
if (resultbutton) |
| 546 |
{ |
| 547 |
if (*resultbutton != button) |
| 548 |
{ |
| 549 |
if ((int)key > 0) |
| 550 |
Key_Event(key, 0, button); |
| 551 |
if (typedtext && typedtext[0] && !*resultbutton) |
| 552 |
{ |
| 553 |
|
| 554 |
int i; |
| 555 |
for (i = 0;typedtext[i];i++) |
| 556 |
{ |
| 557 |
Key_Event(K_TEXT, typedtext[i], true); |
| 558 |
Key_Event(K_TEXT, typedtext[i], false); |
| 559 |
} |
| 560 |
} |
| 561 |
} |
| 562 |
*resultbutton = button; |
| 563 |
} |
| 564 |
return button; |
| 565 |
} |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
static void VID_TouchscreenCursor(float px, float py, float pwidth, float pheight, qboolean *resultbutton, keynum_t key) |
| 570 |
{ |
| 571 |
int finger; |
| 572 |
float fx, fy, fwidth, fheight; |
| 573 |
qboolean button = false; |
| 574 |
static int cursorfinger = -1; |
| 575 |
static int cursorfreemovement = false; |
| 576 |
static int canclick = false; |
| 577 |
static int clickxy[2]; |
| 578 |
static int relclickxy[2]; |
| 579 |
static double clickrealtime = 0; |
| 580 |
|
| 581 |
if (steelstorm_showing_mousecursor && steelstorm_showing_mousecursor->integer) |
| 582 |
if (pwidth > 0 && pheight > 0) |
| 583 |
{ |
| 584 |
fx = px / vid_conwidth.value; |
| 585 |
fy = py / vid_conheight.value; |
| 586 |
fwidth = pwidth / vid_conwidth.value; |
| 587 |
fheight = pheight / vid_conheight.value; |
| 588 |
for (finger = 0;finger < MAXFINGERS;finger++) |
| 589 |
{ |
| 590 |
if (multitouch[finger][0] && multitouch[finger][1] >= fx && multitouch[finger][2] >= fy && multitouch[finger][1] < fx + fwidth && multitouch[finger][2] < fy + fheight) |
| 591 |
{ |
| 592 |
if (cursorfinger == -1) |
| 593 |
{ |
| 594 |
clickxy[0] = multitouch[finger][1] * vid_width.value - 0.5f * pwidth; |
| 595 |
clickxy[1] = multitouch[finger][2] * vid_height.value - 0.5f * pheight; |
| 596 |
relclickxy[0] = (multitouch[finger][1] - fx) * vid_width.value - 0.5f * pwidth; |
| 597 |
relclickxy[1] = (multitouch[finger][2] - fy) * vid_height.value - 0.5f * pheight; |
| 598 |
} |
| 599 |
cursorfinger = finger; |
| 600 |
button = true; |
| 601 |
canclick = true; |
| 602 |
cursorfreemovement = false; |
| 603 |
break; |
| 604 |
} |
| 605 |
} |
| 606 |
if (scr_numtouchscreenareas < 128) |
| 607 |
{ |
| 608 |
if (clickrealtime + 1 > realtime) |
| 609 |
{ |
| 610 |
scr_touchscreenareas[scr_numtouchscreenareas].pic = "gfx/gui/touch_puck_cur_click.tga"; |
| 611 |
} |
| 612 |
else if (button) |
| 613 |
{ |
| 614 |
scr_touchscreenareas[scr_numtouchscreenareas].pic = "gfx/gui/touch_puck_cur_touch.tga"; |
| 615 |
} |
| 616 |
else |
| 617 |
{ |
| 618 |
switch ((int)realtime * 10 % 20) |
| 619 |
{ |
| 620 |
case 0: |
| 621 |
scr_touchscreenareas[scr_numtouchscreenareas].pic = "gfx/gui/touch_puck_cur_touch.tga"; |
| 622 |
break; |
| 623 |
default: |
| 624 |
scr_touchscreenareas[scr_numtouchscreenareas].pic = "gfx/gui/touch_puck_cur_idle.tga"; |
| 625 |
} |
| 626 |
} |
| 627 |
scr_touchscreenareas[scr_numtouchscreenareas].text = ""; |
| 628 |
scr_touchscreenareas[scr_numtouchscreenareas].textheight = 0; |
| 629 |
scr_touchscreenareas[scr_numtouchscreenareas].rect[0] = px; |
| 630 |
scr_touchscreenareas[scr_numtouchscreenareas].rect[1] = py; |
| 631 |
scr_touchscreenareas[scr_numtouchscreenareas].rect[2] = pwidth; |
| 632 |
scr_touchscreenareas[scr_numtouchscreenareas].rect[3] = pheight; |
| 633 |
scr_touchscreenareas[scr_numtouchscreenareas].active = button; |
| 634 |
scr_touchscreenareas[scr_numtouchscreenareas].activealpha = 1.0f; |
| 635 |
scr_touchscreenareas[scr_numtouchscreenareas].inactivealpha = 1.0f; |
| 636 |
scr_numtouchscreenareas++; |
| 637 |
} |
| 638 |
} |
| 639 |
|
| 640 |
if (cursorfinger != -1) |
| 641 |
{ |
| 642 |
if (multitouch[cursorfinger][0]) |
| 643 |
{ |
| 644 |
if (multitouch[cursorfinger][1] * vid_width.value - 0.5f * pwidth < clickxy[0] - 1 || |
| 645 |
multitouch[cursorfinger][1] * vid_width.value - 0.5f * pwidth > clickxy[0] + 1 || |
| 646 |
multitouch[cursorfinger][2] * vid_height.value - 0.5f * pheight< clickxy[1] - 1 || |
| 647 |
multitouch[cursorfinger][2] * vid_height.value - 0.5f * pheight> clickxy[1] + 1) |
| 648 |
{ |
| 649 |
cursorfreemovement = true; |
| 650 |
} |
| 651 |
if (cursorfreemovement) |
| 652 |
{ |
| 653 |
|
| 654 |
in_windowmouse_x = multitouch[cursorfinger][1] * vid_width.value - 0.5f * pwidth - relclickxy[0]; |
| 655 |
in_windowmouse_y = multitouch[cursorfinger][2] * vid_height.value - 0.5f * pheight - relclickxy[1]; |
| 656 |
} |
| 657 |
} |
| 658 |
else |
| 659 |
{ |
| 660 |
cursorfinger = -1; |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
if (resultbutton) |
| 665 |
{ |
| 666 |
if ((int)key > 0) |
| 667 |
{ |
| 668 |
if (!button && !cursorfreemovement && canclick) |
| 669 |
{ |
| 670 |
Key_Event(key, 0, true); |
| 671 |
canclick = false; |
| 672 |
clickrealtime = realtime; |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
if (clickrealtime && clickrealtime + 0.1 < realtime) |
| 677 |
{ |
| 678 |
Key_Event(key, 0, false); |
| 679 |
clickrealtime = 0; |
| 680 |
} |
| 681 |
} |
| 682 |
|
| 683 |
*resultbutton = button; |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
void VID_BuildJoyState(vid_joystate_t *joystate) |
| 688 |
{ |
| 689 |
VID_Shared_BuildJoyState_Begin(joystate); |
| 690 |
|
| 691 |
if (vid_sdljoystick) |
| 692 |
{ |
| 693 |
SDL_Joystick *joy = vid_sdljoystick; |
| 694 |
int j; |
| 695 |
int numaxes; |
| 696 |
int numbuttons; |
| 697 |
numaxes = SDL_JoystickNumAxes(joy); |
| 698 |
for (j = 0;j < numaxes;j++) |
| 699 |
joystate->axis[j] = SDL_JoystickGetAxis(joy, j) * (1.0f / 32767.0f); |
| 700 |
numbuttons = SDL_JoystickNumButtons(joy); |
| 701 |
for (j = 0;j < numbuttons;j++) |
| 702 |
joystate->button[j] = SDL_JoystickGetButton(joy, j); |
| 703 |
} |
| 704 |
|
| 705 |
VID_Shared_BuildJoyState_Finish(joystate); |
| 706 |
} |
| 707 |
|
| 708 |
|
| 709 |
#define Vid_ClearAllTouchscreenAreas(skip) \ |
| 710 |
if (skip != 0) \ |
| 711 |
VID_TouchscreenCursor(0, 0, 0, 0, &buttons[0], K_MOUSE1); \ |
| 712 |
if (skip != 1) \ |
| 713 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, move, &buttons[1], K_MOUSE4, NULL, 0, 0, 0, false); \ |
| 714 |
if (skip != 2) \ |
| 715 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, aim, &buttons[2], K_MOUSE5, NULL, 0, 0, 0, false); \ |
| 716 |
if (skip != 3) \ |
| 717 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[3], K_SHIFT, NULL, 0, 0, 0, false); \ |
| 718 |
if (skip != 4) \ |
| 719 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[4], K_MOUSE2, NULL, 0, 0, 0, false); \ |
| 720 |
if (skip != 9) \ |
| 721 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[9], K_MOUSE3, NULL, 0, 0, 0, false); \ |
| 722 |
if (skip != 10) \ |
| 723 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[10], (keynum_t)'m', NULL, 0, 0, 0, false); \ |
| 724 |
if (skip != 11) \ |
| 725 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[11], (keynum_t)'b', NULL, 0, 0, 0, false); \ |
| 726 |
if (skip != 12) \ |
| 727 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[12], (keynum_t)'q', NULL, 0, 0, 0, false); \ |
| 728 |
if (skip != 13) \ |
| 729 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, false); \ |
| 730 |
if (skip != 14) \ |
| 731 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[14], K_ESCAPE, NULL, 0, 0, 0, false); \ |
| 732 |
if (skip != 15) \ |
| 733 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[15], K_SPACE, NULL, 0, 0, 0, false); \ |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
static void IN_Move_TouchScreen_SteelStorm(void) |
| 740 |
{ |
| 741 |
|
| 742 |
int i, numfingers; |
| 743 |
float xscale, yscale; |
| 744 |
float move[3], aim[3]; |
| 745 |
static qboolean oldbuttons[128]; |
| 746 |
static qboolean buttons[128]; |
| 747 |
keydest_t keydest = (key_consoleactive & KEY_CONSOLEACTIVE_USER) ? key_console : key_dest; |
| 748 |
memcpy(oldbuttons, buttons, sizeof(oldbuttons)); |
| 749 |
memset(multitouchs, 0, sizeof(multitouchs)); |
| 750 |
|
| 751 |
for (i = 0, numfingers = 0; i < MAXFINGERS - 1; i++) |
| 752 |
if (multitouch[i][0]) |
| 753 |
numfingers++; |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
xscale = vid_touchscreen_density.value / 2.0f; |
| 775 |
yscale = vid_touchscreen_density.value / 2.0f; |
| 776 |
switch(keydest) |
| 777 |
{ |
| 778 |
case key_console: |
| 779 |
Vid_ClearAllTouchscreenAreas(14); |
| 780 |
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); |
| 781 |
break; |
| 782 |
case key_game: |
| 783 |
if (steelstorm_showing_map && steelstorm_showing_map->integer) |
| 784 |
{ |
| 785 |
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); |
| 786 |
Vid_ClearAllTouchscreenAreas(10); |
| 787 |
} |
| 788 |
else if (steelstorm_showing_mousecursor && steelstorm_showing_mousecursor->integer) |
| 789 |
{ |
| 790 |
|
| 791 |
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); |
| 792 |
Vid_ClearAllTouchscreenAreas(0); |
| 793 |
} |
| 794 |
else |
| 795 |
{ |
| 796 |
VID_TouchscreenCursor(0, 0, 0, 0, &buttons[0], K_MOUSE1); |
| 797 |
|
| 798 |
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); |
| 799 |
|
| 800 |
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); |
| 801 |
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); |
| 802 |
|
| 803 |
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); |
| 804 |
|
| 805 |
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); |
| 806 |
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); |
| 807 |
|
| 808 |
VID_TouchscreenArea( 1,-100, 0, 100, 100, NULL , 0.0f, NULL, NULL, &buttons[10], (keynum_t)'m', NULL, 0, 0, 0, true); |
| 809 |
VID_TouchscreenArea( 1,-100, 120, 100, 100, NULL , 0.0f, NULL, NULL, &buttons[11], (keynum_t)'b', NULL, 0, 0, 0, true); |
| 810 |
VID_TouchscreenArea( 0, 0, 0, 64, 64, NULL , 0.0f, NULL, NULL, &buttons[12], (keynum_t)'q', NULL, 0, 0, 0, true); |
| 811 |
if (developer.integer) |
| 812 |
VID_TouchscreenArea( 0, 0, 96, 64, 64, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, true); |
| 813 |
else |
| 814 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, false); |
| 815 |
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); |
| 816 |
switch(cl.activeweapon) |
| 817 |
{ |
| 818 |
case 14: |
| 819 |
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); |
| 820 |
break; |
| 821 |
case 12: |
| 822 |
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); |
| 823 |
break; |
| 824 |
default: |
| 825 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[15], K_SPACE, NULL, 0, 0, 0, false); |
| 826 |
} |
| 827 |
} |
| 828 |
break; |
| 829 |
default: |
| 830 |
if (!steelstorm_showing_mousecursor || !steelstorm_showing_mousecursor->integer) |
| 831 |
{ |
| 832 |
Vid_ClearAllTouchscreenAreas(14); |
| 833 |
|
| 834 |
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); |
| 835 |
} |
| 836 |
else |
| 837 |
{ |
| 838 |
|
| 839 |
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); |
| 840 |
Vid_ClearAllTouchscreenAreas(0); |
| 841 |
} |
| 842 |
break; |
| 843 |
} |
| 844 |
|
| 845 |
if (VID_ShowingKeyboard() && (float)in_windowmouse_y > vid_height.value / 2 - 10) |
| 846 |
in_windowmouse_y = 128; |
| 847 |
|
| 848 |
cl.cmd.forwardmove -= move[1] * cl_forwardspeed.value; |
| 849 |
cl.cmd.sidemove += move[0] * cl_sidespeed.value; |
| 850 |
cl.viewangles[0] += aim[1] * cl_pitchspeed.value * cl.realframetime; |
| 851 |
cl.viewangles[1] -= aim[0] * cl_yawspeed.value * cl.realframetime; |
| 852 |
} |
| 853 |
|
| 854 |
static void IN_Move_TouchScreen_Quake(void) |
| 855 |
{ |
| 856 |
int x, y; |
| 857 |
float move[3], aim[3], click[3]; |
| 858 |
static qboolean oldbuttons[128]; |
| 859 |
static qboolean buttons[128]; |
| 860 |
keydest_t keydest = (key_consoleactive & KEY_CONSOLEACTIVE_USER) ? key_console : key_dest; |
| 861 |
memcpy(oldbuttons, buttons, sizeof(oldbuttons)); |
| 862 |
memset(multitouchs, 0, sizeof(multitouchs)); |
| 863 |
|
| 864 |
|
| 865 |
multitouch[MAXFINGERS-1][0] = SDL_GetMouseState(&x, &y); |
| 866 |
multitouch[MAXFINGERS-1][1] = x * 32768 / vid.width; |
| 867 |
multitouch[MAXFINGERS-1][2] = y * 32768 / vid.height; |
| 868 |
|
| 869 |
|
| 870 |
switch(keydest) |
| 871 |
{ |
| 872 |
case key_console: |
| 873 |
VID_TouchscreenArea( 0, 0, 0, 64, 64, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, true); |
| 874 |
VID_TouchscreenArea( 0, 64, 0, 64, 64, "gfx/touch_menu.tga" , 0.0f, NULL, NULL, &buttons[14], K_ESCAPE, NULL, 0, 0, 0, true); |
| 875 |
if (!VID_ShowingKeyboard()) |
| 876 |
{ |
| 877 |
|
| 878 |
Con_ToggleConsole_f(); |
| 879 |
} |
| 880 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[15], (keynum_t)0, NULL, 0, 0, 0, true); |
| 881 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, move, &buttons[0], K_MOUSE4, NULL, 0, 0, 0, true); |
| 882 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, aim, &buttons[1], K_MOUSE5, NULL, 0, 0, 0, true); |
| 883 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, click,&buttons[2], K_MOUSE1, NULL, 0, 0, 0, true); |
| 884 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[3], K_SPACE, NULL, 0, 0, 0, true); |
| 885 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[4], K_MOUSE2, NULL, 0, 0, 0, true); |
| 886 |
break; |
| 887 |
case key_game: |
| 888 |
VID_TouchscreenArea( 0, 0, 0, 64, 64, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, true); |
| 889 |
VID_TouchscreenArea( 0, 64, 0, 64, 64, "gfx/touch_menu.tga" , 0.0f, NULL, NULL, &buttons[14], K_ESCAPE, NULL, 0, 0, 0, true); |
| 890 |
VID_TouchscreenArea( 2, 0,-128, 128, 128, "gfx/touch_movebutton.tga" , 0.0f, NULL, move, &buttons[0], K_MOUSE4, NULL, 0, 0, 0, true); |
| 891 |
VID_TouchscreenArea( 3,-128,-128, 128, 128, "gfx/touch_aimbutton.tga" , 0.0f, NULL, aim, &buttons[1], K_MOUSE5, NULL, 0, 0, 0, true); |
| 892 |
VID_TouchscreenArea( 2, 0,-160, 64, 32, "gfx/touch_jumpbutton.tga" , 0.0f, NULL, NULL, &buttons[3], K_SPACE, NULL, 0, 0, 0, true); |
| 893 |
VID_TouchscreenArea( 3,-128,-160, 64, 32, "gfx/touch_attackbutton.tga" , 0.0f, NULL, NULL, &buttons[2], K_MOUSE1, NULL, 0, 0, 0, true); |
| 894 |
VID_TouchscreenArea( 3, -64,-160, 64, 32, "gfx/touch_attack2button.tga", 0.0f, NULL, NULL, &buttons[4], K_MOUSE2, NULL, 0, 0, 0, true); |
| 895 |
buttons[15] = false; |
| 896 |
break; |
| 897 |
default: |
| 898 |
VID_TouchscreenArea( 0, 0, 0, 64, 64, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, true); |
| 899 |
VID_TouchscreenArea( 0, 64, 0, 64, 64, "gfx/touch_menu.tga" , 0.0f, NULL, NULL, &buttons[14], K_ESCAPE, NULL, 0, 0, 0, true); |
| 900 |
|
| 901 |
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); |
| 902 |
if (buttons[15]) |
| 903 |
VID_ShowKeyboard(true); |
| 904 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, move, &buttons[0], K_MOUSE4, NULL, 0, 0, 0, true); |
| 905 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, aim, &buttons[1], K_MOUSE5, NULL, 0, 0, 0, true); |
| 906 |
VID_TouchscreenArea(16, -320,-480,640, 960, NULL , 0.0f, NULL, click,&buttons[2], K_MOUSE1, NULL, 0, 0, 0, true); |
| 907 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[3], K_SPACE, NULL, 0, 0, 0, true); |
| 908 |
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[4], K_MOUSE2, NULL, 0, 0, 0, true); |
| 909 |
if (buttons[2]) |
| 910 |
{ |
| 911 |
in_windowmouse_x = x; |
| 912 |
in_windowmouse_y = y; |
| 913 |
} |
| 914 |
break; |
| 915 |
} |
| 916 |
|
| 917 |
cl.cmd.forwardmove -= move[1] * cl_forwardspeed.value; |
| 918 |
cl.cmd.sidemove += move[0] * cl_sidespeed.value; |
| 919 |
cl.viewangles[0] += aim[1] * cl_pitchspeed.value * cl.realframetime; |
| 920 |
cl.viewangles[1] -= aim[0] * cl_yawspeed.value * cl.realframetime; |
| 921 |
} |
| 922 |
|
| 923 |
void IN_Move( void ) |
| 924 |
{ |
| 925 |
static int old_x = 0, old_y = 0; |
| 926 |
static int stuck = 0; |
| 927 |
static keydest_t oldkeydest; |
| 928 |
static qboolean oldshowkeyboard; |
| 929 |
int x, y; |
| 930 |
vid_joystate_t joystate; |
| 931 |
keydest_t keydest = (key_consoleactive & KEY_CONSOLEACTIVE_USER) ? key_console : key_dest; |
| 932 |
|
| 933 |
scr_numtouchscreenareas = 0; |
| 934 |
|
| 935 |
|
| 936 |
if (keydest != oldkeydest || !!vid_touchscreen_showkeyboard.integer != oldshowkeyboard) |
| 937 |
{ |
| 938 |
switch(keydest) |
| 939 |
{ |
| 940 |
case key_console: VID_ShowKeyboard(true);break; |
| 941 |
case key_message: VID_ShowKeyboard(true);break; |
| 942 |
default: VID_ShowKeyboard(!!vid_touchscreen_showkeyboard.integer); break; |
| 943 |
} |
| 944 |
} |
| 945 |
oldkeydest = keydest; |
| 946 |
oldshowkeyboard = !!vid_touchscreen_showkeyboard.integer; |
| 947 |
|
| 948 |
if (vid_touchscreen.integer) |
| 949 |
{ |
| 950 |
switch(gamemode) |
| 951 |
{ |
| 952 |
case GAME_STEELSTORM: |
| 953 |
IN_Move_TouchScreen_SteelStorm(); |
| 954 |
break; |
| 955 |
default: |
| 956 |
IN_Move_TouchScreen_Quake(); |
| 957 |
break; |
| 958 |
} |
| 959 |
} |
| 960 |
else |
| 961 |
{ |
| 962 |
if (vid_usingmouse) |
| 963 |
{ |
| 964 |
if (vid_stick_mouse.integer || !vid_usingmouse_relativeworks) |
| 965 |
{ |
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
if(!stuck) |
| 971 |
{ |
| 972 |
SDL_WarpMouseInWindow(window, win_half_width, win_half_height); |
| 973 |
SDL_GetMouseState(&x, &y); |
| 974 |
SDL_GetRelativeMouseState(&x, &y); |
| 975 |
++stuck; |
| 976 |
} else { |
| 977 |
SDL_GetRelativeMouseState(&x, &y); |
| 978 |
in_mouse_x = x + old_x; |
| 979 |
in_mouse_y = y + old_y; |
| 980 |
SDL_GetMouseState(&x, &y); |
| 981 |
old_x = x - win_half_width; |
| 982 |
old_y = y - win_half_height; |
| 983 |
SDL_WarpMouseInWindow(window, win_half_width, win_half_height); |
| 984 |
} |
| 985 |
} else { |
| 986 |
SDL_GetRelativeMouseState( &x, &y ); |
| 987 |
in_mouse_x = x; |
| 988 |
in_mouse_y = y; |
| 989 |
} |
| 990 |
} |
| 991 |
|
| 992 |
SDL_GetMouseState(&x, &y); |
| 993 |
in_windowmouse_x = x; |
| 994 |
in_windowmouse_y = y; |
| 995 |
} |
| 996 |
|
| 997 |
VID_BuildJoyState(&joystate); |
| 998 |
VID_ApplyJoyState(&joystate); |
| 999 |
} |
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
#ifdef SDL_R_RESTART |
| 1006 |
static qboolean sdl_needs_restart; |
| 1007 |
static void sdl_start(void) |
| 1008 |
{ |
| 1009 |
} |
| 1010 |
static void sdl_shutdown(void) |
| 1011 |
{ |
| 1012 |
sdl_needs_restart = false; |
| 1013 |
} |
| 1014 |
static void sdl_newmap(void) |
| 1015 |
{ |
| 1016 |
} |
| 1017 |
#endif |
| 1018 |
|
| 1019 |
static keynum_t buttonremap[] = |
| 1020 |
{ |
| 1021 |
K_MOUSE1, |
| 1022 |
K_MOUSE3, |
| 1023 |
K_MOUSE2, |
| 1024 |
K_MOUSE4, |
| 1025 |
K_MOUSE5, |
| 1026 |
K_MOUSE6, |
| 1027 |
K_MOUSE7, |
| 1028 |
K_MOUSE8, |
| 1029 |
K_MOUSE9, |
| 1030 |
K_MOUSE10, |
| 1031 |
K_MOUSE11, |
| 1032 |
K_MOUSE12, |
| 1033 |
K_MOUSE13, |
| 1034 |
K_MOUSE14, |
| 1035 |
K_MOUSE15, |
| 1036 |
K_MOUSE16, |
| 1037 |
}; |
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
void Sys_SendKeyEvents( void ) |
| 1043 |
{ |
| 1044 |
static qboolean sound_active = true; |
| 1045 |
int keycode; |
| 1046 |
int i; |
| 1047 |
qboolean isdown; |
| 1048 |
Uchar unicode; |
| 1049 |
SDL_Event event; |
| 1050 |
|
| 1051 |
VID_EnableJoystick(true); |
| 1052 |
|
| 1053 |
while( SDL_PollEvent( &event ) ) |
| 1054 |
loop_start: |
| 1055 |
switch( event.type ) { |
| 1056 |
case SDL_QUIT: |
| 1057 |
#ifdef DEBUGSDLEVENTS |
| 1058 |
Con_DPrintf("SDL_Event: SDL_QUIT\n"); |
| 1059 |
#endif |
| 1060 |
Sys_Quit(0); |
| 1061 |
break; |
| 1062 |
case SDL_KEYDOWN: |
| 1063 |
case SDL_KEYUP: |
| 1064 |
#ifdef DEBUGSDLEVENTS |
| 1065 |
if (event.type == SDL_KEYDOWN) |
| 1066 |
Con_DPrintf("SDL_Event: SDL_KEYDOWN %i\n", event.key.keysym.sym); |
| 1067 |
else |
| 1068 |
Con_DPrintf("SDL_Event: SDL_KEYUP %i\n", event.key.keysym.sym); |
| 1069 |
#endif |
| 1070 |
keycode = MapKey(event.key.keysym.sym); |
| 1071 |
isdown = (event.key.state == SDL_PRESSED); |
| 1072 |
unicode = 0; |
| 1073 |
if(isdown) |
| 1074 |
{ |
| 1075 |
if(SDL_PollEvent(&event)) |
| 1076 |
{ |
| 1077 |
if(event.type == SDL_TEXTINPUT) |
| 1078 |
{ |
| 1079 |
|
| 1080 |
|
| 1081 |
#ifdef DEBUGSDLEVENTS |
| 1082 |
Con_DPrintf("SDL_Event: SDL_TEXTINPUT - text: %s\n", event.text.text); |
| 1083 |
#endif |
| 1084 |
unicode = u8_getchar_utf8_enabled(event.text.text + (int)u8_bytelen(event.text.text, 0), NULL); |
| 1085 |
} |
| 1086 |
else |
| 1087 |
{ |
| 1088 |
if (!VID_JoyBlockEmulatedKeys(keycode)) |
| 1089 |
Key_Event(keycode, 0, isdown); |
| 1090 |
goto loop_start; |
| 1091 |
} |
| 1092 |
} |
| 1093 |
} |
| 1094 |
if (!VID_JoyBlockEmulatedKeys(keycode)) |
| 1095 |
Key_Event(keycode, unicode, isdown); |
| 1096 |
break; |
| 1097 |
case SDL_MOUSEBUTTONDOWN: |
| 1098 |
case SDL_MOUSEBUTTONUP: |
| 1099 |
#ifdef DEBUGSDLEVENTS |
| 1100 |
if (event.type == SDL_MOUSEBUTTONDOWN) |
| 1101 |
Con_DPrintf("SDL_Event: SDL_MOUSEBUTTONDOWN\n"); |
| 1102 |
else |
| 1103 |
Con_DPrintf("SDL_Event: SDL_MOUSEBUTTONUP\n"); |
| 1104 |
#endif |
| 1105 |
if (!vid_touchscreen.integer) |
| 1106 |
if (event.button.button > 0 && event.button.button <= ARRAY_SIZE(buttonremap)) |
| 1107 |
Key_Event( buttonremap[event.button.button - 1], 0, event.button.state == SDL_PRESSED ); |
| 1108 |
break; |
| 1109 |
case SDL_MOUSEWHEEL: |
| 1110 |
|
| 1111 |
i = event.wheel.y; |
| 1112 |
while (i > 0) { |
| 1113 |
--i; |
| 1114 |
Key_Event( K_MWHEELUP, 0, true ); |
| 1115 |
Key_Event( K_MWHEELUP, 0, false ); |
| 1116 |
} |
| 1117 |
while (i < 0) { |
| 1118 |
++i; |
| 1119 |
Key_Event( K_MWHEELDOWN, 0, true ); |
| 1120 |
Key_Event( K_MWHEELDOWN, 0, false ); |
| 1121 |
} |
| 1122 |
break; |
| 1123 |
case SDL_JOYBUTTONDOWN: |
| 1124 |
case SDL_JOYBUTTONUP: |
| 1125 |
case SDL_JOYAXISMOTION: |
| 1126 |
case SDL_JOYBALLMOTION: |
| 1127 |
case SDL_JOYHATMOTION: |
| 1128 |
#ifdef DEBUGSDLEVENTS |
| 1129 |
Con_DPrintf("SDL_Event: SDL_JOY*\n"); |
| 1130 |
#endif |
| 1131 |
break; |
| 1132 |
case SDL_WINDOWEVENT: |
| 1133 |
#ifdef DEBUGSDLEVENTS |
| 1134 |
Con_DPrintf("SDL_Event: SDL_WINDOWEVENT %i\n", (int)event.window.event); |
| 1135 |
#endif |
| 1136 |
|
| 1137 |
{ |
| 1138 |
switch(event.window.event) |
| 1139 |
{ |
| 1140 |
case SDL_WINDOWEVENT_SHOWN: |
| 1141 |
vid_hidden = false; |
| 1142 |
break; |
| 1143 |
case SDL_WINDOWEVENT_HIDDEN: |
| 1144 |
vid_hidden = true; |
| 1145 |
break; |
| 1146 |
case SDL_WINDOWEVENT_EXPOSED: |
| 1147 |
#ifdef DEBUGSDLEVENTS |
| 1148 |
Con_DPrintf("SDL_Event: SDL_WINDOWEVENT_EXPOSED\n"); |
| 1149 |
#endif |
| 1150 |
break; |
| 1151 |
case SDL_WINDOWEVENT_MOVED: |
| 1152 |
break; |
| 1153 |
case SDL_WINDOWEVENT_RESIZED: |
| 1154 |
if(vid_resizable.integer < 2) |
| 1155 |
{ |
| 1156 |
vid.width = event.window.data1; |
| 1157 |
vid.height = event.window.data2; |
| 1158 |
#ifdef SDL_R_RESTART |
| 1159 |
|
| 1160 |
|
| 1161 |
if(!sdl_needs_restart) |
| 1162 |
{ |
| 1163 |
Cbuf_AddText("\nr_restart\n"); |
| 1164 |
sdl_needs_restart = true; |
| 1165 |
} |
| 1166 |
#endif |
| 1167 |
} |
| 1168 |
break; |
| 1169 |
case SDL_WINDOWEVENT_MINIMIZED: |
| 1170 |
break; |
| 1171 |
case SDL_WINDOWEVENT_MAXIMIZED: |
| 1172 |
break; |
| 1173 |
case SDL_WINDOWEVENT_RESTORED: |
| 1174 |
break; |
| 1175 |
case SDL_WINDOWEVENT_ENTER: |
| 1176 |
break; |
| 1177 |
case SDL_WINDOWEVENT_LEAVE: |
| 1178 |
break; |
| 1179 |
case SDL_WINDOWEVENT_FOCUS_GAINED: |
| 1180 |
vid_hasfocus = true; |
| 1181 |
break; |
| 1182 |
case SDL_WINDOWEVENT_FOCUS_LOST: |
| 1183 |
vid_hasfocus = false; |
| 1184 |
break; |
| 1185 |
case SDL_WINDOWEVENT_CLOSE: |
| 1186 |
Sys_Quit(0); |
| 1187 |
break; |
| 1188 |
} |
| 1189 |
} |
| 1190 |
break; |
| 1191 |
case SDL_TEXTEDITING: |
| 1192 |
#ifdef DEBUGSDLEVENTS |
| 1193 |
Con_DPrintf("SDL_Event: SDL_TEXTEDITING - composition = %s, cursor = %d, selection lenght = %d\n", event.edit.text, event.edit.start, event.edit.length); |
| 1194 |
#endif |
| 1195 |
|
| 1196 |
break; |
| 1197 |
case SDL_TEXTINPUT: |
| 1198 |
#ifdef DEBUGSDLEVENTS |
| 1199 |
Con_DPrintf("SDL_Event: SDL_TEXTINPUT - text: %s\n", event.text.text); |
| 1200 |
#endif |
| 1201 |
|
| 1202 |
|
| 1203 |
unicode = u8_getchar_utf8_enabled(event.text.text + (int)u8_bytelen(event.text.text, 0), NULL); |
| 1204 |
Key_Event(K_TEXT, unicode, true); |
| 1205 |
Key_Event(K_TEXT, unicode, false); |
| 1206 |
break; |
| 1207 |
case SDL_MOUSEMOTION: |
| 1208 |
break; |
| 1209 |
case SDL_FINGERDOWN: |
| 1210 |
#ifdef DEBUGSDLEVENTS |
| 1211 |
Con_DPrintf("SDL_FINGERDOWN for finger %i\n", (int)event.tfinger.fingerId); |
| 1212 |
#endif |
| 1213 |
for (i = 0;i < MAXFINGERS-1;i++) |
| 1214 |
{ |
| 1215 |
if (!multitouch[i][0]) |
| 1216 |
{ |
| 1217 |
multitouch[i][0] = event.tfinger.fingerId + 1; |
| 1218 |
multitouch[i][1] = event.tfinger.x; |
| 1219 |
multitouch[i][2] = event.tfinger.y; |
| 1220 |
|
| 1221 |
break; |
| 1222 |
} |
| 1223 |
} |
| 1224 |
if (i == MAXFINGERS-1) |
| 1225 |
Con_DPrintf("Too many fingers at once!\n"); |
| 1226 |
break; |
| 1227 |
case SDL_FINGERUP: |
| 1228 |
#ifdef DEBUGSDLEVENTS |
| 1229 |
Con_DPrintf("SDL_FINGERUP for finger %i\n", (int)event.tfinger.fingerId); |
| 1230 |
#endif |
| 1231 |
for (i = 0;i < MAXFINGERS-1;i++) |
| 1232 |
{ |
| 1233 |
if (multitouch[i][0] == event.tfinger.fingerId + 1) |
| 1234 |
{ |
| 1235 |
multitouch[i][0] = 0; |
| 1236 |
break; |
| 1237 |
} |
| 1238 |
} |
| 1239 |
if (i == MAXFINGERS-1) |
| 1240 |
Con_DPrintf("No SDL_FINGERDOWN event matches this SDL_FINGERMOTION event\n"); |
| 1241 |
break; |
| 1242 |
case SDL_FINGERMOTION: |
| 1243 |
#ifdef DEBUGSDLEVENTS |
| 1244 |
Con_DPrintf("SDL_FINGERMOTION for finger %i\n", (int)event.tfinger.fingerId); |
| 1245 |
#endif |
| 1246 |
for (i = 0;i < MAXFINGERS-1;i++) |
| 1247 |
{ |
| 1248 |
if (multitouch[i][0] == event.tfinger.fingerId + 1) |
| 1249 |
{ |
| 1250 |
multitouch[i][1] = event.tfinger.x; |
| 1251 |
multitouch[i][2] = event.tfinger.y; |
| 1252 |
break; |
| 1253 |
} |
| 1254 |
} |
| 1255 |
if (i == MAXFINGERS-1) |
| 1256 |
Con_DPrintf("No SDL_FINGERDOWN event matches this SDL_FINGERMOTION event\n"); |
| 1257 |
break; |
| 1258 |
default: |
| 1259 |
#ifdef DEBUGSDLEVENTS |
| 1260 |
Con_DPrintf("Received unrecognized SDL_Event type 0x%x\n", event.type); |
| 1261 |
#endif |
| 1262 |
break; |
| 1263 |
} |
| 1264 |
|
| 1265 |
|
| 1266 |
if ((!vid_hidden && vid_activewindow) || !snd_mutewhenidle.integer) |
| 1267 |
{ |
| 1268 |
if (!sound_active) |
| 1269 |
{ |
| 1270 |
S_UnblockSound (); |
| 1271 |
sound_active = true; |
| 1272 |
} |
| 1273 |
} |
| 1274 |
else |
| 1275 |
{ |
| 1276 |
if (sound_active) |
| 1277 |
{ |
| 1278 |
S_BlockSound (); |
| 1279 |
sound_active = false; |
| 1280 |
} |
| 1281 |
} |
| 1282 |
} |
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
void *GL_GetProcAddress(const char *name) |
| 1289 |
{ |
| 1290 |
void *p = NULL; |
| 1291 |
p = SDL_GL_GetProcAddress(name); |
| 1292 |
return p; |
| 1293 |
} |
| 1294 |
|
| 1295 |
qboolean GL_ExtensionSupported(const char *name) |
| 1296 |
{ |
| 1297 |
return SDL_GL_ExtensionSupported(name); |
| 1298 |
} |
| 1299 |
|
| 1300 |
static qboolean vid_sdl_initjoysticksystem = false; |
| 1301 |
|
| 1302 |
void VID_Init (void) |
| 1303 |
{ |
| 1304 |
#ifndef __IPHONEOS__ |
| 1305 |
#ifdef MACOSX |
| 1306 |
Cvar_RegisterVariable(&apple_mouse_noaccel); |
| 1307 |
#endif |
| 1308 |
#endif |
| 1309 |
#ifdef DP_MOBILETOUCH |
| 1310 |
Cvar_SetValueQuick(&vid_touchscreen, 1); |
| 1311 |
#endif |
| 1312 |
|
| 1313 |
#ifdef SDL_R_RESTART |
| 1314 |
R_RegisterModule("SDL", sdl_start, sdl_shutdown, sdl_newmap, NULL, NULL); |
| 1315 |
#endif |
| 1316 |
|
| 1317 |
if (SDL_Init(SDL_INIT_VIDEO) < 0) |
| 1318 |
Sys_Error ("Failed to init SDL video subsystem: %s", SDL_GetError()); |
| 1319 |
vid_sdl_initjoysticksystem = SDL_InitSubSystem(SDL_INIT_JOYSTICK) >= 0; |
| 1320 |
if (vid_sdl_initjoysticksystem) |
| 1321 |
Con_Printf("Failed to init SDL joystick subsystem: %s\n", SDL_GetError()); |
| 1322 |
vid_isfullscreen = false; |
| 1323 |
} |
| 1324 |
|
| 1325 |
static int vid_sdljoystickindex = -1; |
| 1326 |
void VID_EnableJoystick(qboolean enable) |
| 1327 |
{ |
| 1328 |
int index = joy_enable.integer > 0 ? joy_index.integer : -1; |
| 1329 |
int numsdljoysticks; |
| 1330 |
qboolean success = false; |
| 1331 |
int sharedcount = 0; |
| 1332 |
int sdlindex = -1; |
| 1333 |
sharedcount = VID_Shared_SetJoystick(index); |
| 1334 |
if (index >= 0 && index < sharedcount) |
| 1335 |
success = true; |
| 1336 |
sdlindex = index - sharedcount; |
| 1337 |
|
| 1338 |
numsdljoysticks = SDL_NumJoysticks(); |
| 1339 |
if (sdlindex < 0 || sdlindex >= numsdljoysticks) |
| 1340 |
sdlindex = -1; |
| 1341 |
|
| 1342 |
|
| 1343 |
if (joy_detected.integer != sharedcount + numsdljoysticks) |
| 1344 |
Cvar_SetValueQuick(&joy_detected, sharedcount + numsdljoysticks); |
| 1345 |
|
| 1346 |
if (vid_sdljoystickindex != sdlindex) |
| 1347 |
{ |
| 1348 |
vid_sdljoystickindex = sdlindex; |
| 1349 |
|
| 1350 |
if (vid_sdljoystick) |
| 1351 |
SDL_JoystickClose(vid_sdljoystick); |
| 1352 |
vid_sdljoystick = NULL; |
| 1353 |
if (sdlindex >= 0) |
| 1354 |
{ |
| 1355 |
vid_sdljoystick = SDL_JoystickOpen(sdlindex); |
| 1356 |
if (vid_sdljoystick) |
| 1357 |
{ |
| 1358 |
const char *joystickname = SDL_JoystickName(vid_sdljoystick); |
| 1359 |
Con_Printf("Joystick %i opened (SDL_Joystick %i is \"%s\" with %i axes, %i buttons, %i balls)\n", index, sdlindex, joystickname, (int)SDL_JoystickNumAxes(vid_sdljoystick), (int)SDL_JoystickNumButtons(vid_sdljoystick), (int)SDL_JoystickNumBalls(vid_sdljoystick)); |
| 1360 |
} |
| 1361 |
else |
| 1362 |
{ |
| 1363 |
Con_Printf("Joystick %i failed (SDL_JoystickOpen(%i) returned: %s)\n", index, sdlindex, SDL_GetError()); |
| 1364 |
sdlindex = -1; |
| 1365 |
} |
| 1366 |
} |
| 1367 |
} |
| 1368 |
|
| 1369 |
if (sdlindex >= 0) |
| 1370 |
success = true; |
| 1371 |
|
| 1372 |
if (joy_active.integer != (success ? 1 : 0)) |
| 1373 |
Cvar_SetValueQuick(&joy_active, success ? 1 : 0); |
| 1374 |
} |
| 1375 |
|
| 1376 |
static void VID_OutputVersion(void) |
| 1377 |
{ |
| 1378 |
SDL_version version; |
| 1379 |
SDL_GetVersion(&version); |
| 1380 |
Con_Printf( "Linked against SDL version %d.%d.%d\n" |
| 1381 |
"Using SDL library version %d.%d.%d\n", |
| 1382 |
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL, |
| 1383 |
version.major, version.minor, version.patch ); |
| 1384 |
} |
| 1385 |
|
| 1386 |
#ifdef WIN32 |
| 1387 |
static void AdjustWindowBounds(viddef_mode_t *mode, RECT *rect) |
| 1388 |
{ |
| 1389 |
LONG width = mode->width; |
| 1390 |
LONG height = mode->height; |
| 1391 |
|
| 1392 |
|
| 1393 |
rect->top = 0; |
| 1394 |
rect->left = 0; |
| 1395 |
rect->right = width; |
| 1396 |
rect->bottom = height; |
| 1397 |
AdjustWindowRectEx(rect, WS_CAPTION|WS_THICKFRAME, false, 0); |
| 1398 |
|
| 1399 |
RECT workArea; |
| 1400 |
SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0); |
| 1401 |
int workWidth = workArea.right - workArea.left; |
| 1402 |
int workHeight = workArea.bottom - workArea.top; |
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
int titleBarPixels = 2; |
| 1408 |
int screenHeight = GetSystemMetrics(SM_CYSCREEN); |
| 1409 |
if (screenHeight == workHeight) |
| 1410 |
titleBarPixels = -rect->top; |
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
if ((width == GetSystemMetrics(SM_CXSCREEN) || width == workWidth) && (height == screenHeight || height == workHeight - titleBarPixels)) |
| 1416 |
{ |
| 1417 |
rect->left = workArea.left; |
| 1418 |
mode->width = workWidth; |
| 1419 |
rect->top = workArea.top + titleBarPixels; |
| 1420 |
mode->height = workHeight - titleBarPixels; |
| 1421 |
} |
| 1422 |
else |
| 1423 |
{ |
| 1424 |
rect->left = workArea.left + max(0, (workWidth - width) / 2); |
| 1425 |
rect->top = workArea.top + max(0, (workHeight - height) / 2); |
| 1426 |
} |
| 1427 |
} |
| 1428 |
#endif |
| 1429 |
|
| 1430 |
static qboolean VID_InitModeGL(viddef_mode_t *mode) |
| 1431 |
{ |
| 1432 |
int windowflags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL; |
| 1433 |
int xPos = SDL_WINDOWPOS_UNDEFINED; |
| 1434 |
int yPos = SDL_WINDOWPOS_UNDEFINED; |
| 1435 |
#ifndef USE_GLES2 |
| 1436 |
int i; |
| 1437 |
const char *drivername; |
| 1438 |
#endif |
| 1439 |
|
| 1440 |
win_half_width = mode->width>>1; |
| 1441 |
win_half_height = mode->height>>1; |
| 1442 |
|
| 1443 |
if(vid_resizable.integer) |
| 1444 |
windowflags |= SDL_WINDOW_RESIZABLE; |
| 1445 |
|
| 1446 |
VID_OutputVersion(); |
| 1447 |
|
| 1448 |
#ifndef USE_GLES2 |
| 1449 |
|
| 1450 |
drivername = NULL; |
| 1451 |
|
| 1452 |
|
| 1453 |
i = COM_CheckParm("-gl_driver"); |
| 1454 |
if (i && i < com_argc - 1) |
| 1455 |
drivername = com_argv[i + 1]; |
| 1456 |
if (SDL_GL_LoadLibrary(drivername) < 0) |
| 1457 |
{ |
| 1458 |
Con_Printf("Unable to load GL driver \"%s\": %s\n", drivername, SDL_GetError()); |
| 1459 |
return false; |
| 1460 |
} |
| 1461 |
#endif |
| 1462 |
|
| 1463 |
#ifdef DP_MOBILETOUCH |
| 1464 |
|
| 1465 |
mode->fullscreen = true; |
| 1466 |
|
| 1467 |
windowflags |= SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS; |
| 1468 |
#endif |
| 1469 |
|
| 1470 |
vid_isfullscreen = false; |
| 1471 |
{ |
| 1472 |
if (mode->fullscreen) { |
| 1473 |
if (vid_desktopfullscreen.integer) |
| 1474 |
{ |
| 1475 |
vid_mode_t *m = VID_GetDesktopMode(); |
| 1476 |
mode->width = m->width; |
| 1477 |
mode->height = m->height; |
| 1478 |
windowflags |= SDL_WINDOW_FULLSCREEN_DESKTOP; |
| 1479 |
} |
| 1480 |
else |
| 1481 |
windowflags |= SDL_WINDOW_FULLSCREEN; |
| 1482 |
vid_isfullscreen = true; |
| 1483 |
} |
| 1484 |
else { |
| 1485 |
#ifdef WIN32 |
| 1486 |
RECT rect; |
| 1487 |
AdjustWindowBounds(mode, &rect); |
| 1488 |
xPos = rect.left; |
| 1489 |
yPos = rect.top; |
| 1490 |
#endif |
| 1491 |
} |
| 1492 |
} |
| 1493 |
|
| 1494 |
|
| 1495 |
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
| 1496 |
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8); |
| 1497 |
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8); |
| 1498 |
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 8); |
| 1499 |
SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 8); |
| 1500 |
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24); |
| 1501 |
SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8); |
| 1502 |
if (mode->stereobuffer) |
| 1503 |
SDL_GL_SetAttribute (SDL_GL_STEREO, 1); |
| 1504 |
if (mode->samples > 1) |
| 1505 |
{ |
| 1506 |
SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); |
| 1507 |
SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, mode->samples); |
| 1508 |
} |
| 1509 |
|
| 1510 |
#ifdef USE_GLES2 |
| 1511 |
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2); |
| 1512 |
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0); |
| 1513 |
SDL_GL_SetAttribute (SDL_GL_RETAINED_BACKING, 1); |
| 1514 |
#else |
| 1515 |
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); |
| 1516 |
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); |
| 1517 |
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, (gl_debug.integer > 0 ? SDL_GL_CONTEXT_DEBUG_FLAG : 0)); |
| 1518 |
#endif |
| 1519 |
|
| 1520 |
video_bpp = mode->bitsperpixel; |
| 1521 |
window_flags = windowflags; |
| 1522 |
window = SDL_CreateWindow(gamename, xPos, yPos, mode->width, mode->height, windowflags); |
| 1523 |
if (window == NULL) |
| 1524 |
{ |
| 1525 |
Con_Printf("Failed to set video mode to %ix%i: %s\n", mode->width, mode->height, SDL_GetError()); |
| 1526 |
VID_Shutdown(); |
| 1527 |
return false; |
| 1528 |
} |
| 1529 |
SDL_GetWindowSize(window, &mode->width, &mode->height); |
| 1530 |
context = SDL_GL_CreateContext(window); |
| 1531 |
if (context == NULL) |
| 1532 |
{ |
| 1533 |
Con_Printf("Failed to initialize OpenGL context: %s\n", SDL_GetError()); |
| 1534 |
VID_Shutdown(); |
| 1535 |
return false; |
| 1536 |
} |
| 1537 |
|
| 1538 |
SDL_GL_SetSwapInterval(bound(-1, vid_vsync.integer, 1)); |
| 1539 |
vid_usingvsync = (vid_vsync.integer != 0); |
| 1540 |
|
| 1541 |
gl_platform = "SDL"; |
| 1542 |
|
| 1543 |
GL_Setup(); |
| 1544 |
|
| 1545 |
|
| 1546 |
extern cvar_t gl_info_vendor; |
| 1547 |
extern cvar_t gl_info_renderer; |
| 1548 |
extern cvar_t gl_info_version; |
| 1549 |
extern cvar_t gl_info_platform; |
| 1550 |
extern cvar_t gl_info_driver; |
| 1551 |
Cvar_SetQuick(&gl_info_vendor, gl_vendor); |
| 1552 |
Cvar_SetQuick(&gl_info_renderer, gl_renderer); |
| 1553 |
Cvar_SetQuick(&gl_info_version, gl_version); |
| 1554 |
Cvar_SetQuick(&gl_info_platform, gl_platform ? gl_platform : ""); |
| 1555 |
Cvar_SetQuick(&gl_info_driver, gl_driver); |
| 1556 |
|
| 1557 |
|
| 1558 |
#ifdef CONFIG_MENU |
| 1559 |
Con_DPrintf("\nQuakeC extensions for server and client: %s\nQuakeC extensions for menu: %s\n", vm_sv_extensions, vm_m_extensions); |
| 1560 |
#else |
| 1561 |
Con_DPrintf("\nQuakeC extensions for server and client: %s\n", vm_sv_extensions); |
| 1562 |
#endif |
| 1563 |
|
| 1564 |
|
| 1565 |
GL_Clear(GL_COLOR_BUFFER_BIT, NULL, 1.0f, 0); |
| 1566 |
|
| 1567 |
vid_hidden = false; |
| 1568 |
vid_activewindow = false; |
| 1569 |
vid_hasfocus = true; |
| 1570 |
vid_usingmouse = false; |
| 1571 |
vid_usinghidecursor = false; |
| 1572 |
|
| 1573 |
return true; |
| 1574 |
} |
| 1575 |
|
| 1576 |
extern cvar_t gl_info_extensions; |
| 1577 |
extern cvar_t gl_info_vendor; |
| 1578 |
extern cvar_t gl_info_renderer; |
| 1579 |
extern cvar_t gl_info_version; |
| 1580 |
extern cvar_t gl_info_platform; |
| 1581 |
extern cvar_t gl_info_driver; |
| 1582 |
|
| 1583 |
qboolean VID_InitMode(viddef_mode_t *mode) |
| 1584 |
{ |
| 1585 |
|
| 1586 |
steelstorm_showing_map = Cvar_FindVar("steelstorm_showing_map"); |
| 1587 |
steelstorm_showing_mousecursor = Cvar_FindVar("steelstorm_showing_mousecursor"); |
| 1588 |
|
| 1589 |
if (!SDL_WasInit(SDL_INIT_VIDEO) && SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) |
| 1590 |
Sys_Error ("Failed to init SDL video subsystem: %s", SDL_GetError()); |
| 1591 |
|
| 1592 |
Cvar_SetValueQuick(&vid_touchscreen_supportshowkeyboard, SDL_HasScreenKeyboardSupport() ? 1 : 0); |
| 1593 |
return VID_InitModeGL(mode); |
| 1594 |
} |
| 1595 |
|
| 1596 |
void VID_Shutdown (void) |
| 1597 |
{ |
| 1598 |
VID_EnableJoystick(false); |
| 1599 |
VID_SetMouse(false, false, false); |
| 1600 |
|
| 1601 |
SDL_DestroyWindow(window); |
| 1602 |
window = NULL; |
| 1603 |
|
| 1604 |
SDL_QuitSubSystem(SDL_INIT_VIDEO); |
| 1605 |
|
| 1606 |
gl_driver[0] = 0; |
| 1607 |
gl_extensions = ""; |
| 1608 |
gl_platform = ""; |
| 1609 |
} |
| 1610 |
|
| 1611 |
void VID_Finish (void) |
| 1612 |
{ |
| 1613 |
qboolean vid_usevsync; |
| 1614 |
vid_activewindow = !vid_hidden && vid_hasfocus; |
| 1615 |
|
| 1616 |
VID_UpdateGamma(); |
| 1617 |
|
| 1618 |
if (!vid_hidden) |
| 1619 |
{ |
| 1620 |
switch(vid.renderpath) |
| 1621 |
{ |
| 1622 |
case RENDERPATH_GL32: |
| 1623 |
case RENDERPATH_GLES2: |
| 1624 |
CHECKGLERROR |
| 1625 |
if (r_speeds.integer == 2 || gl_finish.integer) |
| 1626 |
GL_Finish(); |
| 1627 |
|
| 1628 |
vid_usevsync = (vid_vsync.integer && !cls.timedemo); |
| 1629 |
if (vid_usingvsync != vid_usevsync) |
| 1630 |
{ |
| 1631 |
vid_usingvsync = vid_usevsync; |
| 1632 |
if (SDL_GL_SetSwapInterval(vid_usevsync != 0) >= 0) |
| 1633 |
Con_DPrintf("Vsync %s\n", vid_usevsync ? "activated" : "deactivated"); |
| 1634 |
else |
| 1635 |
Con_DPrintf("ERROR: can't %s vsync\n", vid_usevsync ? "activate" : "deactivate"); |
| 1636 |
} |
| 1637 |
SDL_GL_SwapWindow(window); |
| 1638 |
break; |
| 1639 |
} |
| 1640 |
} |
| 1641 |
} |
| 1642 |
|
| 1643 |
vid_mode_t *VID_GetDesktopMode(void) |
| 1644 |
{ |
| 1645 |
SDL_DisplayMode mode; |
| 1646 |
int bpp; |
| 1647 |
Uint32 rmask, gmask, bmask, amask; |
| 1648 |
SDL_GetDesktopDisplayMode(0, &mode); |
| 1649 |
SDL_PixelFormatEnumToMasks(mode.format, &bpp, &rmask, &gmask, &bmask, &amask); |
| 1650 |
desktop_mode.width = mode.w; |
| 1651 |
desktop_mode.height = mode.h; |
| 1652 |
desktop_mode.bpp = bpp; |
| 1653 |
desktop_mode.refreshrate = mode.refresh_rate; |
| 1654 |
desktop_mode.pixelheight_num = 1; |
| 1655 |
desktop_mode.pixelheight_denom = 1; |
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
return &desktop_mode; |
| 1660 |
} |
| 1661 |
|
| 1662 |
size_t VID_ListModes(vid_mode_t *modes, size_t maxcount) |
| 1663 |
{ |
| 1664 |
size_t k = 0; |
| 1665 |
int modenum; |
| 1666 |
int nummodes = SDL_GetNumDisplayModes(0); |
| 1667 |
SDL_DisplayMode mode; |
| 1668 |
for (modenum = 0;modenum < nummodes;modenum++) |
| 1669 |
{ |
| 1670 |
if (k >= maxcount) |
| 1671 |
break; |
| 1672 |
if (SDL_GetDisplayMode(0, modenum, &mode)) |
| 1673 |
continue; |
| 1674 |
modes[k].width = mode.w; |
| 1675 |
modes[k].height = mode.h; |
| 1676 |
|
| 1677 |
modes[k].refreshrate = mode.refresh_rate; |
| 1678 |
modes[k].pixelheight_num = 1; |
| 1679 |
modes[k].pixelheight_denom = 1; |
| 1680 |
k++; |
| 1681 |
} |
| 1682 |
return k; |
| 1683 |
} |