cl_input.c

Go to the documentation of this file.
00001 
00018 /*
00019 All original material Copyright (C) 2002-2010 UFO: Alien Invasion.
00020 
00021 Original file from Quake 2 v3.21: quake2-2.31/client/cl_input.c
00022 Copyright (C) 1997-2001 Id Software, Inc.
00023 
00024 This program is free software; you can redistribute it and/or
00025 modify it under the terms of the GNU General Public License
00026 as published by the Free Software Foundation; either version 2
00027 of the License, or (at your option) any later version.
00028 
00029 This program is distributed in the hope that it will be useful,
00030 but WITHOUT ANY WARRANTY; without even the implied warranty of
00031 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00032 
00033 See the GNU General Public License for more details.
00034 
00035 You should have received a copy of the GNU General Public License
00036 along with this program; if not, write to the Free Software
00037 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00038 
00039 */
00040 
00041 #include "../client.h"
00042 #include "cl_input.h"
00043 #include "cl_keys.h"
00044 #include "cl_joystick.h"
00045 #include "../battlescape/cl_localentity.h"
00046 #include "../cl_console.h"
00047 #include "../battlescape/cl_actor.h"
00048 #include "../battlescape/cl_view.h"
00049 #include "../battlescape/cl_parse.h"
00050 #include "../battlescape/cl_hud.h"
00051 #include "../ui/ui_main.h"
00052 #include "../ui/ui_input.h"
00053 #include "../ui/node/ui_node_abstractnode.h"
00054 
00055 #include "../../common/tracing.h"
00056 
00057 /* power of two please */
00058 #define MAX_KEYQ 64
00059 
00060 static struct {
00061     unsigned int key;
00062     unsigned short unicode;
00063     int down;
00064 } keyq[MAX_KEYQ];
00065 
00066 static int keyq_head = 0;
00067 static int keyq_tail = 0;
00068 
00069 static cvar_t *in_debug;
00070 cvar_t *cl_isometric;
00071 
00072 int mouseSpace;
00073 int mousePosX, mousePosY;
00074 static int oldMousePosX, oldMousePosY;
00075 
00076 /*
00077 ===============================================================================
00078 KEY BUTTONS
00079 ===============================================================================
00080 */
00081 
00082 typedef struct {
00083     int down[2];                
00084     unsigned downtime;          
00085     unsigned msec;              
00086     int state;                  
00087 } kbutton_t;
00088 
00089 static kbutton_t in_turnleft, in_turnright, in_shiftleft, in_shiftright;
00090 static kbutton_t in_shiftup, in_shiftdown;
00091 static kbutton_t in_zoomin, in_zoomout;
00092 static kbutton_t in_turnup, in_turndown;
00093 
00094 static kbutton_t in_pantilt;
00095 
00101 static void IN_KeyDown (kbutton_t * b)
00102 {
00103     int k;
00104     const char *c = Cmd_Argv(1);
00105 
00106     if (c[0])
00107         k = atoi(c);
00108     else
00109         /* typed manually at the console for continuous down */
00110         k = -1;
00111 
00112     /* repeating key */
00113     if (k == b->down[0] || k == b->down[1])
00114         return;
00115 
00116     if (!b->down[0])
00117         b->down[0] = k;
00118     else if (!b->down[1])
00119         b->down[1] = k;
00120     else {
00121         Com_Printf("Three keys down for a button!\n");
00122         return;
00123     }
00124 
00125     /* still down */
00126     if (b->state)
00127         return;
00128 
00129     /* save timestamp */
00130     c = Cmd_Argv(2);
00131     b->downtime = atoi(c);
00132     if (!b->downtime)
00133         b->downtime = CL_Milliseconds() - 100;
00134 
00135     /* down */
00136     b->state = 1;
00137 }
00138 
00144 static void IN_KeyUp (kbutton_t * b)
00145 {
00146     int k;
00147     unsigned uptime;
00148     const char *c = Cmd_Argv(1);
00149 
00150     if (c[0])
00151         k = atoi(c);
00152     /* typed manually at the console, assume for unsticking, so clear all */
00153     else {
00154         b->down[0] = b->down[1] = 0;
00155         return;
00156     }
00157 
00158     if (b->down[0] == k)
00159         b->down[0] = 0;
00160     else if (b->down[1] == k)
00161         b->down[1] = 0;
00162     /* key up without coresponding down (menu pass through) */
00163     else
00164         return;
00165 
00166     /* some other key is still holding it down */
00167     if (b->down[0] || b->down[1])
00168         return;
00169 
00170     /* still up (this should not happen) */
00171     if (!b->state)
00172         return;
00173 
00174     /* save timestamp */
00175     c = Cmd_Argv(2);
00176     uptime = atoi(c);
00177     if (uptime)
00178         b->msec += uptime - b->downtime;
00179     else
00180         b->msec += 10;
00181 
00182     /* now up */
00183     b->state = 0;
00184 }
00185 
00186 static void IN_TurnLeftDown_f (void)
00187 {
00188     IN_KeyDown(&in_turnleft);
00189 }
00190 static void IN_TurnLeftUp_f (void)
00191 {
00192     IN_KeyUp(&in_turnleft);
00193 }
00194 static void IN_TurnRightDown_f (void)
00195 {
00196     IN_KeyDown(&in_turnright);
00197 }
00198 static void IN_TurnRightUp_f (void)
00199 {
00200     IN_KeyUp(&in_turnright);
00201 }
00202 static void IN_TurnUpDown_f (void)
00203 {
00204     IN_KeyDown(&in_turnup);
00205 }
00206 static void IN_TurnUpUp_f (void)
00207 {
00208     IN_KeyUp(&in_turnup);
00209 }
00210 static void IN_TurnDownDown_f (void)
00211 {
00212     IN_KeyDown(&in_turndown);
00213 }
00214 static void IN_TurnDownUp_f (void)
00215 {
00216     IN_KeyUp(&in_turndown);
00217 }
00218 static void IN_ShiftLeftDown_f (void)
00219 {
00220     IN_KeyDown(&in_shiftleft);
00221 }
00222 static void IN_ShiftLeftUp_f (void)
00223 {
00224     IN_KeyUp(&in_shiftleft);
00225 }
00226 static void IN_ShiftRightDown_f (void)
00227 {
00228     IN_KeyDown(&in_shiftright);
00229 }
00230 static void IN_ShiftRightUp_f (void)
00231 {
00232     IN_KeyUp(&in_shiftright);
00233 }
00234 static void IN_ShiftUpDown_f (void)
00235 {
00236     IN_KeyDown(&in_shiftup);
00237 }
00238 static void IN_ShiftUpUp_f (void)
00239 {
00240     IN_KeyUp(&in_shiftup);
00241 }
00242 static void IN_ShiftDownDown_f (void)
00243 {
00244     IN_KeyDown(&in_shiftdown);
00245 }
00246 static void IN_ShiftDownUp_f (void)
00247 {
00248     IN_KeyUp(&in_shiftdown);
00249 }
00250 static void IN_ZoomInDown_f (void)
00251 {
00252     IN_KeyDown(&in_zoomin);
00253 }
00254 static void IN_ZoomInUp_f (void)
00255 {
00256     IN_KeyUp(&in_zoomin);
00257 }
00258 static void IN_ZoomOutDown_f (void)
00259 {
00260     IN_KeyDown(&in_zoomout);
00261 }
00262 static void IN_ZoomOutUp_f (void)
00263 {
00264     IN_KeyUp(&in_zoomout);
00265 }
00266 
00267 
00271 static void CL_LevelUp_f (void)
00272 {
00273     if (!CL_OnBattlescape())
00274         return;
00275     Cvar_SetValue("cl_worldlevel", (cl_worldlevel->integer < cl.mapMaxLevel - 1) ? cl_worldlevel->integer + 1 : cl.mapMaxLevel - 1);
00276 }
00277 
00281 static void CL_LevelDown_f (void)
00282 {
00283     if (!CL_OnBattlescape())
00284         return;
00285     Cvar_SetValue("cl_worldlevel", (cl_worldlevel->integer > 0) ? cl_worldlevel->integer - 1 : 0);
00286 }
00287 
00288 
00289 static void CL_ZoomInQuant_f (void)
00290 {
00291     if (mouseSpace == MS_UI)
00292         UI_MouseWheel(qfalse, mousePosX, mousePosY);
00293     else
00294         CL_CameraZoomIn();
00295 }
00296 
00297 static void CL_ZoomOutQuant_f (void)
00298 {
00299     if (mouseSpace == MS_UI)
00300         UI_MouseWheel(qtrue, mousePosX, mousePosY);
00301     else
00302         CL_CameraZoomOut();
00303 }
00304 
00308 static void CL_SelectDown_f (void)
00309 {
00310     if (mouseSpace != MS_WORLD)
00311         return;
00312     CL_ActorSelectMouse();
00313 }
00314 
00315 static void CL_SelectUp_f (void)
00316 {
00317     if (mouseSpace == MS_UI)
00318         return;
00319     mouseSpace = MS_NULL;
00320 }
00321 
00325 static void CL_ActionDown_f (void)
00326 {
00327     if (mouseSpace != MS_WORLD)
00328         return;
00329     CL_ActorActionMouse();
00330 }
00331 
00332 static void CL_ActionUp_f (void)
00333 {
00334     if (mouseSpace == MS_UI)
00335         return;
00336     mouseSpace = MS_NULL;
00337 }
00338 
00342 static void CL_TurnDown_f (void)
00343 {
00344     if (mouseSpace == MS_UI)
00345         return;
00346     if (mouseSpace == MS_WORLD)
00347         CL_ActorTurnMouse();
00348 }
00349 
00350 static void CL_TurnUp_f (void)
00351 {
00352     if (mouseSpace == MS_UI)
00353         return;
00354     mouseSpace = MS_NULL;
00355 }
00356 
00360 static void CL_HudRadarDown_f (void)
00361 {
00362     if (!UI_IsWindowOnStack(mn_hud->string))
00363         return;
00364     UI_PushWindow("radarmenu", NULL);
00365 }
00366 
00370 static void CL_HudRadarUp_f (void)
00371 {
00372     if (!UI_IsWindowOnStack(mn_hud->string))
00373         return;
00374     UI_CloseWindow("radarmenu");
00375 }
00376 
00380 static void CL_RightClickDown_f (void)
00381 {
00382     if (mouseSpace == MS_UI) {
00383         UI_MouseDown(mousePosX, mousePosY, K_MOUSE2);
00384     }
00385 }
00386 
00390 static void CL_RightClickUp_f (void)
00391 {
00392     if (mouseSpace == MS_UI) {
00393         UI_MouseUp(mousePosX, mousePosY, K_MOUSE2);
00394     }
00395 }
00396 
00400 static void CL_MiddleClickDown_f (void)
00401 {
00402     if (mouseSpace == MS_UI) {
00403         UI_MouseDown(mousePosX, mousePosY, K_MOUSE3);
00404     }
00405 }
00406 
00410 static void CL_MiddleClickUp_f (void)
00411 {
00412     if (mouseSpace == MS_UI) {
00413         UI_MouseUp(mousePosX, mousePosY, K_MOUSE3);
00414     }
00415 }
00416 
00420 static void CL_LeftClickDown_f (void)
00421 {
00422     if (mouseSpace == MS_UI) {
00423         UI_MouseDown(mousePosX, mousePosY, K_MOUSE1);
00424     }
00425 }
00426 
00430 static void CL_LeftClickUp_f (void)
00431 {
00432     if (mouseSpace == MS_UI) {
00433         UI_MouseUp(mousePosX, mousePosY, K_MOUSE1);
00434     }
00435 }
00436 
00437 #define SCROLL_BORDER   4
00438 #define MOUSE_YAW_SCALE     0.1
00439 #define MOUSE_PITCH_SCALE   0.1
00440 
00444 float CL_GetKeyMouseState (int dir)
00445 {
00446     float value;
00447 
00448     switch (dir) {
00449     case STATE_FORWARD:
00450         /* sum directions, 'true' is use as '1' */
00451         value = (in_shiftup.state & 1) + (mousePosY <= (viddef.y / viddef.ry) + SCROLL_BORDER) - (in_shiftdown.state & 1) - (mousePosY >= ((viddef.y + viddef.viewHeight) / viddef.ry) - SCROLL_BORDER);
00452         break;
00453     case STATE_RIGHT:
00454         /* sum directions, 'true' is use as '1' */
00455         value = (in_shiftright.state & 1) + (mousePosX >= ((viddef.x + viddef.viewWidth) / viddef.rx) - SCROLL_BORDER) - (in_shiftleft.state & 1) - (mousePosX <= (viddef.x / viddef.rx) + SCROLL_BORDER);
00456         break;
00457     case STATE_ZOOM:
00458         value = (in_zoomin.state & 1) - (in_zoomout.state & 1);
00459         break;
00460     case STATE_ROT:
00461         value = (in_turnleft.state & 1) - (in_turnright.state & 1);
00462         if (in_pantilt.state)
00463             value -= (float) (mousePosX - oldMousePosX) * MOUSE_YAW_SCALE;
00464         break;
00465     case STATE_TILT:
00466         value = (in_turnup.state & 1) - (in_turndown.state & 1);
00467         if (in_pantilt.state)
00468             value += (float) (mousePosY - oldMousePosY) * MOUSE_PITCH_SCALE;
00469         break;
00470     default:
00471         value = 0.0;
00472         break;
00473     }
00474 
00475     return value;
00476 }
00477 
00483 static void IN_Parse (void)
00484 {
00485     mouseSpace = MS_NULL;
00486 
00487     /* standard menu and world mouse handling */
00488     if (UI_IsPointOnWindow()) {
00489         mouseSpace = MS_UI;
00490         return;
00491     }
00492 
00493     if (cls.state != ca_active)
00494         return;
00495 
00496     if (!viddef.viewWidth || !viddef.viewHeight)
00497         return;
00498 
00499     if (CL_ActorMouseTrace()) {
00500         /* mouse is in the world */
00501         mouseSpace = MS_WORLD;
00502     }
00503 }
00504 
00508 static inline void IN_PrintKey (const SDL_Event* event, int down)
00509 {
00510     if (in_debug->integer) {
00511         Com_Printf("key name: %s (down: %i)", SDL_GetKeyName(event->key.keysym.sym), down);
00512         if (event->key.keysym.unicode) {
00513             Com_Printf(" unicode: %hx", event->key.keysym.unicode);
00514             if (event->key.keysym.unicode >= '0' && event->key.keysym.unicode <= '~')  /* printable? */
00515                 Com_Printf(" (%c)", (unsigned char)(event->key.keysym.unicode));
00516         }
00517         Com_Printf("\n");
00518     }
00519 }
00520 
00524 static void IN_TranslateKey (SDL_keysym *keysym, unsigned int *ascii, unsigned short *unicode)
00525 {
00526     switch (keysym->sym) {
00527     case SDLK_KP9:
00528         *ascii = K_KP_PGUP;
00529         break;
00530     case SDLK_PAGEUP:
00531         *ascii = K_PGUP;
00532         break;
00533     case SDLK_KP3:
00534         *ascii = K_KP_PGDN;
00535         break;
00536     case SDLK_PAGEDOWN:
00537         *ascii = K_PGDN;
00538         break;
00539     case SDLK_KP7:
00540         *ascii = K_KP_HOME;
00541         break;
00542     case SDLK_HOME:
00543         *ascii = K_HOME;
00544         break;
00545     case SDLK_KP1:
00546         *ascii = K_KP_END;
00547         break;
00548     case SDLK_END:
00549         *ascii = K_END;
00550         break;
00551     case SDLK_KP4:
00552         *ascii = K_KP_LEFTARROW;
00553         break;
00554     case SDLK_LEFT:
00555         *ascii = K_LEFTARROW;
00556         break;
00557     case SDLK_KP6:
00558         *ascii = K_KP_RIGHTARROW;
00559         break;
00560     case SDLK_RIGHT:
00561         *ascii = K_RIGHTARROW;
00562         break;
00563     case SDLK_KP2:
00564         *ascii = K_KP_DOWNARROW;
00565         break;
00566     case SDLK_DOWN:
00567         *ascii = K_DOWNARROW;
00568         break;
00569     case SDLK_KP8:
00570         *ascii = K_KP_UPARROW;
00571         break;
00572     case SDLK_UP:
00573         *ascii = K_UPARROW;
00574         break;
00575     case SDLK_ESCAPE:
00576         *ascii = K_ESCAPE;
00577         break;
00578     case SDLK_KP_ENTER:
00579         *ascii = K_KP_ENTER;
00580         break;
00581     case SDLK_RETURN:
00582         *ascii = K_ENTER;
00583         break;
00584     case SDLK_TAB:
00585         *ascii = K_TAB;
00586         break;
00587     case SDLK_F1:
00588         *ascii = K_F1;
00589         break;
00590     case SDLK_F2:
00591         *ascii = K_F2;
00592         break;
00593     case SDLK_F3:
00594         *ascii = K_F3;
00595         break;
00596     case SDLK_F4:
00597         *ascii = K_F4;
00598         break;
00599     case SDLK_F5:
00600         *ascii = K_F5;
00601         break;
00602     case SDLK_F6:
00603         *ascii = K_F6;
00604         break;
00605     case SDLK_F7:
00606         *ascii = K_F7;
00607         break;
00608     case SDLK_F8:
00609         *ascii = K_F8;
00610         break;
00611     case SDLK_F9:
00612         *ascii = K_F9;
00613         break;
00614     case SDLK_F10:
00615         *ascii = K_F10;
00616         break;
00617     case SDLK_F11:
00618         *ascii = K_F11;
00619         break;
00620     case SDLK_F12:
00621         *ascii = K_F12;
00622         break;
00623     case SDLK_F13:
00624         *ascii = K_F13;
00625         break;
00626     case SDLK_F14:
00627         *ascii = K_F14;
00628         break;
00629     case SDLK_F15:
00630         *ascii = K_F15;
00631         break;
00632     case SDLK_BACKSPACE:
00633         *ascii = K_BACKSPACE;
00634         break;
00635     case SDLK_KP_PERIOD:
00636         *ascii = K_KP_DEL;
00637         break;
00638     case SDLK_DELETE:
00639         *ascii = K_DEL;
00640         break;
00641     case SDLK_PAUSE:
00642         *ascii = K_PAUSE;
00643         break;
00644     case SDLK_LSHIFT:
00645     case SDLK_RSHIFT:
00646         *ascii = K_SHIFT;
00647         break;
00648     case SDLK_LCTRL:
00649     case SDLK_RCTRL:
00650         *ascii = K_CTRL;
00651         break;
00652     case SDLK_LMETA:
00653     case SDLK_RMETA:
00654     case SDLK_LALT:
00655     case SDLK_RALT:
00656         *ascii = K_ALT;
00657         break;
00658     case SDLK_LSUPER:
00659     case SDLK_RSUPER:
00660         *ascii = K_SUPER;
00661         break;
00662     case SDLK_KP5:
00663         *ascii = K_KP_5;
00664         break;
00665     case SDLK_INSERT:
00666         *ascii = K_INS;
00667         break;
00668     case SDLK_KP0:
00669         *ascii = K_KP_INS;
00670         break;
00671     case SDLK_KP_MULTIPLY:
00672         *ascii = '*';
00673         break;
00674     case SDLK_KP_PLUS:
00675         *ascii = K_KP_PLUS;
00676         break;
00677     case SDLK_KP_MINUS:
00678         *ascii = K_KP_MINUS;
00679         break;
00680     case SDLK_KP_DIVIDE:
00681         *ascii = K_KP_SLASH;
00682         break;
00683     /* suggestions on how to handle this better would be appreciated */
00684     case SDLK_WORLD_7:
00685         *ascii = '`';
00686         break;
00687     case SDLK_MODE:
00688         *ascii = K_MODE;
00689         break;
00690     case SDLK_COMPOSE:
00691         *ascii = K_COMPOSE;
00692         break;
00693     case SDLK_HELP:
00694         *ascii = K_HELP;
00695         break;
00696     case SDLK_PRINT:
00697         *ascii = K_PRINT;
00698         break;
00699     case SDLK_SYSREQ:
00700         *ascii = K_SYSREQ;
00701         break;
00702     case SDLK_BREAK:
00703         *ascii = K_BREAK;
00704         break;
00705     case SDLK_MENU:
00706         *ascii = K_MENU;
00707         break;
00708     case SDLK_POWER:
00709         *ascii = K_POWER;
00710         break;
00711     case SDLK_EURO:
00712         *ascii = K_EURO;
00713         break;
00714     case SDLK_UNDO:
00715         *ascii = K_UNDO;
00716         break;
00717     case SDLK_SCROLLOCK:
00718         *ascii = K_SCROLLOCK;
00719         break;
00720     case SDLK_NUMLOCK:
00721         *ascii = K_KP_NUMLOCK;
00722         break;
00723     case SDLK_CAPSLOCK:
00724         *ascii = K_CAPSLOCK;
00725         break;
00726     case SDLK_SPACE:
00727         *ascii = K_SPACE;
00728         break;
00729     default:
00730         *ascii = keysym->sym;
00731         break;
00732     }
00733 
00734     *unicode = keysym->unicode;
00735 
00736     if (in_debug->integer)
00737         Com_Printf("unicode: %hx keycode: %i key: %hx\n", keysym->unicode, *ascii, *ascii);
00738 }
00739 
00740 void IN_EventEnqueue (unsigned int keyNum, unsigned short keyUnicode, qboolean keyDown)
00741 {
00742     if (keyNum > 0) {
00743         if (in_debug->integer)
00744             Com_Printf("Enqueue: %s (%i) (down: %i)\n", Key_KeynumToString(keyNum), keyNum, keyDown);
00745         keyq[keyq_head].down = (keyDown);
00746         keyq[keyq_head].unicode = (keyUnicode);
00747         keyq[keyq_head].key = (keyNum);
00748         keyq_head = (keyq_head + 1) & (MAX_KEYQ - 1);
00749     }
00750 }
00751 
00759 void IN_Frame (void)
00760 {
00761     int mouse_buttonstate;
00762     unsigned short unicode;
00763     unsigned int key;
00764     SDL_Event event;
00765 
00766     IN_Parse();
00767 
00768     IN_JoystickMove();
00769 
00770     if (vid_grabmouse->modified) {
00771         vid_grabmouse->modified = qfalse;
00772 
00773         if (!vid_grabmouse->integer) {
00774             /* ungrab the pointer */
00775             Com_Printf("Switch grab input off\n");
00776             SDL_WM_GrabInput(SDL_GRAB_OFF);
00777         /* don't allow grabbing the input in fullscreen mode */
00778         } else if (!vid_fullscreen->integer) {
00779             /* grab the pointer */
00780             Com_Printf("Switch grab input on\n");
00781             SDL_WM_GrabInput(SDL_GRAB_ON);
00782         } else {
00783             Com_Printf("No input grabbing in fullscreen mode\n");
00784             Cvar_SetValue("vid_grabmouse", 0);
00785         }
00786     }
00787 
00788     oldMousePosX = mousePosX;
00789     oldMousePosY = mousePosY;
00790 
00791     while (SDL_PollEvent(&event)) {
00792         switch (event.type) {
00793         case SDL_MOUSEBUTTONDOWN:
00794             in_pantilt.state = 0;
00795             switch (event.button.button) {
00796             case SDL_BUTTON_MIDDLE:
00797                 mouse_buttonstate = K_MOUSE3;
00798                 in_pantilt.state = 1;
00799                 break;
00800             }
00801             if (in_pantilt.state)
00802                 break;
00803         case SDL_MOUSEBUTTONUP:
00804             switch (event.button.button) {
00805             case SDL_BUTTON_LEFT:
00806                 mouse_buttonstate = K_MOUSE1;
00807                 break;
00808             case SDL_BUTTON_MIDDLE:
00809                 mouse_buttonstate = K_MOUSE3;
00810                 in_pantilt.state = 0;
00811                 break;
00812             case SDL_BUTTON_RIGHT:
00813                 mouse_buttonstate = K_MOUSE2;
00814                 break;
00815             case SDL_BUTTON_WHEELUP:
00816                 mouse_buttonstate = K_MWHEELUP;
00817                 break;
00818             case SDL_BUTTON_WHEELDOWN:
00819                 mouse_buttonstate = K_MWHEELDOWN;
00820                 break;
00821             case 6:
00822                 mouse_buttonstate = K_MOUSE4;
00823                 break;
00824             case 7:
00825                 mouse_buttonstate = K_MOUSE5;
00826                 break;
00827             default:
00828                 mouse_buttonstate = K_AUX1 + (event.button.button - 8) % 16;
00829                 break;
00830             }
00831             IN_EventEnqueue(mouse_buttonstate, 0, (event.type == SDL_MOUSEBUTTONDOWN));
00832             break;
00833 
00834         case SDL_MOUSEMOTION:
00835             SDL_GetMouseState(&mousePosX, &mousePosY);
00836             mousePosX /= viddef.rx;
00837             mousePosY /= viddef.ry;
00838             break;
00839 
00840         case SDL_KEYDOWN:
00841             IN_PrintKey(&event, 1);
00842             if (event.key.keysym.mod & KMOD_ALT && event.key.keysym.sym == SDLK_RETURN) {
00843                 SDL_Surface *surface = SDL_GetVideoSurface();
00844                 if (!SDL_WM_ToggleFullScreen(surface))
00845                     Com_Printf("IN_Frame: Could not toggle fullscreen mode\n");
00846 
00847                 if (surface->flags & SDL_FULLSCREEN) {
00848                     Cvar_SetValue("vid_fullscreen", 1);
00849                     /* make sure, that input grab is deactivated in fullscreen mode */
00850                     Cvar_SetValue("vid_grabmouse", 0);
00851                 } else {
00852                     Cvar_SetValue("vid_fullscreen", 0);
00853                 }
00854                 vid_fullscreen->modified = qfalse; /* we just changed it with SDL. */
00855                 break; /* ignore this key */
00856             }
00857 
00858             if (event.key.keysym.mod & KMOD_CTRL && event.key.keysym.sym == SDLK_g) {
00859                 SDL_GrabMode gm = SDL_WM_GrabInput(SDL_GRAB_QUERY);
00860                 Cvar_SetValue("vid_grabmouse", (gm == SDL_GRAB_ON) ? 0 : 1);
00861                 break; /* ignore this key */
00862             }
00863 
00864             /* console key is hardcoded, so the user can never unbind it */
00865             if (event.key.keysym.mod & KMOD_SHIFT && event.key.keysym.sym == SDLK_ESCAPE) {
00866                 Con_ToggleConsole_f();
00867                 break;
00868             }
00869 
00870             IN_TranslateKey(&event.key.keysym, &key, &unicode);
00871             IN_EventEnqueue(key, unicode, qtrue);
00872             break;
00873 
00874         case SDL_VIDEOEXPOSE:
00875             break;
00876 
00877         case SDL_KEYUP:
00878             IN_PrintKey(&event, 0);
00879             IN_TranslateKey(&event.key.keysym, &key, &unicode);
00880             IN_EventEnqueue(key, unicode, qfalse);
00881             break;
00882 
00883         case SDL_ACTIVEEVENT:
00884             /* make sure menu no more capture input when the game window lose the focus */
00885             if (event.active.state == SDL_APPINPUTFOCUS && event.active.gain == 0)
00886                 UI_ReleaseInput();
00887             break;
00888 
00889         case SDL_QUIT:
00890             Cmd_ExecuteString("quit");
00891             break;
00892 
00893         case SDL_VIDEORESIZE:
00894             /* make sure that SDL_SetVideoMode is called again after we changed the size
00895              * otherwise the mouse will make problems */
00896             vid_mode->modified = qtrue;
00897             break;
00898         }
00899     }
00900 }
00901 
00905 void IN_Init (void)
00906 {
00907     Com_Printf("\n------- input initialization -------\n");
00908 
00909     /* cvars */
00910     in_debug = Cvar_Get("in_debug", "0", 0, "Show input key codes on game console");
00911     cl_isometric = Cvar_Get("r_isometric", "0", CVAR_ARCHIVE, "Draw the world in isometric mode");
00912 
00913     /* commands */
00914     Cmd_AddCommand("+turnleft", IN_TurnLeftDown_f, _("Rotate battlescape camera anti-clockwise"));
00915     Cmd_AddCommand("-turnleft", IN_TurnLeftUp_f, NULL);
00916     Cmd_AddCommand("+turnright", IN_TurnRightDown_f, _("Rotate battlescape camera clockwise"));
00917     Cmd_AddCommand("-turnright", IN_TurnRightUp_f, NULL);
00918     Cmd_AddCommand("+turnup", IN_TurnUpDown_f, _("Tilt battlescape camera up"));
00919     Cmd_AddCommand("-turnup", IN_TurnUpUp_f, NULL);
00920     Cmd_AddCommand("+turndown", IN_TurnDownDown_f, _("Tilt battlescape camera down"));
00921     Cmd_AddCommand("-turndown", IN_TurnDownUp_f, NULL);
00922     Cmd_AddCommand("+shiftleft", IN_ShiftLeftDown_f, _("Move battlescape camera left"));
00923     Cmd_AddCommand("-shiftleft", IN_ShiftLeftUp_f, NULL);
00924     Cmd_AddCommand("+shiftright", IN_ShiftRightDown_f, _("Move battlescape camera right"));
00925     Cmd_AddCommand("-shiftright", IN_ShiftRightUp_f, NULL);
00926     Cmd_AddCommand("+shiftup", IN_ShiftUpDown_f, _("Move battlescape camera forward"));
00927     Cmd_AddCommand("-shiftup", IN_ShiftUpUp_f, NULL);
00928     Cmd_AddCommand("+shiftdown", IN_ShiftDownDown_f, _("Move battlescape camera backward"));
00929     Cmd_AddCommand("-shiftdown", IN_ShiftDownUp_f, NULL);
00930     Cmd_AddCommand("+zoomin", IN_ZoomInDown_f, _("Zoom in"));
00931     Cmd_AddCommand("-zoomin", IN_ZoomInUp_f, NULL);
00932     Cmd_AddCommand("+zoomout", IN_ZoomOutDown_f, _("Zoom out"));
00933     Cmd_AddCommand("-zoomout", IN_ZoomOutUp_f, NULL);
00934 
00935     Cmd_AddCommand("+leftmouse", CL_LeftClickDown_f, _("Left mouse button click (menu)"));
00936     Cmd_AddCommand("-leftmouse", CL_LeftClickUp_f, NULL);
00937     Cmd_AddCommand("+middlemouse", CL_MiddleClickDown_f, _("Middle mouse button click (menu)"));
00938     Cmd_AddCommand("-middlemouse", CL_MiddleClickUp_f, NULL);
00939     Cmd_AddCommand("+rightmouse", CL_RightClickDown_f, _("Right mouse button click (menu)"));
00940     Cmd_AddCommand("-rightmouse", CL_RightClickUp_f, NULL);
00941     Cmd_AddCommand("+select", CL_SelectDown_f, _("Select objects/Walk to a square/In fire mode, fire etc"));
00942     Cmd_AddCommand("-select", CL_SelectUp_f, NULL);
00943     Cmd_AddCommand("+action", CL_ActionDown_f, _("Walk to a square/In fire mode, cancel action"));
00944     Cmd_AddCommand("-action", CL_ActionUp_f, NULL);
00945     Cmd_AddCommand("+turn", CL_TurnDown_f, _("Turn soldier toward mouse pointer"));
00946     Cmd_AddCommand("-turn", CL_TurnUp_f, NULL);
00947     Cmd_AddCommand("+hudradar", CL_HudRadarDown_f, _("Toggles the hud radar mode"));
00948     Cmd_AddCommand("-hudradar", CL_HudRadarUp_f, NULL);
00949 
00950     Cmd_AddCommand("levelup", CL_LevelUp_f, _("Slice through terrain at a higher level"));
00951     Cmd_AddCommand("leveldown", CL_LevelDown_f, _("Slice through terrain at a lower level"));
00952     Cmd_AddCommand("zoominquant", CL_ZoomInQuant_f, _("Zoom in"));
00953     Cmd_AddCommand("zoomoutquant", CL_ZoomOutQuant_f, _("Zoom out"));
00954 
00955     mousePosX = mousePosY = 0.0;
00956 
00957     IN_StartupJoystick();
00958 }
00959 
00963 void IN_SendKeyEvents (void)
00964 {
00965     while (keyq_head != keyq_tail) {
00966         Key_Event(keyq[keyq_tail].key, keyq[keyq_tail].unicode, keyq[keyq_tail].down, CL_Milliseconds());
00967         keyq_tail = (keyq_tail + 1) & (MAX_KEYQ - 1);
00968     }
00969 }

Generated by  doxygen 1.6.2