Debian Codegraph @

src/input.h

raw
1 /**
2 * Keyboard and joystick
3
4 * Copyright (C) 1997, 1998, 1999, 2002, 2003 Seth A. Robinson
5 * Copyright (C) 2005, 2007, 2008, 2009, 2010, 2014, 2015 Sylvain Beucler
6
7 * This file is part of GNU FreeDink
8
9 * GNU FreeDink is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 3 of the
12 * License, or (at your option) any later version.
13
14 * GNU FreeDink is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see
21 * <http://www.gnu.org/licenses/>.
22 */
23
24 #ifndef _INPUT_H
25 #define _INPUT_H
26
27 #include "SDL.h"
28
29 #define NB_BUTTONS 12
30
31 /* Actions that can be dynamically mapped on joystick buttons (and
32 statically mapped to keyboard keys). The indices are important:
33 they are used in the savegame format and in DinkC's
34 wait_for_button() - note that indices 12/14/16/18 are reserved
35 for down/left/right/up in that function. */
36 enum buttons_actions {
37 ACTION_FIRST = 0, // min constant for loops, like SDLKey
38 ACTION_NOOP = 0,
39 ACTION_ATTACK = 1,
40 ACTION_TALK,
41 ACTION_MAGIC,
42 ACTION_INVENTORY,
43 ACTION_MENU,
44 ACTION_MAP,
45 // These execute the 'buttonX.c' DinkC script:
46 ACTION_BUTTON7,
47 ACTION_BUTTON8,
48 ACTION_BUTTON9,
49 ACTION_BUTTON10,
50 // To map buttons to arrow keys
51 // Using the same keys than in wait_for_button()
52 ACTION_DOWN = 12,
53 ACTION_LEFT = 14,
54 ACTION_RIGHT = 16,
55 ACTION_UP = 18,
56 // max+1 constant for loops
57 ACTION_LAST
58 };
59
60 struct seth_joy
61 {
62 int joybit[ACTION_LAST]; // is this action currently pressed?
63 int button[ACTION_LAST]; // was this action just pressed (not maintained pressed)?
64 int joybitold[ACTION_LAST]; // copy of previous joybit state
65 // (used to compute .button and to release an arrow with the bow)
66 // Note: also used by Dinkedit, but with fewer different actions
67
68 int right,left,up,down; // is this arrow currently pressed?
69 int rightd,leftd,upd,downd; // was this arrow just pressed (not maintained pressed)?
70 int rightold,leftold,upold,downold; // copy of previous state (used to compute *d)
71 };
72 extern struct seth_joy sjoy;
73 extern /*bool*/int mouse1;
74
75 /* Joystick */
76 extern /*BOOL*/int joystick;
77 extern SDL_Joystick* jinfo;
78
79 extern void input_update(SDL_Event *ev);
80 extern void input_init();
81 extern void input_quit();
82 extern void input_set_default_buttons();
83 extern int input_get_button_action(int button_index);
84 extern void input_set_button_action(int button_index, int action_index);
85
86 extern void input_reset();
87
88 extern Uint8 input_getscancodestate(SDL_Scancode scancode);
89 extern /*bool*/int input_getscancodejustpressed(SDL_Scancode scancode);
90 extern Uint8 input_getcharstate(SDL_Keycode ch);
91 extern /*bool*/int input_getcharjustpressed(SDL_Keycode ch);
92
93 #endif