[Add] More error checking paranoia.
This commit is contained in:
parent
5e68d64085
commit
8c7a38686c
@ -192,7 +192,7 @@ int main(int argc, char** argv) {
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
fps_control(); // Who doesn't love FPS control?
|
||||
toolkit_update(); // Simulate key repetition.
|
||||
if(toolkit) toolkit_update(); // Simulate key repetition.
|
||||
|
||||
if(!menu_isOpen(MENU_MAIN)) {
|
||||
if(!paused && !toolkit) update_space(); // Update the game.
|
||||
|
@ -300,12 +300,12 @@ void window_addInput(const unsigned int wid,
|
||||
wgt->name = strdup(name);
|
||||
|
||||
// Specific.
|
||||
wgt->dat.inp.max = max;
|
||||
wgt->dat.inp.max = max+1;
|
||||
wgt->dat.inp.oneline = oneline;
|
||||
wgt->dat.inp.pos = 0;
|
||||
wgt->dat.inp.view = 0;
|
||||
wgt->dat.inp.input = malloc(sizeof(char)*max);
|
||||
memset(wgt->dat.inp.input, 0, max*sizeof(char));
|
||||
wgt->dat.inp.input = malloc(sizeof(char)*wgt->dat.inp.max);
|
||||
memset(wgt->dat.inp.input, 0, wgt->dat.inp.max*sizeof(char));
|
||||
|
||||
// Position/Size.
|
||||
wgt->w = (double)w;
|
||||
@ -942,7 +942,7 @@ static int toolkit_inputInput(Uint8 type, Widget* inp, SDLKey key) {
|
||||
// Backspace -> delete text.
|
||||
if((type == SDL_KEYDOWN) && (key == '\b') && (inp->dat.inp.pos > 0))
|
||||
inp->dat.inp.input[--inp->dat.inp.pos] = '\0';
|
||||
else if((type == SDL_KEYDOWN) && (inp->dat.inp.pos < inp->dat.inp.max)) {
|
||||
else if((type == SDL_KEYDOWN) && (inp->dat.inp.pos < inp->dat.inp.max-1)) {
|
||||
if((key == SDLK_RETURN) && !inp->dat.inp.oneline)
|
||||
inp->dat.inp.input[inp->dat.inp.pos++] = '\n';
|
||||
|
||||
@ -956,9 +956,10 @@ static int toolkit_inputInput(Uint8 type, Widget* inp, SDLKey key) {
|
||||
|
||||
// Didn't get a useful key.
|
||||
else return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1100,8 +1101,10 @@ static int toolkit_keyEvent(SDL_Event* event) {
|
||||
Widget* wgt;
|
||||
SDLKey key;
|
||||
|
||||
if(nwindows <= 0) return 0;
|
||||
|
||||
wdw = &windows[nwindows-1];
|
||||
wgt = (wdw->focus >= 0) ? &wdw->widgets[wdw->focus] : NULL;
|
||||
wgt = (wdw->focus != -1) ? &wdw->widgets[wdw->focus] : NULL;
|
||||
key = event->key.keysym.sym;
|
||||
|
||||
// Hack to simulate key repetition.
|
||||
@ -1150,9 +1153,6 @@ void toolkit_update(void) {
|
||||
Window* wdw;
|
||||
Widget* wgt;
|
||||
|
||||
wdw = &windows[nwindows-1];
|
||||
wgt = (wdw->focus >= 0) ? &wdw->widgets[wdw->focus] : NULL;
|
||||
|
||||
t = SDL_GetTicks();
|
||||
|
||||
if(input_key == 0) return;
|
||||
@ -1162,9 +1162,13 @@ void toolkit_update(void) {
|
||||
|
||||
input_keyCounter++;
|
||||
|
||||
if(nwindows > 0) {
|
||||
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)))
|
||||
toolkit_inputInput(SDL_KEYDOWN, wgt, input_key);
|
||||
}
|
||||
|
||||
switch(input_key) {
|
||||
case SDLK_UP:
|
||||
|
Loading…
Reference in New Issue
Block a user