ALLEGRO_GET_EVENT_TYPE(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ ALLEGRO_GET_EVENT_TYPE ✨

okay so bestie, welcome to the Allegro 5 API reference manual, and today's main character is ALLEGRO_GET_EVENT_TYPE. it's giving "tiny macro, huge responsibility" πŸ’…


🌸 SYNOPSIS 🌸

#include <allegro5/allegro.h>

#define ALLEGRO_GET_EVENT_TYPE(a, b, c, d)   AL_ID(a, b, c, d)

like. that's it. that's the whole vibe. πŸŽ€


πŸ’– DESCRIPTION πŸ’–

so what this macro does is make an event type identifier, which is a 32-bit integer. periodt.

usually β€” but not necessarily β€” that identifier gets built out of four 8-bit character codes. for example:

#define MY_EVENT_TYPE   ALLEGRO_GET_EVENT_TYPE('M','I','N','E')

iconic. love that for us. πŸ¦‹

⚠️ okay important thing, no cap: IDs less than 1024 are reserved for Allegro or its addons. do not use anything lower than ALLEGRO_GET_EVENT_TYPE(0, 0, 4, 0). that range is not yours, bestie, it's spoken for. πŸ™ˆ

you should also try to make your IDs unique so they don't clash with any 3rd party code you might be using. and like β€” be creative. numbering from 1024 is not creative. that's the bare minimum and we all know it. 😭

if you need multiple identifiers, you could define them like this:

#define BASE_EVENT   ALLEGRO_GET_EVENT_TYPE('M','I','N','E')
#define BARK_EVENT   (BASE_EVENT + 0)
#define MEOW_EVENT   (BASE_EVENT + 1)
#define SQUAWK_EVENT (BASE_EVENT + 2)

/* Alternatively */
enum {
   BARK_EVENT = ALLEGRO_GET_EVENT_TYPE('M','I','N','E'),
   MEOW_EVENT,
   SQUAWK_EVENT
};

see how the enum one just... keeps going? no explicit values after the first? yeah. it's giving ✨implicit✨ and honestly it ate. πŸ“


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie. this was the Allegro reference manual, page ALLEGRO_GET_EVENT_TYPE(3alleg5) β€” go forth and make your event types unique, stay above 1024, and absolutely do not be boring about it. mwah. πŸ’œπŸ§šβœ¨

πŸ“¦ where this page comes from