static int EventCallback(SDL_Event *event, TXT_UNCAST_ARG(joystick_axis)) { TXT_CAST_ARG(txt_joystick_axis_t, joystick_axis); boolean advance; if (event->type != SDL_JOYBUTTONDOWN) { return 0; } // At this point, we have a button press. // In the first "center" stage, we're just trying to work out which // joystick is being configured and which button the user is pressing. if (joystick_axis->config_stage == CONFIG_CENTER) { joystick_axis->config_button = event->jbutton.button; IdentifyBadAxes(joystick_axis); // Advance to next stage. joystick_axis->config_stage = CONFIG_STAGE1; SetCalibrationLabel(joystick_axis); return 1; } // In subsequent stages, the user is asked to push in a specific // direction and press the button. They must push the same button // as they did before; this is necessary to support button axes. if (event->jbutton.which == SDL_JoystickInstanceID(joystick_axis->joystick) && event->jbutton.button == joystick_axis->config_button) { switch (joystick_axis->config_stage) { default: case CONFIG_STAGE1: advance = CalibrateAxis(joystick_axis); break; case CONFIG_STAGE2: advance = SetButtonAxisPositive(joystick_axis); break; } // Advance to the next calibration stage? if (advance) { joystick_axis->config_stage = NextCalibrateStage(joystick_axis); SetCalibrationLabel(joystick_axis); // Finished? if (joystick_axis->config_stage == CONFIG_CENTER) { TXT_CloseWindow(joystick_axis->config_window); if (joystick_axis->callback != NULL) { joystick_axis->callback(); } } return 1; } } return 0; }
static int CalibrationEventCallback(SDL_Event *event, void *user_data) { boolean advance; if (event->type != SDL_JOYBUTTONDOWN) { return 0; } // At this point, we have a button press. // In the first "center" stage, we're just trying to work out which // joystick is being configured and which button the user is pressing. if (calibrate_stage == CALIBRATE_CENTER) { joystick_index = event->jbutton.which; calibrate_button = event->jbutton.button; IdentifyBadAxes(); // If the joystick is a known one, auto-load default // config for it. if (IsKnownJoystick(joystick_index)) { LoadKnownConfiguration(); usejoystick = 1; TXT_CloseWindow(calibration_window); } else { // Advance to next stage. calibrate_stage = CALIBRATE_LEFT; SetCalibrationLabel(); } return 1; } // In subsequent stages, the user is asked to push in a specific // direction and press the button. They must push the same button // as they did before; this is necessary to support button axes. if (event->jbutton.which == joystick_index && event->jbutton.button == calibrate_button) { switch (calibrate_stage) { default: case CALIBRATE_LEFT: advance = CalibrateAxis(&joystick_x_axis, &joystick_x_invert); break; case CALIBRATE_RIGHT: advance = SetButtonAxisPositive(&joystick_x_axis); break; case CALIBRATE_UP: advance = CalibrateAxis(&joystick_y_axis, &joystick_y_invert); break; case CALIBRATE_DOWN: advance = SetButtonAxisPositive(&joystick_y_axis); break; } // Advance to the next calibration stage? if (advance) { calibrate_stage = NextCalibrateStage(); SetCalibrationLabel(); // Finished? if (calibrate_stage == CALIBRATE_CENTER) { usejoystick = 1; TXT_CloseWindow(calibration_window); } return 1; } } return 0; }