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 eitherSDL_EVENT_MOUSE_BUTTON_DOWNorSDL_EVENT_MOUSE_BUTTON_UP, so like, you already know which half of the click you're in. πreservedβ it'sUint32and it is reserved. that's it. that's the whole personality. leave it alone, bestie. πtimestampβ measured in nanoseconds, populated usingSDL_GetTicksNS(). that's how you know exactly when the click happened, down to the teeny tiny tick. βwindowIDβ anSDL_WindowIDfor the window with mouse focus, if any. and yes, "if any" is doing real work there β sometimes there just isn't one. πͺwhichβ anSDL_MouseID, aka the mouse instance id in relative mode. it'sSDL_TOUCH_MOUSEIDfor touch events, or0. so it could be a real mouse, a touch pretending to be one, or justβ¦ zero. πbuttonβ aUint8, the mouse button index. which button? that's the vibe check. π±οΈdownβ aboolthat'strueif the button is pressed. pressed = true, not pressed = not true. simple as. β¨clicksβ aUint8where1means single-click,2means double-click, etc. so like, it keeps counting. πpaddingβUint8padding, just vibing in the struct, holding space. πxβ afloat, the X coordinate, relative to window. πΈyβ afloat, the Y coordinate, relative to window. πΈ
heads up bestie:xandyare 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
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms