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
| #include <stdlib.h>
#include <gtk/gtk.h>
#include <string.h>
//Declaration des fonctions
//Déclaration variable globales
//Fenetre principale
GtkWidget* pFenetre = NULL;
// Variables pour stocker les images
GdkPixbuf* pixbuf1;
int main(int argc, char** argv)
{
// Initialisation de l'environnement gtk
gtk_init(&argc, &argv);
GtkWidget* pBoutonRecommencer = NULL;
GtkWidget* pBouton1=NULL;
GtkWidget* pBouton2=NULL;
GtkWidget* pBouton3=NULL;
GtkWidget* pLabel=NULL;
// Creation d'une fenêtre
pFenetre = gtk_window_new(GTK_WINDOW_TOPLEVEL);
//Titre de la fenêtre
gtk_window_set_title(GTK_WINDOW(pFenetre), "Le jeu du trésor ");
// On modifie la taille de la fenetre
gtk_window_set_default_size(GTK_WINDOW (pFenetre), 200, 150);
// On interdit de modifier la taille
gtk_window_set_resizable (GTK_WINDOW (pFenetre), TRUE);
//On centre toujours la fenetre
gtk_window_set_position(GTK_WINDOW(pFenetre),GTK_WIN_POS_CENTER_ALWAYS);
pLabel = gtk_label_new ("Choisissez un coffre !");
// Declaration des boites
GtkWidget* pVbox=NULL;
GtkWidget* pHbox=NULL;
GtkWidget* p_main_box = NULL;
// Chargement des images
GdkPixbuf * pb = gdk_pixbuf_new_from_file("coffreFerme.jpeg", NULL);
if (pb==NULL) printf("Erreur en chargeant l'image coffreFerme.jpeg\n");
pixbuf1 = gdk_pixbuf_scale_simple(pb, 100, 100, GDK_INTERP_NEAREST);
// Creation des quatre boutons
pBoutonRecommencer = gtk_button_new_with_label("Recommencer");
pBouton1 = gtk_button_new();
pBouton2 = gtk_button_new();
pBouton3 = gtk_button_new();
// Afiichage des images
gtk_button_set_image(GTK_BUTTON(pBouton1), gtk_image_new_from_pixbuf(pixbuf1));
gtk_button_set_image(GTK_BUTTON(pBouton2), gtk_image_new_from_pixbuf(pixbuf1));
gtk_button_set_image(GTK_BUTTON(pBouton3), gtk_image_new_from_pixbuf(pixbuf1));
// Création des boites
pVbox = gtk_vbox_new (FALSE, 1);
pHbox = gtk_hbox_new (TRUE, 10);
p_main_box = gtk_vbox_new (FALSE, 20);
//Ajoutons les quatre boutons et du label dans les boites
gtk_box_pack_start (GTK_BOX(pVbox), pLabel, FALSE, TRUE, 0);
gtk_box_pack_start (GTK_BOX(pVbox), pBoutonRecommencer, FALSE, TRUE, 0);
gtk_box_pack_end (GTK_BOX(pHbox), pBouton1, TRUE, TRUE, 10);
gtk_box_pack_end (GTK_BOX(pHbox), pBouton2, TRUE, TRUE, 10);
gtk_box_pack_end (GTK_BOX(pHbox), pBouton3, TRUE, TRUE, 10);
// Ajoutons les deux boites dans la boite principale et celle ci dans la fenetre
gtk_container_add (GTK_CONTAINER(p_main_box), pVbox);
gtk_container_add (GTK_CONTAINER(p_main_box), pHbox);
gtk_container_add (GTK_CONTAINER(pFenetre), p_main_box);
// Affichage de la fenêtre
gtk_widget_show_all(pFenetre);
// Fonction qui capte le signal de la petite croix pour fermer la fenetre
gtk_signal_connect(GTK_OBJECT(pFenetre), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_main();
return EXIT_SUCCESS;
} |
Partager