naev 0.12.5
input.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
7#include "SDL_events.h"
9
10#define NMOD_NONE 0
11#define NMOD_SHIFT ( 1 << 0 )
12#define NMOD_CTRL ( 1 << 1 )
13#define NMOD_ALT ( 1 << 2 )
14#define NMOD_META ( 1 << 3 )
15#define NMOD_ANY 0xFFFF
16
17#define KEY_PRESS ( 1. )
18#define KEY_RELEASE ( -1. )
19
23typedef enum KeySemanticType_ {
24 KST_ACCEL = 0,
25 KST_LEFT,
26 KST_RIGHT,
27 KST_REVERSE,
28 KST_FACE,
29
30 KST_STEALTH,
31 KST_GAME_SPEED,
32 KST_PAUSE,
33
34 KST_AUTONAV,
35 KST_APPROACH,
36 KST_MOUSE_FLYING,
37 KST_JUMP,
38
39 KST_TARGET_NEXT,
40 KST_TARGET_PREV,
41 KST_TARGET_CLOSE,
42 KST_TARGET_SPOB,
43 KST_TARGET_JUMP,
44
45 KST_HTARGET_NEXT,
46 KST_HTARGET_PREV,
47 KST_HTARGET_CLOSE,
48
49 KST_TARGET_CLEAR,
50
51 KST_FIRE_PRIMARY,
52 KST_FIRE_SECONDARY,
53 KST_COOLDOWN,
54
55 KST_WEAPSET1,
56 KST_WEAPSET2,
57 KST_WEAPSET3,
58 KST_WEAPSET4,
59 KST_WEAPSET5,
60 KST_WEAPSET6,
61 KST_WEAPSET7,
62 KST_WEAPSET8,
63 KST_WEAPSET9,
64 KST_WEAPSET0,
65
66 KST_OVERLAY_MAP,
67 KST_STAR_MAP,
68
69 KST_MENU_SMALL,
70 KST_MENU_INFO,
71 KST_CONSOLE,
72
73 KST_ESCORT_NEXT,
74 KST_ESCORT_PREV,
75 KST_ESCORT_ATTACK,
76 KST_ESCORT_HALT,
77 KST_ESCORT_RETURN,
78 KST_ESCORT_CLEAR,
79
80 KST_HAIL,
81 KST_AUTOHAIL,
82 KST_SCAN,
83 KST_LOG_UP,
84 KST_LOG_DOWN,
85
86 KST_ZOOM_IN,
87 KST_ZOOM_OUT,
88
89 KST_FULLSCREEN,
90
91 KST_SCREENSHOT,
92
93 KST_PASTE,
94
95 KST_END
96} KeySemanticType;
97
98/* input types */
99typedef enum {
100 KEYBIND_NULL,
101 KEYBIND_KEYBOARD,
102 KEYBIND_JAXISPOS,
103 KEYBIND_JAXISNEG,
104 KEYBIND_JBUTTON,
105 KEYBIND_JHAT_UP,
106 KEYBIND_JHAT_DOWN,
107 KEYBIND_JHAT_LEFT,
108 KEYBIND_JHAT_RIGHT
109} KeybindType;
110
111/*
112 * set input
113 */
114void input_setDefault( int wasd );
115SDL_Keycode input_keyConv( const char *name );
116void input_setKeybind( KeySemanticType keybind, KeybindType type,
117 SDL_Keycode key, SDL_Keymod mod );
118const char *input_modToText( SDL_Keymod mod );
119SDL_Keycode input_getKeybind( KeySemanticType keybind, KeybindType *type,
120 SDL_Keymod *mod );
121void input_getKeybindDisplay( KeySemanticType keybind, char *buf, int len );
122const char *input_getKeybindBrief( KeySemanticType keybind );
123const char *input_getKeybindName( KeySemanticType keybind );
124const char *input_getKeybindDescription( KeySemanticType keybind );
125KeySemanticType input_keyAlreadyBound( KeybindType type, SDL_Keycode key,
126 SDL_Keymod mod );
127KeySemanticType input_keyFromBrief( const char *name );
128/*
129 * Misc.
130 */
131SDL_Keymod input_translateMod( SDL_Keymod mod );
132void input_enableAll( void );
133void input_disableAll( void );
134void input_toggleEnable( KeySemanticType key, int enable );
135int input_clickPos( SDL_Event *event, double x, double y, double zoom,
136 double minpr, double minr );
137int input_clickedJump( int jump, int autonav );
138int input_clickedSpob( int spob, int autonav, int priority );
139int input_clickedAsteroid( int field, int asteroid );
140int input_clickedPilot( unsigned int pilot, int autonav );
141void input_clicked( const void *clicked );
142int input_isDoubleClick( const void *clicked );
143
144/*
145 * handle input
146 */
147void input_handle( SDL_Event *event );
148
149/*
150 * init/exit
151 */
152void input_init( void );
153void input_exit( void );
154
155/*
156 * Updating.
157 */
158void input_update( double dt );
159
160/*
161 * Mouse.
162 */
163void input_mouseShow( void );
164void input_mouseHide( void );
165int input_mouseIsShown( void );
void input_init(void)
Initializes the input subsystem (does not set keys).
Definition input.c:371
void input_disableAll(void)
Disables all the keybinds.
Definition input.c:436
const char * input_getKeybindBrief(KeySemanticType keybind)
Gets the brief descirption of the keybinding.
Definition input.c:681
int input_isDoubleClick(const void *clicked)
Checks whether a clicked item is the same as the last-clicked.
Definition input.c:1789
SDL_Keycode input_getKeybind(KeySemanticType keybind, KeybindType *type, SDL_Keymod *mod)
Gets the value of a keybind.
Definition input.c:525
int input_clickedPilot(unsigned int pilot, int autonav)
Performs an appropriate action when a pilot is clicked.
Definition input.c:1739
void input_toggleEnable(KeySemanticType key, int enable)
Enables or disables a keybind.
Definition input.c:445
SDL_Keycode input_keyConv(const char *name)
Gets the key id from its name.
Definition input.c:485
void input_handle(SDL_Event *event)
Handles global input.
Definition input.c:1833
void input_mouseShow(void)
Shows the mouse.
Definition input.c:453
KeySemanticType input_keyAlreadyBound(KeybindType type, SDL_Keycode key, SDL_Keymod mod)
Checks to see if a key is already bound.
Definition input.c:639
void input_setDefault(int wasd)
Sets the default input keys.
Definition input.c:267
int input_clickPos(SDL_Event *event, double x, double y, double zoom, double minpr, double minr)
Handles a click at a position in the current system.
Definition input.c:1538
int input_clickedAsteroid(int field, int asteroid)
Performs an appropriate action when an asteroid is clicked.
Definition input.c:1724
const char * input_getKeybindName(KeySemanticType keybind)
Gets the name of the keybinding.
Definition input.c:693
KeySemanticType input_keyFromBrief(const char *target)
Definition input.c:1930
void input_setKeybind(KeySemanticType keybind, KeybindType type, SDL_Keycode key, SDL_Keymod mod)
Binds key of type type to action keybind.
Definition input.c:502
void input_update(double dt)
Handles key repeating.
Definition input.c:740
void input_exit(void)
Exits the input system.
Definition input.c:420
int input_clickedSpob(int spob, int autonav, int priority)
Performs an appropriate action when a spob is clicked.
Definition input.c:1671
SDL_Keymod input_translateMod(SDL_Keymod mod)
Translates SDL modifier to Naev modifier.
Definition input.c:723
const char * input_getKeybindDescription(KeySemanticType keybind)
Gets the description of the keybinding.
Definition input.c:708
int input_mouseIsShown(void)
Gets whether or not the mouse is currently shown.
Definition input.c:474
void input_enableAll(void)
Enables all the keybinds.
Definition input.c:427
int input_clickedJump(int jump, int autonav)
Performs an appropriate action when a jump point is clicked.
Definition input.c:1629
const char * input_modToText(SDL_Keymod mod)
Gets the human readable version of mod.
Definition input.c:611
void input_clicked(const void *clicked)
Sets the last-clicked item, for double-click detection.
Definition input.c:1776
void input_mouseHide(void)
Hides the mouse.
Definition input.c:462
void input_getKeybindDisplay(KeySemanticType keybind, char *buf, int len)
Gets the display name (translated and human-readable) of a keybind.
Definition input.c:547