41 #include "../client.h"
45 #include "../battlescape/cl_localentity.h"
46 #include "../battlescape/cl_hud.h"
47 #include "../cl_console.h"
48 #include "../cl_screen.h"
49 #include "../battlescape/cl_actor.h"
50 #include "../battlescape/cl_view.h"
51 #include "../battlescape/cl_parse.h"
52 #include "../ui/ui_main.h"
53 #include "../ui/ui_input.h"
54 #include "../ui/node/ui_node_abstractnode.h"
55 #include "../../shared/utf8.h"
57 #include "../../common/tracing.h"
58 #include "../renderer/r_misc.h"
63 #if SDL_VERSION_ATLEAST(2,0,0)
64 #define SDL_keysym SDL_Keysym
129 if (k == b->
down[0] || k == b->
down[1])
134 else if (!b->
down[1])
137 Com_Printf(
"Three keys down for a button!\n");
178 else if (b->
down[1] == k)
194 const unsigned uptime = atoi(c);
396 if ((SDL_GetMouseState(
nullptr,
nullptr) & SDL_BUTTON(SDL_BUTTON_RIGHT)) == 0)
436 if (in_pantilt.
msec < 250)
539 #define SCROLL_BORDER 4
540 #define MOUSE_YAW_SCALE 0.1
541 #define MOUSE_PITCH_SCALE 0.1
560 value = (in_zoomin.
state & 1) - (in_zoomout.
state & 1);
563 value = (in_turnleft.
state & 1) - (in_turnright.
state & 1);
564 if (in_pantilt.
state)
568 value = (in_turnup.
state & 1) - (in_turndown.
state & 1);
569 if (in_pantilt.
state)
612 Com_Printf(
"key name: %s (down: %i)", SDL_GetKeyName(event->key.keysym.sym), down);
613 #if SDL_VERSION_ATLEAST(2,0,0)
614 const int unicode =
event->key.keysym.sym;
616 const int unicode =
event->key.keysym.unicode;
620 if (unicode >=
'0' && unicode <=
'~')
621 Com_Printf(
" (%c)", (
unsigned char)(unicode));
632 bool translated =
true;
637 #if SDL_VERSION_ATLEAST(2,0,0)
678 case SDLK_PRINTSCREEN:
681 case SDLK_SCROLLLOCK:
866 case SDLK_KP_MULTIPLY:
907 if (keyNum > 0 || keyUnicode > 0) {
919 #if SDL_VERSION_ATLEAST(2,0,0)
920 const int mask = full ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_FULLSCREEN_DESKTOP;
921 const bool isFullScreen = SDL_GetWindowFlags(
cls.window) & mask;
922 SDL_SetWindowFullscreen(
cls.window, isFullScreen ? 0 : mask);
923 return SDL_GetWindowFlags(
cls.window) & mask;
928 SDL_Surface* surface = SDL_GetVideoSurface();
929 if (!SDL_WM_ToggleFullScreen(surface)) {
930 const int flags = surface->flags ^= SDL_FULLSCREEN;
931 SDL_SetVideoMode(surface->w, surface->h, 0, flags);
934 return surface->flags & SDL_FULLSCREEN;
948 int mouse_buttonstate;
965 #if SDL_VERSION_ATLEAST(2,0,0)
966 SDL_SetWindowGrab(
cls.window, SDL_FALSE);
968 SDL_WM_GrabInput(SDL_GRAB_OFF);
973 #if SDL_VERSION_ATLEAST(2,0,0)
974 SDL_SetWindowGrab(
cls.window, SDL_TRUE);
976 SDL_WM_GrabInput(SDL_GRAB_ON);
984 while (SDL_PollEvent(&event)) {
985 switch (event.type) {
986 #if SDL_VERSION_ATLEAST(2,0,0)
991 case SDL_TEXTEDITING:
994 case SDL_TEXTINPUT: {
995 if (!SDL_IsTextInputActive())
998 const char* text =
event.text.text;
999 const char** str = &text;
1001 const int characterUnicode =
UTF8_next(str);
1002 if (characterUnicode == -1) {
1005 unicode = characterUnicode;
1013 case SDL_MOUSEBUTTONDOWN:
1014 case SDL_MOUSEBUTTONUP:
1015 switch (event.button.button) {
1016 case SDL_BUTTON_LEFT:
1019 case SDL_BUTTON_MIDDLE:
1022 case SDL_BUTTON_RIGHT:
1025 #if SDL_VERSION_ATLEAST(2,0,0)
1033 case SDL_BUTTON_WHEELUP:
1036 case SDL_BUTTON_WHEELDOWN:
1047 mouse_buttonstate =
K_AUX1 + (
event.button.button - 8) % 16;
1050 IN_EventEnqueue(mouse_buttonstate, 0, (event.type == SDL_MOUSEBUTTONDOWN));
1053 case SDL_MOUSEMOTION:
1061 if ((event.key.keysym.mod & KMOD_ALT) && event.key.keysym.sym == SDLK_RETURN) {
1074 if ((event.key.keysym.mod & KMOD_CTRL) && event.key.keysym.sym == SDLK_RETURN) {
1085 if ((event.key.keysym.mod & KMOD_CTRL) && event.key.keysym.sym == SDLK_g) {
1086 #if SDL_VERSION_ATLEAST(2,0,0)
1087 const bool grab = SDL_GetWindowGrab(
cls.window);
1090 SDL_GrabMode gm = SDL_WM_GrabInput(SDL_GRAB_QUERY);
1091 Cvar_SetValue(
"vid_grabmouse", (gm == SDL_GRAB_ON) ? 0 : 1);
1098 if ((event.key.keysym.mod & KMOD_SHIFT) && event.key.keysym.sym == SDLK_ESCAPE) {
1103 #if SDL_VERSION_ATLEAST(2,0,0)
1105 if (
IN_TranslateKey(event.key.keysym.sym, &key) || !SDL_IsTextInputActive())
1108 unicode =
event.key.keysym.unicode;
1116 #if SDL_VERSION_ATLEAST(2,0,0)
1118 if (
IN_TranslateKey(event.key.keysym.sym, &key) || !SDL_IsTextInputActive())
1121 unicode =
event.key.keysym.unicode;
1127 #if SDL_VERSION_ATLEAST(2,0,0)
1129 case SDL_WINDOWEVENT:
1130 switch (event.window.type) {
1131 case SDL_WINDOWEVENT_FOCUS_LOST:
1134 case SDL_WINDOWEVENT_RESIZED:
1144 case SDL_VIDEOEXPOSE:
1147 case SDL_ACTIVEEVENT:
1149 if (event.active.state == SDL_APPINPUTFOCUS && event.active.gain == 0)
1153 case SDL_VIDEORESIZE:
1214 Com_Printf(
"\n------- input initialization -------\n");
1217 in_debug =
Cvar_Get(
"in_debug",
"0", 0,
"Show input key codes on game console");
const char * Cmd_Argv(int arg)
Returns a given argument.
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
void CL_BattlescapeMouseDragging(void)
Scroll battlescape touchscreen-style, by clicking and dragging away.
bool CL_ActorMouseTrace(void)
Battlescape cursor positioning.
void CL_InitBattlescapeMouseDragging(void)
Scroll battlescape touchscreen-style, by clicking and dragging away.
void CL_ActorTurnMouse(void)
Turns the actor around without moving.
bool CL_OnBattlescape(void)
Check whether we are in a tactical mission as server or as client. But this only means that we are ab...
bool UI_IsMouseOnWindow(void)
Check if a point is over a window from the stack.
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
void CL_ActorActionMouse(void)
initiates action with mouse.
int UTF8_next(const char **str)
Get the next utf-8 character from the given string.
void Key_Event(unsigned int key, unsigned short unicode, bool down, unsigned time)
Called by the system between frames for both key up and key down events.
void Com_Printf(const char *const fmt,...)
void CL_ActorSelectMouse(void)
Selects an actor using the mouse.
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
Header file for keyboard handler.
uiNode_t * UI_PushWindow(const char *name, const char *parentName, linkedList_t *params)
Push a window onto the window stack.
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
float Cvar_GetValue(const char *varName)
Returns the float value of a cvar.
void CL_CameraZoomIn(void)
Zooms the scene of the battlefield in.
int Cmd_Argc(void)
Return the number of arguments of the current command. "command parameter" will result in a argc of 2...
void UI_CloseWindow(const char *name)
static bool keyDown[K_KEY_SIZE]
int UTF8_encoded_len(int c)
bool CL_BattlescapeRunning(void)
Check whether we already have actors spawned on the battlefield.
void SCR_ChangeCursor(int cursor)
void IN_StartupJoystick(void)
Init available joysticks.
void IN_JoystickMove(void)
void R_ReinitOpenglContext(void)
Re-initializes OpenGL state machine, all textures and renderer variables, this needed when applicatio...
const char * Key_KeynumToString(int keynum)
Convert a given keynum to string.
void Con_ToggleConsole_f(void)
void CL_CameraZoomOut(void)
Zooms the scene of the battlefield out.
int Key_StringToKeynum(const char *str)
Convert to given string to keynum.
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
int CL_Milliseconds(void)