19#undef WIN32_LEAN_AND_MEAN
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#if (MAC_OS_X_VERSION_MIN_REQUIRED < 120000)
34 #define IOMainPort IOMasterPort
36static cvar_t apple_mouse_noaccel = {
CF_CLIENT |
CF_ARCHIVE,
"apple_mouse_noaccel",
"1",
"disables mouse acceleration while DarkPlaces is active"};
37static qbool vid_usingnoaccel;
38static double originalMouseSpeed = -1.0;
39static io_connect_t IN_GetIOHandle(
void)
41 io_connect_t iohandle = MACH_PORT_NULL;
43 io_service_t iohidsystem = MACH_PORT_NULL;
44 mach_port_t masterport;
46 status = IOMainPort(MACH_PORT_NULL, &masterport);
47 if(status != KERN_SUCCESS)
50 iohidsystem = IORegistryEntryFromPath(masterport, kIOServicePlane
":/IOResources/IOHIDSystem");
54 status = IOServiceOpen(iohidsystem, mach_task_self(), kIOHIDParamConnectType, &iohandle);
55 IOObjectRelease(iohidsystem);
86#define SDLK_PERCENT '%'
89static int MapKey(
unsigned int sdlkey )
94 default:
return sdlkey & SDLK_SCANCODE_MASK ? 0 : sdlkey;
96 case SDLK_RETURN:
return K_ENTER;
99 case SDLK_TAB:
return K_TAB;
100 case SDLK_SPACE:
return K_SPACE;
101 case SDLK_EXCLAIM:
return '!';
102 case SDLK_QUOTEDBL:
return '"';
103 case SDLK_HASH:
return '#';
105 case SDLK_DOLLAR:
return '$';
106 case SDLK_AMPERSAND:
return '&';
107 case SDLK_QUOTE:
return '\'';
108 case SDLK_LEFTPAREN:
return '(';
109 case SDLK_RIGHTPAREN:
return ')';
110 case SDLK_ASTERISK:
return '*';
111 case SDLK_PLUS:
return '+';
112 case SDLK_COMMA:
return ',';
113 case SDLK_MINUS:
return '-';
114 case SDLK_PERIOD:
return '.';
115 case SDLK_SLASH:
return '/';
116 case SDLK_0:
return '0';
117 case SDLK_1:
return '1';
118 case SDLK_2:
return '2';
119 case SDLK_3:
return '3';
120 case SDLK_4:
return '4';
121 case SDLK_5:
return '5';
122 case SDLK_6:
return '6';
123 case SDLK_7:
return '7';
124 case SDLK_8:
return '8';
125 case SDLK_9:
return '9';
126 case SDLK_COLON:
return ':';
127 case SDLK_SEMICOLON:
return ';';
128 case SDLK_LESS:
return '<';
129 case SDLK_EQUALS:
return '=';
130 case SDLK_GREATER:
return '>';
131 case SDLK_QUESTION:
return '?';
132 case SDLK_AT:
return '@';
133 case SDLK_LEFTBRACKET:
return '[';
134 case SDLK_BACKSLASH:
return '\\';
135 case SDLK_RIGHTBRACKET:
return ']';
136 case SDLK_CARET:
return '^';
137 case SDLK_UNDERSCORE:
return '_';
138 case SDLK_BACKQUOTE:
return '`';
139 case SDLK_a:
return 'a';
140 case SDLK_b:
return 'b';
141 case SDLK_c:
return 'c';
142 case SDLK_d:
return 'd';
143 case SDLK_e:
return 'e';
144 case SDLK_f:
return 'f';
145 case SDLK_g:
return 'g';
146 case SDLK_h:
return 'h';
147 case SDLK_i:
return 'i';
148 case SDLK_j:
return 'j';
149 case SDLK_k:
return 'k';
150 case SDLK_l:
return 'l';
151 case SDLK_m:
return 'm';
152 case SDLK_n:
return 'n';
153 case SDLK_o:
return 'o';
154 case SDLK_p:
return 'p';
155 case SDLK_q:
return 'q';
156 case SDLK_r:
return 'r';
157 case SDLK_s:
return 's';
158 case SDLK_t:
return 't';
159 case SDLK_u:
return 'u';
160 case SDLK_v:
return 'v';
161 case SDLK_w:
return 'w';
162 case SDLK_x:
return 'x';
163 case SDLK_y:
return 'y';
164 case SDLK_z:
return 'z';
166 case SDLK_F1:
return K_F1;
167 case SDLK_F2:
return K_F2;
168 case SDLK_F3:
return K_F3;
169 case SDLK_F4:
return K_F4;
170 case SDLK_F5:
return K_F5;
171 case SDLK_F6:
return K_F6;
172 case SDLK_F7:
return K_F7;
173 case SDLK_F8:
return K_F8;
174 case SDLK_F9:
return K_F9;
175 case SDLK_F10:
return K_F10;
176 case SDLK_F11:
return K_F11;
177 case SDLK_F12:
return K_F12;
180 case SDLK_PAUSE:
return K_PAUSE;
181 case SDLK_INSERT:
return K_INS;
182 case SDLK_HOME:
return K_HOME;
183 case SDLK_PAGEUP:
return K_PGUP;
187 case SDLK_DELETE:
return K_DEL;
189 case SDLK_END:
return K_END;
190 case SDLK_PAGEDOWN:
return K_PGDN;
195 case SDLK_NUMLOCKCLEAR:
return K_NUMLOCK;
201 case SDLK_KP_1:
return ((SDL_GetModState() & KMOD_NUM) ?
K_KP_1 :
K_END);
203 case SDLK_KP_3:
return ((SDL_GetModState() & KMOD_NUM) ?
K_KP_3 :
K_PGDN);
205 case SDLK_KP_5:
return K_KP_5;
207 case SDLK_KP_7:
return ((SDL_GetModState() & KMOD_NUM) ?
K_KP_7 :
K_HOME);
208 case SDLK_KP_8:
return ((SDL_GetModState() & KMOD_NUM) ?
K_KP_8 :
K_UPARROW);
209 case SDLK_KP_9:
return ((SDL_GetModState() & KMOD_NUM) ?
K_KP_9 :
K_PGUP);
210 case SDLK_KP_0:
return ((SDL_GetModState() & KMOD_NUM) ?
K_KP_0 :
K_INS);
211 case SDLK_KP_PERIOD:
return ((SDL_GetModState() & KMOD_NUM) ?
K_KP_PERIOD :
K_DEL);
301 case SDLK_LCTRL:
return K_CTRL;
302 case SDLK_LSHIFT:
return K_SHIFT;
303 case SDLK_LALT:
return K_ALT;
305 case SDLK_RCTRL:
return K_CTRL;
306 case SDLK_RSHIFT:
return K_SHIFT;
307 case SDLK_RALT:
return K_ALT;
340 return SDL_HasScreenKeyboardSupport() != SDL_FALSE;
345 if (!SDL_HasScreenKeyboardSupport())
350 if (!SDL_IsTextInputActive())
351 SDL_StartTextInput();
355 if (SDL_IsTextInputActive())
362 return SDL_IsTextInputActive() != 0;
367#ifndef DP_MOBILETOUCH
383 originalMouseSpeed = -1.0;
384 if(apple_mouse_noaccel.
integer)
386 io_connect_t mouseDev = IN_GetIOHandle();
389 if(IOHIDGetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &originalMouseSpeed) == kIOReturnSuccess)
391 Con_DPrintf(
"previous mouse acceleration: %f\n", originalMouseSpeed);
392 if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), -1.0) != kIOReturnSuccess)
394 Con_Print(
"Could not disable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n");
400 Con_Print(
"Could not disable mouse acceleration (failed at IOHIDGetAccelerationWithKey).\n");
403 IOServiceClose(mouseDev);
407 Con_Print(
"Could not disable mouse acceleration (failed at IO_GetIOHandle).\n");
412 vid_usingnoaccel = !!apple_mouse_noaccel.
integer;
416 if(originalMouseSpeed != -1.0)
418 io_connect_t mouseDev = IN_GetIOHandle();
421 Con_DPrintf(
"restoring mouse acceleration to: %f\n", originalMouseSpeed);
422 if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess)
423 Con_Print(
"Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n");
424 IOServiceClose(mouseDev);
427 Con_Print(
"Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n");
435 SDL_ShowCursor( hidecursor ? SDL_DISABLE : SDL_ENABLE);
452static qbool VID_TouchscreenArea(
int corner,
float px,
float py,
float pwidth,
float pheight,
const char *icon,
float textheight,
const char *text,
float *resultmove,
qbool *resultbutton,
keynum_t key,
const char *typedtext,
float deadzone,
float oversizepixels_x,
float oversizepixels_y,
qbool iamexclusive)
455 float fx, fy, fwidth, fheight;
456 float overfx, overfy, overfwidth, overfheight;
459 qbool button =
false;
461 if (pwidth > 0 && pheight > 0)
475 if (!(*resultbutton))
477 oversizepixels_x *= 0.2;
478 oversizepixels_y *= 0.2;
484 overfx = fx - oversizepixels_x;
485 overfy = fy - oversizepixels_y;
486 overfwidth = fwidth + 2*oversizepixels_x;
487 overfheight = fheight + 2*oversizepixels_y;
498 rel[0] =
bound(-1, (
multitouch[finger][1] - (fx + 0.5f * fwidth)) * (2.0f / fwidth), 1);
499 rel[1] =
bound(-1, (
multitouch[finger][2] - (fy + 0.5f * fheight)) * (2.0f / fheight), 1);
502 sqsum = rel[0]*rel[0] + rel[1]*rel[1];
504 if (sqsum < deadzone*deadzone)
543 if (*resultbutton != button)
547 if (typedtext && typedtext[0] && !*resultbutton)
551 for (
i = 0;typedtext[
i];
i++)
558 *resultbutton = button;
568 float fx, fy, fwidth, fheight;
569 qbool button =
false;
570 static int cursorfinger = -1;
571 static int cursorfreemovement =
false;
572 static int canclick =
false;
573 static int clickxy[2];
574 static int relclickxy[2];
575 static double clickrealtime = 0;
578 if (pwidth > 0 && pheight > 0)
588 if (cursorfinger == -1)
595 cursorfinger = finger;
598 cursorfreemovement =
false;
636 if (cursorfinger != -1)
645 cursorfreemovement =
true;
647 if (cursorfreemovement)
664 if (!button && !cursorfreemovement && canclick)
672 if (clickrealtime && clickrealtime + 0.1 <
host.
realtime)
679 *resultbutton = button;
694 for (j = 0; j <= SDL_CONTROLLER_AXIS_MAX; ++j)
698 for (j = 0; j < SDL_CONTROLLER_BUTTON_MAX; ++j)
709 numaxes = SDL_JoystickNumAxes(joy);
710 for (j = 0;j < numaxes;j++)
711 joystate->
axis[j] = SDL_JoystickGetAxis(joy, j) * (1.0f / 32767.0f);
712 numbuttons = SDL_JoystickNumButtons(joy);
713 for (j = 0;j < numbuttons;j++)
714 joystate->
button[j] = SDL_JoystickGetButton(joy, j);
722#define Vid_ClearAllTouchscreenAreas(skip) \
724 VID_TouchscreenCursor(0, 0, 0, 0, &buttons[0], K_MOUSE1); \
726 VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, move, &buttons[1], K_MOUSE4, NULL, 0, 0, 0, false); \
728 VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, aim, &buttons[2], K_MOUSE5, NULL, 0, 0, 0, false); \
730 VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[3], K_SHIFT, NULL, 0, 0, 0, false); \
732 VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[4], K_MOUSE2, NULL, 0, 0, 0, false); \
734 VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[9], K_MOUSE3, NULL, 0, 0, 0, false); \
736 VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[10], (keynum_t)'m', NULL, 0, 0, 0, false); \
738 VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[11], (keynum_t)'b', NULL, 0, 0, 0, false); \
740 VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[12], (keynum_t)'q', NULL, 0, 0, 0, false); \
742 VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, false); \
744 VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[14], K_ESCAPE, NULL, 0, 0, 0, false); \
746 VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[15], K_SPACE, NULL, 0, 0, 0, false); \
756 float xscale, yscale;
757 float move[3], aim[3];
758 static qbool oldbuttons[128];
759 static qbool buttons[128];
761 memcpy(oldbuttons, buttons,
sizeof(oldbuttons));
793 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);
798 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);
811 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);
813 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);
814 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);
816 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);
818 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);
819 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);
821 VID_TouchscreenArea( 1,-100, 0, 100, 100,
NULL , 0.0f,
NULL,
NULL, &buttons[10], (
keynum_t)
'm',
NULL, 0, 0, 0,
true);
822 VID_TouchscreenArea( 1,-100, 120, 100, 100,
NULL , 0.0f,
NULL,
NULL, &buttons[11], (
keynum_t)
'b',
NULL, 0, 0, 0,
true);
823 VID_TouchscreenArea( 0, 0, 0, 64, 64,
NULL , 0.0f,
NULL,
NULL, &buttons[12], (
keynum_t)
'q',
NULL, 0, 0, 0,
true);
825 VID_TouchscreenArea( 0, 0, 96, 64, 64,
NULL , 0.0f,
NULL,
NULL, &buttons[13], (
keynum_t)
'`',
NULL, 0, 0, 0,
true);
827 VID_TouchscreenArea( 0, 0, 0, 0, 0,
NULL , 0.0f,
NULL,
NULL, &buttons[13], (
keynum_t)
'`',
NULL, 0, 0, 0,
false);
828 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);
832 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);
835 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);
838 VID_TouchscreenArea( 0, 0, 0, 0, 0,
NULL , 0.0f,
NULL,
NULL, &buttons[15],
K_SPACE,
NULL, 0, 0, 0,
false);
847 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);
870 float move[3], aim[3], click[3];
871 static qbool oldbuttons[128];
872 static qbool buttons[128];
874 memcpy(oldbuttons, buttons,
sizeof(oldbuttons));
886 VID_TouchscreenArea( 0, 0, 0, 64, 64,
NULL , 0.0f,
NULL,
NULL, &buttons[13], (
keynum_t)
'`',
NULL, 0, 0, 0,
true);
887 VID_TouchscreenArea( 0, 64, 0, 64, 64,
"gfx/touch_menu.tga" , 0.0f,
NULL,
NULL, &buttons[14],
K_ESCAPE,
NULL, 0, 0, 0,
true);
893 VID_TouchscreenArea( 0, 0, 0, 0, 0,
NULL , 0.0f,
NULL,
NULL, &buttons[15], (
keynum_t)0,
NULL, 0, 0, 0,
true);
894 VID_TouchscreenArea( 0, 0, 0, 0, 0,
NULL , 0.0f,
NULL, move, &buttons[0],
K_MOUSE4,
NULL, 0, 0, 0,
true);
895 VID_TouchscreenArea( 0, 0, 0, 0, 0,
NULL , 0.0f,
NULL, aim, &buttons[1],
K_MOUSE5,
NULL, 0, 0, 0,
true);
896 VID_TouchscreenArea( 0, 0, 0, 0, 0,
NULL , 0.0f,
NULL, click,&buttons[2],
K_MOUSE1,
NULL, 0, 0, 0,
true);
897 VID_TouchscreenArea( 0, 0, 0, 0, 0,
NULL , 0.0f,
NULL,
NULL, &buttons[3],
K_SPACE,
NULL, 0, 0, 0,
true);
898 VID_TouchscreenArea( 0, 0, 0, 0, 0,
NULL , 0.0f,
NULL,
NULL, &buttons[4],
K_MOUSE2,
NULL, 0, 0, 0,
true);
901 VID_TouchscreenArea( 0, 0, 0, 64, 64,
NULL , 0.0f,
NULL,
NULL, &buttons[13], (
keynum_t)
'`',
NULL, 0, 0, 0,
true);
902 VID_TouchscreenArea( 0, 64, 0, 64, 64,
"gfx/touch_menu.tga" , 0.0f,
NULL,
NULL, &buttons[14],
K_ESCAPE,
NULL, 0, 0, 0,
true);
903 VID_TouchscreenArea( 2, 0,-128, 128, 128,
"gfx/touch_movebutton.tga" , 0.0f,
NULL, move, &buttons[0],
K_MOUSE4,
NULL, 0, 0, 0,
true);
904 VID_TouchscreenArea( 3,-128,-128, 128, 128,
"gfx/touch_aimbutton.tga" , 0.0f,
NULL, aim, &buttons[1],
K_MOUSE5,
NULL, 0, 0, 0,
true);
905 VID_TouchscreenArea( 2, 0,-160, 64, 32,
"gfx/touch_jumpbutton.tga" , 0.0f,
NULL,
NULL, &buttons[3],
K_SPACE,
NULL, 0, 0, 0,
true);
906 VID_TouchscreenArea( 3,-128,-160, 64, 32,
"gfx/touch_attackbutton.tga" , 0.0f,
NULL,
NULL, &buttons[2],
K_MOUSE1,
NULL, 0, 0, 0,
true);
907 VID_TouchscreenArea( 3, -64,-160, 64, 32,
"gfx/touch_attack2button.tga", 0.0f,
NULL,
NULL, &buttons[4],
K_MOUSE2,
NULL, 0, 0, 0,
true);
911 VID_TouchscreenArea( 0, 0, 0, 64, 64,
NULL , 0.0f,
NULL,
NULL, &buttons[13], (
keynum_t)
'`',
NULL, 0, 0, 0,
true);
912 VID_TouchscreenArea( 0, 64, 0, 64, 64,
"gfx/touch_menu.tga" , 0.0f,
NULL,
NULL, &buttons[14],
K_ESCAPE,
NULL, 0, 0, 0,
true);
914 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);
917 VID_TouchscreenArea( 0, 0, 0, 0, 0,
NULL , 0.0f,
NULL, move, &buttons[0],
K_MOUSE4,
NULL, 0, 0, 0,
true);
918 VID_TouchscreenArea( 0, 0, 0, 0, 0,
NULL , 0.0f,
NULL, aim, &buttons[1],
K_MOUSE5,
NULL, 0, 0, 0,
true);
919 VID_TouchscreenArea(16, -320,-480,640, 960,
NULL , 0.0f,
NULL, click,&buttons[2],
K_MOUSE1,
NULL, 0, 0, 0,
true);
920 VID_TouchscreenArea( 0, 0, 0, 0, 0,
NULL , 0.0f,
NULL,
NULL, &buttons[3],
K_SPACE,
NULL, 0, 0, 0,
true);
921 VID_TouchscreenArea( 0, 0, 0, 0, 0,
NULL , 0.0f,
NULL,
NULL, &buttons[4],
K_MOUSE2,
NULL, 0, 0, 0,
true);
938 static int old_x = 0, old_y = 0;
939 static int stuck = 0;
941 static qbool oldshowkeyboard;
958 oldkeydest = keydest;
987 SDL_WarpMouseInWindow(
window, win_half_width, win_half_height);
988 SDL_GetMouseState(&
x, &
y);
989 SDL_GetRelativeMouseState(&
x, &
y);
992 SDL_GetRelativeMouseState(&
x, &
y);
995 SDL_GetMouseState(&
x, &
y);
996 old_x =
x - win_half_width;
997 old_y =
y - win_half_height;
998 SDL_WarpMouseInWindow(
window, win_half_width, win_half_height);
1001 SDL_GetRelativeMouseState( &
x, &
y );
1007 SDL_GetMouseState(&
x, &
y);
1054 while( SDL_PollEvent( &event ) )
1056 switch( event.type ) {
1058#ifdef DEBUGSDLEVENTS
1065#ifdef DEBUGSDLEVENTS
1066 if (event.type == SDL_KEYDOWN)
1067 Con_DPrintf(
"SDL_Event: SDL_KEYDOWN %i\n", event.key.keysym.sym);
1069 Con_DPrintf(
"SDL_Event: SDL_KEYUP %i\n", event.key.keysym.sym);
1071 keycode =
MapKey(event.key.keysym.sym);
1072 isdown = (
event.key.state == SDL_PRESSED);
1076 if(SDL_PollEvent(&event))
1078 if(event.type == SDL_TEXTINPUT)
1082#ifdef DEBUGSDLEVENTS
1083 Con_DPrintf(
"SDL_Event: SDL_TEXTINPUT - text: %s\n", event.text.text);
1098 case SDL_MOUSEBUTTONDOWN:
1099 case SDL_MOUSEBUTTONUP:
1100#ifdef DEBUGSDLEVENTS
1101 if (event.type == SDL_MOUSEBUTTONDOWN)
1110 case SDL_MOUSEWHEEL:
1124 case SDL_JOYBUTTONDOWN:
1125 case SDL_JOYBUTTONUP:
1126 case SDL_JOYAXISMOTION:
1127 case SDL_JOYBALLMOTION:
1128 case SDL_JOYHATMOTION:
1129#ifdef DEBUGSDLEVENTS
1133 case SDL_WINDOWEVENT:
1134#ifdef DEBUGSDLEVENTS
1135 Con_DPrintf(
"SDL_Event: SDL_WINDOWEVENT %i\n", (
int)event.window.event);
1139 switch(event.window.event)
1141 case SDL_WINDOWEVENT_SHOWN:
1144 case SDL_WINDOWEVENT_HIDDEN:
1147 case SDL_WINDOWEVENT_EXPOSED:
1148#ifdef DEBUGSDLEVENTS
1149 Con_DPrintf(
"SDL_Event: SDL_WINDOWEVENT_EXPOSED\n");
1152 case SDL_WINDOWEVENT_MOVED:
1153 vid.
xPos =
event.window.data1;
1154 vid.
yPos =
event.window.data2;
1159 SDL_Rect displaybounds;
1160 if (SDL_GetDisplayBounds(
i, &displaybounds) < 0)
1165 if (
vid.
xPos >= displaybounds.x &&
vid.
xPos < displaybounds.x + displaybounds.w)
1166 if (
vid.
yPos >= displaybounds.y &&
vid.
yPos < displaybounds.y + displaybounds.h)
1185 case SDL_WINDOWEVENT_RESIZED:
1194 case SDL_WINDOWEVENT_SIZE_CHANGED:
1196 case SDL_WINDOWEVENT_MINIMIZED:
1198 case SDL_WINDOWEVENT_MAXIMIZED:
1200 case SDL_WINDOWEVENT_RESTORED:
1202 case SDL_WINDOWEVENT_ENTER:
1204 case SDL_WINDOWEVENT_LEAVE:
1206 case SDL_WINDOWEVENT_FOCUS_GAINED:
1209 case SDL_WINDOWEVENT_FOCUS_LOST:
1212 case SDL_WINDOWEVENT_CLOSE:
1215 case SDL_WINDOWEVENT_TAKE_FOCUS:
1217 case SDL_WINDOWEVENT_HIT_TEST:
1219 case SDL_WINDOWEVENT_ICCPROF_CHANGED:
1221 case SDL_WINDOWEVENT_DISPLAY_CHANGED:
1228 case SDL_DISPLAYEVENT:
1229 switch (event.display.event)
1231 case SDL_DISPLAYEVENT_CONNECTED:
1232 Con_Printf(
CON_WARN "Display %i connected: %s\n", event.display.display, SDL_GetDisplayName(event.display.display));
1240 case SDL_DISPLAYEVENT_DISCONNECTED:
1247 case SDL_DISPLAYEVENT_ORIENTATION:
1251 case SDL_TEXTEDITING:
1252#ifdef DEBUGSDLEVENTS
1253 Con_DPrintf(
"SDL_Event: SDL_TEXTEDITING - composition = %s, cursor = %d, selection lenght = %d\n", event.edit.text, event.edit.start, event.edit.length);
1258#ifdef DEBUGSDLEVENTS
1259 Con_DPrintf(
"SDL_Event: SDL_TEXTINPUT - text: %s\n", event.text.text);
1263 chp =
event.text.text;
1272 case SDL_MOUSEMOTION:
1274 case SDL_FINGERDOWN:
1275#ifdef DEBUGSDLEVENTS
1276 Con_DPrintf(
"SDL_FINGERDOWN for finger %i\n", (
int)event.tfinger.fingerId);
1293#ifdef DEBUGSDLEVENTS
1294 Con_DPrintf(
"SDL_FINGERUP for finger %i\n", (
int)event.tfinger.fingerId);
1298 if (
multitouch[
i][0] == event.tfinger.fingerId + 1)
1305 Con_DPrintf(
"No SDL_FINGERDOWN event matches this SDL_FINGERMOTION event\n");
1307 case SDL_FINGERMOTION:
1308#ifdef DEBUGSDLEVENTS
1309 Con_DPrintf(
"SDL_FINGERMOTION for finger %i\n", (
int)event.tfinger.fingerId);
1313 if (
multitouch[
i][0] == event.tfinger.fingerId + 1)
1321 Con_DPrintf(
"No SDL_FINGERDOWN event matches this SDL_FINGERMOTION event\n");
1324#ifdef DEBUGSDLEVENTS
1325 Con_DPrintf(
"Received unrecognized SDL_Event type 0x%x\n", event.type);
1347 p = SDL_GL_GetProcAddress(
name);
1353 return SDL_GL_ExtensionSupported(
name);
1359 uint32_t fullscreenwanted;
1361 SDL_DisplayMode modefinal;
1363 if (
mode->fullscreen)
1364 fullscreenwanted =
mode->desktopfullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN;
1366 fullscreenwanted = 0;
1370 || !fullscreenwanted)
1372 if (SDL_SetWindowFullscreen(
window, 0) < 0)
1382 if (!fullscreenwanted)
1408 SDL_Rect displaybounds;
1409 if (SDL_GetDisplayBounds(displaywanted, &displaybounds) < 0)
1411 Con_Printf(
CON_ERROR "Error getting bounds of display %i: \"%s\"\n", displaywanted, SDL_GetError());
1422 if (fullscreenwanted)
1424 if (fullscreenwanted == SDL_WINDOW_FULLSCREEN)
1427 SDL_DisplayMode modewanted, modecurrent;
1429 modewanted.w =
mode->width;
1430 modewanted.h =
mode->height;
1431 modewanted.format =
mode->bitsperpixel == 16 ? SDL_PIXELFORMAT_RGB565 : SDL_PIXELFORMAT_RGB888;
1432 modewanted.refresh_rate =
mode->refreshrate;
1433 if (!SDL_GetClosestDisplayMode(displaywanted, &modewanted, &modefinal))
1439 if (SDL_GetCurrentDisplayMode(displaywanted, &modecurrent) < 0)
1444 if (memcmp(&modecurrent, &modefinal,
sizeof(modecurrent)) != 0)
1446 if (
mode->width != modefinal.w ||
mode->height != modefinal.h)
1451 if (SDL_SetWindowDisplayMode(
window, &modefinal) < 0)
1453 Con_Printf(
CON_ERROR "Error setting mode %ix%i@%ihz for display %i: \"%s\"\n", modefinal.w, modefinal.h, modefinal.refresh_rate,
vid.
mode.
display, SDL_GetError());
1459 SDL_SetWindowFullscreen(
window, SDL_WINDOW_FULLSCREEN_DESKTOP);
1463 if (SDL_SetWindowFullscreen(
window, fullscreenwanted) < 0)
1475 if (!fullscreenwanted || fullscreenwanted == SDL_WINDOW_FULLSCREEN_DESKTOP)
1476 SDL_GetDesktopDisplayMode(displaywanted, &modefinal);
1522 if (SDL_GL_SetSwapInterval(vsyncwanted) >= 0)
1523 Con_DPrintf(
"Vsync %s\n", vsyncwanted ?
"activated" :
"deactivated");
1525 Con_Printf(
CON_ERROR "ERROR: can't %s vsync because %s\n", vsyncwanted ?
"activate" :
"deactivate", SDL_GetError());
1543#ifdef DP_MOBILETOUCH
1565 SDL_SetHint(SDL_HINT_WINDOWS_DPI_SCALING,
"0");
1567 SDL_SetHint(SDL_HINT_WINDOWS_DPI_AWARENESS,
"permonitorv2");
1570 if (SDL_Init(SDL_INIT_VIDEO) < 0)
1571 Sys_Error (
"Failed to init SDL video subsystem: %s", SDL_GetError());
1572 if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
1576 Con_Printf(
"Linked against SDL version %d.%d.%d\n"
1577 "Using SDL library version %d.%d.%d\n",
1578 SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL,
1586 int numsdljoysticks;
1587 qbool success =
false;
1588 int sharedcount = 0;
1593 sdlindex =
index - sharedcount;
1595 numsdljoysticks = SDL_NumJoysticks();
1596 if (sdlindex < 0 || sdlindex >= numsdljoysticks)
1650 int titleBarPixels = 2;
1659 rect->right =
width;
1661 AdjustWindowRectEx(rect, WS_CAPTION|WS_THICKFRAME,
false, 0);
1663 SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
1664 workWidth = workArea.right - workArea.left;
1665 workHeight = workArea.bottom - workArea.top;
1670 screenHeight = GetSystemMetrics(SM_CYSCREEN);
1671 if (screenHeight == workHeight)
1672 titleBarPixels = -rect->top;
1677 if ((
width == GetSystemMetrics(SM_CXSCREEN) ||
width == workWidth) && (
height == screenHeight ||
height == workHeight - titleBarPixels))
1679 rect->left = workArea.left;
1680 mode->width = workWidth;
1681 rect->top = workArea.top + titleBarPixels;
1682 mode->height = workHeight - titleBarPixels;
1686 rect->left = workArea.left +
max(0, (workWidth -
width) / 2);
1687 rect->top = workArea.top +
max(0, (workHeight -
height) / 2);
1694 int windowflags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL;
1697 const char *drivername =
NULL;
1707 windowflags |= SDL_WINDOW_RESIZABLE;
1714 if (SDL_GL_LoadLibrary(drivername) < 0)
1716 Con_Printf(
CON_ERROR "Unable to load GL driver \"%s\": %s\n", drivername, SDL_GetError());
1721#ifdef DP_MOBILETOUCH
1723 mode->fullscreen =
true;
1725 windowflags |= SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
1731 if (
mode->fullscreen)
1733 windowflags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
1739 windowflags |= SDL_WINDOW_BORDERLESS;
1743 if (!vid_ignore_taskbar.integer)
1757 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
1758 SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8);
1759 SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8);
1760 SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 8);
1761 SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 8);
1762 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24);
1763 SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8);
1764 if (
mode->stereobuffer)
1766 SDL_GL_SetAttribute (SDL_GL_STEREO, 1);
1769 if (
mode->samples > 1)
1771 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1);
1772 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES,
mode->samples);
1776 SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
1777 SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);
1778 SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0);
1780 SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
1781 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
1782 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
1788 SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, (
gl_debug.
integer > 0 ? SDL_GL_CONTEXT_DEBUG_FLAG : 0));
1800 Sys_Error(
"Failed to initialize OpenGL context: %s\n", SDL_GetError());
1804#if !defined(USE_GLES2) && !defined(MACOSX)
1808 if (strncmp(
gl_vendor,
"NVIDIA", 6) == 0)
1810 Con_DPrint(
"The Way It's Meant To Be Played: replacing OpenGL Core profile with Compatibility profile...\n");
1811 SDL_GL_DeleteContext(
context);
1812 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
1815 Sys_Error(
"Failed to initialize OpenGL context: %s\n", SDL_GetError());
1841 Con_Printf(
"Display %i: %s\n",
i, SDL_GetDisplayName(
i));
1856 if (!SDL_WasInit(SDL_INIT_VIDEO) && SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
1857 Sys_Error (
"Failed to init SDL video subsystem: %s", SDL_GetError());
1868 SDL_GL_DeleteContext(
context);
1870 SDL_DestroyWindow(
window);
1873 SDL_QuitSubSystem(SDL_INIT_VIDEO);
1889 SDL_GL_SwapWindow(
window);
1897 SDL_DisplayMode
mode;
1899 Uint32 rmask, gmask, bmask, amask;
1903 SDL_PixelFormatEnumToMasks(
mode.format, &bpp, &rmask, &gmask, &bmask, &amask);
1906 desktop_mode.
bpp = bpp;
1910 return desktop_mode;
1918 SDL_DisplayMode
mode;
1919 for (modenum = 0;modenum < nummodes;modenum++)
1927 modes[k].bpp = SDL_BITSPERPIXEL(
mode.format);
1928 modes[k].refreshrate =
mode.refresh_rate;
1929 modes[k].pixelheight_num = 1;
1930 modes[k].pixelheight_denom = 1;
int scr_numtouchscreenareas
scr_touchscreenarea_t scr_touchscreenareas[128]
cmd_state_t * cmd_local
command interpreter for local commands injected by SVQC, CSQC, MQC, server or client engine code uses...
#define CF_CLIENT
cvar/command that only the client can change/execute
#define CF_ARCHIVE
cvar should have its set value saved to config.cfg and persist across sessions
@ GAME_STEELSTORM
added by motorsep
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
void Con_DPrintf(const char *fmt,...)
A Con_Printf that only shows up if the "developer" cvar is set.
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
void Con_DPrint(const char *msg)
A Con_Print that only shows up if the "developer" cvar is set.
void Con_ToggleConsole_f(cmd_state_t *cmd)
void Cvar_SetValueQuick(cvar_t *var, float value)
void Cvar_SetQuick(cvar_t *var, const char *value)
void Cvar_RegisterVariable(cvar_t *variable)
registers a cvar that already has the name, string, and optionally the archive elements set.
cvar_t * Cvar_FindVar(cvar_state_t *cvars, const char *var_name, unsigned neededflags)
void Cvar_RegisterCallback(cvar_t *variable, void(*callback)(cvar_t *))
void Cvar_Callback(cvar_t *var)
static int const char * version
void GL_Clear(int mask, const float *colorvalue, float depthvalue, int stencilvalue)
GLenum GLsizei GLsizei height
GLint GLenum GLint GLint y
#define GL_COLOR_BUFFER_BIT
const GLubyte *GLAPIENTRY * qglGetString(GLenum name)
@ host_shutdown
states >= host_shutdown cause graceful shutdown, see Sys_HandleCrash() comments
void Key_Event(int key, int ascii, qbool down)
#define KEY_CONSOLEACTIVE_USER
#define Vector2Normalize2(v, dest)
#define bound(min, num, max)
#define VectorCopy(in, out)
qbool csqc_wantsmousemove
double realtime
the accumulated mainloop time since application started (with filtering), without any slowmo or clamp...
unsigned char button[MAXJOYBUTTON]
0 or 1
float axis[MAXJOYAXIS]
-1 to +1
qbool desktopfullscreen
whether the display hardware mode can be changed
int yPos
current virtual position of the top left corner of the SDL window
viddef_mode_t mode
currently active video mode
void Sys_Error(const char *error,...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN
Causes the entire program to exit ASAP.
int Sys_CheckParm(const char *parm)
size_t u8_bytelen(const char *_s, size_t n)
Get the number of bytes used in a string to represent an amount of characters.
Uchar u8_getchar_utf8_enabled(const char *_s, const char **_end)
Fetch a character from an utf-8 encoded string.
const char * gl_vendor
brand of graphics chip
cvar_t vid_minimize_on_focus_loss
void VID_Shared_BuildJoyState_Finish(vid_joystate_t *joystate)
float VID_JoyState_GetAxis(const vid_joystate_t *joystate, int axis, float sensitivity, float deadzone)
qbool VID_JoyBlockEmulatedKeys(int keycode)
void GL_InitFunctions(void)
cvar_t vid_info_displaycount
cvar_t vid_touchscreen_density
cvar_t vid_touchscreen_showkeyboard
const char * gl_version
begins with 1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.3.0, 1.3.1, or 1.4.0
cvar_t vid_mouse_clickthrough
const char * gl_renderer
graphics chip model and other information
void VID_ApplyJoyState(vid_joystate_t *joystate)
viddef_t vid
global video state
void VID_UpdateGamma(void)
updates cachegamma variables and bumps vid_gammatables_serial if anything changed (ONLY to be called ...
void VID_Shared_BuildJoyState_Begin(vid_joystate_t *joystate)
cvar_t vid_desktopfullscreen
cvar_t vid_touchscreen_supportshowkeyboard
int VID_Shared_SetJoystick(int index)
qbool GL_ExtensionSupported(const char *name)
void VID_EnableJoystick(qbool enable)
static qbool VID_TouchscreenArea(int corner, float px, float py, float pwidth, float pheight, const char *icon, float textheight, const char *text, float *resultmove, qbool *resultbutton, keynum_t key, const char *typedtext, float deadzone, float oversizepixels_x, float oversizepixels_y, qbool iamexclusive)
static qbool vid_wmborderless
static void VID_TouchscreenCursor(float px, float py, float pwidth, float pheight, qbool *resultbutton, keynum_t key)
static qbool vid_usinghidecursor
static int vid_sdljoystickindex
qbool VID_HasScreenKeyboardSupport(void)
qbool vid_supportrefreshrate
static void IN_Move_TouchScreen_Quake(void)
size_t VID_ListModes(vid_mode_t *modes, size_t maxcount)
static cvar_t * steelstorm_showing_map
static void VID_SetVsync_c(cvar_t *var)
static SDL_GameController * vid_sdlgamecontroller
void VID_Init(void)
Called at startup.
static qbool VID_InitModeGL(const viddef_mode_t *mode)
static SDL_GLContext context
vid_mode_t VID_GetDesktopMode(void)
qbool VID_InitMode(const viddef_mode_t *mode)
allocates and opens an appropriate OpenGL context (and its window)
void * GL_GetProcAddress(const char *name)
qbool VID_ShowingKeyboard(void)
void Sys_SDL_HandleEvents(void)
Perform Key_Event () callbacks until the input que is empty.
void VID_Shutdown(void)
Called at shutdown.
static void VID_ApplyDisplayMode_c(cvar_t *var)
int multitouchs[MAXFINGERS]
static SDL_Window * window
static void IN_Move_TouchScreen_SteelStorm(void)
static void VID_ApplyDisplayMode(const viddef_mode_t *mode)
Applies display settings immediately (no vid_restart required).
static void VID_SetHints_c(cvar_t *var)
static cvar_t * steelstorm_showing_mousecursor
static qbool vid_hasfocus
static keynum_t buttonremap[]
void VID_ShowKeyboard(qbool show)
static int MapKey(unsigned int sdlkey)
static qbool vid_usingmouse_relativeworks
static qbool vid_usingmouse
static void VID_SetMouse(qbool relative, qbool hidecursor)
static cvar_t joy_sdl2_trigger_deadzone
static SDL_Joystick * vid_sdljoystick
void VID_BuildJoyState(vid_joystate_t *joystate)
static qbool vid_wmborder_waiting
#define Vid_ClearAllTouchscreenAreas(skip)
float multitouch[MAXFINGERS][3]