static int CalibrationEventCallback(SDL_Event *event, void *user_data) { 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. joystick_index = event->jbutton.which; calibrate_button = event->jbutton.button; // If the joystick is a known one, auto-load default // config for it. Otherwise, proceed with calibration. if (IsKnownJoystick(joystick_index)) { LoadKnownConfiguration(); usejoystick = 1; TXT_CloseWindow(calibration_window); } else { TXT_CloseWindow(calibration_window); // Calibrate joystick axes: Y axis first, then X axis once // completed. TXT_ConfigureJoystickAxis(y_axis_widget, calibrate_button, CalibrateXAxis); } return 1; }
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; }