Exemple #1
0
/* load_sprite: load all the sprites in SPRITE_INDEX and their graphics */
void load_sprites(void)
{
    size_t i, y;
    char bmpname[NAME_LN];
    scew_tree *t = NULL;
    scew_parser *p = NULL;
    scew_element *e = NULL;
    scew_element *r = NULL;
    SPRITE *s = NULL;

    /* setup the parser */
    p = scew_parser_create();
    scew_parser_ignore_whitespaces(p, 1);
    if (!scew_parser_load_file(p, SPRITE_INDEX)) {
        printf("%s\n", scew_error_expat_string(scew_error_code()));
        return;
    }
    t = scew_parser_tree(p);
    r = scew_tree_root(t);
    s = create_sprite();

    /* read all the sprites from SPRITE_INDEX */
    /* parse the SPRITE_INDEX file and outline the list with their names */
    e = scew_element_next(r, e);
    while (e) {
        strncpy(s->long_name, (char *) scew_element_name(e), LONG_NAME_LN);
        s->x = s->y = 0;
        sprite_list = append_sprite_list(s, sprite_list, &sprite_list_sz);
        e = scew_element_next(r, e);
    }

    /* load all their graphics and the sprite data */
    gfx_list = complete_sprite_list(sprite_list, sprite_list_sz, gfx_list,
                                    &gfx_list_sz);

    /* create a list_element for each of them and put them in a list */
    y = SPRITE_WIN.y;
    for (i = 0; i < sprite_list_sz; i++) {
        sprintf(bmpname, "%s0", sprite_list[i].name);
        spr_elem_lst = add_list_element(rec(SPRITE_WIN.x, y, LIST_ELEM_W,
                                            LIST_ELEM_H), 0, DEFAULT_COLOR,
                                        SEL_COLOR, sprite_list[i].name,
                                        search_gfx_list(bmpname, gfx_list,
                                                        gfx_list_sz),
                                        spr_elem_lst, &spr_elem_lst_sz);
        y += LIST_ELEM_H;
    }

    /* cleanup */
    scew_element_free(r);
    destroy_sprite(s);
    scew_element_free(e);
    scew_parser_free(p);
}
Exemple #2
0
void
scew_element_free(scew_element* element)
{
    scew_element* left = NULL;
    scew_element* right = NULL;

    if (element == NULL)
    {
        return;
    }

    left = element->left;
    right = element->right;
    if (left != NULL)
    {
        left->right = right;
    }
    if (right != NULL)
    {
        right->left = left;
    }

    free(element->name);
    free(element->contents);
    attribute_list_free(element->attributes);

    if (element->parent != NULL)
    {
 	if (element->parent->child == element)
	{
            element->parent->child = element->right;
	}
 	if (element->parent->last_child == element)
	{
            element->parent->last_child = element->left;
	}
        element->parent->n_children--;
    }

    while (element->child != NULL)
    {
        scew_element_free(element->child);
    }

    free(element);
}
Exemple #3
0
void
scew_element_list_del(scew_element* element, XML_Char const* name)
{
    unsigned int i = 0;
    unsigned int count = 0;
    scew_element** list = NULL;

    if ((element == NULL) || (name == NULL))
    {
        return;
    }

    list = scew_element_list(element, name, &count);
    if (list == NULL)
    {
        return;
    }

    for (i = 0; i < count; i++)
    {
        scew_element_free(list[i]);
    }
    scew_element_list_free(list);
}
Exemple #4
0
void
scew_element_del_by_index(scew_element* element, unsigned int idx)
{
    scew_element_free(scew_element_by_index(element, idx));
}
Exemple #5
0
void
scew_element_del_by_name(scew_element* element, XML_Char const* name)
{
    scew_element_free(scew_element_by_name(element, name));
}
Exemple #6
0
void
scew_element_del(scew_element* element)
{
    scew_element_free(element);
}