Your First MadButterfly Program.

MadButterfly use SVG as a media to adapt gap between GUI designers and application programmmers. Designers export their works with SVG format. Then some ones, designers or programmers, assign IDs to SVG tags that will be manipulated by application. For example, you have a menu that should be hidden at beginning. When user hit a button, the menu should be showed. So, we assign an ID to the group or other tags that contain all elements in menu. The ID is the name of a object that application manipulate, hide and show it.

After assigning IDs to tags, the file is translated by svg2code.py. Outputs of svg2code.py are M4 macro files. Conventional, foo.svg is translated a M4 file as foo.mb, using .mb as extension of file name. Macro files are translate to *.c and *.h files to link with application programs.

For example, to translate foo.svg with steps

foo.h declares a structure, named 'foo' and two functions, foo_new() and foo_free(). An instance of 'foo' holds all objects for foo.svg. One object, with specified ID as name, for each tag. If you don't assign one, a random one is picked. foo_new() is invoked to create and initialize a 'foo' instance. An instance is released by calling foo_free().

int main(int argc, char * const argv[]) {
    X_MB_runtime_t *rt;
    redraw_man_t *rdman;
    svg2code_ex_t *svg2code;
    ob_factory_t *factory;
    subject_t *subject;
    ex_rt_t ex_rt;

    /*
     * Initialize a runtime with XLib as backend.
     */
    rt = X_MB_new(":0.0", 800, 600);

    /*
     * Instantiate objects from a SVG file.
     */
    rdman = X_MB_rdman(rt);
    svg2code = svg2code_ex_new(rdman, rdman->root_coord);

    /*
     * Get observer factory
     */
    factory = rdman_get_ob_factory(rdman);
    /*
     * Register observers to subjects of events for objects.
     */
    subject = coord_get_mouse_event(svg2code->file_button);
    ex_rt.rt = rt;
    ex_rt.code = svg2code;
    subject_add_observer(factory, subject, file_button_handler, &ex_rt);
    subject = coord_get_mouse_event(svg2code->file_menu);
    subject_add_observer(factory, subject, file_menu_handler, &ex_rt);

    /*
     * Start handle connections, includes one to X server.
     * User start to interact with the application.
     */
    X_MB_handle_connection(rt);

    /*
     * Clean
     */
    svg2code_ex_free(svg2code);
    X_MB_free(rt);

    return 0;
}
SourceForge.net Logo