]> git.cworth.org Git - scherzo/blob - scherzo.c
Initial commit of scherzo.
[scherzo] / scherzo.c
1 /* scherzo - Music notation training
2  *
3  * Copyright © 2010 Carl Worth
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see http://www.gnu.org/licenses/ .
17  */
18
19 #include <gtk/gtk.h>
20
21 #define unused(foo) foo __attribute__((unused))
22
23 static int
24 on_delete_event_quit (unused (GtkWidget *widget),
25                       unused (GdkEvent *event),
26                       unused (gpointer user_data))
27 {
28     gtk_main_quit ();
29
30     /* Returning FALSE allows the default handler for delete-event
31      * to proceed to cleanup the widget. */
32     return FALSE;
33 }
34
35 static int
36 on_expose_event_draw (GtkWidget *widget,
37                       unused (GdkEventExpose *event),
38                       unused (gpointer user_data))
39 {
40     cairo_t *cr;
41     GtkAllocation allocation;
42
43     gtk_widget_get_allocation (widget, &allocation);
44
45     cr = gdk_cairo_create (widget->window);
46
47     /* Paint in medium sea green */
48     cairo_set_source_rgb (cr, 60/255.0, 179/255.0, 113/255.0);
49
50     cairo_paint (cr);
51  
52     return TRUE;
53 }
54
55 int
56 main (int argc, char *argv[])
57 {
58     GtkWidget *window;
59     GtkWidget *drawing_area;
60
61     gtk_init (&argc, &argv);
62
63     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
64
65     gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
66
67     g_signal_connect (window, "delete-event",
68                       G_CALLBACK (on_delete_event_quit), NULL);
69
70     drawing_area = gtk_drawing_area_new ();
71
72     gtk_container_add (GTK_CONTAINER (window), drawing_area);
73
74     g_signal_connect (drawing_area, "expose-event",  
75                       G_CALLBACK (on_expose_event_draw), NULL);
76
77     
78     gtk_widget_show_all (window);
79     
80     gtk_main ();
81
82     return 0;
83 }