4
4
#include <SDL.h>
5
5
#include <stdio.h>
6
6
7
- #include "SDL_log.h"
8
- #include "SDL_timer.h"
9
7
#include "config.h"
10
8
#include "input.h"
11
9
#include "render.h"
@@ -272,36 +270,36 @@ static int get_game_controller_button(config_params_s *conf, SDL_GameController
272
270
// Check digital buttons
273
271
if (SDL_GameControllerGetButton (controller , button_mappings [button ])) {
274
272
return 1 ;
275
- } else {
276
- // If digital button isn't pressed, check the corresponding analog control
277
- switch ( button ) {
278
- case INPUT_UP :
279
- return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_updown ) <
280
- - conf -> gamepad_analog_threshold ;
281
- case INPUT_DOWN :
282
- return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_updown ) >
283
- conf -> gamepad_analog_threshold ;
284
- case INPUT_LEFT :
285
- return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_leftright ) <
286
- - conf -> gamepad_analog_threshold ;
287
- case INPUT_RIGHT :
288
- return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_leftright ) >
289
- conf -> gamepad_analog_threshold ;
290
- case INPUT_OPT :
291
- return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_opt ) >
292
- conf -> gamepad_analog_threshold ;
293
- case INPUT_EDIT :
294
- return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_edit ) >
295
- conf -> gamepad_analog_threshold ;
296
- case INPUT_SELECT :
297
- return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_select ) >
298
- conf -> gamepad_analog_threshold ;
299
- case INPUT_START :
300
- return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_start ) >
301
- conf -> gamepad_analog_threshold ;
302
- default :
303
- return 0 ;
304
- }
273
+ }
274
+
275
+ // If digital button isn't pressed, check the corresponding analog control
276
+ switch ( button ) {
277
+ case INPUT_UP :
278
+ return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_updown ) <
279
+ - conf -> gamepad_analog_threshold ;
280
+ case INPUT_DOWN :
281
+ return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_updown ) >
282
+ conf -> gamepad_analog_threshold ;
283
+ case INPUT_LEFT :
284
+ return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_leftright ) <
285
+ - conf -> gamepad_analog_threshold ;
286
+ case INPUT_RIGHT :
287
+ return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_leftright ) >
288
+ conf -> gamepad_analog_threshold ;
289
+ case INPUT_OPT :
290
+ return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_opt ) >
291
+ conf -> gamepad_analog_threshold ;
292
+ case INPUT_EDIT :
293
+ return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_edit ) >
294
+ conf -> gamepad_analog_threshold ;
295
+ case INPUT_SELECT :
296
+ return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_select ) >
297
+ conf -> gamepad_analog_threshold ;
298
+ case INPUT_START :
299
+ return SDL_GameControllerGetAxis ( controller , conf -> gamepad_analog_axis_start ) >
300
+ conf -> gamepad_analog_threshold ;
301
+ default :
302
+ return 0 ;
305
303
}
306
304
return 0 ;
307
305
}
@@ -318,7 +316,7 @@ static int handle_game_controller_buttons(config_params_s *conf) {
318
316
// Cycle through every active game controller
319
317
for (int gc = 0 ; gc < num_joysticks ; gc ++ ) {
320
318
// Cycle through all M8 buttons
321
- for (int button = 0 ; button < ( input_buttons_t ) INPUT_MAX ; button ++ ) {
319
+ for (int button = 0 ; button < INPUT_MAX ; button ++ ) {
322
320
// If the button is active, add the keycode to the variable containing
323
321
// active keys
324
322
if (get_game_controller_button (conf , game_controllers [gc ], button )) {
@@ -356,87 +354,88 @@ void handle_sdl_events(config_params_s *conf) {
356
354
key = (input_msg_s ){special , msg_reset_display };
357
355
}
358
356
359
- SDL_PollEvent (& event );
357
+ while ( SDL_PollEvent (& event )) {
360
358
361
- switch (event .type ) {
359
+ switch (event .type ) {
362
360
363
- // Reinitialize game controllers on controller add/remove/remap
364
- case SDL_CONTROLLERDEVICEADDED :
365
- case SDL_CONTROLLERDEVICEREMOVED :
366
- initialize_game_controllers ();
367
- break ;
361
+ // Reinitialize game controllers on controller add/remove/remap
362
+ case SDL_CONTROLLERDEVICEADDED :
363
+ case SDL_CONTROLLERDEVICEREMOVED :
364
+ initialize_game_controllers ();
365
+ break ;
368
366
369
- // Handle SDL quit events (for example, window close)
370
- case SDL_QUIT :
371
- key = (input_msg_s ){special , msg_quit };
372
- break ;
367
+ // Handle SDL quit events (for example, window close)
368
+ case SDL_QUIT :
369
+ key = (input_msg_s ){special , msg_quit };
370
+ break ;
373
371
374
- case SDL_WINDOWEVENT :
375
- if (event .window .event == SDL_WINDOWEVENT_RESIZED ) {
376
- static uint32_t ticks_window_resized = 0 ;
377
- if (SDL_GetTicks () - ticks_window_resized > 500 ) {
378
- SDL_Log ("Resizing window..." );
379
- key = (input_msg_s ){special , msg_reset_display };
380
- ticks_window_resized = SDL_GetTicks ();
372
+ case SDL_WINDOWEVENT :
373
+ if (event .window .event == SDL_WINDOWEVENT_RESIZED ) {
374
+ static uint32_t ticks_window_resized = 0 ;
375
+ if (SDL_GetTicks () - ticks_window_resized > 500 ) {
376
+ SDL_Log ("Resizing window..." );
377
+ key = (input_msg_s ){special , msg_reset_display };
378
+ ticks_window_resized = SDL_GetTicks ();
379
+ }
381
380
}
382
- }
383
- break ;
384
-
385
- // Keyboard events. Special events are handled within SDL_KEYDOWN.
386
- case SDL_KEYDOWN :
387
-
388
- if (event .key .repeat > 0 ) {
389
381
break ;
390
- }
391
382
392
- // ALT+ENTER toggles fullscreen
393
- if (event .key .keysym .sym == SDLK_RETURN && (event .key .keysym .mod & KMOD_ALT ) > 0 ) {
394
- toggle_fullscreen ();
395
- break ;
396
- }
383
+ // Keyboard events. Special events are handled within SDL_KEYDOWN.
384
+ case SDL_KEYDOWN :
397
385
398
- // ALT+F4 quits program
399
- else if (event .key .keysym .sym == SDLK_F4 && (event .key .keysym .mod & KMOD_ALT ) > 0 ) {
400
- key = (input_msg_s ){special , msg_quit };
401
- break ;
402
- }
386
+ if (event .key .repeat > 0 ) {
387
+ break ;
388
+ }
403
389
404
- // ESC = toggle keyjazz
405
- else if (event .key .keysym .sym == SDLK_ESCAPE ) {
406
- display_keyjazz_overlay (toggle_input_keyjazz (), keyjazz_base_octave , keyjazz_velocity );
407
- }
390
+ // ALT+ENTER toggles fullscreen
391
+ if (event .key .keysym .sym == SDLK_RETURN && (event .key .keysym .mod & KMOD_ALT ) > 0 ) {
392
+ toggle_fullscreen ();
393
+ break ;
394
+ }
408
395
409
- // Normal keyboard inputs
410
- case SDL_KEYUP :
411
- key = handle_normal_keys (& event , conf , 0 );
396
+ // ALT+F4 quits program
397
+ else if (event .key .keysym .sym == SDLK_F4 && (event .key .keysym .mod & KMOD_ALT ) > 0 ) {
398
+ key = (input_msg_s ){special , msg_quit };
399
+ break ;
400
+ }
412
401
413
- if (keyjazz_enabled )
414
- key = handle_keyjazz (& event , key .value , conf );
415
- break ;
402
+ // ESC = toggle keyjazz
403
+ else if (event .key .keysym .sym == SDLK_ESCAPE ) {
404
+ display_keyjazz_overlay (toggle_input_keyjazz (), keyjazz_base_octave , keyjazz_velocity );
405
+ }
416
406
417
- default :
418
- break ;
419
- }
407
+ // Normal keyboard inputs
408
+ case SDL_KEYUP :
409
+ key = handle_normal_keys ( & event , conf , 0 );
420
410
421
- switch ( key . type ) {
422
- case normal :
423
- if ( event . type == SDL_KEYDOWN ) {
424
- keycode |= key . value ;
425
- } else {
426
- keycode &= ~ key . value ;
411
+ if ( keyjazz_enabled )
412
+ key = handle_keyjazz ( & event , key . value , conf );
413
+ break ;
414
+
415
+ default :
416
+ break ;
427
417
}
428
- break ;
429
- case keyjazz :
430
- // Do not allow pressing multiple keys with keyjazz
431
- case special :
432
- if (event .type == SDL_KEYDOWN ) {
433
- keycode = key .value ;
434
- } else {
435
- keycode = 0 ;
418
+
419
+ switch (key .type ) {
420
+ case normal :
421
+ if (event .type == SDL_KEYDOWN ) {
422
+ keycode |= key .value ;
423
+ } else {
424
+ keycode &= ~key .value ;
425
+ }
426
+ break ;
427
+ case keyjazz :
428
+ // Do not allow pressing multiple keys with keyjazz
429
+ case special :
430
+ if (event .type == SDL_KEYDOWN ) {
431
+ keycode = key .value ;
432
+ } else {
433
+ keycode = 0 ;
434
+ }
435
+ break ;
436
+ default :
437
+ break ;
436
438
}
437
- break ;
438
- default :
439
- break ;
440
439
}
441
440
}
442
441
0 commit comments