SDL_UserEvent(3)

πŸ’– SDL_UserEvent(3) πŸ’–

okay bestie, welcome to the SDL API Reference, and today's main character is SDL_UserEvent β€” the event type that is literally yours. nobody else's. not SDL's. yours. 🫢


✨ NAME ✨

SDL_UserEvent β€” a user-defined event type. it's giving "make your own event" energy, and honestly? iconic. πŸ‘‘


🌸 STRUCTURE DEFINITION 🌸

typedef struct{
  Uint8 type;
  int code;
  void *data1;
  void *data2;
} SDL_UserEvent;

no cap, that's the whole thing. four little fields, infinite possibilities. πŸ’…


πŸŽ€ STRUCTURE DATA πŸŽ€

  • type β€” ranges from SDL_USEREVENT through to SDL_NUMEVENTS-1. that's your little lane, stay in it. 🌈
  • code β€” user defined event code. you make it up, you own it. ✨
  • data1 β€” user defined data pointer. a lil void pointer with main character energy. πŸ’œ
  • data2 β€” user defined data pointer. the sequel. equally user defined. πŸ¦‹

πŸ’« DESCRIPTION πŸ’«

so here's the tea: SDL_UserEvent lives inside the user member of the structure SDL_Event. 🫧

this event is unique, fr fr β€” SDL never creates it. only you do. it's not like SDL is gonna spawn one behind your back; that's simply not a thing that happens. πŸ™ˆ

you get it into the event queue by pushing it with SDL_PushEvent. πŸ“¬

and the contents of the structure members? completely up to the programmer. lowkey the most freeing thing in this whole API. the only requirement β€” and bestie, listen, this one's non-negotiable β€” is that type is a value from SDL_USEREVENT to SDL_NUMEVENTS-1 (inclusive). that's it. that's the rule. slay. πŸ”₯


🌟 EXAMPLES 🌟

here's the vibe, copied exactly so you can steal it:

SDL_Event event;

event.type = SDL_USEREVENT;
event.user.code = my_event_code;
event.user.data1 = significant_data;
event.user.data2 = 0;
SDL_PushEvent(&event);

see how the event.user. prefix is doing all the work? that's the user member of SDL_Event, right there. πŸ’–


πŸ‘€ SEE ALSO πŸ‘€

  • SDL_Event
  • SDL_PushEvent

go read those too, iykyk. πŸ“š


aaaand that's a wrap on SDL_UserEvent(3) from the SDL API Reference! this lil gem is brought to you by SDL, dated Tue 11 Sep 2001, 23:00 β€” yes, the date is literally older than most of the internet, and it still ate. πŸ’€βœ¨ bye bestie, go push some events! πŸŽ€πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from