[Change] More stuff to work with SDL1.3
This commit is contained in:
parent
fb3c093f02
commit
0064c2bf0b
20
src/input.c
20
src/input.c
@ -265,15 +265,23 @@ static void input_keyConvDestroy(void) {
|
|||||||
SDLKey input_keyConv(char* name) {
|
SDLKey input_keyConv(char* name) {
|
||||||
SDLKey k;
|
SDLKey k;
|
||||||
size_t l;
|
size_t l;
|
||||||
char buf[2];
|
char buf;
|
||||||
|
int m;
|
||||||
|
|
||||||
l = strlen(name);
|
l = strlen(name);
|
||||||
buf[0] = tolower(name[0]);
|
buf = tolower(name[0]);
|
||||||
buf[1] = '\0';
|
|
||||||
|
|
||||||
for(k = 0; k < INPUT_NUMKEYS; k++)
|
/* Compare for single character. */
|
||||||
if(strcmp((l==1) ? buf : name, keyconv[k])==0)
|
if(l == 1) {
|
||||||
return k;
|
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);
|
WARN("Keyname '%s' doesn't match any key.", name);
|
||||||
return SDLK_UNKNOWN;
|
return SDLK_UNKNOWN;
|
||||||
|
@ -185,7 +185,7 @@ static int SDL_IsTrans(SDL_Surface* s, int x, int y) {
|
|||||||
static uint8_t* SDL_MapTrans(SDL_Surface* s) {
|
static uint8_t* SDL_MapTrans(SDL_Surface* s) {
|
||||||
int i, j;
|
int i, j;
|
||||||
int size;
|
int size;
|
||||||
uint8* t;
|
Uint8* t;
|
||||||
|
|
||||||
/* Allocate memory for just enough bits to hold all the data we need. */
|
/* 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);
|
size = s->w*s->h/8 + ((s->w*s->h%8)?1:0);
|
||||||
|
@ -27,12 +27,30 @@
|
|||||||
/* Extern. */
|
/* Extern. */
|
||||||
extern const char* keybindNames[]; /* From input.c */
|
extern const char* keybindNames[]; /* From input.c */
|
||||||
|
|
||||||
|
static int opt_isalpha(SDLKey k);
|
||||||
static const char* modToText(SDLMod mod);
|
static const char* modToText(SDLMod mod);
|
||||||
static void menuKeybinds_update(unsigned int wid, char* name);
|
static void menuKeybinds_update(unsigned int wid, char* name);
|
||||||
|
|
||||||
static void opt_setSFXLevel(unsigned int wid, char* str);
|
static void opt_setSFXLevel(unsigned int wid, char* str);
|
||||||
static void opt_setMusicLevel(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.
|
* @brief Opens the keybindings menu.
|
||||||
*/
|
*/
|
||||||
@ -66,7 +84,7 @@ void opt_menuKeybinds(void) {
|
|||||||
switch(type) {
|
switch(type) {
|
||||||
case KEYBIND_KEYBOARD:
|
case KEYBIND_KEYBOARD:
|
||||||
/* SDL_GetKeyName returns lowercase which is ugly. */
|
/* SDL_GetKeyName returns lowercase which is ugly. */
|
||||||
if(isalpha(key))
|
if(opt_isalpha(key))
|
||||||
snprintf(str[j], 64, "%s <%c>", keybindNames[j], toupper(key));
|
snprintf(str[j], 64, "%s <%c>", keybindNames[j], toupper(key));
|
||||||
else
|
else
|
||||||
snprintf(str[j], 64, "%s <%s>", keybindNames[j], SDL_GetKeyName(key));
|
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;
|
break;
|
||||||
case KEYBIND_KEYBOARD:
|
case KEYBIND_KEYBOARD:
|
||||||
/* SDL_GetKeyName returns lowercase which is ugly. */
|
/* SDL_GetKeyName returns lowercase which is ugly. */
|
||||||
if(isalpha(key))
|
if(opt_isalpha(key))
|
||||||
snprintf(bind, 32, "keyboard: %s%s%c",
|
snprintf(bind, 32, "keyboard: %s%s%c",
|
||||||
(mod != KMOD_NONE) ? modToText(mod) : "",
|
(mod != KMOD_NONE) ? modToText(mod) : "",
|
||||||
(mod != KMOD_NONE) ? " + " : "",
|
(mod != KMOD_NONE) ? " + " : "",
|
||||||
|
@ -198,6 +198,8 @@ static void toolkit_clip(double x, double y, double w, double h);
|
|||||||
static void toolkit_unclip(void);
|
static void toolkit_unclip(void);
|
||||||
static void toolkit_drawRect(double x, double y, double w, double h,
|
static void toolkit_drawRect(double x, double y, double w, double h,
|
||||||
glColour* c, glColour* lc);
|
glColour* c, glColour* lc);
|
||||||
|
/* Misc. */
|
||||||
|
static int toolkit_isalnum(SDLKey k);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the internal widget position.
|
* @brief Set the internal widget position.
|
||||||
@ -2198,6 +2200,27 @@ static void toolkit_clearKey(void) {
|
|||||||
input_keyCounter = 0;
|
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.
|
* @brief Handles keyboard events.
|
||||||
* @param event Keyboard event to handle.
|
* @param event Keyboard event to handle.
|
||||||
@ -2217,7 +2240,7 @@ static int toolkit_keyEvent(SDL_Event* event) {
|
|||||||
key = event->key.keysym.sym;
|
key = event->key.keysym.sym;
|
||||||
|
|
||||||
/* Hack to simulate key repetition. */
|
/* 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);
|
if(event->type == SDL_KEYDOWN) toolkit_regKey(key);
|
||||||
else if(event->type == SDL_KEYUP) toolkit_unregKey(key);
|
else if(event->type == SDL_KEYUP) toolkit_unregKey(key);
|
||||||
}
|
}
|
||||||
@ -2290,7 +2313,7 @@ void toolkit_update(void) {
|
|||||||
wdw = &windows[nwindows-1];
|
wdw = &windows[nwindows-1];
|
||||||
wgt = (wdw->focus >= 0) ? &wdw->widgets[wdw->focus] : NULL;
|
wgt = (wdw->focus >= 0) ? &wdw->widgets[wdw->focus] : NULL;
|
||||||
if(wgt && (wgt->type == WIDGET_INPUT) &&
|
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);
|
toolkit_inputInput(SDL_KEYDOWN, wgt, input_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user