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
| gboolean ChargementImage(GtkWidget *widget, GdkEventMotion *event, gpointer data)
{
gint x1, y1;
gint x2, y2;
int coord[MAX_LIGNE][MAX_COLONNE];
//Création du nom de l'image
int i;
char nom_image[10];
//Mise à jour du label et de l'image
ParamEBox* paramEBox;
//On charge dans paramEBox les paramètres passés en argument
paramEBox = (ParamEBox*)data;
/* Position dans la fenêtre */
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;
}
/*RECUPERATION DES COORDONNEES ICI*/
coord[0][0]=x1;
coord[0][1]=y1;
coord[0][2]=x2;
coord[0][3]=y2;
printf("%d \t%d\n %d\t %d\n",coord[0][0],coord[0][1],coord[0][2],coord[0][3]);
/** Mise à jour du label **/
gtk_label_set_label(GTK_LABEL(paramEBox->Label), "Il reste 4 secondes.");
/** 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);
return TRUE;
}
/***********************************************************************************************/
// Callback Quitter
void quit(GtkWidget* pBouton, gpointer pNull)
{
gtk_main_quit();
}
// 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;
// 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 'Demarrer' pour commencer le test.");
pLabelEtat2 = gtk_label_new("Il reste 5 secondes.");
pBoutonDemarrer = gtk_button_new_with_mnemonic("_Demarrer");
pBoutonQuitter = gtk_button_new_with_mnemonic("_Quitter");
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_container_add(GTK_CONTAINER(pEBox), pImage);
gtk_image_set_from_file(GTK_IMAGE (pImage), "2.png");
//Mise à jour de la structure
paramEBox.Label = pLabelEtat2;
paramEBox.Image = pImage;
// 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(quit), NULL);
// Connexion des signaux
gtk_signal_connect(GTK_OBJECT(pBoutonDemarrer), "clicked", G_CALLBACK(CommencerTest), pLabelEtat1);
gtk_signal_connect(GTK_OBJECT(pBoutonQuitter), "clicked", G_CALLBACK(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