input.c: Pass Joystick events by pointer

This commit is contained in:
Thomas Bernard 2019-02-22 12:00:01 +01:00
parent 81932d5407
commit b44225833b
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -956,14 +956,14 @@ static int Handle_key_release(SDL_KeyboardEvent * event)
// Joystick management // Joystick management
#if defined(USE_JOYSTICK) && (defined(USE_SDL) || defined(USE_SDL2)) #if defined(USE_JOYSTICK) && (defined(USE_SDL) || defined(USE_SDL2))
static int Handle_joystick_press(SDL_JoyButtonEvent event) static int Handle_joystick_press(SDL_JoyButtonEvent * event)
{ {
if (event.button == Joybutton_shift) if (event->button == Joybutton_shift)
{ {
SDL_SetModState(SDL_GetModState() | KMOD_SHIFT); SDL_SetModState(SDL_GetModState() | KMOD_SHIFT);
return 0; return 0;
} }
if (event.button == Joybutton_control) if (event->button == Joybutton_control)
{ {
SDL_SetModState(SDL_GetModState() | KMOD_CTRL); SDL_SetModState(SDL_GetModState() | KMOD_CTRL);
if (Config.Swap_buttons == GFX2_MOD_CTRL && Button_inverter==0) if (Config.Swap_buttons == GFX2_MOD_CTRL && Button_inverter==0)
@ -977,7 +977,7 @@ static int Handle_joystick_press(SDL_JoyButtonEvent event)
} }
return 0; return 0;
} }
if (event.button == Joybutton_alt) if (event->button == Joybutton_alt)
{ {
#if defined(USE_SDL) #if defined(USE_SDL)
SDL_SetModState(SDL_GetModState() | (KMOD_ALT|KMOD_META)); SDL_SetModState(SDL_GetModState() | (KMOD_ALT|KMOD_META));
@ -995,17 +995,17 @@ static int Handle_joystick_press(SDL_JoyButtonEvent event)
} }
return 0; return 0;
} }
if (event.button == Joybutton_left_click) if (event->button == Joybutton_left_click)
{ {
Input_new_mouse_K = Button_inverter ? 2 : 1; Input_new_mouse_K = Button_inverter ? 2 : 1;
return Handle_mouse_btn_change(); return Handle_mouse_btn_change();
} }
if (event.button == Joybutton_right_click) if (event->button == Joybutton_right_click)
{ {
Input_new_mouse_K = Button_inverter ? 1 : 2; Input_new_mouse_K = Button_inverter ? 1 : 2;
return Handle_mouse_btn_change(); return Handle_mouse_btn_change();
} }
switch(event.button) switch(event->button)
{ {
#ifdef JOY_BUTTON_UP #ifdef JOY_BUTTON_UP
case JOY_BUTTON_UP: case JOY_BUTTON_UP:
@ -1052,25 +1052,25 @@ static int Handle_joystick_press(SDL_JoyButtonEvent event)
break; break;
} }
Key = (KEY_JOYBUTTON+event.button)|Get_Key_modifiers(); Key = (KEY_JOYBUTTON + event->button) | Get_Key_modifiers();
// TODO: systeme de répétition // TODO: systeme de répétition
return 1; return 1;
} }
static int Handle_joystick_release(SDL_JoyButtonEvent event) static int Handle_joystick_release(SDL_JoyButtonEvent * event)
{ {
if (event.button == Joybutton_shift) if (event->button == Joybutton_shift)
{ {
SDL_SetModState(SDL_GetModState() & ~KMOD_SHIFT); SDL_SetModState(SDL_GetModState() & ~KMOD_SHIFT);
return Release_control(0,GFX2_MOD_SHIFT); return Release_control(0,GFX2_MOD_SHIFT);
} }
if (event.button == Joybutton_control) if (event->button == Joybutton_control)
{ {
SDL_SetModState(SDL_GetModState() & ~KMOD_CTRL); SDL_SetModState(SDL_GetModState() & ~KMOD_CTRL);
return Release_control(0,GFX2_MOD_CTRL); return Release_control(0,GFX2_MOD_CTRL);
} }
if (event.button == Joybutton_alt) if (event->button == Joybutton_alt)
{ {
#if defined(USE_SDL) #if defined(USE_SDL)
SDL_SetModState(SDL_GetModState() & ~(KMOD_ALT|KMOD_META)); SDL_SetModState(SDL_GetModState() & ~(KMOD_ALT|KMOD_META));
@ -1079,18 +1079,18 @@ static int Handle_joystick_release(SDL_JoyButtonEvent event)
#endif #endif
return Release_control(0,GFX2_MOD_ALT); return Release_control(0,GFX2_MOD_ALT);
} }
if (event.button == Joybutton_left_click) if (event->button == Joybutton_left_click)
{ {
Input_new_mouse_K &= ~1; Input_new_mouse_K &= ~1;
return Handle_mouse_btn_change(); return Handle_mouse_btn_change();
} }
if (event.button == Joybutton_right_click) if (event->button == Joybutton_right_click)
{ {
Input_new_mouse_K &= ~2; Input_new_mouse_K &= ~2;
return Handle_mouse_btn_change(); return Handle_mouse_btn_change();
} }
switch(event.button) switch(event->button)
{ {
#ifdef JOY_BUTTON_UP #ifdef JOY_BUTTON_UP
case JOY_BUTTON_UP: case JOY_BUTTON_UP:
@ -1139,26 +1139,22 @@ static int Handle_joystick_release(SDL_JoyButtonEvent event)
return 1; return 1;
} }
static void Handle_joystick_movement(SDL_JoyAxisEvent event) static void Handle_joystick_movement(SDL_JoyAxisEvent * event)
{ {
if (event.axis==JOYSTICK_AXIS_X) if (event->axis == JOYSTICK_AXIS_X)
{
Directional_right=Directional_left=0;
if (event.value<-JOYSTICK_THRESHOLD)
{ {
Directional_right = Directional_left = 0;
if (event->value < -JOYSTICK_THRESHOLD)
Directional_left=1; Directional_left=1;
} else if (event->value > JOYSTICK_THRESHOLD)
else if (event.value>JOYSTICK_THRESHOLD)
Directional_right=1; Directional_right=1;
} }
else if (event.axis==JOYSTICK_AXIS_Y) else if (event->axis == JOYSTICK_AXIS_Y)
{ {
Directional_up=Directional_down=0; Directional_up = Directional_down = 0;
if (event.value<-JOYSTICK_THRESHOLD) if (event->value < -JOYSTICK_THRESHOLD)
{ Directional_up = 1;
Directional_up=1; else if (event->value > JOYSTICK_THRESHOLD)
}
else if (event.value>JOYSTICK_THRESHOLD)
Directional_down=1; Directional_down=1;
} }
} }
@ -1378,17 +1374,17 @@ int Get_input(int sleep_time)
#ifdef USE_JOYSTICK #ifdef USE_JOYSTICK
case SDL_JOYBUTTONUP: case SDL_JOYBUTTONUP:
Handle_joystick_release(event.jbutton); Handle_joystick_release(&event.jbutton);
user_feedback_required = 1; user_feedback_required = 1;
break; break;
case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONDOWN:
Handle_joystick_press(event.jbutton); Handle_joystick_press(&event.jbutton);
user_feedback_required = 1; user_feedback_required = 1;
break; break;
case SDL_JOYAXISMOTION: case SDL_JOYAXISMOTION:
Handle_joystick_movement(event.jaxis); Handle_joystick_movement(&event.jaxis);
break; break;
#endif #endif