|
|
|
@ -23,7 +23,8 @@ void add_key_listener(SDL_Scancode negative, SDL_Scancode positive,
|
|
|
|
|
g_key_listeners_endptr->axis.delegate = delegate;
|
|
|
|
|
g_key_listeners_endptr->axis.positive = positive;
|
|
|
|
|
g_key_listeners_endptr->axis.negative = negative;
|
|
|
|
|
g_key_listeners_endptr->axis.last = 0;
|
|
|
|
|
g_key_listeners_endptr->axis.last_positive =
|
|
|
|
|
g_key_listeners_endptr->axis.last_negative = 0;
|
|
|
|
|
++g_key_listeners_endptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -101,13 +102,14 @@ static inline
|
|
|
|
|
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) {
|
|
|
|
|
if(listener->axis.positive == event.key.keysym.scancode
|
|
|
|
|
|| listener->axis.negative == event.key.keysym.scancode) {
|
|
|
|
|
const SDL_Scancode scode = event.key.keysym.scancode;
|
|
|
|
|
const int value = (event.type == SDL_KEYDOWN ? 1 : -1) * (scode == listener->axis.negative ? -1 : 1);
|
|
|
|
|
listener->axis.last += value;
|
|
|
|
|
listener->axis.delegate(listener->axis.last);
|
|
|
|
|
const SDL_Scancode scode = event.key.keysym.scancode;
|
|
|
|
|
if(listener->axis.positive == scode) {
|
|
|
|
|
listener->axis.last_positive = event.key.state == SDL_PRESSED;
|
|
|
|
|
}
|
|
|
|
|
if(listener->axis.negative == scode) {
|
|
|
|
|
listener->axis.last_negative = event.key.state == SDL_PRESSED;
|
|
|
|
|
}
|
|
|
|
|
listener->axis.delegate(listener->axis.last_positive - listener->axis.last_negative);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|