[gcompris-devel] 2 programming questions
Bruno Coudoin
bcoudoin at anfora.fr
Fri Nov 16 01:05:02 UTC 2001
le jeu 15-11-2001 à 20:26, pgeorges a écrit :
> I have 2 problems and would like to know if somebody can help :
>
> 1. How to move an item at an absolute position (not a relative one). I
> am using a work around with a mix of
>
> gnome_canvas_item_get_bounds(item, &dx1, &dy1, &dx2, &dy2);
> gnome_canvas_item_move(item, xOffset-dx1, line[0]-dy2);
>
I did not find either. The shape board is full of what your doing :(
> (don't stare at parameters). This works but I would like something less
> ugly.
>
> 2. More important (here i am stuck) : I don't know how to clear a GList.
>
> If I use
> g_list_free(int_model_list);
>
I think that when you free it, then you keep the pointer to a freed
memory. It is different concept than clearing or emptying it.
Look at my code, I m using it with some success ;)
> the length of the list is not 0 !!
>
> worse if I use my helper function below, the length of the list is not
> 0, but remains the same as it was before !
>
> /* ==================================== */
> static void reset_list(GList * list) {
> int i;
> for (i=0; i<g_list_length(list); i++)
> list = g_list_remove(list, g_list_nth_data(list,0));
> }
>
First a remark, you do a for loop but do not use 'i'. It probably means
that the 'for' is not the correct answer here.
In fact, i is being increased and g_list_length(list) decreases so you
will never complete the clenup. It you have 10 elements, when i is 5,
the remaining list nth is 5 and you end the loop :(
This code works:
static void algebra_destroy_item(GnomeCanvasItem *item)
{
item_list = g_list_remove (item_list, item);
gtk_object_destroy (GTK_OBJECT(item));
}
while(g_list_length(item_list)>0)
{
item = g_list_nth_data(item_list, 0);
algebra_destroy_item(item);
}
>
> I checked the news, but It seems that I am alone not to be able to cope
> with this.
>
> Pascal
>
>
> _______________________________________________
> gcompris-devel mailing list
> gcompris-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gcompris-devel
--
Bruno Coudoin
ANFORA - http://www.anfora.fr
Tel: (33)5 61 00 34 67
More information about the Gcompris-devel
mailing list