Version 2, last updated by wycc at August 17, 2010 14:58 UTC

Event integration

The event integration is easy part. We cna use the connect function of the window to deliver the events to the MadButterfly

this->window->onHandleInput->connect(sigc::mem_fun(this,&MMSMadButterfly::onHandleInput));

The MMSMadButterfly::onHandleInput will convert the Disko event into the MadButterfly events. It will be very similiar with the flash function.

The MadButterfly use the observer pattern to deliver the events(EventDispatch). In the onHandleInput, we will convert the input into the mouse and keyboard events.

Mouse events

For the mouse events, we need to find the object that should receive the events by using find_shape_at_pos

shape = find_shape_at_pos(rdman, x, y, &in_stroke);

and then send events to the shape according to its type

static void notify_coord_or_shape(redraw_man_t *rdman,
                               mb_obj_t *obj,
                               co_aix x, co_aix y, int etype,
                               unsigned int state,
                               unsigned int button) {
    mouse_event_t mouse_event;
    subject_t *subject;

    mouse_event.event.type = etype;
    mouse_event.x = x;
    mouse_event.y = y;
    mouse_event.but_state = state;
    mouse_event.button = button;

    if(IS_MBO_SHAPES(obj))
        subject = sh_get_mouse_event_subject((shape_t *)obj);
    else
        subject = coord_get_mouse_event((coord_t *)obj);

    subject_notify(subject, (event_t *)&mouse_event);
}

Keyboard events

For the keyboard events, we will convert it to the Madbutterfly key object and send it to the global key observer. Currently, the MadButterfly has only one key observer and all pages should use it. This may change in the future. By that time, we need to modify the key dispatcher here.