Input
Defines
-
BINOCLE_INPUT_TEXT_SIZE
Typedefs
-
typedef enum binocle_input_mouse_button binocle_input_mouse_button
-
typedef enum binocle_input_finger_type binocle_input_finger_type
-
typedef struct binocle_input_touch binocle_input_touch
-
typedef enum binocle_input_keyboard_key binocle_input_keyboard_key
Keyboard scan codes, based on: http://wiki.libsdl.org/SDLScancodeLookup
-
typedef struct binocle_input binocle_input
Enums
-
enum binocle_input_mouse_button
Values:
-
enumerator MOUSE_LEFT
-
enumerator MOUSE_MIDDLE
-
enumerator MOUSE_RIGHT
-
enumerator MOUSE_MAX
-
enumerator MOUSE_LEFT
-
enum binocle_input_finger_type
Values:
-
enumerator FINGER_MOTION
-
enumerator FINGER_DOWN
-
enumerator FINGER_UP
-
enumerator FINGER_MAX
-
enumerator FINGER_MOTION
-
enum binocle_input_keyboard_key
Keyboard scan codes, based on: http://wiki.libsdl.org/SDLScancodeLookup
Values:
-
enumerator KEY_UNKNOWN
-
enumerator KEY_A
-
enumerator KEY_B
-
enumerator KEY_C
-
enumerator KEY_D
-
enumerator KEY_E
-
enumerator KEY_F
-
enumerator KEY_G
-
enumerator KEY_H
-
enumerator KEY_I
-
enumerator KEY_J
-
enumerator KEY_K
-
enumerator KEY_L
-
enumerator KEY_M
-
enumerator KEY_N
-
enumerator KEY_O
-
enumerator KEY_P
-
enumerator KEY_Q
-
enumerator KEY_R
-
enumerator KEY_S
-
enumerator KEY_T
-
enumerator KEY_U
-
enumerator KEY_V
-
enumerator KEY_W
-
enumerator KEY_X
-
enumerator KEY_Y
-
enumerator KEY_Z
-
enumerator KEY_1
-
enumerator KEY_2
-
enumerator KEY_3
-
enumerator KEY_4
-
enumerator KEY_5
-
enumerator KEY_6
-
enumerator KEY_7
-
enumerator KEY_8
-
enumerator KEY_9
-
enumerator KEY_0
-
enumerator KEY_RETURN
-
enumerator KEY_ESCAPE
-
enumerator KEY_BACKSPACE
-
enumerator KEY_TAB
-
enumerator KEY_SPACE
-
enumerator KEY_MINUS
-
enumerator KEY_EQUALS
-
enumerator KEY_LEFTBRACKET
-
enumerator KEY_RIGHTBRACKET
-
enumerator KEY_BACKSLASH
-
enumerator KEY_NONUSHASH
-
enumerator KEY_SEMICOLON
-
enumerator KEY_APOSTROPHE
-
enumerator KEY_GRAVE
-
enumerator KEY_COMMA
-
enumerator KEY_PERIOD
-
enumerator KEY_SLASH
-
enumerator KEY_CAPSLOCK
-
enumerator KEY_F1
-
enumerator KEY_F2
-
enumerator KEY_F3
-
enumerator KEY_F4
-
enumerator KEY_F5
-
enumerator KEY_F6
-
enumerator KEY_F7
-
enumerator KEY_F8
-
enumerator KEY_F9
-
enumerator KEY_F10
-
enumerator KEY_F11
-
enumerator KEY_F12
-
enumerator KEY_PRINTSCREEN
-
enumerator KEY_SCROLLLOCK
-
enumerator KEY_PAUSE
-
enumerator KEY_INSERT
-
enumerator KEY_HOME
-
enumerator KEY_PAGEUP
-
enumerator KEY_DELETE
-
enumerator KEY_END
-
enumerator KEY_PAGEDOWN
-
enumerator KEY_RIGHT
-
enumerator KEY_LEFT
-
enumerator KEY_DOWN
-
enumerator KEY_UP
-
enumerator KEY_NUMLOCKCLEAR
-
enumerator KEY_KEYPAD_DIVIDE
-
enumerator KEY_KEYPAD_MULTIPLY
-
enumerator KEY_KEYPAD_MINUS
-
enumerator KEY_KEYPAD_PLUS
-
enumerator KEY_KEYPAD_ENTER
-
enumerator KEY_KEYPAD_1
-
enumerator KEY_KEYPAD_2
-
enumerator KEY_KEYPAD_3
-
enumerator KEY_KEYPAD_4
-
enumerator KEY_KEYPAD_5
-
enumerator KEY_KEYPAD_6
-
enumerator KEY_KEYPAD_7
-
enumerator KEY_KEYPAD_8
-
enumerator KEY_KEYPAD_9
-
enumerator KEY_KEYPAD_0
-
enumerator KEY_KEYPAD_PERIOD
-
enumerator KEY_NONUSBACKSLASH
-
enumerator KEY_APPLICATION
-
enumerator KEY_POWER
-
enumerator KEY_KEYPAD_EQUALS
-
enumerator KEY_F13
-
enumerator KEY_F14
-
enumerator KEY_F15
-
enumerator KEY_F16
-
enumerator KEY_F17
-
enumerator KEY_F18
-
enumerator KEY_F19
-
enumerator KEY_F20
-
enumerator KEY_F21
-
enumerator KEY_F22
-
enumerator KEY_F23
-
enumerator KEY_F24
-
enumerator KEY_EXECUTE_EX
-
enumerator KEY_HELP
-
enumerator KEY_MENU
-
enumerator KEY_SELECT
-
enumerator KEY_STOP
-
enumerator KEY_AGAIN
-
enumerator KEY_UNDO
-
enumerator KEY_CUT
-
enumerator KEY_COPY
-
enumerator KEY_PASTE
-
enumerator KEY_FIND
-
enumerator KEY_MUTE
-
enumerator KEY_VOLUMEUP
-
enumerator KEY_VOLUMEDOWN
-
enumerator KEY_KEYPAD_COMMA
-
enumerator KEY_KEYPAD_EQUALSAS400
-
enumerator KEY_INTERNATIONAL1
-
enumerator KEY_INTERNATIONAL2
-
enumerator KEY_INTERNATIONAL3
-
enumerator KEY_INTERNATIONAL4
-
enumerator KEY_INTERNATIONAL5
-
enumerator KEY_INTERNATIONAL6
-
enumerator KEY_INTERNATIONAL7
-
enumerator KEY_INTERNATIONAL8
-
enumerator KEY_INTERNATIONAL9
-
enumerator KEY_LANG1
-
enumerator KEY_LANG2
-
enumerator KEY_LANG3
-
enumerator KEY_LANG4
-
enumerator KEY_LANG5
-
enumerator KEY_LANG6
-
enumerator KEY_LANG7
-
enumerator KEY_LANG8
-
enumerator KEY_LANG9
-
enumerator KEY_ALTERASE
-
enumerator KEY_SYSREQ
-
enumerator KEY_CANCEL
-
enumerator KEY_CLEAR
-
enumerator KEY_PRIOR
-
enumerator KEY_RETURN2
-
enumerator KEY_SEPARATOR
-
enumerator KEY_OUT
-
enumerator KEY_OPER
-
enumerator KEY_CLEARAGAIN
-
enumerator KEY_CRSEL
-
enumerator KEY_EXSEL
-
enumerator KEY_KEYPAD_00
-
enumerator KEY_KEYPAD_000
-
enumerator KEY_THOUSANDSSEPARATOR
-
enumerator KEY_DECIMALSEPARATOR
-
enumerator KEY_CURRENCYUNIT
-
enumerator KEY_CURRENCYSUBUNIT
-
enumerator KEY_KEYPAD_LEFTPAREN
-
enumerator KEY_KEYPAD_RIGHTPAREN
-
enumerator KEY_KEYPAD_LEFTBRACE
-
enumerator KEY_KEYPAD_RIGHTBRACE
-
enumerator KEY_KEYPAD_TAB
-
enumerator KEY_KEYPAD_BACKSPACE
-
enumerator KEY_KEYPAD_A
-
enumerator KEY_KEYPAD_B
-
enumerator KEY_KEYPAD_C
-
enumerator KEY_KEYPAD_D
-
enumerator KEY_KEYPAD_E
-
enumerator KEY_KEYPAD_F
-
enumerator KEY_KEYPAD_XOR
-
enumerator KEY_KEYPAD_POWER
-
enumerator KEY_KEYPAD_PERCENT
-
enumerator KEY_KEYPAD_LESS
-
enumerator KEY_KEYPAD_GREATER
-
enumerator KEY_KEYPAD_AMPERSAND
-
enumerator KEY_KEYPAD_DBLAMPERSAND
-
enumerator KEY_KEYPAD_VERTICALBAR
-
enumerator KEY_KEYPAD_DBLVERTICALBAR
-
enumerator KEY_KEYPAD_COLON
-
enumerator KEY_KEYPAD_HASH
-
enumerator KEY_KEYPAD_SPACE
-
enumerator KEY_KEYPAD_AT
-
enumerator KEY_KEYPAD_EXCLAM
-
enumerator KEY_KEYPAD_MEMSTORE
-
enumerator KEY_KEYPAD_MEMRECALL
-
enumerator KEY_KEYPAD_MEMCLEAR
-
enumerator KEY_KEYPAD_MEMADD
-
enumerator KEY_KEYPAD_MEMSUBTRACT
-
enumerator KEY_KEYPAD_MEMMULTIPLY
-
enumerator KEY_KEYPAD_MEMDIVIDE
-
enumerator KEY_KEYPAD_PLUSMINUS
-
enumerator KEY_KEYPAD_CLEAR
-
enumerator KEY_KEYPAD_CLEARENTRY
-
enumerator KEY_KEYPAD_BINARY
-
enumerator KEY_KEYPAD_OCTAL
-
enumerator KEY_KEYPAD_DECIMAL
-
enumerator KEY_KEYPAD_HEXADECIMAL
-
enumerator KEY_LEFT_CTRL
-
enumerator KEY_LEFT_SHIFT
-
enumerator KEY_LEFT_ALT
-
enumerator KEY_LEFT_GUI
-
enumerator KEY_RIGHT_CTRL
-
enumerator KEY_RIGHT_SHIFT
-
enumerator KEY_RIGHT_ALT
-
enumerator KEY_RIGHT_GUI
-
enumerator KEY_MODE
-
enumerator KEY_AUDIONEXT
-
enumerator KEY_AUDIOPREV
-
enumerator KEY_AUDIOSTOP
-
enumerator KEY_AUDIOPLAY
-
enumerator KEY_AUDIOMUTE
-
enumerator KEY_MEDIASELECT
-
enumerator KEY_AC_SEARCH
-
enumerator KEY_AC_HOME
-
enumerator KEY_AC_BACK
-
enumerator KEY_AC_FORWARD
-
enumerator KEY_AC_STOP
-
enumerator KEY_AC_REFRESH
-
enumerator KEY_AC_BOOKMARKS
-
enumerator KEY_EJECT
-
enumerator KEY_SLEEP
-
enumerator KEY_MAX
-
enumerator KEY_UNKNOWN
Functions
-
binocle_input binocle_input_new()
Creates a new input manager.
- Returns:
the input manager instance
-
void binocle_input_update(binocle_input *input)
Updates the input manager. This function should be called at every frame update as it consumes the SDL events and sets the appropriate values.
- Parameters:
input – the input manager instance
-
bool binocle_input_is_printable(SDL_Keycode key)
Checks whether an SDL keycode can be printed as an ASCII character.
- Parameters:
key – the SDL keycode
- Returns:
true if the keycode is a printable ASCII character
-
bool binocle_input_is_key_down(binocle_input input, int key)
Checks if a key has just been pressed.
- Parameters:
input – the input manager
key – the key to check
- Returns:
true if the key is being held down at the current frame and wasn’t at the previous one.
-
bool binocle_input_is_key_up(binocle_input input, int key)
Checks if a key has just been released.
- Parameters:
input – the input manager
key – the key to check
- Returns:
true if the key has been released at the current frame while it was held down at the previous one.
-
bool binocle_input_is_key_pressed(binocle_input *input, binocle_input_keyboard_key key)
Checks if a key is currently pressed, no matter the previous state.
- Parameters:
input – the input manager
key – the key to check
- Returns:
true if the key is pressed at the current frame
-
bool binocle_input_shift(binocle_input input)
Checks if one of the SHIFT keys is currently pressed, no matter the previous state.
- Parameters:
input – the input manager
- Returns:
true if one of the SHIFT keys is pressed at the current frame
-
bool binocle_input_left_shift(binocle_input input)
Checks if the LEFT SHIFT key is currently pressed, no matter the previous state.
- Parameters:
input – the input manager
- Returns:
true if the LEFT SHIFT keys is pressed at the current frame
-
bool binocle_input_right_shift(binocle_input input)
Checks if the RIGHT SHIFT key is currently pressed, no matter the previous state.
- Parameters:
input – the input manager
- Returns:
true if the RIGHT SHIFT keys is pressed at the current frame
-
bool binocle_input_ctrl(binocle_input input)
Checks if one of the CTRL keys is currently pressed, no matter the previous state.
- Parameters:
input – the input manager
- Returns:
true if one of the CTRL keys is pressed at the current frame
-
bool binocle_input_left_ctrl(binocle_input input)
Checks if the LEFT CTRL key is currently pressed, no matter the previous state.
- Parameters:
input – the input manager
- Returns:
true if the LEFT CTRL keys is pressed at the current frame
-
bool binocle_input_right_ctrl(binocle_input input)
Checks if the RIGHT CTRL key is currently pressed, no matter the previous state.
- Parameters:
input – the input manager
- Returns:
true if the RIGHT CTRL keys is pressed at the current frame
-
bool binocle_input_alt(binocle_input input)
Checks if one of the ALT keys is currently pressed, no matter the previous state.
- Parameters:
input – the input manager
- Returns:
true if one of the ALT keys is pressed at the current frame
-
bool binocle_input_left_alt(binocle_input input)
Checks if the LEFT ALT key is currently pressed, no matter the previous state.
- Parameters:
input – the input manager
- Returns:
true if the LEFT ALT keys is pressed at the current frame
-
bool binocle_input_right_alt(binocle_input input)
Checks if the RIGHT ALT key is currently pressed, no matter the previous state.
- Parameters:
input – the input manager
- Returns:
true if the RIGHT ALT keys is pressed at the current frame
-
bool binocle_input_is_mouse_down(binocle_input input, binocle_input_mouse_button button)
Checks if a mouse button has just been pressed.
See also
binocle_input_mouse_button
- Parameters:
input – the input manager
button – the button to check,
- Returns:
true if the mouse button is being held down at the current frame and wasn’t at the previous one.
-
bool binocle_input_is_mouse_up(binocle_input input, binocle_input_mouse_button button)
Checks if a mouse button has just been released.
See also
binocle_input_mouse_button
- Parameters:
input – the input manager
button – the button to check,
- Returns:
true if the mouse button has been released at the current frame while it was held down at the previous one.
-
bool binocle_input_is_mouse_pressed(binocle_input input, binocle_input_mouse_button button)
Checks if a mouse button is currently pressed, no matter the previous state.
See also
binocle_input_mouse_button
- Parameters:
input – the input manager
button – the button to check,
- Returns:
true if the mouse button is pressed at the current frame
-
int binocle_input_get_mouse_x(binocle_input input)
Gets the mouse X position in screen space.
- Parameters:
input – the input manager
- Returns:
the mouse X position in screen space
-
int binocle_input_get_mouse_y(binocle_input input)
Gets the mouse Y position in screen space.
- Parameters:
input – the input manager
- Returns:
the mouse Y position in screen space
-
bool binocle_input_quit_requested(binocle_input input)
Checks if the user requested to quit the application either by pressing the combination of keys or by clicking on the close window icon.
- Parameters:
input – the input manager
- Returns:
true if the user requested to terminate the application
-
bool binocle_input_pause_requested(binocle_input input)
Checks if the application is going into pause by losing the window focus.
- Parameters:
input – the input manager
- Returns:
true if the window has lost focus and the application should go into pause
-
bool binocle_input_is_mouse_inside(binocle_input input, kmAABB2 rectangle)
Checks if the mouse coordinates are inside a bounding box (screen space coordinates)
- Parameters:
input – the input manager
rectangle – the bounding box
- Returns:
true if the mouse is inside the bounding box
-
kmVec2 binocle_input_get_mouse_position(binocle_input input, struct binocle_camera camera)
Returns a vector with the X and Y coordinates of the mouse cursor in world space.
- Parameters:
input – the input manager
camera – the camera used to offset the mouse position to find the world space coordinates
- Returns:
-
bool binocle_input_is_printable_key_down(binocle_input input)
Checks if the current key being held down is a printable ASCII character.
- Parameters:
input – the input manager
- Returns:
true if the current key held down is a printable ASCII character
-
const char binocle_input_get_cur_printable_key(binocle_input input)
Gets the current printable character.
- Parameters:
input – the input manager
- Returns:
the printable character
-
void binocle_input_lock(binocle_input input)
Locks user input.
- Parameters:
input – the input manager
-
void binocle_input_unlock(binocle_input input)
Unlocks user input.
- Parameters:
input – the input manager
-
bool binocle_input_is_touch_down(binocle_input input, unsigned int finger)
Checks if the given finger is being held down on a touch screen.
- Parameters:
input – the input manager
finger – the index of the finger
- Returns:
true if the finger is being held down
-
kmVec2 binocle_input_get_touch_position(binocle_input input, unsigned int finger, struct binocle_camera camera)
Gets the current position of the given finger in world coordinates.
- Parameters:
finger – the index of the finger
camera – the camera used to offset the position to convert to world coordinates
- Returns:
the position of the finger in world coordinates
-
void binocle_input_invert_mouse_position(binocle_input *input, uint32_t screen_height)
Inverts the mouse position setting the origin at the bottom-left of the screen. If the window/screen size changes you have to call this function again to set the new height.
- Parameters:
input – the iunput manager
screen_height – the height of the screen, used to calculate the mouse origin
-
void binocle_input_default_mouse_position(binocle_input *input)
Sets the mouse position to have the origin at the top-left of the screen.
- Parameters:
input – the input manager
-
struct binocle_input_touch
-
struct binocle_input
Public Members
-
bool quit_requested
-
int mouseX
Current mouse X position.
-
int mouseY
Current mouse Y position.
-
int mouseWheelX
Current mouse wheel X value.
-
int mouseWheelY
Current mouse wheel Y value.
-
binocle_input_keyboard_key curPrintableKey
If the user pressed a printable key, this is where it’ll be stored.
-
bool isLocked
Tells if the input manager is currently locked.
-
bool willPause
Tells if we must pause tha game (i.e. lost window focus)
-
bool force_skip_pause
If true we ignore the
willPauseflag and keep running at full speed.
-
bool resized
-
kmVec2 newWindowSize
-
binocle_input_touch touch
-
char text[BINOCLE_INPUT_TEXT_SIZE]
-
bool inverted_mouse_position
By default the mouse position has the origin at the top-left of the screen. When this is set to true, we consider the origin at the bottom-left instead.
-
uint32_t screen_height
The screen height, used to calculate the inverted mouse position.
-
bool quit_requested