Loading...
Searching...
No Matches
mouse.h File Reference
`#include "arc/math/point.h"`
`#include <stdint.h>`

Go to the source code of this file.

## Macros

#define | ARC_MOUSE_BUTTON_NUM 5

## Typedefs

typedef struct ARC_Mouse | ARC_Mouse
typedef enum ARC_MouseState | ARC_MouseState
typedef enum ARC_MouseButton | ARC_MouseButton

## Enumerations

enum | ARC_MouseState { ARC_MOUSE_NONE , ARC_MOUSE_PRESSED , ARC_MOUSE_RELEASED }
enum | ARC_MouseButton { ARC_MOUSE_LEFT = 0 , ARC_MOUSE_MIDDLE = 1 , ARC_MOUSE_RIGHT = 2 , ARC_MOUSE_X1 = 3 , ARC_MOUSE_X2 = 4 }

## Functions

void | ARC_Mouse_CreateWithInput (ARC_Mouse **mouse, ARC_Input *input)
void | ARC_Mouse_Destroy (ARC_Mouse *mouse)
void | ARC_Mouse_Update (ARC_Mouse *mouse)
ARC_Point * | ARC_Mouse_GetCoords (ARC_Mouse *mouse)
ARC_MouseState | ARC_Mouse_GetState (ARC_Mouse *mouse, ARC_MouseButton button)
int32_t * | ARC_Mouse_GetScrollY (ARC_Mouse *mouse)

## Macro Definition Documentation

## ARC_MOUSE_BUTTON_NUM

#define ARC_MOUSE_BUTTON_NUM 5

Definition at line 32 of file mouse.h.

Referenced by ARC_Mouse_CreateWithInput().

## Typedef Documentation

## ARC_Mouse

typedef struct ARC_Mouse ARC_Mouse

Definition at line 16 of file mouse.h.

## ARC_MouseButton

typedef enum ARC_MouseButton ARC_MouseButton

## ARC_MouseState

typedef enum ARC_MouseState ARC_MouseState

## Enumeration Type Documentation

## ARC_MouseButton

enum ARC_MouseButton

Enumerator
ARC_MOUSE_LEFT |
ARC_MOUSE_MIDDLE |
ARC_MOUSE_RIGHT |
ARC_MOUSE_X1 |
ARC_MOUSE_X2 |

Definition at line 24 of file mouse.h.

{
ARC_MOUSE_LEFT = 0,
ARC_MOUSE_MIDDLE = 1,
ARC_MOUSE_RIGHT = 2,
ARC_MOUSE_X1 = 3,
ARC_MOUSE_X2 = 4
} ARC_MouseButton;
ARC_MouseButton
ARC_MouseButton
Definition mouse.h:24
ARC_MOUSE_X2
@ ARC_MOUSE_X2
Definition mouse.h:29
ARC_MOUSE_LEFT
@ ARC_MOUSE_LEFT
Definition mouse.h:25
ARC_MOUSE_RIGHT
@ ARC_MOUSE_RIGHT
Definition mouse.h:27
ARC_MOUSE_X1
@ ARC_MOUSE_X1
Definition mouse.h:28
ARC_MOUSE_MIDDLE
@ ARC_MOUSE_MIDDLE
Definition mouse.h:26

## ARC_MouseState

enum ARC_MouseState

Enumerator
ARC_MOUSE_NONE |
ARC_MOUSE_PRESSED |
ARC_MOUSE_RELEASED |

Definition at line 18 of file mouse.h.

{
ARC_MOUSE_NONE,
ARC_MOUSE_PRESSED,
ARC_MOUSE_RELEASED
} ARC_MouseState;
ARC_MouseState
ARC_MouseState
Definition mouse.h:18
ARC_MOUSE_RELEASED
@ ARC_MOUSE_RELEASED
Definition mouse.h:21
ARC_MOUSE_PRESSED
@ ARC_MOUSE_PRESSED
Definition mouse.h:20
ARC_MOUSE_NONE
@ ARC_MOUSE_NONE
Definition mouse.h:19

## Function Documentation

## ARC_Mouse_CreateWithInput()

void ARC_Mouse_CreateWithInput | ( | ARC_Mouse ** | mouse,
|  | ARC_Input * | input )

Definition at line 12 of file mouse.c.

{
*mouse = (ARC_Mouse *)malloc(sizeof(ARC_Mouse));
(*mouse)->event = input->event;
(*mouse)->coords = (ARC_Point *)malloc(sizeof(ARC_Point));
(*mouse)->scrollY = (int32_t *)malloc(sizeof(int32_t ));
(*mouse)->buttons = (ARC_MouseState *)malloc(sizeof(ARC_MouseState) * ARC_MOUSE_BUTTON_NUM);
(*mouse)->buttonsReleased = (uint8_t *)malloc(sizeof(uint8_t));
*(*mouse)->coords = (ARC_Point){0, 0};
*(*mouse)->scrollY = 0;
for(uint8_t i = 0; i < ARC_MOUSE_BUTTON_NUM; i++){
(*mouse)->buttons[i] = ARC_MOUSE_NONE;
}
*(*mouse)->buttonsReleased = 0;
}
ARC_MOUSE_BUTTON_NUM
#define ARC_MOUSE_BUTTON_NUM
Definition mouse.h:32
ARC_Point
struct ARC_Point ARC_Point
ARC_Input::event
SDL_Event * event
Definition input.h:12
ARC_Mouse
Definition mouse.h:8
ARC_Mouse::event
SDL_Event * event
Definition mouse.h:9
ARC_Point
Definition point.h:10

References ARC_MOUSE_BUTTON_NUM, ARC_MOUSE_NONE, ARC_Input::event, and ARC_Mouse::event.

Referenced by ARC_Input_CreateWithEngineData().

## ARC_Mouse_Destroy()

void ARC_Mouse_Destroy | ( | ARC_Mouse * | mouse | ) |

Definition at line 31 of file mouse.c.

{
free(mouse->buttonsReleased);
free(mouse->buttons);
free(mouse->scrollY);
free(mouse->coords );
free(mouse);
}
ARC_Mouse::coords
ARC_Point * coords
Definition mouse.h:10
ARC_Mouse::buttons
ARC_MouseState * buttons
Definition mouse.h:13
ARC_Mouse::scrollY
int32_t * scrollY
Definition mouse.h:11
ARC_Mouse::buttonsReleased
uint8_t * buttonsReleased
Definition mouse.h:14

References ARC_Mouse::buttons, ARC_Mouse::buttonsReleased, ARC_Mouse::coords, and ARC_Mouse::scrollY.

Referenced by ARC_EngineData_Destroy(), and ARC_Input_Destroy().

## ARC_Mouse_GetCoords()

ARC_Point * ARC_Mouse_GetCoords | ( | ARC_Mouse * | mouse | ) |

Definition at line 95 of file mouse.c.

{
return mouse->coords;
}

References ARC_Mouse::coords.

## ARC_Mouse_GetScrollY()

int32_t * ARC_Mouse_GetScrollY | ( | ARC_Mouse * | mouse | ) |

Definition at line 103 of file mouse.c.

{
return mouse->scrollY;
}

References ARC_Mouse::scrollY.

## ARC_Mouse_GetState()

ARC_MouseState ARC_Mouse_GetState | ( | ARC_Mouse * | mouse,
|  | ARC_MouseButton | button )

Definition at line 99 of file mouse.c.

{
return mouse->buttons[button];
}

References ARC_Mouse::buttons.

## ARC_Mouse_Update()

void ARC_Mouse_Update | ( | ARC_Mouse * | mouse | ) |

Definition at line 61 of file mouse.c.

{
*mouse->scrollY = 0;
if(mouse->event->type == SDL_MOUSEWHEEL){
*mouse->scrollY = mouse->event->wheel.y;
}
uint32_t buttons = SDL_GetMouseState(&(mouse->coords->x), &(mouse->coords->y));
if(mouse->event->type != SDL_MOUSEBUTTONDOWN && mouse->event->type != SDL_MOUSEBUTTONUP){
if(!*mouse->buttonsReleased){
return;
}
for(uint8_t i = *mouse->buttonsReleased; i > 0; i--){
if(mouse->buttons[i - 1] == ARC_MOUSE_RELEASED){
mouse->buttons[i - 1] = ARC_MOUSE_NONE;
--*mouse->buttonsReleased;
}
}
// if(*mouse->buttonsReleased){
// arc_errno = ARC_ERRNO_DATA;
// ARC_DEBUG_LOG(arc_errno, "in ARC_Mouse_Update mouse->buttonsReleased == %u, it needs to be 0\n", *(mouse->buttonsReleased));
// }
return;
}
ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_LEFT , &buttons, SDL_BUTTON_LMASK );
ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_MIDDLE, &buttons, SDL_BUTTON_MMASK );
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_X2 , &buttons, SDL_BUTTON_X2MASK);
}
ARC_Mouse_UpdateButton
void ARC_Mouse_UpdateButton(ARC_Mouse *mouse, uint8_t button, uint32_t *buttons, uint32_t mask)
Definition mouse.c:41
ARC_Point::y
int32_t y
Definition point.h:12
ARC_Point::x
int32_t x
Definition point.h:11

References ARC_MOUSE_LEFT, ARC_MOUSE_MIDDLE, ARC_MOUSE_NONE, ARC_MOUSE_RELEASED, ARC_MOUSE_RIGHT, ARC_Mouse_UpdateButton(), ARC_MOUSE_X1, ARC_MOUSE_X2, ARC_Mouse::buttons, ARC_Mouse::buttonsReleased, ARC_Mouse::coords, ARC_Mouse::event, ARC_Mouse::scrollY, ARC_Point::x, and ARC_Point::y.

Referenced by ARC_Input_Update().