1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
gboolean DesactiverEBox (gpointer pEBox)
{
decompteur++;
printf("Entree dans DesactiverEBox\n");
if (decompteur <= 5)
{
gtk_widget_set_sensitive (GTK_WIDGET (pEBox), FALSE);
return TRUE;
}
else
{
decompteur=1;
gtk_widget_set_sensitive (GTK_WIDGET (pEBox), TRUE);
return FALSE;
}
}
gboolean ChargementImage(GtkWidget *pEBox, GdkEventMotion *event, gpointer data)
{
#ifdef DEBUG
printf("Entree dans ChargementImage\n");
#endif
//Fichier log
FILE* fp;
//Position souris
gint x1, y1;
gint x2, y2;
int coord[MAX_LIGNE][MAX_COLONNE];
//Création du nom de l'image
int i;
char nom_image[256];
//Mise à jour du label et de l'image
ParamEBox* paramEBox;
char nouveau_label[256];
//On charge dans paramEBox les paramètres passés en argument
paramEBox = (ParamEBox*)data;
if (cpt_image <= 10)
{
/** Mise à jour des labels **/
sprintf(nouveau_label,"Image n %d",cpt_image);
gtk_label_set_label(GTK_LABEL(paramEBox->Label1), nouveau_label);
gtk_label_set_label(GTK_LABEL(paramEBox->Label2), "Decompteur a realiser.");
/** Mise à jour de l'image **/
srand(time (NULL));
i = rand() % 8;
sprintf(nom_image,"%d",i);
strcat(nom_image,".png");
gtk_image_set_from_file(GTK_IMAGE (paramEBox->Image), nom_image);
/** Attente **/
printf("Avant le timeout\n");
g_timeout_add (1000, (gpointer)DesactiverEBox, pEBox);
printf("Apres le timeout\n");
/** Position de la souris **/
if (event->is_hint)
gdk_window_get_pointer (event->window, &x1, &y1, NULL);
else
{
x1 = event->x;
y1 = event->y;
}
/* Position dans l'écran */
if (event->is_hint)
gdk_window_get_pointer (gdk_screen_get_root_window(gdk_screen_get_default()),&x2, &y2, NULL);
else
{
x2 = event->x_root;
y2 = event->y_root;
}
/*Stockage des coordonnées*/
coord[0][0]=x1;
coord[0][1]=y1;
coord[0][2]=x2;
coord[0][3]=y2;
//Ecriture des coordonnées sur dans le shell et le fichier texte
printf("%d %d %d %d\n",coord[0][0],coord[0][1],coord[0][2],coord[0][3]);
fp=fopen("log.txt","a");
fprintf(fp,"%d %d %d %d\n",coord[0][0],coord[0][1],coord[0][2],coord[0][3]);
fclose(fp);
cpt_image++;
}
else//Le test est fini
{
gtk_label_set_label(GTK_LABEL(paramEBox->Label1), "Le test est termine. Vous pouvez quitter.");
gtk_label_set_label(GTK_LABEL(paramEBox->Label2), "Vous pouvez egalement commencer un nouveau test.");
DebutTestPossible = TRUE;
cpt_image=1;
gtk_widget_set_sensitive (GTK_WIDGET (pEBox), FALSE);
}
#ifdef DEBUG
printf("Sortie de ChargementImage\n");
#endif
return TRUE;
}
/***********************************************************************************************/
// Fonction main
int main(int argc,char **argv)
{
// Declaration des objets
GtkWidget *pFenetre; // Fenêtre
GtkWidget *pLabelEtat1; // Label
GtkWidget *pLabelEtat2; // Label
GtkWidget *pBoutonDemarrer; // Bouton 1
GtkWidget *pBoutonQuitter; // Bouton 2
GtkWidget *pVBox; // Boîte
GtkWidget *pHBox; // Boîte
GtkWidget *pEBox;
GtkWidget *pImage;
GtkWidget *pSeparateur1;
GtkWidget *pSeparateur2;
ParamEBox paramEBox;
ParamBoutonDemarrer paramBoutonDemarrer;
// Initialisation de l'environnement Gtk
gtk_init(&argc, &argv);
// Creation des objets
pFenetre = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size( GTK_WINDOW(pFenetre), 500, 500);
gtk_window_set_position( GTK_WINDOW(pFenetre), GTK_WIN_POS_CENTER_ALWAYS);
pLabelEtat1 = gtk_label_new("Bonjour ! Appuyer sur 'Nouveau' pour vous enregistrer et debuter le test");
pLabelEtat2 = gtk_label_new("");
pBoutonDemarrer = gtk_button_new_from_stock(GTK_STOCK_NEW);
pBoutonQuitter = gtk_button_new_from_stock(GTK_STOCK_QUIT);
pVBox = gtk_vbox_new(FALSE,0);
pHBox = gtk_hbox_new(FALSE,0);
pEBox=gtk_event_box_new();
pSeparateur1 = gtk_hseparator_new();
pSeparateur2 = gtk_hseparator_new();
pImage = gtk_image_new();
gtk_image_set_from_file(GTK_IMAGE (pImage), "1.png");
gtk_container_add(GTK_CONTAINER(pEBox), pImage);
//Désactivation de l'EventBox car le test ne commence pas tout de suite
gtk_widget_set_sensitive (GTK_WIDGET (pEBox), FALSE);
//Mise à jour des structures
paramEBox.Label1 = pLabelEtat1;
paramEBox.Label2 = pLabelEtat2;
paramEBox.Image = pImage;
paramBoutonDemarrer.Fenetre = pFenetre;
paramBoutonDemarrer.EBox = pEBox;
// Paramamétrage des objets
gtk_window_set_title(GTK_WINDOW(pFenetre), "AVANT-PROJET : Prise de mesures");
// Association de la boîte à la fenêtre
gtk_container_add(GTK_CONTAINER(pFenetre), pVBox);
// Association des différents objets à la boîte horizontale
gtk_box_pack_start(GTK_BOX(pHBox), pBoutonDemarrer, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(pHBox), pBoutonQuitter, FALSE, FALSE, 0);
// Association des différents objets à la boîte verticale
gtk_box_pack_start(GTK_BOX(pVBox), pHBox, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(pVBox), pSeparateur1, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(pVBox), pLabelEtat1, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(pVBox), pLabelEtat2, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(pVBox), pSeparateur2, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(pVBox), pEBox, FALSE, FALSE, 0);
// On associe la fonction gtk_main_quit au signal de fermeture de la fenêtre
gtk_signal_connect(GTK_OBJECT(pFenetre), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_signal_connect(GTK_OBJECT(pBoutonDemarrer), "clicked", G_CALLBACK(ClicDemarrer), ¶mBoutonDemarrer);
gtk_signal_connect(GTK_OBJECT(pBoutonQuitter), "clicked", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(G_OBJECT(pEBox), "motion-notify-event", G_CALLBACK(ChargementImage), ¶mEBox);
gtk_widget_set_events (pEBox, GDK_POINTER_MOTION_HINT_MASK);
// Affichage de la fenetre
gtk_widget_show_all(pFenetre);
// Lancement de la boucle évènementielle
gtk_main();
return 0;
} |
Partager