feat: added compositeaxis1d_from_keys and from_buttons
This required moving InputDelegateFn from input.h to input_axis.h
This commit is contained in:
parent
1dc6f8352a
commit
aca01507ed
4 changed files with 21 additions and 12 deletions
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
struct PlayerInput;
|
||||
|
||||
typedef void (*InputDelegateFn)(void* self, InputEvent event);
|
||||
|
||||
typedef struct InputListener {
|
||||
void* self;
|
||||
InputDelegateFn fn;
|
||||
|
|
|
|||
|
|
@ -225,3 +225,17 @@ void compositeaxis1d_drop(CompositeAxis1D* self) {
|
|||
self->right.drop->drop(self->right.data);
|
||||
free(self);
|
||||
}
|
||||
|
||||
CompositeAxis1D* compositeaxis1d_from_keys(SDL_Scancode negative, SDL_Scancode positive) {
|
||||
return compositeaxis1d_new(
|
||||
KeyBind_as_InputAxis(keybind_new(negative)),
|
||||
KeyBind_as_InputAxis(keybind_new(positive)),
|
||||
InputEvent_Float);
|
||||
}
|
||||
|
||||
CompositeAxis1D* compositeaxis1d_from_buttons(int negative, int positive) {
|
||||
return compositeaxis1d_new(
|
||||
ControllerButton_as_InputAxis(controllerbutton_new(negative)),
|
||||
ControllerButton_as_InputAxis(controllerbutton_new(positive)),
|
||||
InputEvent_Float);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ typedef struct {
|
|||
IDrop const* drop;
|
||||
} InputAxis;
|
||||
|
||||
typedef void (*InputDelegateFn)(void* self, InputEvent event);
|
||||
|
||||
#define impl_InputAxis_for(T, is_changed_by_f, evaluate_f, set_device_f)\
|
||||
InputAxis T##_as_InputAxis(T* x) {\
|
||||
TC_FN_TYPECHECK(int, is_changed_by_f, T*, SDL_Event);\
|
||||
|
|
@ -105,6 +107,9 @@ extern struct InputEvent compositeaxis1d_evaluate(CompositeAxis1D* self, SDL_Eve
|
|||
extern void compositeaxis1d_set_device(CompositeAxis1D* self, struct InputDevice* device);
|
||||
extern void compositeaxis1d_drop(CompositeAxis1D* self);
|
||||
|
||||
extern CompositeAxis1D* compositeaxis1d_from_keys(SDL_Scancode negative, SDL_Scancode positive);
|
||||
extern CompositeAxis1D* compositeaxis1d_from_buttons(int negative, int positive);
|
||||
|
||||
decl_typeclass_impl(InputAxis, CompositeAxis1D)
|
||||
decl_typeclass_impl(Drop, CompositeAxis1D)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue