| 1 | /* |
| 2 | * OpenTyrian: A modern cross-platform port of Tyrian |
| 3 | * Copyright (C) 2007-2009 The OpenTyrian Development Team |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | #ifndef JOYSTICK_H |
| 20 | #define JOYSTICK_H |
| 21 | |
| 22 | #include "opentyr.h" |
| 23 | #include "config_file.h" |
| 24 | |
| 25 | #include "SDL.h" |
| 26 | |
| 27 | typedef enum |
| 28 | { |
| 29 | NONE, |
| 30 | AXIS, |
| 31 | BUTTON, |
| 32 | HAT |
| 33 | } |
| 34 | Joystick_assignment_types; |
| 35 | |
| 36 | typedef struct |
| 37 | { |
| 38 | Joystick_assignment_types type; |
| 39 | int num; |
| 40 | |
| 41 | // if hat |
| 42 | bool x_axis; // else y_axis |
| 43 | |
| 44 | // if hat or axis |
| 45 | bool negative_axis; // else positive |
| 46 | } |
| 47 | Joystick_assignment; |
| 48 | |
| 49 | typedef struct |
| 50 | { |
| 51 | SDL_Joystick *handle; |
| 52 | |
| 53 | Joystick_assignment assignment[10][2]; // 0-3: directions, 4-9: actions |
| 54 | |
| 55 | bool analog; |
| 56 | int sensitivity, threshold; |
| 57 | |
| 58 | signed int x, y; |
| 59 | int analog_direction[4]; |
| 60 | bool direction[4], direction_pressed[4]; // up, right, down, left (_pressed, for emulating key presses) |
| 61 | |
| 62 | bool confirm, cancel; |
| 63 | bool action[6], action_pressed[6]; // fire, mode swap, left fire, right fire, menu, pause |
| 64 | |
| 65 | Uint32 joystick_delay; |
| 66 | bool input_pressed; |
| 67 | } |
| 68 | Joystick; |
| 69 | |
| 70 | extern int joystick_repeat_delay; |
| 71 | extern bool joydown; |
| 72 | extern bool ignore_joystick; |
| 73 | extern int joysticks; |
| 74 | extern Joystick *joystick; |
| 75 | |
| 76 | int joystick_axis_reduce(int j, int value); |
| 77 | bool joystick_analog_angle(int j, float *angle); |
| 78 | |
| 79 | void poll_joystick(int j); |
| 80 | void poll_joysticks(void); |
| 81 | |
| 82 | void push_key(SDL_Scancode key); |
| 83 | void push_joysticks_as_keyboard(void); |
| 84 | |
| 85 | void init_joysticks(void); |
| 86 | void deinit_joysticks(void); |
| 87 | |
| 88 | void reset_joystick_assignments(int j); |
| 89 | bool load_joystick_assignments(Config* config, int j); |
| 90 | bool save_joystick_assignments(Config* config, int j); |
| 91 | |
| 92 | void joystick_assignments_to_string(char *buffer, size_t buffer_len, const Joystick_assignment *assignments); |
| 93 | |
| 94 | bool detect_joystick_assignment(int j, Joystick_assignment *assignment); |
| 95 | bool joystick_assignment_cmp(const Joystick_assignment *, const Joystick_assignment *); |
| 96 | |
| 97 | #endif /* JOYSTICK_H */ |