Starter project for SDL2.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
967 B

  1. #ifndef IZ_JOYSTICK_H
  2. #define IZ_JOYSTICK_H
  3. #include <SDL_joystick.h>
  4. #include <SDL_events.h>
  5. #include <minIni.h>
  6. #include "../IZ_action.h"
  7. #include "../IZ_config.h"
  8. typedef uint8_t IZ_PadButton;
  9. typedef enum {
  10. IZ_JOYAXIS_DIRECTION_HORIZONTAL1 = 0,
  11. IZ_JOYAXIS_DIRECTION_VERTICAL1 = 1,
  12. IZ_JOYAXIS_DIRECTION_HORIZONTAL2 = 3,
  13. IZ_JOYAXIS_DIRECTION_VERTICAL2 = 4,
  14. } IZ_JoyAxisDirection;
  15. typedef struct {
  16. uint16_t axis_threshold;
  17. IZ_PadButton control_mapping[CONTROLS];
  18. } IZ_JoystickConfig;
  19. typedef struct {
  20. SDL_Joystick* joystick_instance;
  21. IZ_JoystickConfig config;
  22. } IZ_JoystickState;
  23. static IZ_PadButton IZ_DEFAULT_JOYSTICK_CONTROLS[PLAYERS][CONTROLS] = {
  24. {
  25. 255,
  26. 255,
  27. 255,
  28. 255,
  29. 11,
  30. 10,
  31. 1,
  32. 0,
  33. 4,
  34. 3,
  35. 6,
  36. 7,
  37. 8,
  38. 9,
  39. 13,
  40. 14,
  41. },
  42. };
  43. void IZ_LoadJoystickConfig(IZ_JoystickConfig*, uint8_t);
  44. void IZ_SaveJoystickConfig(IZ_JoystickConfig*, uint8_t);
  45. void IZ_HandleJoystickEvents(SDL_Event, IZ_JoystickState*, IZ_Action*);
  46. #endif