SDL_MouseButtonEvent(3type)

πŸ’– SDL_MouseButtonEvent πŸ’–

okay bestie, we're looking at the SDL_MouseButtonEvent page from the SDL3 DATATYPES section of the SDL3 manual, and it's literally the blueprint for every single time your mouse gets clicked. no cap.


✨ NAME ✨

SDL_MouseButtonEvent β€” the mouse button event structure (aka event.button.*, iykyk)


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <SDL3/SDL_events.h>

typedef struct SDL_MouseButtonEvent
{
    SDL_EventType type; /**< SDL_EVENT_MOUSE_BUTTON_DOWN or SDL_EVENT_MOUSE_BUTTON_UP */
    Uint32 reserved;
    Uint64 timestamp;   /**< In nanoseconds, populated using SDL_GetTicksNS() */
    SDL_WindowID windowID; /**< The window with mouse focus, if any */
    SDL_MouseID which;  /**< The mouse instance id in relative mode, SDL_TOUCH_MOUSEID for touch events, or 0 */
    Uint8 button;       /**< The mouse button index */
    bool down;          /**< true if the button is pressed */
    Uint8 clicks;       /**< 1 for single-click, 2 for double-click, etc. */
    Uint8 padding;
    float x;            /**< X coordinate, relative to window */
    float y;            /**< Y coordinate, relative to window */
} SDL_MouseButtonEvent;

🌸 DESCRIPTION 🌸

so. this struct is the whole moment when a mouse button goes down or comes back up. it's giving "the plot twist AND the resolution in one tidy lil package." πŸŽ€

let's go field by field, because every single one of them is doing something and we are NOT skipping anybody:

  • type β€” the main character energy field. it's either SDL_EVENT_MOUSE_BUTTON_DOWN or SDL_EVENT_MOUSE_BUTTON_UP, so like, you already know which half of the click you're in. πŸ’…
  • reserved β€” it's Uint32 and it is reserved. that's it. that's the whole personality. leave it alone, bestie. πŸ™ˆ
  • timestamp β€” measured in nanoseconds, populated using SDL_GetTicksNS(). that's how you know exactly when the click happened, down to the teeny tiny tick. ⭐
  • windowID β€” an SDL_WindowID for the window with mouse focus, if any. and yes, "if any" is doing real work there β€” sometimes there just isn't one. πŸͺŸ
  • which β€” an SDL_MouseID, aka the mouse instance id in relative mode. it's SDL_TOUCH_MOUSEID for touch events, or 0. so it could be a real mouse, a touch pretending to be one, or just… zero. πŸ‘‘
  • button β€” a Uint8, the mouse button index. which button? that's the vibe check. πŸ–±οΈ
  • down β€” a bool that's true if the button is pressed. pressed = true, not pressed = not true. simple as. ✨
  • clicks β€” a Uint8 where 1 means single-click, 2 means double-click, etc. so like, it keeps counting. πŸ“ˆ
  • padding β€” Uint8 padding, just vibing in the struct, holding space. 🌈
  • x β€” a float, the X coordinate, relative to window. 🌸
  • y β€” a float, the Y coordinate, relative to window. 🌸
heads up bestie: x and y are relative to the window, not to your screen and not to your soul. don't forget it. πŸ’€

πŸ’œ AVAILABILITY πŸ’œ

this struct is available since SDL 3.2.0. so if you're on anything older, it's giving "not invited to the party." 😭


and that's the whole page, babe. this one came from the Simple Directmedia Layer manual, version SDL 3.4.18 β€” so go forth and handle your mouse buttons with main character energy. πŸ«Άβœ¨πŸ’–

πŸ“¦ where this page comes from