added scrollY functions

This commit is contained in:
herbglitch 2023-02-23 16:31:18 -07:00
parent b2055f667c
commit 7fe9d6d491
3 changed files with 15 additions and 7 deletions

View file

@ -6,6 +6,7 @@ extern "C" {
#endif #endif
#include "arc/math/point.h" #include "arc/math/point.h"
#include <stdint.h>
typedef struct ARC_Mouse ARC_Mouse; typedef struct ARC_Mouse ARC_Mouse;
@ -32,6 +33,7 @@ void ARC_Mouse_Destroy(ARC_Mouse *mouse);
void ARC_Mouse_Update(ARC_Mouse *mouse); void ARC_Mouse_Update(ARC_Mouse *mouse);
ARC_Point *ARC_Mouse_GetCoords(ARC_Mouse *mouse); ARC_Point *ARC_Mouse_GetCoords(ARC_Mouse *mouse);
ARC_MouseState ARC_Mouse_GetState(ARC_Mouse *mouse, ARC_MouseButton button); ARC_MouseState ARC_Mouse_GetState(ARC_Mouse *mouse, ARC_MouseButton button);
int32_t *ARC_Mouse_GetScrollY(ARC_Mouse *mouse);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -9,7 +9,7 @@
struct ARC_Mouse { struct ARC_Mouse {
SDL_Event *event; SDL_Event *event;
ARC_Point *coords; ARC_Point *coords;
int32_t *scroll; int32_t *scrollY;
ARC_MouseState *buttons; ARC_MouseState *buttons;
uint8_t *buttonsReleased; uint8_t *buttonsReleased;

View file

@ -12,13 +12,13 @@ void ARC_Mouse_Create(ARC_Mouse **mouse, ARC_MouseInfo *info){
*mouse = (ARC_Mouse *)malloc(sizeof(ARC_Mouse)); *mouse = (ARC_Mouse *)malloc(sizeof(ARC_Mouse));
(*mouse)->event = info->event; (*mouse)->event = info->event;
(*mouse)->coords = (ARC_Point *)malloc(sizeof(ARC_Point)); (*mouse)->coords = (ARC_Point *)malloc(sizeof(ARC_Point));
(*mouse)->scroll = (int32_t *)malloc(sizeof(int32_t )); (*mouse)->scrollY = (int32_t *)malloc(sizeof(int32_t ));
(*mouse)->buttons = (ARC_MouseState *)malloc(sizeof(ARC_MouseState) * ARC_MOUSE_BUTTON_NUM); (*mouse)->buttons = (ARC_MouseState *)malloc(sizeof(ARC_MouseState) * ARC_MOUSE_BUTTON_NUM);
(*mouse)->buttonsReleased = (uint8_t *)malloc(sizeof(uint8_t)); (*mouse)->buttonsReleased = (uint8_t *)malloc(sizeof(uint8_t));
*(*mouse)->coords = (ARC_Point){0, 0}; *(*mouse)->coords = (ARC_Point){0, 0};
*(*mouse)->scroll = 0; *(*mouse)->scrollY = 0;
for(uint8_t i = 0; i < ARC_MOUSE_BUTTON_NUM; i++){ for(uint8_t i = 0; i < ARC_MOUSE_BUTTON_NUM; i++){
(*mouse)->buttons[i] = ARC_MOUSE_NONE; (*mouse)->buttons[i] = ARC_MOUSE_NONE;
@ -31,7 +31,7 @@ void ARC_Mouse_Destroy(ARC_Mouse *mouse){
free(mouse->buttonsReleased); free(mouse->buttonsReleased);
free(mouse->buttons); free(mouse->buttons);
free(mouse->scroll ); free(mouse->scrollY);
free(mouse->coords ); free(mouse->coords );
free(mouse); free(mouse);
@ -58,9 +58,9 @@ void ARC_Mouse_UpdateButton(ARC_Mouse *mouse, uint8_t button, uint32_t *buttons,
} }
void ARC_Mouse_Update(ARC_Mouse *mouse){ void ARC_Mouse_Update(ARC_Mouse *mouse){
*mouse->scroll = 0; *mouse->scrollY = 0;
if(mouse->event->type == SDL_MOUSEWHEEL){ if(mouse->event->type == SDL_MOUSEWHEEL){
*mouse->scroll = mouse->event->wheel.y; *mouse->scrollY = mouse->event->wheel.y;
} }
uint32_t buttons = SDL_GetMouseState(&(mouse->coords->x), &(mouse->coords->y)); uint32_t buttons = SDL_GetMouseState(&(mouse->coords->x), &(mouse->coords->y));
@ -89,6 +89,8 @@ void ARC_Mouse_Update(ARC_Mouse *mouse){
ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_RIGHT , &buttons, SDL_BUTTON_RMASK ); ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_RIGHT , &buttons, SDL_BUTTON_RMASK );
ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_X1 , &buttons, SDL_BUTTON_X1MASK); ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_X1 , &buttons, SDL_BUTTON_X1MASK);
ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_X2 , &buttons, SDL_BUTTON_X2MASK); ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_X2 , &buttons, SDL_BUTTON_X2MASK);
} }
ARC_Point *ARC_Mouse_GetCoords(ARC_Mouse *mouse){ ARC_Point *ARC_Mouse_GetCoords(ARC_Mouse *mouse){
@ -99,4 +101,8 @@ ARC_MouseState ARC_Mouse_GetState(ARC_Mouse *mouse, ARC_MouseButton button){
return mouse->buttons[button]; return mouse->buttons[button];
} }
int32_t *ARC_Mouse_GetScrollY(ARC_Mouse *mouse){
return mouse->scrollY;
}
#endif // ARC_SDL #endif // ARC_SDL