annotate src/mouse.c @ 263:755bbf274259

Manage dsc_3241.png in svg2code_ex/Makefile.am.
author Thinker K.F. Li <thinker@branda.to>
date Fri, 23 Jan 2009 23:21:27 +0800
parents 65cabbdd5284
children 1ca96c158125
rev   line source
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include "mb_types.h"
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include "mb_redraw_man.h"
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #define ASSERT(x)
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 static void mouse_event_interpreter(event_t *evt, void *arg) {
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 mouse_event_t *mevt = (mouse_event_t *)evt;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 redraw_man_t *rdman = (redraw_man_t *)arg;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 mb_obj_t *obj;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 mouse_event_t new_evt;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 coord_t *coord;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 shape_t *shape;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 ASSERT(evt->type == EVT_MOUSE_MOVE_RAW);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 obj = (mb_obj_t *)subject_get_object(evt->cur_tgt);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 if(rdman->last_mouse_over == obj) {
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 evt->type = EVT_MOUSE_MOVE;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 return;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 new_evt.x = mevt->x;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 new_evt.y = mevt->y;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 new_evt.but_state = mevt->but_state;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 new_evt.button = mevt->button;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 if(rdman->last_mouse_over != NULL) {
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 new_evt.event.type = EVT_MOUSE_OUT;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 if(IS_MBO_COORD(rdman->last_mouse_over)) {
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 coord = (coord_t *)rdman->last_mouse_over;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 231
diff changeset
31 subject_notify(coord_get_mouse_event(coord), (event_t *)&new_evt);
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 } else if(IS_MBO_SHAPES(rdman->last_mouse_over)) {
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 shape = (shape_t *)rdman->last_mouse_over;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 ASSERT(shape->geo != NULL);
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 231
diff changeset
35 subject_notify(sh_get_mouse_event_subject(shape),
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 231
diff changeset
36 (event_t *)&new_evt);
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 new_evt.event.type = EVT_MOUSE_OVER;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 subject_notify(evt->cur_tgt, (event_t *)&new_evt);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 rdman->last_mouse_over = obj;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 evt->flags |= EVTF_STOP_NOTIFY;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 /*! \brief This is event handler that observes addrm_monitor subject.
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 *
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 * addrm_monitor subject is a member of redraw manager objects.
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 * Monitor of mouse event subjects of mb_obj_t objects are set to this
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 * subject by redraw manager.
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 *
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 * addrm_monitor_hdlr() monitor adding and removing observers of mouse
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 * event subjects, and install special observers to these subjects to handle
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 * and interpret mouse events (EVT_MOUSE_MOVE_RAW).
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 */
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 void addrm_monitor_hdlr(event_t *evt, void *arg) {
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 monitor_event_t *mevt;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 redraw_man_t *rdman;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 mb_obj_t *obj;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 mb_prop_store_t *props;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 observer_t *observer;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 int cnt = 0;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 mevt = (monitor_event_t *)evt;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 rdman = (redraw_man_t *)evt->tgt;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 obj = (mb_obj_t *)subject_get_object(mevt->subject);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 props = mb_obj_prop_store(obj);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 switch(evt->type) {
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 case EVT_MONITOR_ADD:
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 if(!mb_prop_has(props, PROP_MEVT_OB_CNT))
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 cnt = 0;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 else
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 cnt = (int)mb_prop_get(props, PROP_MEVT_OB_CNT);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 cnt++;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 mb_prop_set(props, PROP_MEVT_OB_CNT, (void *)cnt);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 if(cnt == 1) {
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 observer =
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 subject_add_event_observer_head(mevt->subject,
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 EVT_MOUSE_MOVE_RAW,
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 mouse_event_interpreter,
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84 rdman);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 ASSERT(observer != NULL);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 mb_prop_set(props, PROP_MEVT_OBSERVER, observer);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 break;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 case EVT_MONITOR_REMOVE:
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 cnt = (int)mb_prop_get(props, PROP_MEVT_OB_CNT);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 cnt--;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93 mb_prop_set(props, PROP_MEVT_OB_CNT, (void *)cnt);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 if(cnt == 1) {
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 observer = (observer_t *)mb_prop_get(props, PROP_MEVT_OBSERVER);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96 subject_remove_observer(mevt->subject, observer);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97 mb_prop_del(props, PROP_MEVT_OBSERVER);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 break;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 case EVT_MONITOR_FREE:
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 break;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105