1al_init_user_event_source(3)Library Functions Manualal_init_user_event_source(3)
2
3
4

NAME

6       al_init_user_event_source
7

SYNOPSIS

9              #include <allegro5/allegro.h>
10
11              void al_init_user_event_source(ALLEGRO_EVENT_SOURCE *src)
12

DESCRIPTION

14       Initialise an event source for emitting user events.  The space for the
15       event source must already have been allocated.
16
17       One possible way of creating custom event sources is  to  derive  other
18       structures with ALLEGRO_EVENT_SOURCE at the head, e.g.
19
20              typedef struct THING THING;
21
22              struct THING {
23                  ALLEGRO_EVENT_SOURCE event_source;
24                  int field1;
25                  int field2;
26                  /* etc. */
27              };
28
29              THING *create_thing(void)
30              {
31                  THING *thing = malloc(sizeof(THING));
32
33                  if (thing) {
34                      al_init_user_event_source(&thing->event_source);
35                      thing->field1 = 0;
36                      thing->field2 = 0;
37                  }
38
39                  return thing;
40              }
41
42       The  advantage  here  is that the THING pointer will be the same as the
43       ALLEGRO_EVENT_SOURCE pointer.  Events emitted by the event source  will
44       have  the  event source pointer as the source field, from which you can
45       get a pointer to a THING by a simple cast (after ensuring checking  the
46       event is of the correct type).
47
48       However, it is only one technique and you are not obliged to use it.
49
50       The  user event source will never be destroyed automatically.  You must
51       destroy it manually with al_destroy_user_event_source(3).
52

SEE ALSO

54       ALLEGRO_EVENT_SOURCE(3),                         al_emit_user_event(3),
55       al_destroy_user_event_source(3)
56
57
58
59Allegro reference manual                          al_init_user_event_source(3)
Impressum