Merge pull request 'key listeners are now only triggered if their value changed' (#18) from key-repeat-events into development

Reviewed-on: #18
development
Sara 2023-07-16 21:41:21 +00:00
commit b025e81c54
1 changed files with 11 additions and 4 deletions

View File

@ -131,13 +131,20 @@ void _handle_key_event(const SDL_Event event) {
for(input_listener_t* listener = g_key_listeners; listener < g_key_listeners_endptr; ++listener) {
if(listener->type == INPUT_LISTENER_AXIS) {
const SDL_Scancode scode = event.key.keysym.scancode;
int changed = 0;
if(listener->axis.positive == scode) {
listener->axis.last_positive = event.key.state == SDL_PRESSED;
int new = event.key.state == SDL_PRESSED;
changed = new != listener->axis.last_positive;
listener->axis.last_positive = new;
}
if(listener->axis.negative == scode) {
listener->axis.last_negative = event.key.state == SDL_PRESSED;
else if(listener->axis.negative == scode) {
int new = event.key.state == SDL_PRESSED;
changed = new != listener->axis.last_negative;
listener->axis.last_negative = new;
}
listener->axis.delegate(listener->axis.last_positive - listener->axis.last_negative);
if(changed)
listener->axis.delegate(listener->axis.last_positive - listener->axis.last_negative);
}
}
}