annotate src/observer.h @ 76:8706356a61b4

-
author Thinker K.F. Li <thinker@branda.to>
date Tue, 19 Aug 2008 19:14:01 +0800
parents 9ab15ebc9061
children 3645e29e4986
rev   line source
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #ifndef __OBSERVER_H_
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #define __OBSERVER_H_
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include "tools.h"
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 typedef struct _event event_t;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 typedef struct _observer observer_t;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 typedef struct _subject subject_t;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 typedef struct _mouse_event mouse_event_t;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 typedef struct _ob_factory ob_factory_t;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 typedef void (*evt_handler)(event_t *event, void *arg);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 struct _event {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 int type;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 subject_t *tgt, *cur_tgt;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 };
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 struct _observer {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 evt_handler hdr;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 void *arg;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 observer_t *next;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 };
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 struct _subject {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 int obj_type;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 void *obj;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 int flags;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 STAILQ(observer_t) observers;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 };
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 #define SUBF_STOP_PROPAGATE 0x1
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 enum {OBJT_GEO, OBJT_COORD};
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 struct _mouse_event {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 event_t event;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 int x, y;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 int button;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 };
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39
76
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
40 #define MOUSE_BUT1 0x1
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
41 #define MOUSE_BUT2 0x2
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
42 #define MOUSE_BUT3 0x4
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
43
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 /*! \brief Observer factory.
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 *
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 * It provides functions for allocation of subject and observer objects,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 * and strategy function for getting the subject of parent coord object.
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 */
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 struct _ob_factory {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 subject_t *(*subject_alloc)(ob_factory_t *factory);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 void (*subject_free)(ob_factory_t *factory, subject_t *subject);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 observer_t *(*observer_alloc)(ob_factory_t *factory);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 void (*observer_free)(ob_factory_t *factory, observer_t *observer);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 /*! This is a strategy function to get subjects of parents. */
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 subject_t *(*get_parent_subject)(ob_factory_t *factory,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 subject_t *cur_subject);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 };
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 enum {EVT_MOUSE_OVER, EVT_MOUSE_OUT, EVT_MOUSE_MOVE,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 EVT_MOUSE_BUT_PRESS, EVT_MOUSE_BUT_RELEASE};
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 extern subject_t *subject_new(ob_factory_t *factory,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 void *obj, int obj_type);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 extern void subject_free(ob_factory_t *factory, subject_t *subject);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 extern void subject_notify(ob_factory_t *factory,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 subject_t *subject, event_t *evt);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 extern observer_t *subject_add_observer(ob_factory_t *factory,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 subject_t *subject,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 evt_handler hdr, void *arg);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 extern void subject_remove_observer(ob_factory_t *factory,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 subject_t *subject,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 observer_t *observer);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 #endif /* __OBSERVER_H_ */