File: al_init_user_event_source.3

package info (click to toggle)
allegro5 2%3A5.0.10-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 14,856 kB
  • ctags: 15,948
  • sloc: ansic: 87,540; cpp: 9,693; objc: 3,491; python: 2,057; sh: 829; makefile: 93; perl: 37; pascal: 24
file content (62 lines) | stat: -rw-r--r-- 1,624 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
.TH al_init_user_event_source 3 "" "Allegro reference manual"
.SH NAME
.PP
al_init_user_event_source \- Allegro 5 API
.SH SYNOPSIS
.IP
.nf
\f[C]
#include\ <allegro5/allegro.h>

void\ al_init_user_event_source(ALLEGRO_EVENT_SOURCE\ *src)
\f[]
.fi
.SH DESCRIPTION
.PP
Initialise an event source for emitting user events.
The space for the event source must already have been allocated.
.PP
One possible way of creating custom event sources is to derive other
structures with ALLEGRO_EVENT_SOURCE at the head, e.g.
.IP
.nf
\f[C]
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;
}
\f[]
.fi
.PP
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 \f[C]source\f[] 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).
.PP
However, it is only one technique and you are not obliged to use it.
.PP
The user event source will never be destroyed automatically.
You must destroy it manually with al_destroy_user_event_source(3).
.SH SEE ALSO
.PP
ALLEGRO_EVENT_SOURCE(3), al_destroy_user_event_source(3),
al_emit_user_event(3), ALLEGRO_USER_EVENT(3)