mistrial@xxxxxxxxx wrote:
ciao
First of all I make excuses myself for my English not too much corrected. I write in order to speak you to you about a problem that I have found with my first program written in C with gtk.
I have written the algorithm in order to resolve the puzzle and have set up all the graphical interface but when start the simulation does not visualize me in real Time the graphic regarding the algorithm that is under.
I enclose the code of my program with the hope that someone can gives some council to me.
You need to read this:
http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html
[...]
void dohanoi(gint N, gint da, gint a, gint usando){
int i,j,h,parz;
if (N > 0){
dohanoi(N-1,da,usando,a);
g_print("\n\nmuovo da %d --> a %d\n",da,a);
sleep(1);
for(i=disk-1;i>=0;i--){
if(asta[i][da]==0){
parz=i+1;
//salvo in h la posizione dell'anello da rimuovere(il valore contenuto nell'array riflette l'indice del vettore che contiene gli anelli)
h=asta[parz][da];
//salvo il numero dell'anello in valoreAnelloDrag.Mi servira' dopo nella sezione DROP
valoreAnelloDrag=h;
rigaAnelloDrag=parz;
//setto a 0 l'elemento trovato
asta[parz][da]=0;
//rimuovo l'anello dal container
gtk_container_remove (GTK_CONTAINER (event_box[parz][da]), ring[h]);
break;
};
};
//se non trova niente nel for vuol dire che sto togliendo il primo anello di un asta
if(asta[0][da]!=0){
h=asta[0][da];
valoreAnelloDrag=asta[0][da];
asta[0][da]=0;
//ora rimuovo il widget anello dall'event box
gtk_container_remove (GTK_CONTAINER (event_box[0][da]), ring[h]);
};
for(i=disk-1;i>=0;i--){
if(asta[i][a]==0){
asta[i][a]=valoreAnelloDrag;
//aggiungo l'anello al container
gtk_container_add (GTK_CONTAINER (event_box[i][a]), ring[valoreAnelloDrag]);
break;
};
};
for (i=0;i<=disk-1;i++){
g_print("\n");
for (j=0;j<=2;j++){
g_print("%4d",asta[i][j]);
};
};
dohanoi(N-1,usando,a,da);
};
};
What you need to do, is remove "sleep (1)" and replace it
with "return", and then deal with the catastrophy that follows :)
i.e. You need to break down your algorythm into itterations and
return to the event loop so that GTK+ can process events.
You can use something like g_timeout_add() to do this.
Cheers,
-Tristan
_______________________________________________
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list