naev 0.12.5
input.c File Reference

Handles all the keybindings and input. More...

#include "input.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 "player_autonav.h"
#include "toolkit.h"
#include "utf8.h"
Include dependency graph for input.c:

Go to the source code of this file.

Data Structures

struct  Keybind
 Naev Keybinding. More...

Macros

#define INGAME()
#define HYP()
#define NOHYP()
#define DEAD()
#define NODEAD()
#define LAND()
#define NOLAND()
#define MAP()

Functions

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

Variables

static const char * keybind_info [KST_END][3]
static Keybind input_keybinds [KST_END]
static Keybindinput_paste
static KeySemanticType doubletap_key = KST_END
static unsigned int doubletap_t = 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 const void * input_lastClicked
double player_left
double player_right

Detailed Description

Handles all the keybindings and input.

Definition in file input.c.

Macro Definition Documentation

◆ DEAD

#define DEAD ( )
Value:
( ( player.p == NULL ) || \
pilot_isFlag( player.p, PILOT_DEAD ) )
Player_t player
Definition player.c:77

Player is dead.

Definition at line 791 of file input.c.

◆ HYP

#define HYP ( )
Value:
( ( player.p == NULL ) || pilot_isFlag( player.p, PILOT_HYP_PREP ) || \
pilot_isFlag( player.p, PILOT_HYP_BEGIN ) || \
pilot_isFlag( \
player.p, \
PILOT_HYPERSPACE ) )

Make sure the player isn't jumping.

Definition at line 779 of file input.c.

◆ INGAME

#define INGAME ( )
Value:
( !toolkit_isOpen() && \
( ( value == KEY_RELEASE ) || !player_isFlag( PLAYER_CINEMATICS ) ) && \
( player.p != NULL ) && \
!pilot_isFlag( player.p, \
PILOT_DEAD ) )
int toolkit_isOpen(void)
Checks to see if the toolkit is open.
Definition toolkit.c:93

Makes sure player is in game.

Definition at line 773 of file input.c.

◆ LAND

#define LAND ( )
Value:
( ( player.p == NULL ) || landed || \
pilot_isFlag( player.p, PILOT_LANDING ) )
int landed
Definition land.c:78

Player isn't landed.

Definition at line 797 of file input.c.

◆ MAP

#define MAP ( )
Value:
( map_isOpen() )

Definition at line 805 of file input.c.

◆ NODEAD

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

Player isn't dead.

Definition at line 794 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 ) )

Make sure the player isn't jumping.

Definition at line 785 of file input.c.

◆ NOLAND

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

Player isn't landed.

Definition at line 800 of file input.c.

Function Documentation

◆ input_clicked()

void input_clicked ( const void * clicked)

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

Parameters
clickedPointer to the clicked item.

Definition at line 1776 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 1724 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 1629 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 1739 of file input.c.

◆ input_clickedSpob()

int input_clickedSpob ( int spob,
int autonav,
int priority )

Performs an appropriate action when a spob is clicked.

Parameters
spobIndex of the spob.
autonavWhether to autonav to the target.
priorityWhether to consider priority targets.
Returns
Whether the click was used.

Definition at line 1671 of file input.c.

◆ input_clickevent()

void input_clickevent ( SDL_Event * event)
static

Handles a click event.

Definition at line 1475 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 1538 of file input.c.

◆ input_clickZoom()

void input_clickZoom ( double modifier)
static

Handles zoom.

Definition at line 1455 of file input.c.

◆ input_disableAll()

void input_disableAll ( void )

Disables all the keybinds.

Definition at line 436 of file input.c.

◆ input_doubleClickTest()

int input_doubleClickTest ( unsigned int * time,
const void ** last,
const void * clicked )
static

Definition at line 1806 of file input.c.

◆ input_enableAll()

void input_enableAll ( void )

Enables all the keybinds.

Definition at line 427 of file input.c.

◆ input_exit()

void input_exit ( void )

Exits the input system.

Definition at line 420 of file input.c.

◆ input_getKeybind()

SDL_Keycode input_getKeybind ( KeySemanticType keybind,
KeybindType * type,
SDL_Keymod * mod )

Gets the value of a keybind.

Parameters
[in]keybindKeySemanticType 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 525 of file input.c.

◆ input_getKeybindBrief()

const char * input_getKeybindBrief ( KeySemanticType keybind)

Gets the brief descirption of the keybinding.

Definition at line 681 of file input.c.

◆ input_getKeybindDescription()

const char * input_getKeybindDescription ( KeySemanticType keybind)

Gets the description of the keybinding.

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

Definition at line 708 of file input.c.

◆ input_getKeybindDisplay()

void input_getKeybindDisplay ( KeySemanticType 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 547 of file input.c.

◆ input_getKeybindName()

const char * input_getKeybindName ( KeySemanticType keybind)

Gets the name of the keybinding.

Definition at line 693 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 1833 of file input.c.

◆ input_init()

void input_init ( void )

Initializes the input subsystem (does not set keys).

Definition at line 371 of file input.c.

◆ input_isDoubleClick()

int input_isDoubleClick ( const void * clicked)

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

Parameters
clickedPointer to the clicked item.

Definition at line 1789 of file input.c.

◆ input_joyaxis()

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 1349 of file input.c.

◆ input_joyevent()

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 1377 of file input.c.

◆ input_joyhatevent()

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 1393 of file input.c.

◆ input_key()

void input_key ( KeySemanticType 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 815 of file input.c.

◆ input_keyAlreadyBound()

KeySemanticType 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 639 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 485 of file input.c.

◆ input_keyevent()

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.

Definition at line 1431 of file input.c.

◆ input_keyFromBrief()

KeySemanticType input_keyFromBrief ( const char * target)

Gets the semantic key binding from a brief description name.

Definition at line 1930 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 611 of file input.c.

◆ input_mouseHide()

void input_mouseHide ( void )

Hides the mouse.

Definition at line 462 of file input.c.

◆ input_mouseIsShown()

int input_mouseIsShown ( void )

Gets whether or not the mouse is currently shown.

Definition at line 474 of file input.c.

◆ input_mouseMove()

void input_mouseMove ( SDL_Event * event)
static

Provides mouse X and Y coordinates for mouse flying.

Definition at line 1464 of file input.c.

◆ input_mouseShow()

void input_mouseShow ( void )

Shows the mouse.

Definition at line 453 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 267 of file input.c.

◆ input_setKeybind()

void input_setKeybind ( KeySemanticType keybind,
KeybindType type,
SDL_Keycode key,
SDL_Keymod mod )

Binds key of type type to action keybind.

Parameters
keybindThe KeySemanticType of the keybind (as defined above).
typeThe type of the keybind.
keyThe key to bind to.
modModifiers to check for.

Definition at line 502 of file input.c.

◆ input_toggleEnable()

void input_toggleEnable ( KeySemanticType key,
int enable )

Enables or disables a keybind.

Definition at line 445 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 723 of file input.c.

◆ input_update()

void input_update ( double dt)

Handles key repeating.

Definition at line 740 of file input.c.

Variable Documentation

◆ doubletap_key

KeySemanticType doubletap_key = KST_END
static

Last key double tapped.

Definition at line 222 of file input.c.

◆ doubletap_t

unsigned int doubletap_t = 0
static

Used to see if double tap accel.

Definition at line 223 of file input.c.

◆ input_keybinds

Keybind input_keybinds[KST_END]
static

contains the players keybindings

Definition at line 216 of file input.c.

◆ input_lastClicked

const void* input_lastClicked
static
Initial value:
=
NULL

Pointer to the last-clicked item.

Definition at line 238 of file input.c.

◆ input_mouseClickLast

unsigned int input_mouseClickLast = 0
static

Time of last click (in ms)

Definition at line 237 of file input.c.

◆ input_mouseCounter

int input_mouseCounter = 1
static

Counter for mouse display/hiding.

Definition at line 236 of file input.c.

◆ input_mouseTimer

double input_mouseTimer = 1.
static

Timer for hiding again.

Definition at line 235 of file input.c.

◆ input_paste

Keybind* input_paste
static

Definition at line 217 of file input.c.

◆ keybind_info

const char* keybind_info[KST_END][3]
static

Definition at line 49 of file input.c.

◆ player_left

double player_left
extern

player.c

Player left turn velocity from input.

Definition at line 130 of file player.c.

◆ player_right

double player_right
extern

player.c

Player right turn velocity from input.

Definition at line 131 of file player.c.

◆ repeat_key

int repeat_key = -1
static

Key to repeat.

Definition at line 228 of file input.c.

◆ repeat_keyCounter

unsigned int repeat_keyCounter = 0
static

Counter for key repeats.

Definition at line 230 of file input.c.

◆ repeat_keyTimer

unsigned int repeat_keyTimer = 0
static

Repeat timer.

Definition at line 229 of file input.c.