Kohi Game Engine
input.h File Reference

This file contains everything having to do with input on deskop environments from keyboards and mice. Gamepads and touch controls will likely be handled separately at a future date. More...

#include "defines.h"
#include "input_types.h"

Go to the source code of this file.

Functions

b8 input_system_initialize (u64 *memory_requirement, void *state, void *config)
 Initializes the input system. Call twice; once to obtain memory requirement (passing state = 0), then a second time passing allocated memory to state. More...
 
void input_system_shutdown (void *state)
 Shuts the input system down. More...
 
void input_update (const struct frame_data *p_frame_data)
 Updates the input system every frame. More...
 
KAPI void input_key_repeats_enable (b8 enable)
 Enables/disables keyboard key repeats. More...
 
KAPI b8 input_is_key_down (keys key)
 Indicates if the given key is currently pressed down. More...
 
KAPI b8 input_is_key_up (keys key)
 Indicates if the given key is NOT currently pressed down. More...
 
KAPI b8 input_was_key_down (keys key)
 Indicates if the given key was previously pressed down on the last frame. More...
 
KAPI b8 input_was_key_up (keys key)
 Indicates if the given key was previously pressed down in the last frame. More...
 
void input_process_key (keys key, b8 pressed)
 Sets the state for the given key. More...
 
KAPI b8 input_is_button_down (mouse_buttons button)
 Indicates if the given mouse button is currently pressed. More...
 
KAPI b8 input_is_button_up (mouse_buttons button)
 Indicates if the given mouse button is currently released. More...
 
KAPI b8 input_was_button_down (mouse_buttons button)
 Indicates if the given mouse button was previously pressed in the last frame. More...
 
KAPI b8 input_was_button_up (mouse_buttons button)
 Indicates if the given mouse button was previously released in the last frame. More...
 
KAPI b8 input_is_button_dragging (mouse_buttons button)
 Indicates if the mouse is currently being dragged with the provided button being held down. More...
 
KAPI void input_get_mouse_position (i32 *x, i32 *y)
 Obtains the current mouse position. More...
 
KAPI void input_get_previous_mouse_position (i32 *x, i32 *y)
 Obtains the previous mouse position. More...
 
void input_process_button (mouse_buttons button, b8 pressed)
 Sets the press state of the given mouse button. More...
 
void input_process_mouse_move (i16 x, i16 y)
 Sets the current position of the mouse to the given x and y positions. Also updates the previous position beforehand. More...
 
void input_process_mouse_wheel (i8 z_delta)
 Processes mouse wheel scrolling. More...
 
KAPI const char * input_keycode_str (keys key)
 Returns a string representation of the provided key. Ex. "tab" for the tab key. More...
 
KAPI void input_keymap_push (const struct keymap *map)
 Pushes a new keymap onto the keymap stack, making it the active keymap. A copy of the keymap is taken when pushing onto the stack. More...
 
KAPI b8 input_keymap_pop (void)
 Attempts to pop the top-most keymap from the stack, if there is one. More...
 

Detailed Description

This file contains everything having to do with input on deskop environments from keyboards and mice. Gamepads and touch controls will likely be handled separately at a future date.

Author
Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
Version
1.0
Date
2022-01-10

Function Documentation

◆ input_get_mouse_position()

KAPI void input_get_mouse_position ( i32 x,
i32 y 
)

Obtains the current mouse position.

Parameters
xA pointer to hold the current mouse position on the x-axis.
yA pointer to hold the current mouse position on the y-axis.

◆ input_get_previous_mouse_position()

KAPI void input_get_previous_mouse_position ( i32 x,
i32 y 
)

Obtains the previous mouse position.

Parameters
xA pointer to hold the previous mouse position on the x-axis.
yA pointer to hold the previous mouse position on the y-axis.

◆ input_is_button_down()

KAPI b8 input_is_button_down ( mouse_buttons  button)

Indicates if the given mouse button is currently pressed.

Parameters
buttonThe button to check.
Returns
True if currently pressed; otherwise false.

◆ input_is_button_dragging()

KAPI b8 input_is_button_dragging ( mouse_buttons  button)

Indicates if the mouse is currently being dragged with the provided button being held down.

Parameters
buttonThe button to check.
Returns
True if dragging; otherwise false.

◆ input_is_button_up()

KAPI b8 input_is_button_up ( mouse_buttons  button)

Indicates if the given mouse button is currently released.

Parameters
buttonThe button to check.
Returns
True if currently released; otherwise false.

◆ input_is_key_down()

KAPI b8 input_is_key_down ( keys  key)

Indicates if the given key is currently pressed down.

Parameters
keyThey key to be checked.
Returns
True if currently pressed; otherwise false.

◆ input_is_key_up()

KAPI b8 input_is_key_up ( keys  key)

Indicates if the given key is NOT currently pressed down.

Parameters
keyThey key to be checked.
Returns
True if currently released; otherwise false.

◆ input_key_repeats_enable()

KAPI void input_key_repeats_enable ( b8  enable)

Enables/disables keyboard key repeats.

Parameters
enableIndicates if key repeats should be enabled.

◆ input_keycode_str()

KAPI const char* input_keycode_str ( keys  key)

Returns a string representation of the provided key. Ex. "tab" for the tab key.

Parameters
key
Returns
const char*

◆ input_keymap_pop()

KAPI b8 input_keymap_pop ( void  )

Attempts to pop the top-most keymap from the stack, if there is one.

Returns
True if a keymap was popped; otherwise false.

◆ input_keymap_push()

KAPI void input_keymap_push ( const struct keymap map)

Pushes a new keymap onto the keymap stack, making it the active keymap. A copy of the keymap is taken when pushing onto the stack.

Parameters
mapA constant pointer to the keymap to be pushed.

◆ input_process_button()

void input_process_button ( mouse_buttons  button,
b8  pressed 
)

Sets the press state of the given mouse button.

Parameters
buttonThe mouse button whose state to set.
pressedIndicates if the mouse button is currently pressed.

◆ input_process_key()

void input_process_key ( keys  key,
b8  pressed 
)

Sets the state for the given key.

Parameters
keyThe key to be processed.
pressedIndicates whether the key is currently pressed.

◆ input_process_mouse_move()

void input_process_mouse_move ( i16  x,
i16  y 
)

Sets the current position of the mouse to the given x and y positions. Also updates the previous position beforehand.

◆ input_process_mouse_wheel()

void input_process_mouse_wheel ( i8  z_delta)

Processes mouse wheel scrolling.

Parameters
z_deltaThe amount of scrolling which occurred on the z axis (mouse wheel)

◆ input_system_initialize()

b8 input_system_initialize ( u64 memory_requirement,
void *  state,
void *  config 
)

Initializes the input system. Call twice; once to obtain memory requirement (passing state = 0), then a second time passing allocated memory to state.

Parameters
memory_requirementThe required size of the state memory.
stateEither 0 or the allocated block of state memory.
configIgnored.
Returns
True on success; otherwise false.

◆ input_system_shutdown()

void input_system_shutdown ( void *  state)

Shuts the input system down.

Parameters
stateA pointer to the system state.

◆ input_update()

void input_update ( const struct frame_data p_frame_data)

Updates the input system every frame.

Parameters
p_frame_dataA constant pointer to the current frame's data. NOTE: Does not use system manager update because it must be called at end of a frame.

◆ input_was_button_down()

KAPI b8 input_was_button_down ( mouse_buttons  button)

Indicates if the given mouse button was previously pressed in the last frame.

Parameters
buttonThe button to check.
Returns
True if previously pressed; otherwise false.

◆ input_was_button_up()

KAPI b8 input_was_button_up ( mouse_buttons  button)

Indicates if the given mouse button was previously released in the last frame.

Parameters
buttonThe button to check.
Returns
True if previously released; otherwise false.

◆ input_was_key_down()

KAPI b8 input_was_key_down ( keys  key)

Indicates if the given key was previously pressed down on the last frame.

Parameters
keyThey key to be checked.
Returns
True if was previously pressed; otherwise false.

◆ input_was_key_up()

KAPI b8 input_was_key_up ( keys  key)

Indicates if the given key was previously pressed down in the last frame.

Parameters
keyThey key to be checked.
Returns
True if previously released; otherwise false.