diff --git a/src/input.c b/src/input.c index 9c109cb..6c3cf9c 100644 --- a/src/input.c +++ b/src/input.c @@ -265,15 +265,23 @@ static void input_keyConvDestroy(void) { SDLKey input_keyConv(char* name) { SDLKey k; size_t l; - char buf[2]; + char buf; + int m; l = strlen(name); - buf[0] = tolower(name[0]); - buf[1] = '\0'; + buf = tolower(name[0]); - for(k = 0; k < INPUT_NUMKEYS; k++) - if(strcmp((l==1) ? buf : name, keyconv[k])==0) - return k; + /* Compare for single character. */ + if(l == 1) { + m = MIN(256, INPUT_NUMKEYS); + for(k = 0; k < m; k++) /* Only valid for char range. */ + if((buf == tolower(keyconv[k][0])) && (keyconv[k][1] == '\0')) + return k; + } else { /* Compare for strings. */ + for(k = 0; k < INPUT_NUMKEYS; k++) + if(strcmp(name, keyconv[k])==0) + return k; + } WARN("Keyname '%s' doesn't match any key.", name); return SDLK_UNKNOWN; diff --git a/src/opengl.c b/src/opengl.c index 5fca21b..261ef1c 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -185,7 +185,7 @@ static int SDL_IsTrans(SDL_Surface* s, int x, int y) { static uint8_t* SDL_MapTrans(SDL_Surface* s) { int i, j; int size; - uint8* t; + Uint8* t; /* Allocate memory for just enough bits to hold all the data we need. */ size = s->w*s->h/8 + ((s->w*s->h%8)?1:0); diff --git a/src/options.c b/src/options.c index 699a3d4..eead090 100644 --- a/src/options.c +++ b/src/options.c @@ -27,12 +27,30 @@ /* Extern. */ extern const char* keybindNames[]; /* From input.c */ +static int opt_isalpha(SDLKey k); static const char* modToText(SDLMod mod); static void menuKeybinds_update(unsigned int wid, char* name); static void opt_setSFXLevel(unsigned int wid, char* str); static void opt_setMusicLevel(unsigned int wid, char* str); +/** + * @brief Check to see if a key is alpha. + * @param k Key to check. + * @return 1 if is alpha. + */ +static int opt_isalpha(SDLKey k) { + int ret; + + ret = 0; + + /* Alpha. */ + if((k >= SDLK_a) && (k <= SDLK_z)) + ret = 1; + + return ret; +} + /** * @brief Opens the keybindings menu. */ @@ -66,7 +84,7 @@ void opt_menuKeybinds(void) { switch(type) { case KEYBIND_KEYBOARD: /* SDL_GetKeyName returns lowercase which is ugly. */ - if(isalpha(key)) + if(opt_isalpha(key)) snprintf(str[j], 64, "%s <%c>", keybindNames[j], toupper(key)); else snprintf(str[j], 64, "%s <%s>", keybindNames[j], SDL_GetKeyName(key)); @@ -147,7 +165,7 @@ static void menuKeybinds_update(unsigned int wid, char* name) { break; case KEYBIND_KEYBOARD: /* SDL_GetKeyName returns lowercase which is ugly. */ - if(isalpha(key)) + if(opt_isalpha(key)) snprintf(bind, 32, "keyboard: %s%s%c", (mod != KMOD_NONE) ? modToText(mod) : "", (mod != KMOD_NONE) ? " + " : "", diff --git a/src/toolkit.c b/src/toolkit.c index 0d2178b..d32d8c5 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -198,6 +198,8 @@ static void toolkit_clip(double x, double y, double w, double h); static void toolkit_unclip(void); static void toolkit_drawRect(double x, double y, double w, double h, glColour* c, glColour* lc); +/* Misc. */ +static int toolkit_isalnum(SDLKey k); /** * @brief Set the internal widget position. @@ -2198,6 +2200,27 @@ static void toolkit_clearKey(void) { input_keyCounter = 0; } +/** + * @brief Like isalnum but for keysyms. + * @param k Key to check. + * @return 1 if is alnum. + */ +static int toolkit_isalnum(SDLKey k) { + int ret; + + ret = 0; + + /* Alpha. */ + if((k >= SDLK_a) && (k <= SDLK_z)) + ret = 1; + + /* Number. */ + if((k >= SDLK_0) && (k <= SDLK_9)) + ret = 1; + + return ret; +} + /** * @brief Handles keyboard events. * @param event Keyboard event to handle. @@ -2217,7 +2240,7 @@ static int toolkit_keyEvent(SDL_Event* event) { key = event->key.keysym.sym; /* Hack to simulate key repetition. */ - if((key == SDLK_BACKSPACE) || isalnum(key)) { + if((key == SDLK_BACKSPACE) || toolkit_isalnum(key)) { if(event->type == SDL_KEYDOWN) toolkit_regKey(key); else if(event->type == SDL_KEYUP) toolkit_unregKey(key); } @@ -2290,7 +2313,7 @@ void toolkit_update(void) { wdw = &windows[nwindows-1]; wgt = (wdw->focus >= 0) ? &wdw->widgets[wdw->focus] : NULL; if(wgt && (wgt->type == WIDGET_INPUT) && - (input_key == SDLK_BACKSPACE || isalnum(input_key))) + (input_key == SDLK_BACKSPACE || toolkit_isalnum(input_key))) toolkit_inputInput(SDL_KEYDOWN, wgt, input_key); }