annotate src/mouse.c @ 868:f41ac71266bc

Remove rdman pointer from structure of paints. Since a pointer of rdman is passed when calling free function of paint, this pointer can be removed.
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 23 Sep 2010 10:51:25 +0800
parents 586e50f82c1f
children
rev   line source
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 315
diff changeset
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 315
diff changeset
2 // vim: sw=4:ts=8:sts=4
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #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
4 #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
5
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 #define ASSERT(x)
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 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
9 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
10 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
11 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
12 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
13 coord_t *coord;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 shape_t *shape;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 315
diff changeset
15
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 ASSERT(evt->type == EVT_MOUSE_MOVE_RAW);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 315
diff changeset
17
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 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
19 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
20 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
21 return;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 315
diff changeset
23
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 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
25 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
26 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
27 new_evt.button = mevt->button;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 315
diff changeset
28
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 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
30 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
31 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
32 coord = (coord_t *)rdman->last_mouse_over;
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 231
diff changeset
33 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
34 } 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
35 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
36 ASSERT(shape->geo != NULL);
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 231
diff changeset
37 subject_notify(sh_get_mouse_event_subject(shape),
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 315
diff changeset
38 (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
39 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 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
43 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
44 rdman->last_mouse_over = obj;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 315
diff changeset
45
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 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
47 }
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 /*! \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
50 *
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 * 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
52 * 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
53 * 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
54 *
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 * 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
56 * 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
57 * 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
58 */
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 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
60 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
61 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
62 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
63 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
64 observer_t *observer;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 int cnt = 0;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 315
diff changeset
66
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 mevt = (monitor_event_t *)evt;
315
1ca96c158125 Fix bug that examples/drag can not drag star.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
68 rdman = (redraw_man_t *)arg;
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 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
70 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
71
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 switch(evt->type) {
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 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
74 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
75 cnt = 0;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 else
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 cnt = (int)mb_prop_get(props, PROP_MEVT_OB_CNT);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 315
diff changeset
78
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 cnt++;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 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
81 if(cnt == 1) {
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 observer =
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 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
84 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
85 mouse_event_interpreter,
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 rdman);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 ASSERT(observer != NULL);
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 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
89 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 break;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 315
diff changeset
91
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 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
93 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
94 cnt--;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 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
96 if(cnt == 1) {
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97 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
98 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
99 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
100 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 break;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 315
diff changeset
102
231
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103 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
104 break;
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 }
2637519e2bd7 Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107