]> Pileus Git - ~andy/gtk/blob - examples/fixed/fixed.c
Merge libgdk and libgtk
[~andy/gtk] / examples / fixed / fixed.c
1
2 #include <gtk/gtk.h>
3
4 /* I'm going to be lazy and use some global variables to
5  * store the position of the widget within the fixed
6  * container */
7 gint x = 50;
8 gint y = 50;
9
10 /* This callback function moves the button to a new position
11  * in the Fixed container. */
12 static void move_button( GtkWidget *widget,
13                          GtkWidget *fixed )
14 {
15   x = (x + 30) % 300;
16   y = (y + 50) % 300;
17   gtk_fixed_move (GTK_FIXED (fixed), widget, x, y); 
18 }
19
20 int main( int   argc,
21           char *argv[] )
22 {
23   /* GtkWidget is the storage type for widgets */
24   GtkWidget *window;
25   GtkWidget *fixed;
26   GtkWidget *button;
27   gint i;
28
29   /* Initialise GTK */
30   gtk_init (&argc, &argv);
31     
32   /* Create a new window */
33   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
34   gtk_window_set_title (GTK_WINDOW (window), "Fixed Container");
35
36   /* Here we connect the "destroy" event to a signal handler */ 
37   g_signal_connect (G_OBJECT (window), "destroy",
38                     G_CALLBACK (gtk_main_quit), NULL);
39  
40   /* Sets the border width of the window. */
41   gtk_container_set_border_width (GTK_CONTAINER (window), 10);
42
43   /* Create a Fixed Container */
44   fixed = gtk_fixed_new ();
45   gtk_container_add (GTK_CONTAINER (window), fixed);
46   gtk_widget_show (fixed);
47   
48   for (i = 1 ; i <= 3 ; i++) {
49     /* Creates a new button with the label "Press me" */
50     button = gtk_button_new_with_label ("Press me");
51   
52     /* When the button receives the "clicked" signal, it will call the
53      * function move_button() passing it the Fixed Container as its
54      * argument. */
55     g_signal_connect (G_OBJECT (button), "clicked",
56                       G_CALLBACK (move_button), (gpointer) fixed);
57   
58     /* This packs the button into the fixed containers window. */
59     gtk_fixed_put (GTK_FIXED (fixed), button, i*50, i*50);
60   
61     /* The final step is to display this newly created widget. */
62     gtk_widget_show (button);
63   }
64
65   /* Display the window */
66   gtk_widget_show (window);
67     
68   /* Enter the event loop */
69   gtk_main ();
70     
71   return 0;
72 }