66 lines
1.6 KiB
C
66 lines
1.6 KiB
C
#ifndef _input_h
|
|
#define _input_h
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "SDL2/SDL.h"
|
|
|
|
typedef void(*input_axis_delegate_t)(int value);
|
|
typedef void(*input_mouse_delegate_t)(float dx, float dy);
|
|
typedef void(*input_button_delegate_t)(int down);
|
|
typedef void(*input_scroll_delegate_t)(float delta);
|
|
|
|
enum INPUT_LISTENER_TYPE_T {
|
|
INPUT_LISTENER_MOUSE,
|
|
INPUT_LISTENER_AXIS,
|
|
INPUT_LISTENER_SCROLL,
|
|
INPUT_LISTENER_BUTTON,
|
|
};
|
|
|
|
typedef struct input_listener_t {
|
|
enum INPUT_LISTENER_TYPE_T type;
|
|
union {
|
|
struct {
|
|
input_axis_delegate_t delegate;
|
|
SDL_Scancode positive, negative;
|
|
int last_positive, last_negative;
|
|
} axis;
|
|
struct {
|
|
input_mouse_delegate_t delegate;
|
|
} mouse;
|
|
struct {
|
|
input_button_delegate_t delegate;
|
|
uint32_t button;
|
|
int last;
|
|
} button;
|
|
struct {
|
|
input_scroll_delegate_t delegate;
|
|
} scroll;
|
|
};
|
|
} input_listener_t;
|
|
|
|
extern const Uint8* g_key_states;
|
|
|
|
extern void add_key_listener(SDL_Scancode negative, SDL_Scancode positive,
|
|
input_axis_delegate_t delegate);
|
|
extern void add_mouse_listener(input_mouse_delegate_t delegate);
|
|
extern void add_mouse_button_listener(uint32_t button, input_button_delegate_t delegate);
|
|
extern void add_scroll_listener(input_scroll_delegate_t delegate);
|
|
extern void remove_listener_at(size_t index);
|
|
extern void mouse_screen_position(float* ox, float* oy);
|
|
extern void mouse_world_position(float* ox, float* oy);
|
|
|
|
extern void input_init();
|
|
extern void update_input();
|
|
extern void input_notify_event(SDL_Event event);
|
|
extern int input_get_keydown(SDL_Scancode scancode);
|
|
extern int input_get_mousedown(int mousebtn);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _input_h */
|