1 /** 2 * Keyboard and joystick 3 4 * Copyright (C) 1997, 1998, 1999, 2002, 2003 Seth A. Robinson 5 * Copyright (C) 2005, 2007, 2008 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 #ifdef __cplusplus 28 extern "C" 29 { 30 #endif 31 32 #define NB_BUTTONS 12 33 34 /* Actions that can be dynamically mapped on joystick buttons (and 35 statically mapped to keyboard keys). The indices are important: 36 they are used in the savegame format and in DinkC's 37 wait_for_button() - note that indices 12/14/16/18 are reserved 38 for down/left/right/up in that function. */ 39 enum buttons_actions { 40 ACTION_FIRST = 0, // min constant for loops, like SDLKey 41 ACTION_NOOP = 0, 42 ACTION_ATTACK = 1, 43 ACTION_TALK, 44 ACTION_MAGIC, 45 ACTION_INVENTORY, 46 ACTION_MENU, 47 ACTION_MAP, 48 // These execute the 'buttonX.c' DinkC script: 49 ACTION_BUTTON7, 50 ACTION_BUTTON8, 51 ACTION_BUTTON9, 52 ACTION_BUTTON10, 53 // To map buttons to arrow keys 54 // Using the same keys than in wait_for_button() 55 ACTION_DOWN = 12, 56 ACTION_LEFT = 14, 57 ACTION_RIGHT = 16, 58 ACTION_UP = 18, 59 // max+1 constant for loops 60 ACTION_LAST 61 }; 62 63 struct seth_joy 64 { 65 int joybit[ACTION_LAST]; // is this action currently pressed? 66 int button[ACTION_LAST]; // was this action just pressed (not maintained pressed)? 67 int joybitold[ACTION_LAST]; // copy of previous joybit state 68 // (used to compute .button and to release an arrow with the bow) 69 // Note: also used by Dinkedit, but with fewer different actions 70 71 /* Only used in the editor (for now): */ 72 /* State of the keyboard, SDL-supported keys */ 73 #if SDL_VERSION_ATLEAST(1, 3, 0) 74 /* SDL 1.3 TODO */ 75 #else 76 int keystate[SDLK_LAST]; /* current GetAsyncKeyState value, in 77 cache */ 78 int keyjustpressed[SDLK_LAST]; /* true if key was just pressed, false 79 if kept pressed or released */ 80 #endif 81 82 /* Idem, but with unicode characters - layout-independant */ 83 char charstate[65536]; 84 char charjustpressed[65536]; 85 char key2char[65536]; /* to retrieve matching unicode on SDL_KEYUP, 86 if possible */ 87 Uint16 last_unicode; /* last character typed by the user, used for 88 text input */ 89 Uint16 last_nokey_unicode; /* char with no key match, so no KEYUP 90 support - reset it next time */ 91 92 int right,left,up,down; // is this arrow currently pressed? 93 int rightd,leftd,upd,downd; // was this arrow just pressed (not maintained pressed)? 94 int rightold,leftold,upold,downold; // copy of previous state (used to compute *d) 95 }; 96 extern struct seth_joy sjoy; 97 98 extern int GetKeyboard(int key); 99 extern void input_init(void); 100 extern void input_quit(void); 101 extern void input_set_default_buttons(void); 102 extern enum buttons_actions input_get_button_action(int button_index); 103 extern void input_set_button_action(int button_index, enum buttons_actions action_index); 104 105 #ifdef __cplusplus 106 } 107 #endif 108 109 #endif 110