From 809805a849a4ac1fc0ba037ddfdf4bf899f2dc9f Mon Sep 17 00:00:00 2001 From: Chukobyte Date: Mon, 25 Mar 2024 22:21:02 -0400 Subject: [PATCH] Adding missing mouse from refactor. --- seika/input/input.c | 5 +++++ seika/input/input.h | 6 ++++++ seika/input/sdl_input.h | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/seika/input/input.c b/seika/input/input.c index 68a4e36..5a11e11 100644 --- a/seika/input/input.c +++ b/seika/input/input.c @@ -44,6 +44,7 @@ typedef struct SkaInputState { #define DEFAULT_INPUT_STATE {0} static SkaInputState inputState = DEFAULT_INPUT_STATE; +static SkaMouse globalMouse = {0}; static SkaInputKey get_key_from_2d_axis_key(SkaInputKey axis2DKey, SkaAxisInputValues* axisInputValues, f32 axisValue); static void set_prev_input_axis_value(SkaInputKey key, SkaAxisInputValues* axisInputValues, f32 axisValue); @@ -340,6 +341,10 @@ SkaVector2 ska_input_get_axis_input(SkaInputAxis axis, SkaInputDeviceIndex devic return (SkaVector2) { .x = xKeyState->strength, .y = yKeyState->strength }; } +SkaMouse* ska_input_get_mouse() { + return &globalMouse; +} + // Input Action SkaInputActionHandle ska_input_add_input_action(const char* actionName, const SkaInputActionValue* actionValues, SkaInputDeviceIndex deviceIndex) { SKA_ASSERT(inputState.inputActionHandleIndex + 1 < SKA_INPUT_MAX_INPUT_ACTIONS); diff --git a/seika/input/input.h b/seika/input/input.h index 9b6b6f5..c569a7a 100644 --- a/seika/input/input.h +++ b/seika/input/input.h @@ -227,6 +227,10 @@ typedef enum SkaInputAxis { SkaInputAxis_RIGHT, } SkaInputAxis; +typedef struct SkaMouse { + SkaVector2 position; +} SkaMouse; + typedef struct SkaInputEvent { SkaInputSourceType sourceType; SkaInputInteractionStatus interactionStatus; @@ -265,6 +269,8 @@ bool ska_input_is_key_just_released(SkaInputKey key, SkaInputDeviceIndex deviceI f32 ska_input_get_key_strength(SkaInputKey key, SkaInputDeviceIndex deviceIndex); SkaVector2 ska_input_get_axis_input(SkaInputAxis axis, SkaInputDeviceIndex deviceIndex); +SkaMouse* ska_input_get_mouse(); + // Input Action SkaInputActionHandle ska_input_add_input_action(const char* actionName, const SkaInputActionValue* actionValues, SkaInputDeviceIndex deviceIndex); SkaInputAction* ska_input_get_input_action(SkaInputActionHandle handle, SkaInputDeviceIndex deviceIndex); diff --git a/seika/input/sdl_input.h b/seika/input/sdl_input.h index d2139a4..eedb92e 100644 --- a/seika/input/sdl_input.h +++ b/seika/input/sdl_input.h @@ -208,6 +208,12 @@ void ska_sdl_process_event(SDL_Event event) { switch (event.type) { // Mouse + case SDL_EVENT_MOUSE_MOTION: { + SkaMouse* mouse = ska_input_get_mouse(); + mouse->position = (SkaVector2){ .x = (f32)event.motion.x, .y = (f32)event.motion.y }; + break; + } + case SDL_EVENT_MOUSE_BUTTON_DOWN: case SDL_EVENT_MOUSE_BUTTON_UP: { inputEvent.sourceType = SkaInputSourceType_MOUSE;