Mercurial > MadButterfly
comparison src/redraw_man.c @ 231:2637519e2bd7
Move mouse event handler and interpreter to src/mouse.c.
- Also change makefiles of examples with a better configuration.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 18 Dec 2008 22:37:15 +0800 |
parents | 29e1b2bffe4c |
children | 65cabbdd5284 |
comparison
equal
deleted
inserted
replaced
230:3e6da6f6a226 | 231:2637519e2bd7 |
---|---|
240 } | 240 } |
241 | 241 |
242 static void mouse_event_root_dummy(event_t *evt, void *arg) { | 242 static void mouse_event_root_dummy(event_t *evt, void *arg) { |
243 } | 243 } |
244 | 244 |
245 static void mouse_event_interpreter(event_t *evt, void *arg) { | |
246 mouse_event_t *mevt = (mouse_event_t *)evt; | |
247 redraw_man_t *rdman = (redraw_man_t *)arg; | |
248 mb_obj_t *obj; | |
249 mouse_event_t new_evt; | |
250 coord_t *coord; | |
251 shape_t *shape; | |
252 | |
253 ASSERT(evt->type == EVT_MOUSE_MOVE_RAW); | |
254 | |
255 obj = (mb_obj_t *)subject_get_object(evt->cur_tgt); | |
256 if(rdman->last_mouse_over == obj) { | |
257 evt->type = EVT_MOUSE_MOVE; | |
258 return; | |
259 } | |
260 | |
261 new_evt.x = mevt->x; | |
262 new_evt.y = mevt->y; | |
263 new_evt.but_state = mevt->but_state; | |
264 new_evt.button = mevt->button; | |
265 | |
266 if(rdman->last_mouse_over != NULL) { | |
267 new_evt.event.type = EVT_MOUSE_OUT; | |
268 if(IS_MBO_COORD(rdman->last_mouse_over)) { | |
269 coord = (coord_t *)rdman->last_mouse_over; | |
270 subject_notify(coord->mouse_event, (event_t *)&new_evt); | |
271 } else if(IS_MBO_SHAPES(rdman->last_mouse_over)) { | |
272 shape = (shape_t *)rdman->last_mouse_over; | |
273 ASSERT(shape->geo != NULL); | |
274 subject_notify(shape->geo->mouse_event, (event_t *)&new_evt); | |
275 } | |
276 } | |
277 | |
278 new_evt.event.type = EVT_MOUSE_OVER; | |
279 subject_notify(evt->cur_tgt, (event_t *)&new_evt); | |
280 rdman->last_mouse_over = obj; | |
281 | |
282 evt->flags |= EVTF_STOP_NOTIFY; | |
283 } | |
284 | |
285 static void addrm_monitor_hdlr(event_t *evt, void *arg) { | |
286 monitor_event_t *mevt; | |
287 redraw_man_t *rdman; | |
288 mb_obj_t *obj; | |
289 mb_prop_store_t *props; | |
290 observer_t *observer; | |
291 int cnt = 0; | |
292 | |
293 mevt = (monitor_event_t *)evt; | |
294 rdman = (redraw_man_t *)evt->tgt; | |
295 obj = (mb_obj_t *)subject_get_object(mevt->subject); | |
296 props = mb_obj_prop_store(obj); | |
297 | |
298 switch(evt->type) { | |
299 case EVT_MONITOR_ADD: | |
300 if(!mb_prop_has(props, PROP_MEVT_OB_CNT)) | |
301 cnt = 0; | |
302 else | |
303 cnt = (int)mb_prop_get(props, PROP_MEVT_OB_CNT); | |
304 | |
305 cnt++; | |
306 mb_prop_set(props, PROP_MEVT_OB_CNT, (void *)cnt); | |
307 if(cnt == 1) { | |
308 observer = | |
309 subject_add_event_observer_head(mevt->subject, | |
310 EVT_MOUSE_MOVE_RAW, | |
311 mouse_event_interpreter, | |
312 rdman); | |
313 ASSERT(observer != NULL); | |
314 mb_prop_set(props, PROP_MEVT_OBSERVER, observer); | |
315 } | |
316 break; | |
317 | |
318 case EVT_MONITOR_REMOVE: | |
319 cnt = (int)mb_prop_get(props, PROP_MEVT_OB_CNT); | |
320 cnt--; | |
321 mb_prop_set(props, PROP_MEVT_OB_CNT, (void *)cnt); | |
322 if(cnt == 1) { | |
323 observer = (observer_t *)mb_prop_get(props, PROP_MEVT_OBSERVER); | |
324 subject_remove_observer(mevt->subject, observer); | |
325 mb_prop_del(props, PROP_MEVT_OBSERVER); | |
326 } | |
327 break; | |
328 | |
329 case EVT_MONITOR_FREE: | |
330 break; | |
331 } | |
332 } | |
333 | |
334 int redraw_man_init(redraw_man_t *rdman, cairo_t *cr, cairo_t *backend) { | 245 int redraw_man_init(redraw_man_t *rdman, cairo_t *cr, cairo_t *backend) { |
335 extern void redraw_man_destroy(redraw_man_t *rdman); | 246 extern void redraw_man_destroy(redraw_man_t *rdman); |
336 extern int _paint_color_size; | 247 extern int _paint_color_size; |
337 observer_t *addrm_ob; | 248 observer_t *addrm_ob; |
249 extern void addrm_monitor_hdlr(event_t *evt, void *arg); | |
338 | 250 |
339 memset(rdman, 0, sizeof(redraw_man_t)); | 251 memset(rdman, 0, sizeof(redraw_man_t)); |
340 | 252 |
341 rdman->geo_pool = elmpool_new(sizeof(geo_t), 128); | 253 rdman->geo_pool = elmpool_new(sizeof(geo_t), 128); |
342 rdman->coord_pool = elmpool_new(sizeof(coord_t), 16); | 254 rdman->coord_pool = elmpool_new(sizeof(coord_t), 16); |