naev 0.10.4
Data Structures | Macros | Functions | Variables
input.c File Reference

Handles all the keybindings and input. More...

#include "input.h"
#include "array.h"
#include "board.h"
#include "camera.h"
#include "conf.h"
#include "console.h"
#include "escort.h"
#include "gui.h"
#include "hook.h"
#include "info.h"
#include "land.h"
#include "log.h"
#include "map.h"
#include "map_overlay.h"
#include "menu.h"
#include "nstring.h"
#include "pause.h"
#include "pilot.h"
#include "player.h"
#include "toolkit.h"
#include "weapon.h"
#include "utf8.h"

Go to the source code of this file.

Data Structures

struct  Keybind
 Naev Keybinding. More...
 

Macros

#define MOUSE_HIDE   (3.)
 
#define KEY(s)   (strcmp(input_keybinds[keynum].name,s)==0)
 
#define INGAME()   (!toolkit_isOpen() && ((value==KEY_RELEASE) || !player_isFlag(PLAYER_CINEMATICS)))
 
#define NOHYP()
 
#define NODEAD()   ((player.p != NULL) && !pilot_isFlag(player.p,PILOT_DEAD))
 
#define NOLAND()   ((player.p != NULL) && (!landed && !pilot_isFlag(player.p,PILOT_LANDING)))
 

Functions

static void input_key (int keynum, double value, double kabs, int repeat)
 Runs the input command. More...
 
static void input_clickZoom (double modifier)
 Handles zoom. More...
 
static void input_clickevent (SDL_Event *event)
 Handles a click event. More...
 
static void input_mouseMove (SDL_Event *event)
 Provides mouse X and Y coordinates for mouse flying. More...
 
void input_setDefault (int wasd)
 Sets the default input keys. More...
 
void input_init (void)
 Initializes the input subsystem (does not set keys). More...
 
void input_exit (void)
 exits the input subsystem. More...
 
void input_enableAll (void)
 Enables all the keybinds. More...
 
void input_disableAll (void)
 Disables all the keybinds. More...
 
void input_toggleEnable (const char *key, int enable)
 Enables or disables a keybind. More...
 
void input_mouseShow (void)
 Shows the mouse. More...
 
void input_mouseHide (void)
 Hides the mouse. More...
 
SDL_Keycode input_keyConv (const char *name)
 Gets the key id from its name. More...
 
void input_setKeybind (const char *keybind, KeybindType type, SDL_Keycode key, SDL_Keymod mod)
 Binds key of type type to action keybind. More...
 
SDL_Keycode input_getKeybind (const char *keybind, KeybindType *type, SDL_Keymod *mod)
 Gets the value of a keybind. More...
 
void input_getKeybindDisplay (const char *keybind, char *buf, int len)
 Gets the display name (translated and human-readable) of a keybind. More...
 
const char * input_modToText (SDL_Keymod mod)
 Gets the human readable version of mod. More...
 
const char * input_keyAlreadyBound (KeybindType type, SDL_Keycode key, SDL_Keymod mod)
 Checks to see if a key is already bound. More...
 
const char * input_getKeybindDescription (const char *keybind)
 Gets the description of the keybinding. More...
 
SDL_Keymod input_translateMod (SDL_Keymod mod)
 Translates SDL modifier to Naev modifier. More...
 
void input_update (double dt)
 Handles key repeating. More...
 
static void input_joyaxis (const SDL_Keycode axis, const int value)
 Filters a joystick axis event. More...
 
static void input_joyevent (const int event, const SDL_Keycode button)
 Filters a joystick button event. More...
 
static void input_keyevent (const int event, SDL_Keycode key, const SDL_Keymod mod, const int repeat)
 Filters a keyboard event. More...
 
static void input_joyhatevent (const Uint8 value, const Uint8 hat)
 Filters a joystick hat event. More...
 
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. More...
 
int input_clickedJump (int jump, int autonav)
 Performs an appropriate action when a jump point is clicked. More...
 
int input_clickedSpob (int spob, int autonav)
 Performs an appropriate action when a spob is clicked. More...
 
int input_clickedAsteroid (int field, int asteroid)
 Performs an appropriate action when an asteroid is clicked. More...
 
int input_clickedPilot (unsigned int pilot, int autonav)
 Performs an appropriate action when a pilot is clicked. More...
 
void input_clicked (void *clicked)
 Sets the last-clicked item, for double-click detection. More...
 
int input_isDoubleClick (void *clicked)
 Checks whether a clicked item is the same as the last-clicked. More...
 
void input_handle (SDL_Event *event)
 Handles global input. More...
 

Variables

const char * keybind_info [][3]
 
static Keybindinput_keybinds
 
const int input_numbinds = ( sizeof( keybind_info ) / sizeof( keybind_info[ 0 ] ) ) - 1
 
static Keybindinput_paste
 
static unsigned int input_accelLast = 0
 
static unsigned int input_revLast = 0
 
static int input_accelButton = 0
 
static int repeat_key = -1
 
static unsigned int repeat_keyTimer = 0
 
static unsigned int repeat_keyCounter = 0
 
static double input_mouseTimer = -1.
 
static int input_mouseCounter = 1
 
static unsigned int input_mouseClickLast = 0
 
static void * input_lastClicked = NULL
 
double player_left
 
double player_right
 

Detailed Description

Handles all the keybindings and input.

Definition in file input.c.

Macro Definition Documentation

◆ INGAME

#define INGAME ( )    (!toolkit_isOpen() && ((value==KEY_RELEASE) || !player_isFlag(PLAYER_CINEMATICS)))

Makes sure player is in game.

Definition at line 651 of file input.c.

◆ KEY

#define KEY (   s)    (strcmp(input_keybinds[keynum].name,s)==0)

Shortcut for ease.

Definition at line 650 of file input.c.

◆ MOUSE_HIDE

#define MOUSE_HIDE   (3.)

Time in seconds to wait before hiding mouse again.

Definition at line 37 of file input.c.

◆ NODEAD

#define NODEAD ( )    ((player.p != NULL) && !pilot_isFlag(player.p,PILOT_DEAD))

Player isn't dead.

Definition at line 659 of file input.c.

◆ NOHYP

#define NOHYP ( )
Value:
((player.p != NULL) && !pilot_isFlag(player.p,PILOT_HYP_PREP) &&\
!pilot_isFlag(player.p,PILOT_HYP_BEGIN) &&\
!pilot_isFlag(player.p,PILOT_HYPERSPACE))
Player_t player
Definition: player.c:73
Pilot * p
Definition: player.h:101

Make sure the player isn't jumping.

Definition at line 658 of file input.c.

◆ NOLAND

#define NOLAND ( )    ((player.p != NULL) && (!landed && !pilot_isFlag(player.p,PILOT_LANDING)))

Player isn't landed.

Definition at line 660 of file input.c.

Function Documentation

◆ input_clicked()

void input_clicked ( void *  clicked)

Sets the last-clicked item, for double-click detection.

Parameters
clickedPointer to the clicked item.

Definition at line 1453 of file input.c.

◆ input_clickedAsteroid()

int input_clickedAsteroid ( int  field,
int  asteroid 
)

Performs an appropriate action when an asteroid is clicked.

Parameters
fieldIndex of the parent field of the asteoid.
asteroidIndex of the oasteoid in the field.
Returns
Whether the click was used.

Definition at line 1404 of file input.c.

◆ input_clickedJump()

int input_clickedJump ( int  jump,
int  autonav 
)

Performs an appropriate action when a jump point is clicked.

Parameters
jumpIndex of the jump point.
autonavWhether to autonav to the target.
Returns
Whether the click was used.

Definition at line 1326 of file input.c.

◆ input_clickedPilot()

int input_clickedPilot ( unsigned int  pilot,
int  autonav 
)

Performs an appropriate action when a pilot is clicked.

Parameters
pilotIndex of the pilot.
autonavWhether this is an autonav action.
Returns
Whether the click was used.

Definition at line 1420 of file input.c.

◆ input_clickedSpob()

int input_clickedSpob ( int  spob,
int  autonav 
)

Performs an appropriate action when a spob is clicked.

Parameters
spobIndex of the spob.
autonavWhether to autonav to the target.
Returns
Whether the click was used.

Definition at line 1361 of file input.c.

◆ input_clickevent()

static void input_clickevent ( SDL_Event *  event)
static

Handles a click event.

Definition at line 1174 of file input.c.

◆ input_clickPos()

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.

event The click event itself, used for button information.

x X coordinate within the system.

y Y coordinate within the system.

zoom Camera zoom (mostly for on-screen targeting).

minpr Minimum radius to assign to pilots.

minr Minimum radius to assign to spobs and jumps.

Returns
Whether the click was used to trigger an action.

Definition at line 1237 of file input.c.

◆ input_clickZoom()

static void input_clickZoom ( double  modifier)
static

Handles zoom.

Definition at line 1154 of file input.c.

◆ input_disableAll()

void input_disableAll ( void  )

Disables all the keybinds.

Definition at line 351 of file input.c.

◆ input_enableAll()

void input_enableAll ( void  )

Enables all the keybinds.

Definition at line 342 of file input.c.

◆ input_exit()

void input_exit ( void  )

exits the input subsystem.

Definition at line 334 of file input.c.

◆ input_getKeybind()

SDL_Keycode input_getKeybind ( const char *  keybind,
KeybindType *  type,
SDL_Keymod *  mod 
)

Gets the value of a keybind.

Parameters
[in]keybindName of the keybinding to get.
[out]typeStores the type of the keybinding.
[out]modStores the modifiers used with the keybinding.
Returns
The key associated with the keybinding.

Definition at line 436 of file input.c.

◆ input_getKeybindDescription()

const char * input_getKeybindDescription ( const char *  keybind)

Gets the description of the keybinding.

Parameters
keybindKeybinding to get the description of.
Returns
Description of the keybinding.

Definition at line 587 of file input.c.

◆ input_getKeybindDisplay()

void input_getKeybindDisplay ( const char *  keybind,
char *  buf,
int  len 
)

Gets the display name (translated and human-readable) of a keybind.

Parameters
[in]keybindName of the keybinding to get display name of.
[out]bufBuffer to write the display name to.
[in]lenLength of buffer.

Definition at line 458 of file input.c.

◆ input_handle()

void input_handle ( SDL_Event *  event)

Handles global input.

Basically separates the event types

Parameters
eventIncoming SDL_Event.

Definition at line 1489 of file input.c.

◆ input_init()

void input_init ( void  )

Initializes the input subsystem (does not set keys).

Definition at line 283 of file input.c.

◆ input_isDoubleClick()

int input_isDoubleClick ( void *  clicked)

Checks whether a clicked item is the same as the last-clicked.

Parameters
clickedPointer to the clicked item.

Definition at line 1466 of file input.c.

◆ input_joyaxis()

static void input_joyaxis ( const SDL_Keycode  axis,
const int  value 
)
static

Filters a joystick axis event.

Parameters
axisAxis generated by the event.
valueValue of the axis.

Definition at line 1052 of file input.c.

◆ input_joyevent()

static void input_joyevent ( const int  event,
const SDL_Keycode  button 
)
static

Filters a joystick button event.

Parameters
eventEvent type (down/up).
buttonButton generating the event.

Definition at line 1081 of file input.c.

◆ input_joyhatevent()

static void input_joyhatevent ( const Uint8  value,
const Uint8  hat 
)
static

Filters a joystick hat event.

Parameters
valueDirection on hat.
hatHat generating the event.

Definition at line 1097 of file input.c.

◆ input_key()

static void input_key ( int  keynum,
double  value,
double  kabs,
int  repeat 
)
static

Runs the input command.

Parameters
keynumThe index of the keybind.
valueThe value of the keypress (defined above).
kabsThe absolute value.
repeatWhether the key is still held down, rather than newly pressed.

Definition at line 669 of file input.c.

◆ input_keyAlreadyBound()

const char * input_keyAlreadyBound ( KeybindType  type,
SDL_Keycode  key,
SDL_Keymod  mod 
)

Checks to see if a key is already bound.

Parameters
typeType of key.
keyKey.
modKey modifiers.
Returns
Name of the key that is already bound to it.

Definition at line 542 of file input.c.

◆ input_keyConv()

SDL_Keycode input_keyConv ( const char *  name)

Gets the key id from its name.

Parameters
nameName of the key to get id from.
Returns
ID of the key.

Definition at line 397 of file input.c.

◆ input_keyevent()

static void input_keyevent ( const int  event,
SDL_Keycode  key,
const SDL_Keymod  mod,
const int  repeat 
)
static

Filters a keyboard event.

Parameters
eventEvent type (down/up).
keyKey generating the event.
modModifiers active when event was generated.
repeatWhether the key is still held down, rather than newly pressed.

< Release always gets through.

Definition at line 1133 of file input.c.

◆ input_modToText()

const char * input_modToText ( SDL_Keymod  mod)

Gets the human readable version of mod.

Parameters
modMod to get human readable version from.
Returns
Human readable version of mod.

Definition at line 521 of file input.c.

◆ input_mouseHide()

void input_mouseHide ( void  )

Hides the mouse.

Definition at line 382 of file input.c.

◆ input_mouseMove()

static void input_mouseMove ( SDL_Event *  event)
static

Provides mouse X and Y coordinates for mouse flying.

Definition at line 1163 of file input.c.

◆ input_mouseShow()

void input_mouseShow ( void  )

Shows the mouse.

Definition at line 373 of file input.c.

◆ input_setDefault()

void input_setDefault ( int  wasd)

Sets the default input keys.

Parameters
wasdWhether to use the WASD layout.

Definition at line 176 of file input.c.

◆ input_setKeybind()

void input_setKeybind ( const char *  keybind,
KeybindType  type,
SDL_Keycode  key,
SDL_Keymod  mod 
)

Binds key of type type to action keybind.

Parameters
keybindThe name of the keybind defined above.
typeThe type of the keybind.
keyThe key to bind to.
modModifiers to check for.

Definition at line 414 of file input.c.

◆ input_toggleEnable()

void input_toggleEnable ( const char *  key,
int  enable 
)

Enables or disables a keybind.

Definition at line 360 of file input.c.

◆ input_translateMod()

SDL_Keymod input_translateMod ( SDL_Keymod  mod)

Translates SDL modifier to Naev modifier.

Parameters
modSDL modifier to translate.
Returns
Naev modifier.

Definition at line 602 of file input.c.

◆ input_update()

void input_update ( double  dt)

Handles key repeating.

Definition at line 619 of file input.c.

Variable Documentation

◆ input_accelButton

int input_accelButton = 0
static

Used to show whether accel is pressed.

Definition at line 140 of file input.c.

◆ input_accelLast

unsigned int input_accelLast = 0
static

Used to see if double tap accel.

Definition at line 138 of file input.c.

◆ input_keybinds

Keybind* input_keybinds
static

contains the players keybindings

Definition at line 131 of file input.c.

◆ input_lastClicked

void* input_lastClicked = NULL
static

Pointer to the last-clicked item.

Definition at line 155 of file input.c.

◆ input_mouseClickLast

unsigned int input_mouseClickLast = 0
static

Time of last click (in ms)

Definition at line 154 of file input.c.

◆ input_mouseCounter

int input_mouseCounter = 1
static

Counter for mouse display/hiding.

Definition at line 153 of file input.c.

◆ input_mouseTimer

double input_mouseTimer = -1.
static

Timer for hiding again.

Definition at line 152 of file input.c.

◆ input_numbinds

const int input_numbinds = ( sizeof( keybind_info ) / sizeof( keybind_info[ 0 ] ) ) - 1

Number of keybindings.

Definition at line 132 of file input.c.

◆ input_paste

Keybind* input_paste
static

Definition at line 133 of file input.c.

◆ input_revLast

unsigned int input_revLast = 0
static

Used to see if double tap reverse.

Definition at line 139 of file input.c.

◆ keybind_info

const char* keybind_info[][3]

Names of possible keybindings.

Definition at line 52 of file input.c.

◆ player_left

double player_left
extern

player.c

Player left turn velocity from input.

Definition at line 120 of file player.c.

◆ player_right

double player_right
extern

player.c

Player right turn velocity from input.

Definition at line 121 of file player.c.

◆ repeat_key

int repeat_key = -1
static

Key to repeat.

Definition at line 145 of file input.c.

◆ repeat_keyCounter

unsigned int repeat_keyCounter = 0
static

Counter for key repeats.

Definition at line 147 of file input.c.

◆ repeat_keyTimer

unsigned int repeat_keyTimer = 0
static

Repeat timer.

Definition at line 146 of file input.c.