From 944c675b2e538c352a98d90c994c27d8e5969958 Mon Sep 17 00:00:00 2001 From: Spoike Date: Mon, 8 Apr 2013 06:47:27 +0000 Subject: [PATCH] Use SDL1.3 text input instead of button input, this gives (me) actual unicode values, so you're no longer all forced to use an en-gb charmap, lucky you. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4301 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/in_sdl.c | 222 ++++++++-------------------------------- engine/qclib/pr_multi.c | 12 +-- engine/qclib/progslib.h | 2 +- 3 files changed, 49 insertions(+), 187 deletions(-) diff --git a/engine/client/in_sdl.c b/engine/client/in_sdl.c index 079099516..c7f1b91ab 100644 --- a/engine/client/in_sdl.c +++ b/engine/client/in_sdl.c @@ -9,6 +9,13 @@ qboolean mouseactive; extern qboolean mouseusedforgui; extern qboolean vid_isfullscreen; +#ifdef FTE_TARGET_WEB //theoretically generic, but the IME is probably going to be more annoying on systems where its actually implemented properly. + +#if SDL_MAJOR_VERSION > 1 || (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION >= 3) +#define HAVE_SDL_TEXTINPUT +#endif +#endif + void IN_ActivateMouse(void) { if (mouseactive) @@ -206,159 +213,6 @@ static unsigned int tbl_sdltoquake[] = 0 //SDLK_UNDO = 322, /* Atari keyboard has Undo */ }; -#ifdef FTE_TARGET_WEB -//this matches my UK keymap. Sucks to be you if you're not british. Sorry. Blame emscripten. -static unsigned int tbl_sdlshifttounicode[] = -{ - 0,0,0,0, //SDLK_UNKNOWN = 0, - 0,0,0,0, //SDLK_FIRST = 0, - K_BACKSPACE, //SDLK_BACKSPACE = 8, - K_TAB, //SDLK_TAB = 9, - 0,0, - 0, //SDLK_CLEAR = 12, - K_ENTER, //SDLK_RETURN = 13, - 0,0,0,0,0, - K_PAUSE, //SDLK_PAUSE = 19, - 0,0,0,0,0,0,0, - K_ESCAPE, //SDLK_ESCAPE = 27, - 0,0,0,0, - K_SPACE, //SDLK_SPACE = 32, - '!', //SDLK_EXCLAIM = 33, - '"', //SDLK_QUOTEDBL = 34, - '~', //SDLK_HASH = 35, - '$', //SDLK_DOLLAR = 36, - 0, - '&', //SDLK_AMPERSAND = 38, - '@', //SDLK_QUOTE = 39, - '(', //SDLK_LEFTPAREN = 40, - ')', //SDLK_RIGHTPAREN = 41, - '*', //SDLK_ASTERISK = 42, - '+', //SDLK_PLUS = 43, - '<', //SDLK_COMMA = 44, - '_', //SDLK_MINUS = 45, - '>', //SDLK_PERIOD = 46, - '?', //SDLK_SLASH = 47, - ')', //SDLK_0 = 48, - '!', //SDLK_1 = 49, - '\"', //SDLK_2 = 50, - L'£', //SDLK_3 = 51, - '$', //SDLK_4 = 52, - '%', //SDLK_5 = 53, - '^', //SDLK_6 = 54, - '&', //SDLK_7 = 55, - '*', //SDLK_8 = 56, - '(', //SDLK_9 = 57, - ':', //SDLK_COLON = 58, - ':', //SDLK_SEMICOLON = 59, - '<', //SDLK_LESS = 60, - '+', //SDLK_EQUALS = 61, - '>', //SDLK_GREATER = 62, - '?', //SDLK_QUESTION = 63, - '@', //SDLK_AT = 64, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - '{', //SDLK_LEFTBRACKET = 91, - '|', //SDLK_BACKSLASH = 92, - '}', //SDLK_RIGHTBRACKET = 93, - '^', //SDLK_CARET = 94, - '_', //SDLK_UNDERSCORE = 95, - L'¬', //SDLK_BACKQUOTE = 96, - 'A', //SDLK_a = 97, - 'B', //SDLK_b = 98, - 'C', //SDLK_c = 99, - 'D', //SDLK_d = 100, - 'E', //SDLK_e = 101, - 'F', //SDLK_f = 102, - 'G', //SDLK_g = 103, - 'H', //SDLK_h = 104, - 'I', //SDLK_i = 105, - 'J', //SDLK_j = 106, - 'K', //SDLK_k = 107, - 'L', //SDLK_l = 108, - 'M', //SDLK_m = 109, - 'N', //SDLK_n = 110, - 'O', //SDLK_o = 111, - 'P', //SDLK_p = 112, - 'Q', //SDLK_q = 113, - 'R', //SDLK_r = 114, - 'S', //SDLK_s = 115, - 'T', //SDLK_t = 116, - 'U', //SDLK_u = 117, - 'V', //SDLK_v = 118, - 'W', //SDLK_w = 119, - 'X', //SDLK_x = 120, - 'Y', //SDLK_y = 121, - 'Z', //SDLK_z = 122, - 0,0,0,0, - K_DEL, //SDLK_DELETE = 127, - hundredoh /*227*/, tenoh, tenoh, 0,0,0,0,0,0,0,0, - K_KP_INS, //SDLK_KP0 = 256, - K_KP_END, //SDLK_KP1 = 257, - K_KP_DOWNARROW, //SDLK_KP2 = 258, - K_KP_PGDN, //SDLK_KP3 = 259, - K_KP_LEFTARROW, //SDLK_KP4 = 260, - K_KP_5, //SDLK_KP5 = 261, - K_KP_RIGHTARROW, //SDLK_KP6 = 262, - K_KP_HOME, //SDLK_KP7 = 263, - K_KP_UPARROW, //SDLK_KP8 = 264, - K_KP_PGUP, //SDLK_KP9 = 265, - K_KP_DEL,//SDLK_KP_PERIOD = 266, - K_KP_SLASH,//SDLK_KP_DIVIDE = 267, - K_KP_STAR,//SDLK_KP_MULTIPLY= 268, - K_KP_MINUS, //SDLK_KP_MINUS = 269, - K_KP_PLUS, //SDLK_KP_PLUS = 270, - K_KP_ENTER, //SDLK_KP_ENTER = 271, - K_KP_EQUALS,//SDLK_KP_EQUALS = 272, - K_UPARROW, //SDLK_UP = 273, - K_DOWNARROW,//SDLK_DOWN = 274, - K_RIGHTARROW,//SDLK_RIGHT = 275, - K_LEFTARROW,//SDLK_LEFT = 276, - K_INS, //SDLK_INSERT = 277, - K_HOME, //SDLK_HOME = 278, - K_END, //SDLK_END = 279, - K_PGUP, //SDLK_PAGEUP = 280, - K_PGDN, //SDLK_PAGEDOWN = 281, - K_F1, //SDLK_F1 = 282, - K_F2, //SDLK_F2 = 283, - K_F3, //SDLK_F3 = 284, - K_F4, //SDLK_F4 = 285, - K_F5, //SDLK_F5 = 286, - K_F6, //SDLK_F6 = 287, - K_F7, //SDLK_F7 = 288, - K_F8, //SDLK_F8 = 289, - K_F9, //SDLK_F9 = 290, - K_F10, //SDLK_F10 = 291, - K_F11, //SDLK_F11 = 292, - K_F12, //SDLK_F12 = 293, - 0, //SDLK_F13 = 294, - 0, //SDLK_F14 = 295, - 0, //SDLK_F15 = 296, - 0,0,0, - 0,//K_NUMLOCK, //SDLK_NUMLOCK = 300, - K_CAPSLOCK, //SDLK_CAPSLOCK = 301, - 0,//K_SCROLLOCK,//SDLK_SCROLLOCK= 302, - K_SHIFT, //SDLK_RSHIFT = 303, - K_SHIFT, //SDLK_LSHIFT = 304, - K_CTRL, //SDLK_RCTRL = 305, - K_CTRL, //SDLK_LCTRL = 306, - K_ALT, //SDLK_RALT = 307, - K_ALT, //SDLK_LALT = 308, - 0, //SDLK_RMETA = 309, - 0, //SDLK_LMETA = 310, - 0, //SDLK_LSUPER = 311, /* Left "Windows" key */ - 0, //SDLK_RSUPER = 312, /* Right "Windows" key */ - 0, //SDLK_MODE = 313, /* "Alt Gr" key */ - 0, //SDLK_COMPOSE = 314, /* Multi-key compose key */ - 0, //SDLK_HELP = 315, - 0, //SDLK_PRINT = 316, - 0, //SDLK_SYSREQ = 317, - K_PAUSE, //SDLK_BREAK = 318, - 0, //SDLK_MENU = 319, - 0, //SDLK_POWER = 320, /* Power Macintosh power key */ - 'e', //SDLK_EURO = 321, /* Some european keyboards */ - 0 //SDLK_UNDO = 322, /* Atari keyboard has Undo */ -}; -#endif - static unsigned int tbl_sdltoquakemouse[] = { K_MOUSE1, @@ -391,21 +245,15 @@ void Sys_SendKeyEvents(void) break; case SDL_VIDEORESIZE: - switch(qrenderer) +#ifndef SERVERONLY + vid.pixelwidth = event.resize.w; + vid.pixelheight = event.resize.h; { -#ifdef GLQUAKE - case QR_OPENGL: - vid.pixelwidth = event.resize.w; - vid.pixelheight = event.resize.h; - { - extern cvar_t vid_conautoscale, vid_conwidth; //make sure the screen is updated properly. - Cvar_ForceCallback(&vid_conautoscale); - Cvar_ForceCallback(&vid_conwidth); - } - - break; -#endif + extern cvar_t vid_conautoscale, vid_conwidth; //make sure the screen is updated properly. + Cvar_ForceCallback(&vid_conautoscale); + Cvar_ForceCallback(&vid_conwidth); } +#endif break; case SDL_KEYUP: @@ -422,26 +270,36 @@ void Sys_SendKeyEvents(void) #ifdef FTE_TARGET_WEB if (s == 1249) qs = K_SHIFT; - //emscripten doesn't support unicode, but does pretend to. override it so we get something usable. - u = 0; - extern qboolean shift_down; - if (shift_down) - { - if (s < sizeof(tbl_sdlshifttounicode) / sizeof(tbl_sdlshifttounicode[0])) - u = tbl_sdlshifttounicode[s]; - } - else - { - if (s < sizeof(tbl_sdltoquake) / sizeof(tbl_sdltoquake[0])) - u = tbl_sdltoquake[s]; - } #endif +#ifdef HAVE_SDL_TEXTINPUT + IN_KeyEvent(0, event.key.state, qs, 0); +#else IN_KeyEvent(0, event.key.state, qs, u); +#endif } break; +#ifdef HAVE_SDL_TEXTINPUT + case SDL_TEXTINPUT: + { + int i; + unsigned int uc; + int err; + char *text = event.text.text; + while(*text) + { + uc = utf8_decode(&err, text, &text); + if (uc && !err) + { + IN_KeyEvent(0, true, 0, uc); + IN_KeyEvent(0, false, 0, uc); + } + } + } + break; +#endif case SDL_MOUSEMOTION: - IN_MouseMove(0, 0, event.motion.xrel, event.motion.yrel, 0, 0); + IN_MouseMove(0, (SDL_ShowCursor(SDL_QUERY) == SDL_DISABLE), event.motion.xrel, event.motion.yrel, 0, 0); break; case SDL_MOUSEBUTTONDOWN: @@ -473,7 +331,11 @@ void INS_ReInit (void) { IN_ActivateMouse(); +#ifdef HAVE_SDL_TEXTINPUT + SDL_StartTextInput(); +#else SDL_EnableUNICODE(SDL_ENABLE); +#endif } //stubs, all the work is done in Sys_SendKeyEvents diff --git a/engine/qclib/pr_multi.c b/engine/qclib/pr_multi.c index e12c528f8..16938857b 100644 --- a/engine/qclib/pr_multi.c +++ b/engine/qclib/pr_multi.c @@ -243,6 +243,7 @@ int PDECL QC_RegisterFieldVar(pubprogfuncs_t *ppf, unsigned int type, char *name if (!name) //engine can use this to offset all progs fields { //which fixes constant field offsets (some ktpro arrays) progfuncs->funcs.fieldadjust = fields_size/4; +// printf("FIELD ADJUST: %i %i %i\n", progfuncs->funcs.fieldadjust, fields_size, (int)fields_size/4); return 0; } @@ -272,7 +273,7 @@ int PDECL QC_RegisterFieldVar(pubprogfuncs_t *ppf, unsigned int type, char *name if (prinst.field[i].progsofs == -1) prinst.field[i].progsofs = progsofs; -// printf("Dupfield %s %i -> %i\n", name, prinst.field[i].progsofs,field[i].ofs); +// printf("Dupfield %s %i -> %i\n", name, prinst.field[i].progsofs,prinst.field[i].ofs); return prinst.field[i].ofs-progfuncs->funcs.fieldadjust; //got a match } } @@ -342,7 +343,7 @@ int PDECL QC_RegisterFieldVar(pubprogfuncs_t *ppf, unsigned int type, char *name { if (prinst.field[i].progsofs == (unsigned)progsofs) { -// printf("found union field %s %i -> %i\n", field[i].name, field[i].progsofs, field[i].ofs); +// printf("found union field %s %i -> %i\n", prinst.field[i].name, prinst.field[i].progsofs, prinst.field[i].ofs); prinst.field[fnum].ofs = ofs = prinst.field[i].ofs; break; } @@ -359,7 +360,7 @@ int PDECL QC_RegisterFieldVar(pubprogfuncs_t *ppf, unsigned int type, char *name prinst.field[fnum].progsofs = progsofs; -// printf("Field %s %i -> %i\n", name, field[fnum].progsofs,field[fnum].ofs); +// printf("Field %s %i -> %i\n", name, prinst.field[fnum].progsofs,prinst.field[fnum].ofs); //we've finished setting the structure return ofs - progfuncs->funcs.fieldadjust; @@ -401,8 +402,7 @@ void PDECL QC_AddSharedFieldVar(pubprogfuncs_t *ppf, int num, char *stringtable) { // int old = *(int *)&pr_globals[pr_globaldefs16[num].ofs]; *(int *)&pr_globals[pr_globaldefs16[num].ofs] = QC_RegisterFieldVar(&progfuncs->funcs, pr_fielddefs16[i].type, pr_globaldefs16[num].s_name+stringtable, -1, *(int *)&pr_globals[pr_globaldefs16[num].ofs]); - -// printf("Field %s %i -> %i\n", pr_globaldefs16[num].s_name+stringtable, old, *(int *)&pr_globals[pr_globaldefs16[num].ofs]); +// printf("Field=%s global %i -> %i\n", pr_globaldefs16[num].s_name+stringtable, old, *(volatile int *)&pr_globals[pr_globaldefs16[num].ofs]); return; } } @@ -416,7 +416,7 @@ void PDECL QC_AddSharedFieldVar(pubprogfuncs_t *ppf, int num, char *stringtable) { // int old = *(int *)&pr_globals[pr_globaldefs16[num].ofs]; *(int *)&pr_globals[pr_globaldefs16[num].ofs] = prinst.field[i].ofs-progfuncs->funcs.fieldadjust; -// printf("Field %s %i -> %i\n", pr_globaldefs16[num].s_name+stringtable, old, *(int *)&pr_globals[pr_globaldefs16[num].ofs]); +// printf("Field global=%s %i -> %i\n", pr_globaldefs16[num].s_name+stringtable, old, *(volatile int *)&pr_globals[pr_globaldefs16[num].ofs]); return; } } diff --git a/engine/qclib/progslib.h b/engine/qclib/progslib.h index 178940d00..b48a0f2a7 100644 --- a/engine/qclib/progslib.h +++ b/engine/qclib/progslib.h @@ -53,7 +53,7 @@ typedef struct fdef_s { unsigned int type; // if DEF_SAVEGLOBAL bit is set // the variable needs to be saved in savegames - unsigned int ofs; + int ofs; //runtime offset. add fieldadj to get the real array index. unsigned int progsofs; //used at loading time, so maching field offsets (unions/members) are positioned at the same runtime offset. char * name; } fdef_t;