Skip to content

Commit

Permalink
Adding missing mouse from refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chukobyte committed Mar 26, 2024
1 parent 059c5b8 commit 809805a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions seika/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions seika/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ typedef enum SkaInputAxis {
SkaInputAxis_RIGHT,
} SkaInputAxis;

typedef struct SkaMouse {
SkaVector2 position;
} SkaMouse;

typedef struct SkaInputEvent {
SkaInputSourceType sourceType;
SkaInputInteractionStatus interactionStatus;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions seika/input/sdl_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 809805a

Please sign in to comment.