SDL_MouseMotionEvent(3)

✨ SDL_MouseMotionEvent ✨

okay bestie, welcome to the SDL_MouseMotionEvent page from the SDL API Reference πŸ’– this is the lil struct that tells you when somebody moved their mouse, and honestly? it's giving essential.


πŸŽ€ STRUCTURE DEFINITION πŸŽ€

here's the whole vibe, literally character for character:

typedef struct{
  Uint8 type;
  Uint8 state;
  Uint16 x, y;
  Sint16 xrel, yrel;
} SDL_MouseMotionEvent;

🌸 STRUCTURE DATA 🌸

every field, no gatekeeping:

  • type β€” it's SDL_MOUSEMOTION, that's the whole personality πŸ¦‹
  • state β€” the current button state, aka which buttons are being held down rn
  • x, y β€” the X/Y coordinates of the mouse, absolute and iconic
  • xrel, yrel β€” relative motion in the X/Y direction, the delta of it all

πŸ’… DESCRIPTION πŸ’…

so SDL_MouseMotionEvent is a member of the SDL_Event union, and it shows up whenever an event of type SDL_MOUSEMOTION gets reported. that's the lore.

simply put β€” and bestie I mean simply β€” a SDL_MOUSEMOTION type event occurs when a user moves the mouse within the application window, or when SDL_WarpMouse is called. both situations, same energy. ✨

and you don't just get one kind of coordinate, you get BOTH:

  • the absolute ones (x and y)
  • the relative ones (xrel and yrel)

...all reported along with the current button states (state). and how do you read that button state? you interpret it using the SDL_BUTTON macro (peep SDL_GetMouseState for that one, iykyk). 🫢

🌈 now here's the spicy part: if the cursor is hidden (SDL_ShowCursor(0)) and the input is grabbed (SDL_WM_GrabInput(SDL_GRAB_ON)), then the mouse will give relative motion events even when the cursor reaches the edge of the screen. no cap. but heads up β€” this is currently only implemented on Windows and Linux/Unix-a-likes. so if you're on something else, don't come for me, it's just not there yet 😭

πŸ‘‘ SEE ALSO πŸ‘‘

go read these next, fr fr:

  • SDL_Event
  • SDL_MouseButtonEvent

SDL β€” Tue 11 Sep 2001, 22:59 🌸

and that's the whole page bestie, mwah πŸ’‹ this dropped way back on Tue 11 Sep 2001, 22:59 under the SDL umbrella, and it's still serving main character energy. go move some mice. πŸ¦‹βœ¨

πŸ“¦ where this page comes from