al_init_user_event_source
void al_init_user_event_source(ALLEGRO_EVENT_SOURCE *src)
Introduced in 5.0.0
Initialise an event source for emitting user events. The space for the event source must already have been allocated.
One possible way of creating custom event sources is to derive other structures with ALLEGRO_EVENT_SOURCE at the head, e.g.
typedef struct THING THING;
struct THING {
ALLEGRO_EVENT_SOURCE event_source;
int field1;
int field2;
/* etc. */
};
THING *create_thing(void)
{
THING *thing = malloc(sizeof(THING));
if (thing) {
al_init_user_event_source(&thing->event_source);
thing->field1 = 0;
thing->field2 = 0;
}
return thing;
}
The advantage here is that the THING pointer will be the same as the ALLEGRO_EVENT_SOURCE pointer. Events emitted by the event source will have the event source pointer as the source
field, from which you can get a pointer to a THING by a simple cast (after ensuring checking the event is of the correct type).
However, it is only one technique and you are not obliged to use it.
The user event source will never be destroyed automatically. You must destroy it manually with al_destroy_user_event_source.
See also: ALLEGRO_EVENT_SOURCE, al_emit_user_event, al_destroy_user_event_source
Examples: ex_native_filechooser, ex_user_events
Most helpful discussions:
- ALLEGRO_EVENT_DISPLAY_SWITCH_OUT
- Synchronizing Threads
- I do not quite understand the custom events mentioned in the user manual
- Redrawing smoothly while display is being resized
- [A5] Destroying event sources
- Joystick Event Injection
- [A5] Event and socket messages ?
- Listeners, threads, synchronization
- Crash in d3d_shutdown
- Intro to threading and cpu free waiting for signals
Other recent discussions:
- [A5] User Event are giving me a hard time.
- [A5] simulate_keypress()?
- user event ref counting problem
- [a5] simulate keystroke?
- Generating timer event
- [A5] ideas on how to handle timers/user events/expose events in a widget class.
- Is it possible to generate keyboard events when running in the background?
- custom events
- User Events?
- [A5] does al_destroy_user_event_source free the event source memory?