int SDL_PrivateJoystickBall(SDL_Joystick * joystick, Uint8 ball, Sint16 xrel, Sint16 yrel) { int posted; /* Make sure we're not getting garbage events */ if (ball >= joystick->nballs) { return 0; } /* We ignore events if we don't have keyboard focus. */ if (SDL_PrivateJoystickShouldIgnoreEvent()) { return 0; } /* Update internal mouse state */ joystick->balls[ball].dx += xrel; joystick->balls[ball].dy += yrel; /* Post the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED if (SDL_GetEventState(SDL_JOYBALLMOTION) == SDL_ENABLE) { SDL_Event event; event.jball.type = SDL_JOYBALLMOTION; event.jball.which = joystick->instance_id; event.jball.ball = ball; event.jball.xrel = xrel; event.jball.yrel = yrel; posted = SDL_PushEvent(&event) == 1; } #endif /* !SDL_EVENTS_DISABLED */ return (posted); }
int SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value) { int posted; /* Make sure we're not getting garbage or duplicate events */ if (axis >= joystick->naxes) { return 0; } if (!joystick->axes[axis].has_initial_value) { joystick->axes[axis].initial_value = value; joystick->axes[axis].value = value; joystick->axes[axis].zero = value; joystick->axes[axis].has_initial_value = SDL_TRUE; } if (value == joystick->axes[axis].value) { return 0; } if (!joystick->axes[axis].sent_initial_value) { /* Make sure we don't send motion until there's real activity on this axis */ const int MAX_ALLOWED_JITTER = SDL_JOYSTICK_AXIS_MAX / 80; /* ShanWan PS3 controller needed 96 */ if (SDL_abs(value - joystick->axes[axis].value) <= MAX_ALLOWED_JITTER) { return 0; } joystick->axes[axis].sent_initial_value = SDL_TRUE; joystick->axes[axis].value = value; /* Just so we pass the check above */ SDL_PrivateJoystickAxis(joystick, axis, joystick->axes[axis].initial_value); } /* We ignore events if we don't have keyboard focus, except for centering * events. */ if (SDL_PrivateJoystickShouldIgnoreEvent()) { if ((value > joystick->axes[axis].zero && value >= joystick->axes[axis].value) || (value < joystick->axes[axis].zero && value <= joystick->axes[axis].value)) { return 0; } } /* Update internal joystick state */ joystick->axes[axis].value = value; /* Post the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED if (SDL_GetEventState(SDL_JOYAXISMOTION) == SDL_ENABLE) { SDL_Event event; event.type = SDL_JOYAXISMOTION; event.jaxis.which = joystick->instance_id; event.jaxis.axis = axis; event.jaxis.value = value; posted = SDL_PushEvent(&event) == 1; } #endif /* !SDL_EVENTS_DISABLED */ return (posted); }
int SDL_PrivateJoystickButton(SDL_Joystick * joystick, Uint8 button, Uint8 state) { int posted; #if !SDL_EVENTS_DISABLED SDL_Event event; switch (state) { case SDL_PRESSED: event.type = SDL_JOYBUTTONDOWN; break; case SDL_RELEASED: event.type = SDL_JOYBUTTONUP; break; default: /* Invalid state -- bail */ return (0); } #endif /* !SDL_EVENTS_DISABLED */ /* Make sure we're not getting garbage or duplicate events */ if (button >= joystick->nbuttons) { return 0; } if (state == joystick->buttons[button]) { return 0; } /* We ignore events if we don't have keyboard focus, except for button * release. */ if (SDL_PrivateJoystickShouldIgnoreEvent()) { if (state == SDL_PRESSED) { return 0; } } /* Update internal joystick state */ joystick->buttons[button] = state; /* Post the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED if (SDL_GetEventState(event.type) == SDL_ENABLE) { event.jbutton.which = joystick->instance_id; event.jbutton.button = button; event.jbutton.state = state; posted = SDL_PushEvent(&event) == 1; } #endif /* !SDL_EVENTS_DISABLED */ return (posted); }
int SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value) { int posted; /* Make sure we're not getting garbage or duplicate events */ if (axis >= joystick->naxes) { return 0; } if (value == joystick->axes[axis]) { return 0; } /* We ignore events if we don't have keyboard focus, except for centering * events. */ if (SDL_PrivateJoystickShouldIgnoreEvent()) { if ((value > joystick->axes_zero[axis] && value >= joystick->axes[axis]) || (value < joystick->axes_zero[axis] && value <= joystick->axes[axis])) { return 0; } } /* Update internal joystick state */ joystick->axes[axis] = value; /* Post the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED if (SDL_GetEventState(SDL_JOYAXISMOTION) == SDL_ENABLE) { SDL_Event event; event.type = SDL_JOYAXISMOTION; event.jaxis.which = joystick->instance_id; event.jaxis.axis = axis; event.jaxis.value = value; posted = SDL_PushEvent(&event) == 1; } #endif /* !SDL_EVENTS_DISABLED */ return (posted); }
int SDL_PrivateJoystickHat(SDL_Joystick * joystick, Uint8 hat, Uint8 value) { int posted; /* Make sure we're not getting garbage or duplicate events */ if (hat >= joystick->nhats) { return 0; } if (value == joystick->hats[hat]) { return 0; } /* We ignore events if we don't have keyboard focus, except for centering * events. */ if (SDL_PrivateJoystickShouldIgnoreEvent()) { if (value != SDL_HAT_CENTERED) { return 0; } } /* Update internal joystick state */ joystick->hats[hat] = value; /* Post the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED if (SDL_GetEventState(SDL_JOYHATMOTION) == SDL_ENABLE) { SDL_Event event; event.jhat.type = SDL_JOYHATMOTION; event.jhat.which = joystick->instance_id; event.jhat.hat = hat; event.jhat.value = value; posted = SDL_PushEvent(&event) == 1; } #endif /* !SDL_EVENTS_DISABLED */ return (posted); }