Table of Contents
- Purpose
- Interface
- void add_key_listener(SDL_Scancode negative, SDL_Scancode positive, input_axis_fn delegate)
- void add_mouse_listener(input_mouse_fn delegate)
- void add_scroll_listener(input_scroll_fn delegate)
- void mouse_screen_position(float* ox, float* oy)
- void mouse_world_position(float* ox, float* oy)
- int input_get_keydown(SDL_Scancode scancode)
- int input_get_mousedown(int mousebtn)
- Definitions
Purpose
Provide simple event based input functionality.
Interface
void add_key_listener(SDL_Scancode negative, SDL_Scancode positive, input_axis_fn delegate)
Attach an event callback to the stated axis. Pass 0 to negative
and a desired button to positive
to attach a single key listener. delegate
will be called every time either negative
or positive
changes.
void add_mouse_listener(input_mouse_fn delegate)
Attach an event callback for whenever the mouse changes. delegate
will be called every frame that the mouse position changes.
void add_scroll_listener(input_scroll_fn delegate)
Add an event callback for whenever the scroll wheel is moved. delegate
will be called for every frame that the scrollwheel is moved.
void mouse_screen_position(float* ox, float* oy)
Fills ox
and oy
with the horizontal and vertical mouse position in screen space. (0,0) in the top left, (1,1) in the bottom right.
void mouse_world_position(float* ox, float* oy)
Fills ox
and oy
with the horizontal and vertical mouse position in world space according to the g_active_view
.
int input_get_keydown(SDL_Scancode scancode)
returns: 1
if the key identified by scancode
is down.
int input_get_mousedown(int mousebtn)
returns: 1
if the mouse button of number mousebtn
is down.
Definitions
input_axis_fn
void(*input_axis_fn)(int value)
Callback type to be used by keyboard listeners. value
will be -1 if negative is down, 1 if positive is pressed, or zero if both are up.
input_mouse_fn
void(*input_mouse_fn)(float dx, float dy)
Callback type to be used by mouse movement listeners. dx
is the horizontal delta. dy
is the vertical delta.
input_button_fn
void(*input_button_fn)(int down)
Callback type to be used by mouse button listeners. down
will be 1 if the mouse button was pressed, or 0 if the mouse button was released.
input_scroll_fn
void(*input_scroll_fn)(float delta)
Callback type to be used by mouse scroll listeners. delta
will be the amount the scrollwheel moved.